← All changes
|
vendor/masterminds/html5/src/HTML5/Parser/UTF8Utils.php
+23
-23
3.0.13
→
3.2.90
View file →
| @@ -43,18 +43,18 @@ | ||
| 43 | 43 | */ |
| 44 | 44 | public static function countChars($string) |
| 45 | 45 | { |
| 46 | 46 | // Get the length for the string we need. |
| 47 | - if (\function_exists('mb_strlen')) { | |
| 48 | - return \mb_strlen($string, 'utf-8'); | |
| 47 | + if (function_exists('mb_strlen')) { | |
| 48 | + return mb_strlen($string, 'utf-8'); | |
| 49 | 49 | } |
| 50 | - if (\function_exists('iconv_strlen')) { | |
| 51 | - return \iconv_strlen($string, 'utf-8'); | |
| 50 | + if (function_exists('iconv_strlen')) { | |
| 51 | + return iconv_strlen($string, 'utf-8'); | |
| 52 | 52 | } |
| 53 | - $count = \count_chars($string); | |
| 53 | + $count = count_chars($string); | |
| 54 | 54 | // 0x80 = 0x7F - 0 + 1 (one added to get inclusive range) |
| 55 | 55 | // 0x33 = 0xF4 - 0x2C + 1 (one added to get inclusive range) |
| 56 | - return \array_sum(\array_slice($count, 0, 0x80)) + \array_sum(\array_slice($count, 0xc2, 0x33)); | |
| 56 | + return array_sum(array_slice($count, 0, 0x80)) + array_sum(array_slice($count, 0xc2, 0x33)); | |
| 57 | 57 | } |
| 58 | 58 | /** |
| 59 | 59 | * Convert data from the given encoding to UTF-8. |
| 60 | 60 | * |
| @@ -79,9 +79,9 @@ | ||
| 79 | 79 | // mb_convert_encoding is chosen over iconv because of a bug. The best |
| 80 | 80 | // details for the bug are on http://us1.php.net/manual/en/function.iconv.php#108643 |
| 81 | 81 | // which contains links to the actual but reports as well as work around |
| 82 | 82 | // details. |
| 83 | - if (\function_exists('mb_convert_encoding')) { | |
| 83 | + if (function_exists('mb_convert_encoding')) { | |
| 84 | 84 | // mb library has the following behaviors: |
| 85 | 85 | // - UTF-16 surrogates result in false. |
| 86 | 86 | // - Overlongs and outside Plane 16 result in empty strings. |
| 87 | 87 | // Before we run mb_convert_encoding we need to tell it what to do with |
| @@ -88,19 +88,19 @@ | ||
| 88 | 88 | // characters it does not know. This could be different than the parent |
| 89 | 89 | // application executing this library so we store the value, change it |
| 90 | 90 | // to our needs, and then change it back when we are done. This feels |
| 91 | 91 | // a little excessive and it would be great if there was a better way. |
| 92 | - $save = \mb_substitute_character(); | |
| 93 | - \mb_substitute_character('none'); | |
| 94 | - $data = \mb_convert_encoding($data, 'UTF-8', $encoding); | |
| 95 | - \mb_substitute_character($save); | |
| 96 | - } elseif (\function_exists('iconv') && 'auto' !== $encoding) { | |
| 92 | + $save = mb_substitute_character(); | |
| 93 | + mb_substitute_character('none'); | |
| 94 | + $data = mb_convert_encoding($data, 'UTF-8', $encoding); | |
| 95 | + mb_substitute_character($save); | |
| 96 | + } elseif (function_exists('iconv') && 'auto' !== $encoding) { | |
| 97 | 97 | // fprintf(STDOUT, "iconv found\n"); |
| 98 | 98 | // iconv has the following behaviors: |
| 99 | 99 | // - Overlong representations are ignored. |
| 100 | 100 | // - Beyond Plane 16 is replaced with a lower char. |
| 101 | 101 | // - Incomplete sequences generate a warning. |
| 102 | - $data = @\iconv($encoding, 'UTF-8//IGNORE', $data); | |
| 102 | + $data = @iconv($encoding, 'UTF-8//IGNORE', $data); | |
| 103 | 103 | } else { |
| 104 | 104 | throw new Exception('Not implemented, please install mbstring or iconv'); |
| 105 | 105 | } |
| 106 | 106 | /* |
| @@ -105,10 +105,10 @@ | ||
| 105 | 105 | } |
| 106 | 106 | /* |
| 107 | 107 | * One leading U+FEFF BYTE ORDER MARK character must be ignored if any are present. |
| 108 | 108 | */ |
| 109 | - if ("" === \substr($data, 0, 3)) { | |
| 110 | - $data = \substr($data, 3); | |
| 109 | + if ("" === substr($data, 0, 3)) { | |
| 110 | + $data = substr($data, 3); | |
| 111 | 111 | } |
| 112 | 112 | return $data; |
| 113 | 113 | } |
| 114 | 114 | /** |
| @@ -125,9 +125,9 @@ | ||
| 125 | 125 | /* |
| 126 | 126 | * All U+0000 null characters in the input must be replaced by U+FFFD REPLACEMENT CHARACTERs. |
| 127 | 127 | * Any occurrences of such characters is a parse error. |
| 128 | 128 | */ |
| 129 | - for ($i = 0, $count = \substr_count($data, "\x00"); $i < $count; ++$i) { | |
| 129 | + for ($i = 0, $count = substr_count($data, "\x00"); $i < $count; ++$i) { | |
| 130 | 130 | $errors[] = 'null-character'; |
| 131 | 131 | } |
| 132 | 132 | /* |
| 133 | 133 | * Any occurrences of any characters in the ranges U+0001 to U+0008, U+000B, U+000E to U+001F, U+007F |
| @@ -137,20 +137,20 @@ | ||
| 137 | 137 | * U+DFFFE, U+DFFFF, U+EFFFE, U+EFFFF, U+FFFFE, U+FFFFF, U+10FFFE, and U+10FFFF are parse errors. |
| 138 | 138 | * (These are all control characters or permanently undefined Unicode characters.) |
| 139 | 139 | */ |
| 140 | 140 | // Check PCRE is loaded. |
| 141 | - $count = \preg_match_all('/(?: | |
| 142 | - [\\x01-\\x08\\x0B\\x0E-\\x1F\\x7F] # U+0001 to U+0008, U+000B, U+000E to U+001F and U+007F | |
| 141 | + $count = preg_match_all('/(?: | |
| 142 | + [\x01-\x08\x0B\x0E-\x1F\x7F] # U+0001 to U+0008, U+000B, U+000E to U+001F and U+007F | |
| 143 | 143 | | |
| 144 | - \\xC2[\\x80-\\x9F] # U+0080 to U+009F | |
| 144 | + \xC2[\x80-\x9F] # U+0080 to U+009F | |
| 145 | 145 | | |
| 146 | - \\xED(?:\\xA0[\\x80-\\xFF]|[\\xA1-\\xBE][\\x00-\\xFF]|\\xBF[\\x00-\\xBF]) # U+D800 to U+DFFFF | |
| 146 | + \xED(?:\xA0[\x80-\xFF]|[\xA1-\xBE][\x00-\xFF]|\xBF[\x00-\xBF]) # U+D800 to U+DFFFF | |
| 147 | 147 | | |
| 148 | - \\xEF\\xB7[\\x90-\\xAF] # U+FDD0 to U+FDEF | |
| 148 | + \xEF\xB7[\x90-\xAF] # U+FDD0 to U+FDEF | |
| 149 | 149 | | |
| 150 | - \\xEF\\xBF[\\xBE\\xBF] # U+FFFE and U+FFFF | |
| 150 | + \xEF\xBF[\xBE\xBF] # U+FFFE and U+FFFF | |
| 151 | 151 | | |
| 152 | - [\\xF0-\\xF4][\\x8F-\\xBF]\\xBF[\\xBE\\xBF] # U+nFFFE and U+nFFFF (1 <= n <= 10_{16}) | |
| 152 | + [\xF0-\xF4][\x8F-\xBF]\xBF[\xBE\xBF] # U+nFFFE and U+nFFFF (1 <= n <= 10_{16}) | |
| 153 | 153 | )/x', $data, $matches); |
| 154 | 154 | for ($i = 0; $i < $count; ++$i) { |
| 155 | 155 | $errors[] = 'invalid-codepoint'; |
| 156 | 156 | } |