PHP Класс StringScanner, HamlPHP

Наследование: implements ArrayAccess
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$magic_get_methods

Открытые методы

Метод Описание
__construct ( string $str, string $encoding = null ) Creates a new StringScanner object to scan over the given $string.
check ( string $pattern ) This returns the value that scan would return, without advancing the scan pointer. The match register is affected, though.
checkUntil ( string $pattern ) : string This returns the value that {@link scanUntil()} would return, without advancing the scan @mlink{$pointer}.
concat ( $str ) Appends $str to the @mlink{$string} being scanned.
exist ( string $pattern ) Looks ahead to see if the $pattern exists anywhere in the @mlink{$string}, without advancing the scan @mlink{$pointer}.
getMatched ( ) : string Returns the last matched string.
getMatchedSize ( ) : integer Returns the size of the most recent match (see matched), or null if there was no recent match.
getPos ( ) : integer Returns the character position of the scan @mlink{$pointer}. In the '{@link reset() reset}' position, this value is zero. In the '{@link terminate() terminated}' position (i.e. the string is exhausted), this value is the size of the @mlink{$string}.
getPostMatch ( ) : string Return the post-match (in the regular expression sense) of the last scan.
getPreMatch ( ) : string Return the pre-match (in the regular expression sense) of the last scan.
getRest ( ) : string Returns the "rest" of the string (i.e. everything after the scan pointer).
getScanned ( ) : string Returns the last matched string.
getString ( ) : string Returns the string being scanned.
getch ( ) Scans one character and returns it. This method is multibyte character sensitive.
inspect ( ) Returns a string that represents the StringScanner object, showing: - the current position - the size of the string - the characters surrounding the scan pointer
isBeginningOfLine ( ) : boolean Returns true if the scan @mlink{$pointer} is at the beginning of the line.
match ( string $pattern ) : integer Tests whether the given $pattern is matched from the current scan @mlink{$pointer}.
matched ( ) : boolean Returns true if the last match was successful.
offsetExists ( integer $offset ) Wether the n-th group was caught or not in the last match.
offsetGet ( integer $offset ) Implements ArrayAccess Return the n-th subgroup in the most recent match.
offsetSet ( $offset, $value ) Calling this method will throw an exception.
offsetUnset ( $offset ) Calling this method will throw an exception.
peek ( $len ) : string Extracts a string corresponding to mb_substr(@mlink{$rest}, 0, $len), without advancing the scan pointer.
reset ( ) Reset the scan pointer (index 0) and clear matching data.
restSize ( ) $s->restSize() is equivalent to mb_strlen($s->rest)
scan ( string $pattern ) Tries to match with $pattern at the current position. If there's a match, the scanner advances the scan @mlink{$pointer} and returns the matched string.
scanFull ( string $pattern, boolean $advance_pointer, boolean $return_string ) : mixed Tests whether the given +pattern+ is matched from the current scan pointer.
scanUntil ( string $pattern ) : string Scans the string _until_ the +pattern+ is matched. Returns the substring up to and including the end of the match, advancing the scan pointer to that location. If there is no match, +null+ is returned.
searchFull ( string $pattern, boolean $advance_pointer, boolean $return_string ) : mixed Scans the string _until_ the $pattern is matched.
setPointer ( integer $i ) : integer Set the byte position of the scan pointer.
setPos ( integer $i ) : integer Same as {@link setPointer()} Set the byte position of the scan pointer.
setString ( string $str ) : string Changes the string being scanned to +str+ and resets the scanner.
skip ( string $pattern ) : integer Attempts to skip over the given +pattern+ beginning with the scan pointer.
skipUntil ( string $pattern ) : string Advances the scan pointer until +pattern+ is matched and consumed. Returns the number of bytes advanced, or +null+ if no match was found.
terminate ( ) Set the scan pointer to the end of the string and clear matching data.
unscan ( ) Set the scan pointer to the previous position. Only one previous position is remembered, and it changes with each scanning operation.

Защищенные методы

Метод Описание
isEos ( ) : boolean Returns true if the scan @mlink{$pointer} is at the end of the string.

Приватные методы

Метод Описание
_clear_matched ( )
_matched ( boolean $update_curr, MATCH_MODE $matchMode )
_string_updated ( $keep_pointer )
doScan ( string $regex, boolean $update_ptr, boolean $get_str, boolean $head_only ) : mixed

Описание методов

__construct() публичный Метод

Creates a new StringScanner object to scan over the given $string.
public __construct ( string $str, string $encoding = null )
$str string The string to be scanned
$encoding string The encoding of the string

check() публичный Метод

This returns the value that scan would return, without advancing the scan pointer. The match register is affected, though.
public check ( string $pattern )
$pattern string

checkUntil() публичный Метод

The match register is affected, though.
public checkUntil ( string $pattern ) : string
$pattern string
Результат string

concat() публичный Метод

This method does not affect scan @mlink{$pointer}.
public concat ( $str )
$str

exist() публичный Метод

This predicts whether a {@link scanUntil()} will return a value.
public exist ( string $pattern )
$pattern string

getMatched() публичный Метод

Returns the last matched string.
public getMatched ( ) : string
Результат string

getMatchedSize() публичный Метод

Returns the size of the most recent match (see matched), or null if there was no recent match.
public getMatchedSize ( ) : integer
Результат integer

getPos() публичный Метод

