PHP Class StringScanner, HamlPHP

Inheritance: implements ArrayAccess
Afficher le fichier Open project: hamlphp/hamlphp Class Usage Examples

Protected Properties

Свойство Type Description
$magic_get_methods

Méthodes publiques

Méthode Description
__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.

Méthodes protégées

Méthode Description
isEos ( ) : boolean Returns true if the scan @mlink{$pointer} is at the end of the string.

Private Methods

Méthode Description
_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

Method Details

__construct() public méthode

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() public méthode

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() public méthode

The match register is affected, though.
public checkUntil ( string $pattern ) : string
$pattern string
Résultat string

concat() public méthode

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

exist() public méthode

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

getMatched() public méthode

Returns the last matched string.
public getMatched ( ) : string
Résultat string

getMatchedSize() public méthode

Returns the size of the most recent match (see matched), or null if there was no recent match.
public getMatchedSize ( ) : integer
Résultat integer

getPos() public méthode

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
Résultat integer

getPostMatch() public méthode

Return the post-match (in the regular expression sense) of the last scan.
public getPostMatch ( ) : string
Résultat string

getPreMatch() public méthode

Return the pre-match (in the regular expression sense) of the last scan.
public getPreMatch ( ) : string
Résultat string

getRest() public méthode

If there is no more data (eos? = true), it returns "".
public getRest ( ) : string
Résultat string

getScanned() public méthode

Returns the last matched string.
public getScanned ( ) : string
Résultat string

getString() public méthode

Returns the string being scanned.
public getString ( ) : string
Résultat string

getch() public méthode

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

inspect() public méthode

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() public méthode

Returns true if the scan @mlink{$pointer} is at the beginning of the line.
public isBeginningOfLine ( ) : boolean
Résultat boolean

isEos() protected méthode

Returns true if the scan @mlink{$pointer} is at the end of the string.
protected isEos ( ) : boolean
Résultat boolean

match() public méthode

Returns the length of the match, or
null
. The scan @mlink{$pointer} is not advanced.
public match ( string $pattern ) : integer
$pattern string
Résultat integer

matched() public méthode

Returns true if the last match was successful.
public matched ( ) : boolean
Résultat boolean

offsetExists() public méthode

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

offsetGet() public méthode

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

offsetSet() public méthode

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

offsetUnset() public méthode

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

peek() public méthode

Extracts a string corresponding to mb_substr(@mlink{$rest}, 0, $len), without advancing the scan pointer.
public peek ( $len ) : string
$len
Résultat string

reset() public méthode

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

restSize() public méthode

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

scan() public méthode

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

scanFull() public méthode

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
Résultat mixed Either the matched string (if $return_string is true) or the end position of the match

scanUntil() public méthode

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
Résultat string The matched string

searchFull() public méthode

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
Résultat mixed Either the matched string (if $return_string is true) or the end position of the match

setPointer() public méthode

Set the byte position of the scan pointer.
public setPointer ( integer $i ) : integer
$i integer
Résultat integer The new position

setPos() public méthode

Same as {@link setPointer()} Set the byte position of the scan pointer.
public setPos ( integer $i ) : integer
$i integer
Résultat integer The new position

setString() public méthode

Changes the string being scanned to +str+ and resets the scanner.
public setString ( string $str ) : string
$str string
Résultat string $str

skip() public méthode

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
Résultat integer The new position

skipUntil() public méthode

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
Résultat string The new pointer position

terminate() public méthode

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

unscan() public méthode

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

Property Details

$magic_get_methods protected_oe property

protected $magic_get_methods