10 #[\AllowDynamicProperties] 15 $this->
string = $string;
20 list($opener, $closer) = str_split($brackets, 1);
22 if (
strpos($string->raw, $opener, $this->offset) ===
false) {
27 if (substr_count($string->raw, $opener) !== substr_count($string->raw, $closer)) {
28 $sample =
substr($string->raw, $this->offset, 25);
29 warning(
"Unmatched token near '$sample'.");
34 $patt = ($opener ===
'{') ? Regex::$patt->block : Regex::$patt->parens;
36 if (
preg_match($patt, $string->raw, $m, PREG_OFFSET_CAPTURE, $this->offset)) {
39 $this->matchLength =
strlen($m[0][0]);
40 $this->matchStart = $m[0][1];
41 $this->matchEnd = $this->matchStart + $this->matchLength;
45 warning(
"Could not match '$opener'. Exiting.");
51 return $this->match[2][0];
56 return substr($this->string->raw, $this->offset, $this->length);
61 $this->
string->splice($replacement, $this->offset, $this->length);
66 $this->
string->splice($this->inside(), $this->offset, $this->length);
Balanced bracket matching on string objects.
__construct(StringObject $string, $offset, $brackets= '{}')