Returns the character position of the scan @mlink{$pointer}. In the '{@link reset() reset}' position, this value is zero. In the '{@link terminate() terminated}' position (i.e. the string is exhausted), this value is the size of the @mlink{$string}.
public getPos ( ) : integer
Результат integer

getPostMatch() публичный Метод

Return the post-match (in the regular expression sense) of the last scan.
public getPostMatch ( ) : string
Результат string

getPreMatch() публичный Метод

Return the pre-match (in the regular expression sense) of the last scan.
public getPreMatch ( ) : string
Результат string

getRest() публичный Метод

If there is no more data (eos? = true), it returns "".
public getRest ( ) : string
Результат string

getScanned() публичный Метод

Returns the last matched string.
public getScanned ( ) : string
Результат string

getString() публичный Метод

Returns the string being scanned.
public getString ( ) : string
Результат string

getch() публичный Метод

Scans one character and returns it. This method is multibyte character sensitive.
public getch ( )

inspect() публичный Метод

Returns a string that represents the StringScanner object, showing: - the current position - the size of the string - the characters surrounding the scan pointer
public inspect ( )

isBeginningOfLine() публичный Метод

Returns true if the scan @mlink{$pointer} is at the beginning of the line.
public isBeginningOfLine ( ) : boolean
Результат boolean

isEos() защищенный Метод

Returns true if the scan @mlink{$pointer} is at the end of the string.
protected isEos ( ) : boolean
Результат boolean

match() публичный Метод

Returns the length of the match, or
null
. The scan @mlink{$pointer} is not advanced.
public match ( string $pattern ) : integer
$pattern string
Результат integer

matched() публичный Метод

Returns true if the last match was successful.
public matched ( ) : boolean
Результат boolean

offsetExists() публичный Метод

0 stands for the whole match. This method is executed when using isset() or empty().
public offsetExists ( integer $offset )
$offset integer

offsetGet() публичный Метод

Implements ArrayAccess Return the n-th subgroup in the most recent match.
public offsetGet ( integer $offset )
$offset integer

offsetSet() публичный Метод

You can't set the value of the last match.
public offsetSet ( $offset, $value )

offsetUnset() публичный Метод

You can't unset the value of the last match.
public offsetUnset ( $offset )

peek() публичный Метод

Extracts a string corresponding to mb_substr(@mlink{$rest}, 0, $len), without advancing the scan pointer.
public peek ( $len ) : string
$len
Результат string

reset() публичный Метод

Reset the scan pointer (index 0) and clear matching data.
public reset ( )

restSize() публичный Метод

$s->restSize() is equivalent to mb_strlen($s->rest)
public restSize ( )

scan() публичный Метод

Otherwise, the scanner returns
null
.
public scan ( string $pattern )
$pattern string

scanFull() публичный Метод

Advances the scan pointer if +advance_pointer_p+ is true. Returns the matched string if +return_string_p+ is true. The match register is affected. "full" means "#scan with full parameters".
public scanFull ( string $pattern, boolean $advance_pointer, boolean $return_string ) : mixed
$pattern string The regular expression
$advance_pointer boolean Wheter to update the pointer or not
$return_string boolean Wheter to return the matched string or the position
Результат mixed Either the matched string (if $return_string is true) or the end position of the match

scanUntil() публичный Метод

Scans the string _until_ the +pattern+ is matched. Returns the substring up to and including the end of the match, advancing the scan pointer to that location. If there is no match, +null+ is returned.
public scanUntil ( string $pattern ) : string
$pattern string
Результат string The matched string

searchFull() публичный Метод

Advances the scan pointer if $advance_pointer, otherwise not. Returns the matched string if $return_string is true, otherwise returns the number of bytes advanced. This method does affect the match register.
public searchFull ( string $pattern, boolean $advance_pointer, boolean $return_string ) : mixed
$pattern string The regular expression
$advance_pointer boolean Wheter to update the pointer or not
$return_string boolean Wheter to return the matched string or the position
Результат mixed Either the matched string (if $return_string is true) or the end position of the match

setPointer() публичный Метод

Set the byte position of the scan pointer.
public setPointer ( integer $i ) : integer
$i integer
Результат integer The new position

setPos() публичный Метод

Same as {@link setPointer()} Set the byte position of the scan pointer.
public setPos ( integer $i ) : integer
$i integer
Результат integer The new position

setString() публичный Метод

Changes the string being scanned to +str+ and resets the scanner.
public setString ( string $str ) : string
$str string
Результат string $str

skip() публичный Метод

If it matches, the scan pointer is advanced to the end of the match, and the length of the match is returned. Otherwise, +null+ is returned. It's similar to #scan, but without returning the matched string.
public skip ( string $pattern ) : integer
$pattern string
Результат integer The new position

skipUntil() публичный Метод

Look ahead to match +pattern+, and advance the scan pointer to the _end_ of the match. Return the number of characters advanced, or +null+ if the match was unsuccessful. It's similar to #scanUntil, but without returning the intervening string.
public skipUntil ( string $pattern ) : string
$pattern string
Результат string The new pointer position

terminate() публичный Метод

Set the scan pointer to the end of the string and clear matching data.
public terminate ( )

unscan() публичный Метод

Set the scan pointer to the previous position. Only one previous position is remembered, and it changes with each scanning operation.
public unscan ( )

Описание свойств

$magic_get_methods защищенное свойство

protected $magic_get_methods