Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,3 @@ parameters:
reportUnmatchedIgnoredErrors: true
excludePaths:
- tools/doctum-config.php
dynamicConstantNames:
- USE_UTF_STRINGS
3 changes: 0 additions & 3 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4841,9 +4841,6 @@
<code>parseOperator</code>
<code>parseSymbol</code>
</PossiblyUnusedMethod>
<RedundantCondition>
<code>USE_UTF_STRINGS</code>
</RedundantCondition>
</file>
<file src="src/Parser.php">
<InvalidPropertyAssignmentValue>
Expand Down
22 changes: 2 additions & 20 deletions src/Lexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,13 @@

use PhpMyAdmin\SqlParser\Exceptions\LexerException;

use function define;
use function defined;
use function in_array;
use function mb_strlen;
use function sprintf;
use function str_ends_with;
use function strlen;
use function substr;

if (! defined('USE_UTF_STRINGS')) {
// NOTE: In previous versions of PHP (5.5 and older) the default
// internal encoding is "ISO-8859-1".
// All `mb_` functions must specify the correct encoding, which is
// 'UTF-8' in order to work properly.

/*
* Forces usage of `UtfString` if the string is multibyte.
* `UtfString` may be slower, but it gives better results.
*
* @var bool
*/
define('USE_UTF_STRINGS', true);
}

/**
* Defines the lexer of the library.
*
Expand Down Expand Up @@ -199,9 +182,8 @@ public function __construct($str, $strict = false, $delimiter = null)
// parse each byte of the input.
$len = $str instanceof UtfString ? $str->length() : strlen($str);

// For multi-byte strings, a new instance of `UtfString` is
// initialized (only if `UtfString` usage is forced.
if (! $str instanceof UtfString && USE_UTF_STRINGS && $len !== mb_strlen($str, 'UTF-8')) {
// For multi-byte strings, a new instance of `UtfString` is initialized.
if (! $str instanceof UtfString && $len !== mb_strlen($str, 'UTF-8')) {
$str = new UtfString($str);
}

Expand Down