function LSM::remove
Removes a sequence
Parameters
string $sequence Sequence to remove:
Return value
$this
File
-
vendor/
mck89/ peast/ lib/ Peast/ Syntax/ LSM.php, line 84
Class
- LSM
- Longest Sequence Matcher. Utility class used by the scanner to consume the longest sequence of character given a set of allowed characters sequences.
Namespace
Peast\SyntaxCode
public function remove($sequence) {
if ($this->handleEncoding) {
$s = Utils::stringToUTF8Array($sequence);
$first = $s[0];
}
else {
$first = $sequence[0];
}
if (isset($this->map[$first])) {
$len = $this->handleEncoding ? count($s) : strlen($sequence);
$this->map[$first]["map"] = array_diff($this->map[$first]["map"], array(
$sequence,
));
if (!count($this->map[$first]["map"])) {
unset($this->map[$first]);
}
elseif ($this->map[$first]["maxLen"] === $len) {
// Recalculate the max length if necessary
foreach ($this->map[$first]["map"] as $m) {
$this->map[$first]["maxLen"] = max($this->map[$first]["maxLen"], strlen($m));
}
}
}
return $this;
}