Skip to content

Commit 5bf4eb5

Browse files
committed
Don't use Multibyte String functions for parsing query, as it's done manually byte per byte.
1 parent 009d4c4 commit 5bf4eb5

File tree

11 files changed

+26
-29
lines changed

11 files changed

+26
-29
lines changed

.idea/php-test-framework.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.php_cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ return Config::create()
3030
'final_static_access' => true,
3131
'global_namespace_import' => true,
3232
'linebreak_after_opening_tag' => true,
33-
'mb_str_functions' => true,
3433
'native_function_invocation' => false,
3534
'no_unset_on_property' => false,
3635
'php_unit_test_case_static_method_calls' => ['call_type' => 'self'],

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
"require": {
2525
"php": "^7.0",
2626
"ext-json": "*",
27-
"ext-pdo": "*",
28-
"symfony/polyfill-php74": "^1.0"
27+
"ext-pdo": "*"
2928
},
3029
"require-dev": {
3130
"phpunit/phpunit": "^6.0|^7.0",

examples/index.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
<ul id="example-list">
88
<?php
99
foreach (new DirectoryIterator(__DIR__) as $file) {
10-
if ($file->isFile() && '.php' === mb_substr($file->getFilename(), -4) && !in_array($file->getFilename(), ['index.php', 'init.php'], true)) {
11-
echo '<li><a href="'.$file->getFilename().'">'.ucwords(str_replace('_', ' ', mb_substr($file->getFilename(), 0, -4))).'</a></li>';
10+
if ($file->isFile() && '.php' === substr($file->getFilename(), -4) && !in_array($file->getFilename(), ['index.php', 'init.php'], true)) {
11+
echo '<li><a href="'.$file->getFilename().'">'.ucwords(str_replace('_', ' ', substr($file->getFilename(), 0, -4))).'</a></li>';
1212
}
1313
}
1414
?>

lib/MC/Google/Visualization.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public function setDefaultFormat(string $type, string $format)
137137
if (!isset($this->defaultFormat[$type])) {
138138
throw new Visualization_Error('Unknown or unformattable type: "'.$type.'"');
139139
}
140-
if ('boolean' === $type && false === mb_strpos($format, ':')) {
140+
if ('boolean' === $type && false === strpos($format, ':')) {
141141
throw new Visualization_Error('Invalid boolean format string: "'.$format.'"');
142142
}
143143
$this->defaultFormat[$type] = $format;
@@ -535,14 +535,14 @@ public function getRowValues(array $row, array $meta): string
535535
break;
536536

537537
case 'date':
538-
if (!is_numeric($val) || (is_string($val) && (6 !== mb_strlen($val)))) {
538+
if (!is_numeric($val) || (is_string($val) && (6 !== strlen($val)))) {
539539
$time = strtotime($val);
540540
list($year, $month, $day) = explode('-', date('Y-m-d', $time));
541541
$formatted = date($format, $time);
542542
} else {
543543
assert(is_string($val));
544-
$year = mb_substr($val, 0, 4);
545-
$week = mb_substr($val, -2);
544+
$year = substr($val, 0, 4);
545+
$week = substr($val, -2);
546546
$time = strtotime($year.'0104 +'.$week.' weeks');
547547
assert(false !== $time);
548548
$monday = strtotime('-'.((int) date('w', $time) - 1).' days', $time);
@@ -754,7 +754,7 @@ public function parseQuery(string $str): array
754754
$field = $orderby[$i];
755755
$dir = 'asc';
756756
if (isset($orderby[$i + 1])) {
757-
$dir = mb_strtolower($orderby[$i + 1]);
757+
$dir = strtolower($orderby[$i + 1]);
758758
if ('asc' === $dir || 'desc' === $dir) {
759759
++$i;
760760
} else {
@@ -1015,7 +1015,7 @@ protected function generateSQL(array &$meta): string
10151015

10161016
case 'null':
10171017
case 'notnull':
1018-
$wherePart['value'] = mb_strtoupper(implode(' ', $wherePart['value']));
1018+
$wherePart['value'] = strtoupper(implode(' ', $wherePart['value']));
10191019
break;
10201020
}
10211021

@@ -1064,7 +1064,7 @@ protected function generateSQL(array &$meta): string
10641064
$sql .= ',';
10651065
}
10661066

1067-
$sql .= ' '.$this->getFieldSQL($field, $spec).' '.mb_strtoupper($dir);
1067+
$sql .= ' '.$this->getFieldSQL($field, $spec).' '.strtoupper($dir);
10681068
$first = false;
10691069
}
10701070
}
@@ -1248,7 +1248,7 @@ protected function getFieldSQL(string $name, array $spec, bool $alias = false, s
12481248
$q = $this->getFieldQuote();
12491249
if (null !== $func) {
12501250
if (null === $pivot) {
1251-
$sql = mb_strtoupper($func).'('.$sql.')';
1251+
$sql = strtoupper($func).'('.$sql.')';
12521252
if ($alias) {
12531253
$sql .= ' AS '.$q.$func.'-'.$name.$q;
12541254
}
@@ -1260,7 +1260,7 @@ protected function getFieldSQL(string $name, array $spec, bool $alias = false, s
12601260
$pivotField = $pivotFields[$key];
12611261
$casewhen[] = $pivotField['field'].'='.$this->db->quote($val);
12621262
}
1263-
$sql = mb_strtoupper($func).'(CASE WHEN '.implode(' AND ', $casewhen).' THEN '.$sql.' ELSE NULL END)';
1263+
$sql = strtoupper($func).'(CASE WHEN '.implode(' AND ', $casewhen).' THEN '.$sql.' ELSE NULL END)';
12641264
if ($alias) {
12651265
$sql .= ' AS '.$q.implode(',', $pivot).' '.$func.'-'.$name.$q;
12661266
}
@@ -1320,7 +1320,7 @@ protected function parseFieldTokens(Token $token, array &$fields = null)
13201320
if ($token->hasChildren()) {
13211321
if ('function' === $token->name) {
13221322
$field = $token->getValues();
1323-
$field[0] = mb_strtolower($field[0]);
1323+
$field[0] = strtolower($field[0]);
13241324
$fields[] = $field;
13251325
} else {
13261326
foreach ($token->getChildren() as $field) {

lib/MC/Parser.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function word(string $firstChars, string $restChars = null): Word
6161
public function quotedString(string $quoteChars = '\'"', string $escChar = '\\'): Regex
6262
{
6363
$quoteChars = trim($quoteChars);
64-
if (mb_strlen($escChar) > 1) {
64+
if (strlen($escChar) > 1) {
6565
throw new DefError('Only one $escChar can be defined');
6666
}
6767
if ('' !== $escChar) {
@@ -71,8 +71,7 @@ public function quotedString(string $quoteChars = '\'"', string $escChar = '\\')
7171
if ('' === $quoteChars) {
7272
throw new DefError('$quoteChars cannot be an empty string');
7373
}
74-
$quoteCharsArray = mb_str_split($quoteChars);
75-
assert(is_array($quoteCharsArray));
74+
$quoteCharsArray = str_split($quoteChars);
7675

7776
$tpl = '(?:Q(?:[^Q\n\rE]|(?:QQ)|(?:Ex[0-9a-fA-F]+)|(?:E.))*Q)';
7877
$pats = [];
@@ -229,6 +228,6 @@ public function nums(): string
229228
*/
230229
public static function isWhitespace($test): bool
231230
{
232-
return false !== mb_strpos(self::$whitespace, $test);
231+
return false !== strpos(self::$whitespace, $test);
233232
}
234233
}

lib/MC/Parser/Def.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ public function parse(string $str): Token
2828
$str = ltrim($str);
2929

3030
list($loc, $tok) = $this->parsePart($str, 0);
31-
if ($loc !== mb_strlen($str)) {
32-
throw new ParseError('An error occurred: "'.mb_substr($str, $loc).'"', $str, $loc);
31+
if ($loc !== strlen($str)) {
32+
throw new ParseError('An error occurred: "'.substr($str, $loc).'"', $str, $loc);
3333
}
3434

3535
return $tok;

lib/MC/Parser/Def/Literal.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ public function __construct(string $str, bool $caseless = false, bool $fullword
4040
*/
4141
public function _parse(string $str, int $loc): array
4242
{
43-
$match = !$this->caseless ? mb_strpos($str, $this->search, $loc) : mb_stripos($str, $this->search, $loc);
43+
$match = !$this->caseless ? strpos($str, $this->search, $loc) : stripos($str, $this->search, $loc);
4444

4545
if ($match !== $loc) {
4646
throw new ParseError('Expected: '.$this->search, $str, $loc);
4747
}
4848

49-
$loc += mb_strlen($this->search);
49+
$loc += strlen($this->search);
5050

51-
if ($this->fullword && $loc < mb_strlen($str) && !Parser::isWhitespace($str[$loc])) {
51+
if ($this->fullword && $loc < strlen($str) && !Parser::isWhitespace($str[$loc])) {
5252
throw new ParseError('Expected: '.$this->search, $str, $loc);
5353
}
5454

lib/MC/Parser/Def/Regex.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ public function __construct(string $regex = null, string $flags = null, string $
4949
*/
5050
public function _parse(string $str, int $loc): array
5151
{
52-
preg_match(self::DELIMITER.'^'.$this->regex.self::DELIMITER.$this->flags, mb_substr($str, $loc), $matches, PREG_OFFSET_CAPTURE);
52+
preg_match(self::DELIMITER.'^'.$this->regex.self::DELIMITER.$this->flags, substr($str, $loc), $matches, PREG_OFFSET_CAPTURE);
5353
$success = $matches[$this->retgroup] ?? null;
5454
if ((null === $success) || 0 !== $success[1]) {
5555
throw new ParseError('Expected: '.($this->errstr ?: 'matching '.$this->regex), $str, $loc);
5656
}
5757

58-
$loc += mb_strlen($success[0]);
58+
$loc += strlen($success[0]);
5959

6060
return [$loc, $this->token($success[0])];
6161
}

tests/ExampleTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function testQueryComplete()
5151
$vis->setDefaultEntity('timeline');
5252

5353
$parameters = [
54-
'tq' => 'select country, year, birth_control, infant_mort where birth_control!=0 AND infant_mort!=0 group by country, year label country "Country", year "Year", birth_control "Birth Control Penetration", gdp_us "Per-capita GDP (US Dollars)", savings_rate "Savings Rate", investment_rate "Investment Rate", infant_mort "Infant Mortality", life_expect "Life Expectancy" format year "%d"',
54+
'tq' => 'select country, year, birth_control, infant_mort where birth_control!=0 AND infant_mort!=0 group by country, year label country "Country", year "Année", birth_control "Birth Control Penetration", gdp_us "Per-capita GDP (US Dollars)", savings_rate "Savings Rate", investment_rate "Investment Rate", infant_mort "Infant Mortality", life_expect "Life Expectancy" format year "%d"',
5555
'tqx' => 'reqId:1',
5656
];
5757

0 commit comments

Comments
 (0)