Update parseCharacterRanges with dashless
This commit is contained in:
@@ -287,6 +287,10 @@ class Strings
|
|||||||
// Remove all spaces
|
// Remove all spaces
|
||||||
$input = str_replace(' ', '', $input);
|
$input = str_replace(' ', '', $input);
|
||||||
$result = [];
|
$result = [];
|
||||||
|
// if there is no - inside, return unique characters as array
|
||||||
|
if (strpos($input, '-') === false) {
|
||||||
|
return array_unique(mb_str_split($input));
|
||||||
|
}
|
||||||
// Find all patterns like "A-Z" (character-dash-character)
|
// Find all patterns like "A-Z" (character-dash-character)
|
||||||
preg_match_all('/(.)-(.)/u', $input, $matches, PREG_SET_ORDER);
|
preg_match_all('/(.)-(.)/u', $input, $matches, PREG_SET_ORDER);
|
||||||
foreach ($matches as $match) {
|
foreach ($matches as $match) {
|
||||||
|
|||||||
@@ -743,6 +743,11 @@ final class CoreLibsConvertStringsTest extends TestCase
|
|||||||
'abcdefghijklmnopqrstuvwxyz0123',
|
'abcdefghijklmnopqrstuvwxyz0123',
|
||||||
null,
|
null,
|
||||||
],
|
],
|
||||||
|
'range without dashes' => [
|
||||||
|
['abcddfff'],
|
||||||
|
'abcdf',
|
||||||
|
null,
|
||||||
|
],
|
||||||
'invalid ranges' => [
|
'invalid ranges' => [
|
||||||
['a-あ', 'A-あ', '0-あ'],
|
['a-あ', 'A-あ', '0-あ'],
|
||||||
'',
|
'',
|
||||||
|
|||||||
Reference in New Issue
Block a user