PHP Class StringScanner, HamlPHP

Inheritance: implements ArrayAccess
Mostra file Open project: hamlphp/hamlphp Class Usage Examples

Protected Properties

Property Type Description
$magic_get_methods

Public Methods

Method 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.

Protected Methods

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

Private Methods

Method 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 method

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 method

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 method

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

concat() public method

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

exist() public method

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

getMatched() public method

Returns the last matched string.
public getMatched ( ) : string
return string

getMatchedSize() public method

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

getPos() public method

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
return integer

getPostMatch() public method

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

getPreMatch() public method

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

getRest() public method

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

getScanned() public method

Returns the last matched string.
public getScanned ( ) : string
return string

getString() public method

Returns the string being scanned.
public getString ( ) : string
return string

getch() public method

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

inspect() public method

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 method

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

isEos() protected method

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

match() public method

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

matched() public method

Returns true if the last match was successful.
public matched ( ) : boolean
return boolean

offsetExists() public method

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

offsetGet() public method

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

offsetSet() public method

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

offsetUnset() public method

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

peek() public method

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

reset() public method

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

restSize() public method

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

scan() public method

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

scanFull() public method

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

scanUntil() public method

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
return string The matched string

searchFull() public method

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

setPointer() public method

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

setPos() public method

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

setString() public method

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

skip() public method

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
return integer The new position

skipUntil() public method

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
return string The new pointer position

terminate() public method

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

unscan() public method

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