Skip to content

Commit 2d67c1f

Browse files
HellFirePvPnicolas-grekas
HellFirePvP
authored andcommitted
[Filesystem] Remove needless mb_* calls
1 parent 6699fb0 commit 2d67c1f

File tree

2 files changed

+36
-34
lines changed

2 files changed

+36
-34
lines changed

Path.php

+34-34
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public static function canonicalize(string $path): string
8181

8282
// Replace "~" with user's home directory.
8383
if ('~' === $path[0]) {
84-
$path = self::getHomeDirectory().mb_substr($path, 1);
84+
$path = self::getHomeDirectory().substr($path, 1);
8585
}
8686

8787
$path = self::normalize($path);
@@ -151,14 +151,14 @@ public static function getDirectory(string $path): string
151151
$path = self::canonicalize($path);
152152

153153
// Maintain scheme
154-
if (false !== ($schemeSeparatorPosition = mb_strpos($path, '://'))) {
155-
$scheme = mb_substr($path, 0, $schemeSeparatorPosition + 3);
156-
$path = mb_substr($path, $schemeSeparatorPosition + 3);
154+
if (false !== $schemeSeparatorPosition = strpos($path, '://')) {
155+
$scheme = substr($path, 0, $schemeSeparatorPosition + 3);
156+
$path = substr($path, $schemeSeparatorPosition + 3);
157157
} else {
158158
$scheme = '';
159159
}
160160

161-
if (false === ($dirSeparatorPosition = strrpos($path, '/'))) {
161+
if (false === $dirSeparatorPosition = strrpos($path, '/')) {
162162
return '';
163163
}
164164

@@ -169,10 +169,10 @@ public static function getDirectory(string $path): string
169169

170170
// Directory equals Windows root "C:/"
171171
if (2 === $dirSeparatorPosition && ctype_alpha($path[0]) && ':' === $path[1]) {
172-
return $scheme.mb_substr($path, 0, 3);
172+
return $scheme.substr($path, 0, 3);
173173
}
174174

175-
return $scheme.mb_substr($path, 0, $dirSeparatorPosition);
175+
return $scheme.substr($path, 0, $dirSeparatorPosition);
176176
}
177177

178178
/**
@@ -219,7 +219,7 @@ public static function getRoot(string $path): string
219219
}
220220

221221
// Maintain scheme
222-
if (false !== ($schemeSeparatorPosition = strpos($path, '://'))) {
222+
if (false !== $schemeSeparatorPosition = strpos($path, '://')) {
223223
$scheme = substr($path, 0, $schemeSeparatorPosition + 3);
224224
$path = substr($path, $schemeSeparatorPosition + 3);
225225
} else {
@@ -233,7 +233,7 @@ public static function getRoot(string $path): string
233233
return $scheme.'/';
234234
}
235235

236-
$length = mb_strlen($path);
236+
$length = \strlen($path);
237237

238238
// Windows root
239239
if ($length > 1 && ':' === $path[1] && ctype_alpha($firstCharacter)) {
@@ -349,16 +349,16 @@ public static function changeExtension(string $path, string $extension): string
349349
$extension = ltrim($extension, '.');
350350

351351
// No extension for paths
352-
if ('/' === mb_substr($path, -1)) {
352+
if ('/' === substr($path, -1)) {
353353
return $path;
354354
}
355355

356356
// No actual extension in path
357357
if (empty($actualExtension)) {
358-
return $path.('.' === mb_substr($path, -1) ? '' : '.').$extension;
358+
return $path.('.' === substr($path, -1) ? '' : '.').$extension;
359359
}
360360

361-
return mb_substr($path, 0, -mb_strlen($actualExtension)).$extension;
361+
return substr($path, 0, -\strlen($actualExtension)).$extension;
362362
}
363363

364364
public static function isAbsolute(string $path): bool
@@ -368,8 +368,8 @@ public static function isAbsolute(string $path): bool
368368
}
369369

370370
// Strip scheme
371-
if (false !== ($schemeSeparatorPosition = mb_strpos($path, '://'))) {
372-
$path = mb_substr($path, $schemeSeparatorPosition + 3);
371+
if (false !== $schemeSeparatorPosition = strpos($path, '://')) {
372+
$path = substr($path, $schemeSeparatorPosition + 3);
373373
}
374374

375375
$firstCharacter = $path[0];
@@ -380,9 +380,9 @@ public static function isAbsolute(string $path): bool
380380
}
381381

382382
// Windows root
383-
if (mb_strlen($path) > 1 && ctype_alpha($firstCharacter) && ':' === $path[1]) {
383+
if (\strlen($path) > 1 && ctype_alpha($firstCharacter) && ':' === $path[1]) {
384384
// Special case: "C:"
385-
if (2 === mb_strlen($path)) {
385+
if (2 === \strlen($path)) {
386386
return true;
387387
}
388388

@@ -451,9 +451,9 @@ public static function makeAbsolute(string $path, string $basePath): string
451451
return self::canonicalize($path);
452452
}
453453

454-
if (false !== ($schemeSeparatorPosition = mb_strpos($basePath, '://'))) {
455-
$scheme = mb_substr($basePath, 0, $schemeSeparatorPosition + 3);
456-
$basePath = mb_substr($basePath, $schemeSeparatorPosition + 3);
454+
if (false !== $schemeSeparatorPosition = strpos($basePath, '://')) {
455+
$scheme = substr($basePath, 0, $schemeSeparatorPosition + 3);
456+
$basePath = substr($basePath, $schemeSeparatorPosition + 3);
457457
} else {
458458
$scheme = '';
459459
}
@@ -574,7 +574,7 @@ public static function makeRelative(string $path, string $basePath): string
574574
*/
575575
public static function isLocal(string $path): bool
576576
{
577-
return '' !== $path && false === mb_strpos($path, '://');
577+
return '' !== $path && false === strpos($path, '://');
578578
}
579579

580580
/**
@@ -638,7 +638,7 @@ public static function getLongestCommonBasePath(string ...$paths): ?string
638638

639639
// Prevent false positives for common prefixes
640640
// see isBasePath()
641-
if (0 === mb_strpos($path.'/', $basePath.'/')) {
641+
if (0 === strpos($path.'/', $basePath.'/')) {
642642
// next path
643643
continue 2;
644644
}
@@ -666,12 +666,12 @@ public static function join(string ...$paths): string
666666
if (null === $finalPath) {
667667
// For first part we keep slashes, like '/top', 'C:\' or 'phar://'
668668
$finalPath = $path;
669-
$wasScheme = (false !== mb_strpos($path, '://'));
669+
$wasScheme = (false !== strpos($path, '://'));
670670
continue;
671671
}
672672

673673
// Only add slash if previous part didn't end with '/' or '\'
674-
if (!\in_array(mb_substr($finalPath, -1), ['/', '\\'])) {
674+
if (!\in_array(substr($finalPath, -1), ['/', '\\'])) {
675675
$finalPath .= '/';
676676
}
677677

@@ -717,7 +717,7 @@ public static function isBasePath(string $basePath, string $ofPath): bool
717717
// Don't append a slash for the root "/", because then that root
718718
// won't be discovered as common prefix ("//" is not a prefix of
719719
// "/foobar/").
720-
return 0 === mb_strpos($ofPath.'/', rtrim($basePath, '/').'/');
720+
return 0 === strpos($ofPath.'/', rtrim($basePath, '/').'/');
721721
}
722722

723723
/**
@@ -776,28 +776,28 @@ private static function split(string $path): array
776776
}
777777

778778
// Remember scheme as part of the root, if any
779-
if (false !== ($schemeSeparatorPosition = mb_strpos($path, '://'))) {
780-
$root = mb_substr($path, 0, $schemeSeparatorPosition + 3);
781-
$path = mb_substr($path, $schemeSeparatorPosition + 3);
779+
if (false !== $schemeSeparatorPosition = strpos($path, '://')) {
780+
$root = substr($path, 0, $schemeSeparatorPosition + 3);
781+
$path = substr($path, $schemeSeparatorPosition + 3);
782782
} else {
783783
$root = '';
784784
}
785785

786-
$length = mb_strlen($path);
786+
$length = \strlen($path);
787787

788788
// Remove and remember root directory
789-
if (0 === mb_strpos($path, '/')) {
789+
if (0 === strpos($path, '/')) {
790790
$root .= '/';
791-
$path = $length > 1 ? mb_substr($path, 1) : '';
791+
$path = $length > 1 ? substr($path, 1) : '';
792792
} elseif ($length > 1 && ctype_alpha($path[0]) && ':' === $path[1]) {
793793
if (2 === $length) {
794794
// Windows special case: "C:"
795795
$root .= $path.'/';
796796
$path = '';
797797
} elseif ('/' === $path[2]) {
798798
// Windows normal case: "C:/"..
799-
$root .= mb_substr($path, 0, 3);
800-
$path = $length > 3 ? mb_substr($path, 3) : '';
799+
$root .= substr($path, 0, 3);
800+
$path = $length > 3 ? substr($path, 3) : '';
801801
}
802802
}
803803

@@ -806,11 +806,11 @@ private static function split(string $path): array
806806

807807
private static function toLower(string $string): string
808808
{
809-
if (false !== $encoding = mb_detect_encoding($string)) {
809+
if (false !== $encoding = mb_detect_encoding($string, null, true)) {
810810
return mb_strtolower($string, $encoding);
811811
}
812812

813-
return strtolower($string, $encoding);
813+
return strtolower($string);
814814
}
815815

816816
private function __construct()

Tests/PathTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ public function provideGetDirectoryTests(): \Generator
223223
yield ['/..', '/'];
224224

225225
yield ['C:webmozart', ''];
226+
227+
yield ['D:/Folder/Aééé/Subfolder', 'D:/Folder/Aééé'];
226228
}
227229

228230
/**

0 commit comments

Comments
 (0)