Skip to content

Commit b48a2ac

Browse files
committed
Use multi-bytes functions
1 parent c5c2a91 commit b48a2ac

File tree

7 files changed

+23
-23
lines changed

7 files changed

+23
-23
lines changed

src/JsPhpize/Compiler/Compiler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ function ($pair) use ($visitNode, $indent) {
167167
protected function visitConstant(Constant $constant)
168168
{
169169
$value = $constant->value;
170-
if ($constant->type === 'string' && substr($constant->value, 0, 1) === '"') {
170+
if ($constant->type === 'string' && mb_substr($constant->value, 0, 1) === '"') {
171171
$value = str_replace('$', '\\$', $value);
172172
}
173173

src/JsPhpize/JsPhpize.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function compile($input, $filename = null)
7272
$php = preg_replace('/\)[\s;]*$/', '', $php);
7373
}
7474

75-
if (substr(ltrim($end), 0, 1) === '{') {
75+
if (mb_substr(ltrim($end), 0, 1) === '{') {
7676
$php = preg_replace('/\s*\{\s*\}\s*$/', '', $php);
7777
}
7878

@@ -185,8 +185,8 @@ public function render($input, $filename = null, array $variables = array())
185185
throw $e;
186186
} catch (\Exception $e) {
187187
$summary = $input;
188-
if (strlen($summary) > 50) {
189-
$summary = substr($summary, 0, 47) . '...';
188+
if (mb_strlen($summary) > 50) {
189+
$summary = mb_substr($summary, 0, 47) . '...';
190190
}
191191

192192
throw new Exception("An error occur in [$summary]:\n" . $e->getMessage(), 2, E_ERROR, __FILE__, __LINE__, $e);

src/JsPhpize/Lexer/Lexer.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ public function exceptionInfos()
6363

6464
protected function consume($consumed)
6565
{
66-
$consumed = is_int($consumed) ? substr($this->input, 0, $consumed) : $consumed;
67-
$this->consumed = strlen(trim($consumed)) > 1 ? $consumed : $this->consumed . $consumed;
68-
$this->line += substr_count($consumed, "\n");
69-
$this->input = substr($this->input, strlen($consumed));
66+
$consumed = is_int($consumed) ? mb_substr($this->input, 0, $consumed) : $consumed;
67+
$this->consumed = mb_strlen(trim($consumed)) > 1 ? $consumed : $this->consumed . $consumed;
68+
$this->line += mb_substr_count($consumed, "\n");
69+
$this->input = mb_substr($this->input, mb_strlen($consumed));
7070
}
7171

7272
protected function token($type, $data = array())
@@ -107,7 +107,7 @@ protected function scan($pattern, $method)
107107
*/
108108
public function next()
109109
{
110-
if (!strlen($this->input)) {
110+
if (!mb_strlen($this->input)) {
111111
return false;
112112
}
113113

@@ -126,6 +126,6 @@ public function next()
126126
}
127127
}
128128

129-
throw new Exception('Unknow pattern found at: ' . substr($this->input, 0, 100), 12);
129+
throw new Exception('Unknow pattern found at: ' . mb_substr($this->input, 0, 100), 12);
130130
}
131131
}

src/JsPhpize/Lexer/Scanner.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function scanConstant($matches)
2020
{
2121
$constant = trim($matches[0]);
2222
$constPrefix = $this->engine->getOption('constPrefix', JsPhpize::CONST_PREFIX);
23-
if (strpos($constant, $constPrefix) === 0) {
23+
if (mb_strpos($constant, $constPrefix) === 0) {
2424
throw new Exception('Constants cannot start with ' . $constPrefix . ', this prefix is reserved for JsPhpize' . $this->exceptionInfos(), 1);
2525
}
2626

@@ -32,8 +32,8 @@ public function scanConstant($matches)
3232

3333
if (isset($translate[$constant])) {
3434
$constant = $translate[$constant];
35-
} elseif (substr($matches[0], 0, 5) === 'Math.') {
36-
$constant = 'M_' . substr($constant, 5);
35+
} elseif (mb_substr($matches[0], 0, 5) === 'Math.') {
36+
$constant = 'M_' . mb_substr($constant, 5);
3737
}
3838

3939
$this->consume($matches[0]);
@@ -69,12 +69,12 @@ public function scanOperator($matches)
6969
public function scanVariable($matches)
7070
{
7171
$varPrefix = $this->engine->getOption('varPrefix', JsPhpize::VAR_PREFIX);
72-
if (strpos($matches[1], $varPrefix) === 0) {
72+
if (mb_strpos($matches[1], $varPrefix) === 0) {
7373
throw new Exception('Variables cannot start with ' . $varPrefix . ', this prefix is reserved for JsPhpize' . $this->exceptionInfos(), 4);
7474
}
7575

76-
if ($this->engine->getOption('ignoreDollarVariable') && substr($matches[0], 0, 1) === '$') {
77-
$matches[0] = ' ' . substr($matches[0], 1);
76+
if ($this->engine->getOption('ignoreDollarVariable') && mb_substr($matches[0], 0, 1) === '$') {
77+
$matches[0] = ' ' . mb_substr($matches[0], 1);
7878
}
7979

8080
return $this->valueToken('variable', $matches);

src/JsPhpize/Lexer/Token.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function isLeftHandOperator()
8080

8181
public function isAssignation()
8282
{
83-
return substr($this->type, -1) === '=' && !$this->isComparison();
83+
return mb_substr($this->type, -1) === '=' && !$this->isComparison();
8484
}
8585

8686
public function isOperator()

src/JsPhpize/Nodes/Constant.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function getNonAssignableReason()
3333
if (in_array($this->value, array('NAN', 'INF'))) {
3434
return "{$this->value} is not assignable.";
3535
}
36-
if (substr($this->value, 0, 2) === 'M_') {
36+
if (mb_substr($this->value, 0, 2) === 'M_') {
3737
return "'M_' prefix is reserved to mathematical constants.";
3838
}
3939

src/JsPhpize/Stream/ExpressionStream.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class ExpressionStream
2626
*/
2727
public function stream_open($path)
2828
{
29-
$this->data = substr(strstr($path, ';'), 1);
29+
$this->data = mb_substr(mb_strstr($path, ';'), 1);
3030

3131
return true;
3232
}
@@ -45,8 +45,8 @@ public function stream_stat()
4545
*/
4646
public function stream_read($count)
4747
{
48-
$ret = substr($this->data, $this->position, $count);
49-
$this->position += strlen($ret);
48+
$ret = mb_substr($this->data, $this->position, $count);
49+
$this->position += mb_strlen($ret);
5050

5151
return $ret;
5252
}
@@ -64,7 +64,7 @@ public function stream_tell()
6464
*/
6565
public function stream_eof()
6666
{
67-
return $this->position >= strlen($this->data);
67+
return $this->position >= mb_strlen($this->data);
6868
}
6969

7070
/**
@@ -74,6 +74,6 @@ public function stream_eof()
7474
*/
7575
public function url_stat($path, $flags)
7676
{
77-
return array(0, 0, 0, 0, 0, 0, 0, strlen($this->data), 0, 0, 0, 0);
77+
return array(0, 0, 0, 0, 0, 0, 0, mb_strlen($this->data), 0, 0, 0, 0);
7878
}
7979
}

0 commit comments

Comments
 (0)