From 04fde93f07af13fdf5ddf5d5d539467135221d2a Mon Sep 17 00:00:00 2001 From: Matt Butcher Date: Wed, 10 Apr 2013 10:38:26 -0500 Subject: Use UTF8Utils. --- src/HTML5/Parser/StringInputStream.php | 30 +----------------------------- 1 file changed, 1 insertion(+), 29 deletions(-) (limited to 'src/HTML5/Parser/StringInputStream.php') diff --git a/src/HTML5/Parser/StringInputStream.php b/src/HTML5/Parser/StringInputStream.php index 3d6b96e..4ceae44 100644 --- a/src/HTML5/Parser/StringInputStream.php +++ b/src/HTML5/Parser/StringInputStream.php @@ -258,35 +258,7 @@ class StringInputStream implements InputStream { $findLengthOf = substr($this->data, 0, $this->char); } - return self::countChars($findLengthOf); - } - - /** - * Count the number of characters in a string. - * - * UTF-8 aware. This will try (in order) iconv, - * MB, libxml, and finally a custom counter. - * - * @todo Move this to a general utility class. - */ - public static function countChars($string) { - // Get the length for the string we need. - if(function_exists('iconv_strlen')) { - return iconv_strlen($string, 'utf-8'); - } - elseif(function_exists('mb_strlen')) { - return mb_strlen($string, 'utf-8'); - } - elseif(function_exists('utf8_decod')) { - // MPB: Will this work? Won't certain decodes lead to two chars - // extrapolated out of 2-byte chars? - return strlen(utf8_decode($string)); - } - $count = count_chars($string); - // 0x80 = 0x7F - 0 + 1 (one added to get inclusive range) - // 0x33 = 0xF4 - 0x2C + 1 (one added to get inclusive range) - return array_sum(array_slice($count, 0, 0x80)) + - array_sum(array_slice($count, 0xC2, 0x33)); + return UTF8Utils::countChars($findLengthOf); } /** -- cgit v1.2.3