mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-26 20:32:18 +00:00
[PHP] Use mb_detect_encoding when available (#3952)
I've faced an issue where I want to serialize UTF-8 emojis and FlatBufferBuilder::is_utf8 would return false on them. I was not able to add the corresponding hexadecimal code because I don't understand how the whole thing works but what i've done is using the `mb_detect_encoding` function which handles correctly all supposed UTF-8 characters.
This commit is contained in:
committed by
Wouter van Oortmerssen
parent
c05803bf96
commit
dbecdf209d
@@ -593,6 +593,10 @@ class FlatbufferBuilder
|
|||||||
|
|
||||||
protected function is_utf8($bytes)
|
protected function is_utf8($bytes)
|
||||||
{
|
{
|
||||||
|
if (function_exists('mb_detect_encoding')) {
|
||||||
|
return (bool) mb_detect_encoding($bytes, 'UTF-8', true);
|
||||||
|
}
|
||||||
|
|
||||||
$len = strlen($bytes);
|
$len = strlen($bytes);
|
||||||
if ($len < 1) {
|
if ($len < 1) {
|
||||||
/* NOTE: always return 1 when passed string is null */
|
/* NOTE: always return 1 when passed string is null */
|
||||||
|
|||||||
Reference in New Issue
Block a user