X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/mediawiki.git/blobdiff_plain/19e297c21b10b1b8a3acad5e73fc71dcb35db44a..6932310fd58ebef145fa01eb76edf7150284d8ea:/vendor/wikimedia/remex-html/RemexHtml/TreeBuilder/InsertionMode.php diff --git a/vendor/wikimedia/remex-html/RemexHtml/TreeBuilder/InsertionMode.php b/vendor/wikimedia/remex-html/RemexHtml/TreeBuilder/InsertionMode.php new file mode 100644 index 00000000..5d4cd086 --- /dev/null +++ b/vendor/wikimedia/remex-html/RemexHtml/TreeBuilder/InsertionMode.php @@ -0,0 +1,122 @@ +builder = $builder; + $this->dispatcher = $dispatcher; + } + + public function __set( $name, $value ) { + PropGuard::set( $this, $name, $value ); + } + + public function doctype( $name, $public, $system, $quirks, $sourceStart, $sourceLength ) { + $this->builder->error( "unexpected doctype", $sourceStart ); + } + + public function comment( $text, $sourceStart, $sourceLength ) { + $this->builder->comment( null, $text, $sourceStart, $sourceLength ); + } + + public function error( $text, $pos ) { + $this->builder->error( $text, $pos ); + } + + protected function splitInitialMatch( $isStartOfToken, $mask, $text, $start, $length, + $sourceStart, $sourceLength + ) { + $matchLength = strspn( $text, $mask, $start, $length ); + if ( $isStartOfToken && $matchLength ) { + // Do some extra work to figure out a plausible start position if + // the text node started with builder->tokenizer->getPreprocessedText(); + $isCdata = substr_compare( $sourceText, 'builder; + + do { + list( $part1, $part2 ) = $this->splitInitialMatch( + $isStartOfToken, "\t\n\f\r ", $text, $start, $length, $sourceStart, $sourceLength ); + $isStartOfToken = false; + + list( $start, $length, $sourceStart, $sourceLength ) = $part1; + if ( $length ) { + if ( $inBody ) { + $this->dispatcher->inBody->characters( $text, $start, $length, + $sourceStart, $sourceLength ); + } else { + $builder->insertCharacters( $text, $start, $length, $sourceStart, $sourceLength ); + } + } + + list( $start, $length, $sourceStart, $sourceLength ) = $part2; + if ( $length ) { + $builder->error( "unexpected non-whitespace character", $sourceStart ); + $start++; + $length--; + $sourceStart++; + $sourceLength--; + } + } while ( $length > 0 ); + } + + protected function stripNulls( $callback, $text, $start, $length, $sourceStart, $sourceLength ) { + $originalLength = $length; + $errorOffset = $sourceStart - $start; + while ( $length > 0 ) { + $validLength = strcspn( $text, "\0", $start, $length ); + if ( $validLength ) { + $callback( $text, $start, $validLength, $sourceStart, $sourceLength ); + $start += $validLength; + $length -= $validLength; + } + if ( $length <= 0 ) { + break; + } + $this->error( 'unexpected null character', $start + $errorOffset ); + $start++; + $length--; + } + } + + abstract public function characters( $text, $start, $length, $sourceStart, $sourceLength ); + abstract public function startTag( $name, Attributes $attrs, $selfClose, + $sourceStart, $sourceLength ); + abstract public function endTag( $name, $sourceStart, $sourceLength ); + abstract public function endDocument( $pos ); +} +