Skip to content

Commit 5833053

Browse files
committed
[run-tests.php] Combine multiple str_replace calls to a single strtr call
Makes the replacement easier to see, neatly aligned, and only takes one function call. This is safe because none of the combined replacement values contain tokens that would be recursively replaced.
1 parent 0fcd07a commit 5833053

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

run-tests.php

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2567,19 +2567,20 @@ function run_test(string $php, $file, array $env): string
25672567
$wanted_re = $temp;
25682568

25692569
// Stick to basics
2570-
$wanted_re = str_replace('%e', '\\' . DIRECTORY_SEPARATOR, $wanted_re);
2571-
$wanted_re = str_replace('%s', '[^\r\n]+', $wanted_re);
2572-
$wanted_re = str_replace('%S', '[^\r\n]*', $wanted_re);
2573-
$wanted_re = str_replace('%a', '.+', $wanted_re);
2574-
$wanted_re = str_replace('%A', '.*', $wanted_re);
2575-
$wanted_re = str_replace('%w', '\s*', $wanted_re);
2576-
$wanted_re = str_replace('%i', '[+-]?\d+', $wanted_re);
2577-
$wanted_re = str_replace('%d', '\d+', $wanted_re);
2578-
$wanted_re = str_replace('%x', '[0-9a-fA-F]+', $wanted_re);
2579-
$wanted_re = str_replace('%f', '[+-]?\.?\d+\.?\d*(?:[Ee][+-]?\d+)?', $wanted_re);
2580-
$wanted_re = str_replace('%c', '.', $wanted_re);
2581-
$wanted_re = str_replace('%0', '\x00', $wanted_re);
2582-
// %f allows two points "-.0.0" but that is the best *simple* expression
2570+
$wanted_re = strtr($wanted_re, [
2571+
'%e' => '\\' . DIRECTORY_SEPARATOR,
2572+
'%s' => '[^\r\n]+',
2573+
'%S' => '[^\r\n]*',
2574+
'%a' => '.+',
2575+
'%A' => '.*',
2576+
'%w' => '\s*',
2577+
'%i' => '[+-]?\d+',
2578+
'%d' => '\d+',
2579+
'%x' => '[0-9a-fA-F]+',
2580+
'%f' => '[+-]?\.?\d+\.?\d*(?:[Ee][+-]?\d+)?', // %f allows two points "-.0.0" but that is the best *simple* expression
2581+
'%c' => '.',
2582+
'%0' => '\x00',
2583+
]);
25832584
}
25842585

25852586
if (preg_match("/^$wanted_re\$/s", $output)) {

0 commit comments

Comments
 (0)