Skip to content

[String] Leverage grapheme_str_split() #60887

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"psr/log": "^1|^2|^3",
"symfony/contracts": "^3.6",
"symfony/polyfill-ctype": "~1.8",
"symfony/polyfill-intl-grapheme": "~1.0",
"symfony/polyfill-intl-grapheme": "~1.33",
"symfony/polyfill-intl-icu": "~1.0",
"symfony/polyfill-intl-idn": "^1.10",
"symfony/polyfill-intl-normalizer": "~1.0",
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/String/AbstractUnicodeString.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@
public function reverse(): static
{
$str = clone $this;
$str->string = implode('', array_reverse(preg_split('/(\X)/u', $str->string, -1, \PREG_SPLIT_DELIM_CAPTURE | \PREG_SPLIT_NO_EMPTY)));
$str->string = implode('', array_reverse(grapheme_str_split($str->string)));

Check failure on line 363 in src/Symfony/Component/String/AbstractUnicodeString.php

View workflow job for this annotation

GitHub Actions / Psalm

UndefinedFunction

src/Symfony/Component/String/AbstractUnicodeString.php:363:50: UndefinedFunction: Function Symfony\Component\String\grapheme_str_split does not exist, consider enabling the allFunctionsGlobal config option if scanning legacy codebases (see https://psalm.dev/021)

Check failure on line 363 in src/Symfony/Component/String/AbstractUnicodeString.php

View workflow job for this annotation

GitHub Actions / Psalm

UndefinedFunction

src/Symfony/Component/String/AbstractUnicodeString.php:363:50: UndefinedFunction: Function Symfony\Component\String\grapheme_str_split does not exist, consider enabling the allFunctionsGlobal config option if scanning legacy codebases (see https://psalm.dev/021)

return $str;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ public static function provideReverse()
[
['äuß⭐erst', 'tsre⭐ßuä'],
['漢字ーユニコードéèΣσς', 'ςσΣèéドーコニユー字漢'],
['नमस्ते', 'तेस्मन'],
// ['नमस्ते', 'तेस्मन'], this case requires a version of intl that supports Unicode 15.1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this test case previously passed and no longer passes with the change you are making, isn't that a regression that could affect users?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes it is, but that's only for exotic scripts, which can be managed fine with a recent enough version of ICU (which is likely a requirement anyway when dealing with such scripts)

]
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/String/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"require": {
"php": ">=8.2",
"symfony/polyfill-ctype": "~1.8",
"symfony/polyfill-intl-grapheme": "~1.0",
"symfony/polyfill-intl-grapheme": "~1.33",
"symfony/polyfill-intl-normalizer": "~1.0",
"symfony/polyfill-mbstring": "~1.0"
},
Expand Down
Loading