diff options
-rw-r--r-- | src/Lexer.php | 9 | ||||
-rw-r--r-- | src/Token.php | 6 | ||||
-rw-r--r-- | src/UtfString.php | 2 |
3 files changed, 5 insertions, 12 deletions
diff --git a/src/Lexer.php b/src/Lexer.php index de44eea..a129dfa 100644 --- a/src/Lexer.php +++ b/src/Lexer.php @@ -42,13 +42,6 @@ namespace SqlParser { define('USE_UTF_STRINGS', true); } - // Set internal character to UTF-8. - // In previous versions of PHP (5.5 and older) the default internal encoding is - // "ISO-8859-1". - if ((defined('USE_UTF_STRINGS')) && (USE_UTF_STRINGS)) { - mb_internal_encoding('UTF-8'); - } - /** * Performs lexical analysis over a SQL statement and splits it in multiple * tokens. @@ -192,7 +185,7 @@ namespace SqlParser { // For multi-byte strings, a new instance of `UtfString` is // initialized (only if `UtfString` usage is forced. if (!($str instanceof UtfString)) { - if ((USE_UTF_STRINGS) && ($len != mb_strlen($str))) { + if ((USE_UTF_STRINGS) && ($len !== mb_strlen($str, 'UTF-8'))) { $str = new UtfString($str); } } diff --git a/src/Token.php b/src/Token.php index 56b46b5..a65b13f 100644 --- a/src/Token.php +++ b/src/Token.php @@ -250,18 +250,18 @@ class Token case Token::TYPE_STRING: $quote = $this->token[0]; $str = str_replace($quote . $quote, $quote, $this->token); - return mb_substr($str, 1, -1); // trims quotes + return mb_substr($str, 1, -1, 'UTF-8'); // trims quotes case Token::TYPE_SYMBOL: $str = $this->token; if ((isset($str[0])) && ($str[0] === '@')) { - $str = mb_substr($str, 1); + $str = mb_substr($str, 1, null, 'UTF-8'); } if ((isset($str[0])) && (($str[0] === '`') || ($str[0] === '"') || ($str[0] === '\'')) ) { $quote = $str[0]; $str = str_replace($quote . $quote, $quote, $str); - $str = mb_substr($str, 1, -1); + $str = mb_substr($str, 1, -1, 'UTF-8'); } return $str; } diff --git a/src/UtfString.php b/src/UtfString.php index 1e863a4..cac93ab 100644 --- a/src/UtfString.php +++ b/src/UtfString.php @@ -81,7 +81,7 @@ class UtfString implements \ArrayAccess // overloading is enabled. // https://php.net/manual/ro/mbstring.overload.php $this->byteLen = strlen($str); - $this->charLen = mb_strlen($str); + $this->charLen = mb_strlen($str, 'UTF-8'); } /** |