Skip to content

Commit

Permalink
Lower mbstring dep, remove it for Yaml and CssSelector components
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed May 12, 2014
1 parent 0d2ab42 commit 2ff53e8
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions Parser/Tokenizer/TokenizerEscaping.php
Expand Up @@ -65,14 +65,18 @@ public function escapeUnicodeAndNewLine($value)
*/
private function replaceUnicodeSequences($value)
{
return preg_replace_callback($this->patterns->getUnicodeEscapePattern(), function (array $match) {
$code = $match[1];
return preg_replace_callback($this->patterns->getUnicodeEscapePattern(), function ($match) {
$c = hexdec($match[1]);

if (bin2hex($code) > 0xFFFD) {
$code = '\\FFFD';
if (0x80 > $c %= 0x200000) {
return chr($c);
}
if (0x800 > $c) {
return chr(0xC0 | $c>>6).chr(0x80 | $c & 0x3F);
}
if (0x10000 > $c) {
return chr(0xE0 | $c>>12).chr(0x80 | $c>>6 & 0x3F).chr(0x80 | $c & 0x3F);
}

return mb_convert_encoding(pack('H*', $code), 'UTF-8', 'UCS-2BE');
}, $value);
}
}

0 comments on commit 2ff53e8

Please sign in to comment.