diff vendor/masterminds/html5/src/HTML5/Parser/StringInputStream.php @ 4:a9cd425dd02b

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:11:55 +0000
parents c75dbcec494b
children
line wrap: on
line diff
--- a/vendor/masterminds/html5/src/HTML5/Parser/StringInputStream.php	Thu Feb 28 11:14:44 2019 +0000
+++ b/vendor/masterminds/html5/src/HTML5/Parser/StringInputStream.php	Thu Feb 28 13:11:55 2019 +0000
@@ -2,6 +2,7 @@
 /**
  * Loads a string to be parsed.
  */
+
 namespace Masterminds\HTML5\Parser;
 
 /*
@@ -39,16 +40,18 @@
 //
 // - // indicates regular comments
 
+/**
+ * @deprecated since 2.4, to remove in 3.0. Use a string in the scanner instead.
+ */
 class StringInputStream implements InputStream
 {
-
     /**
      * The string data we're parsing.
      */
     private $data;
 
     /**
-     * The current integer byte position we are in $data
+     * The current integer byte position we are in $data.
      */
     private $char;
 
@@ -65,22 +68,21 @@
     /**
      * Create a new InputStream wrapper.
      *
-     * @param $data Data
-     *            to parse
+     * @param string $data     Data to parse.
+     * @param string $encoding The encoding to use for the data.
+     * @param string $debug    A fprintf format to use to echo the data on stdout.
      */
     public function __construct($data, $encoding = 'UTF-8', $debug = '')
     {
         $data = UTF8Utils::convertToUTF8($data, $encoding);
-        if ($debug)
+        if ($debug) {
             fprintf(STDOUT, $debug, $data, strlen($data));
+        }
 
-            // There is good reason to question whether it makes sense to
-            // do this here, since most of these checks are done during
-            // parsing, and since this check doesn't actually *do* anything.
+        // There is good reason to question whether it makes sense to
+        // do this here, since most of these checks are done during
+        // parsing, and since this check doesn't actually *do* anything.
         $this->errors = UTF8Utils::checkForIllegalCodepoints($data);
-        // if (!empty($e)) {
-        // throw new ParseError("UTF-8 encoding issues: " . implode(', ', $e));
-        // }
 
         $data = $this->replaceLinefeeds($data);
 
@@ -89,18 +91,27 @@
         $this->EOF = strlen($data);
     }
 
+    public function __toString()
+    {
+        return $this->data;
+    }
+
     /**
      * Replace linefeed characters according to the spec.
      */
     protected function replaceLinefeeds($data)
     {
         /*
-         * U+000D CARRIAGE RETURN (CR) characters and U+000A LINE FEED (LF) characters are treated specially. Any CR characters that are followed by LF characters must be removed, and any CR characters not followed by LF characters must be converted to LF characters. Thus, newlines in HTML DOMs are represented by LF characters, and there are never any CR characters in the input to the tokenization stage.
+         * U+000D CARRIAGE RETURN (CR) characters and U+000A LINE FEED (LF) characters are treated specially.
+         * Any CR characters that are followed by LF characters must be removed, and any CR characters not
+         * followed by LF characters must be converted to LF characters. Thus, newlines in HTML DOMs are
+         * represented by LF characters, and there are never any CR characters in the input to the tokenization
+         * stage.
          */
         $crlfTable = array(
             "\0" => "\xEF\xBF\xBD",
             "\r\n" => "\n",
-            "\r" => "\n"
+            "\r" => "\n",
         );
 
         return strtr($data, $crlfTable);
@@ -111,7 +122,7 @@
      */
     public function currentLine()
     {
-        if (empty($this->EOF) || $this->char == 0) {
+        if (empty($this->EOF) || 0 === $this->char) {
             return 1;
         }
         // Add one to $this->char because we want the number for the next
@@ -120,18 +131,15 @@
     }
 
     /**
-     *
      * @deprecated
-     *
      */
     public function getCurrentLine()
     {
-        return currentLine();
+        return $this->currentLine();
     }
 
     /**
      * Returns the current column of the current line that the tokenizer is at.
-     *
      * Newlines are column 0. The first char after a newline is column 1.
      *
      * @return int The column number.
@@ -139,7 +147,7 @@
     public function columnOffset()
     {
         // Short circuit for the first char.
-        if ($this->char == 0) {
+        if (0 === $this->char) {
             return 0;
         }
         // strrpos is weird, and the offset needs to be negative for what we
@@ -152,7 +160,7 @@
 
         // However, for here we want the length up until the next byte to be
         // processed, so add one to the current byte ($this->char).
-        if ($lastLine !== false) {
+        if (false !== $lastLine) {
             $findLengthOf = substr($this->data, $lastLine + 1, $this->char - 1 - $lastLine);
         } else {
             // After a newline.
@@ -163,9 +171,7 @@
     }
 
     /**
-     *
      * @deprecated
-     *
      */
     public function getColumnOffset()
     {
@@ -188,7 +194,7 @@
      */
     public function next()
     {
-        $this->char ++;
+        ++$this->char;
     }
 
     /**
@@ -202,15 +208,11 @@
     /**
      * Is the current pointer location valid.
      *
-     * @return bool Is the current pointer location valid.
+     * @return bool Whether the current pointer location is valid.
      */
     public function valid()
     {
-        if ($this->char < $this->EOF) {
-            return true;
-        }
-
-        return false;
+        return $this->char < $this->EOF;
     }
 
     /**
@@ -219,10 +221,10 @@
      * This reads to the end of the file, and sets the read marker at the
      * end of the file.
      *
-     * @note This performs bounds checking
+     * Note this performs bounds checking.
      *
      * @return string Returns the remaining text. If called when the InputStream is
-     *         already exhausted, it returns an empty string.
+     *                already exhausted, it returns an empty string.
      */
     public function remainingChars()
     {
@@ -244,12 +246,11 @@
      * Matches as far as possible until we reach a certain set of bytes
      * and returns the matched substring.
      *
-     * @param string $bytes
-     *            Bytes to match.
-     * @param int $max
-     *            Maximum number of bytes to scan.
+     * @param string $bytes Bytes to match.
+     * @param int    $max   Maximum number of bytes to scan.
+     *
      * @return mixed Index or false if no match is found. You should use strong
-     *         equality when checking the result, since index could be 0.
+     *               equality when checking the result, since index could be 0.
      */
     public function charsUntil($bytes, $max = null)
     {
@@ -257,7 +258,7 @@
             return false;
         }
 
-        if ($max === 0 || $max) {
+        if (0 === $max || $max) {
             $len = strcspn($this->data, $bytes, $this->char, $max);
         } else {
             $len = strcspn($this->data, $bytes, $this->char);
@@ -275,12 +276,12 @@
      * Matches as far as possible with a certain set of bytes
      * and returns the matched substring.
      *
-     * @param string $bytes
-     *            A mask of bytes to match. If ANY byte in this mask matches the
-     *            current char, the pointer advances and the char is part of the
-     *            substring.
-     * @param int $max
-     *            The max number of chars to read.
+     * @param string $bytes A mask of bytes to match. If ANY byte in this mask matches the
+     *                      current char, the pointer advances and the char is part of the
+     *                      substring.
+     * @param int    $max   The max number of chars to read.
+     *
+     * @return string
      */
     public function charsWhile($bytes, $max = null)
     {
@@ -288,7 +289,7 @@
             return false;
         }
 
-        if ($max === 0 || $max) {
+        if (0 === $max || $max) {
             $len = strspn($this->data, $bytes, $this->char, $max);
         } else {
             $len = strspn($this->data, $bytes, $this->char);
@@ -302,13 +303,12 @@
     /**
      * Unconsume characters.
      *
-     * @param int $howMany
-     *            The number of characters to unconsume.
+     * @param int $howMany The number of characters to unconsume.
      */
     public function unconsume($howMany = 1)
     {
         if (($this->char - $howMany) >= 0) {
-            $this->char = $this->char - $howMany;
+            $this->char -= $howMany;
         }
     }