Skip to content

Commit 36d6518

Browse files
committed
minor #19149 [String] New locale aware casing methods (alamirault)
This PR was merged into the 7.1 branch. Discussion ---------- [String] New locale aware casing methods Fix #19148 Commits ------- 7349989 [String] New locale aware casing methods
2 parents 9294543 + 7349989 commit 36d6518

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

components/string.rst

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,10 @@ Methods to Change Case
203203
::
204204

205205
// changes all graphemes/code points to lower case
206-
u('FOO Bar')->lower(); // 'foo bar'
206+
u('FOO Bar Brİan')->lower(); // 'foo bar bri̇an'
207+
// changes all graphemes/code points to lower case according to locale-specific case mappings
208+
u('FOO Bar Brİan')->localeLower('en'); // 'foo bar bri̇an'
209+
u('FOO Bar Brİan')->localeLower('lt'); // 'foo bar bri̇̇an'
207210

208211
// when dealing with different languages, uppercase/lowercase is not enough
209212
// there are three cases (lower, upper, title), some characters have no case,
@@ -213,11 +216,17 @@ Methods to Change Case
213216
u('Die O\'Brian Straße')->folded(); // "die o'brian strasse"
214217

215218
// changes all graphemes/code points to upper case
216-
u('foo BAR')->upper(); // 'FOO BAR'
219+
u('foo BAR bάz')->upper(); // 'FOO BAR BΆZ'
220+
// changes all graphemes/code points to upper case according to locale-specific case mappings
221+
u('foo BAR bάz')->localeUpper('en'); // 'FOO BAR BΆZ'
222+
u('foo BAR bάz')->localeUpper('el'); // 'FOO BAR BAZ'
217223

218224
// changes all graphemes/code points to "title case"
219-
u('foo bar')->title(); // 'Foo bar'
220-
u('foo bar')->title(true); // 'Foo Bar'
225+
u('foo ijssel ')->title(); // 'Foo ijssel'
226+
u('foo ijssel')->title(true); // 'Foo Ijssel'
227+
// changes all graphemes/code points to "title case" according to locale-specific case mappings
228+
u('foo ijssel')->localeTitle('en'); // 'Foo ijssel'
229+
u('foo ijssel')->localeTitle('nl'); // 'Foo IJssel'
221230

222231
// changes all graphemes/code points to camelCase
223232
u('Foo: Bar-baz.')->camel(); // 'fooBarBaz'
@@ -226,6 +235,10 @@ Methods to Change Case
226235
// other cases can be achieved by chaining methods. E.g. PascalCase:
227236
u('Foo: Bar-baz.')->camel()->title(); // 'FooBarBaz'
228237

238+
.. versionadded:: 7.1
239+
The ``localeLower()``, ``localeUpper()`` and ``localeTitle()`` methods were
240+
introduced in Symfony 7.1.
241+
229242
The methods of all string classes are case-sensitive by default. You can perform
230243
case-insensitive operations with the ``ignoreCase()`` method::
231244

0 commit comments

Comments
 (0)