Skip to content

Commit

Permalink
uses mb_string when iconv is not available
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Feb 28, 2021
1 parent f6d8ff8 commit e4ca6f4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
],
"require": {
"php": ">=7.1",
"ext-iconv": "*",
"ext-json": "*"
},
"require-dev": {
Expand Down
6 changes: 5 additions & 1 deletion src/Neon/Decoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -367,10 +367,14 @@ private function cbString(array $m): string
if ($code >= 0xD800 && $code <= 0xDFFF) {
$this->error("Invalid UTF-8 (lone surrogate) $sq");
}
return iconv('UTF-32BE', 'UTF-8//IGNORE', pack('N', $code));
return function_exists('iconv')
? iconv('UTF-32BE', 'UTF-8//IGNORE', pack('N', $code))
: mb_convert_encoding(pack('N', $code), 'UTF-8', 'UTF-32BE');

} elseif ($sq[1] === 'x' && strlen($sq) === 4) {
trigger_error("Neon: '$sq' is deprecated, use '\\uXXXX' instead.", E_USER_DEPRECATED);
return chr(hexdec(substr($sq, 2)));

} else {
$this->error("Invalid escaping sequence $sq");
}
Expand Down

0 comments on commit e4ca6f4

Please sign in to comment.