java.lang.Object
io.github.mmm.base.text.CaseHelper
Simple helper for case conversion like
Simply use this small helper as indirection to the standard
toLowerCase(String) or toUpperCase(String). This seems
pointless in the first place but prevents typical programming mistakes. Many developers will expect that
"HI".toLowerCase() returns "hi". However, this is not always the
case! String.toLowerCase() will actually do toLowerCase(Locale.getDefault()). The latter operation is obviously a Locale sensitive operation and
can behave differently depending on the given Locale. So e.g. if your Locale is actually Turkish
(tr_TR resp. tr-TR) the result of "HI".toLowerCase() will
actually be "hı" (notice the missing dot on the i character!). This can lead to serious bugs when creating
filenames, URLs or the like via case conversion. Due to such bug nobody with Turkish locale could install Lotus Notes
8.5.1 when it was released.Simply use this small helper as indirection to the standard
String case operations to prevent such mistakes
and also to document this fact.- Since:
- 1.0.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic Stringcapitalize(String string) static StringtoLowerCase(String string) Indirection forString.toLowerCase(Locale)with a standardLocaleto prevent accidents.static StringtoLowerCase(String string, Locale locale) Indirection forString.toLowerCase(Locale).static StringtoUpperCase(String string) Indirection forString.toUpperCase(Locale)with a standardLocale.USto prevent accidents.static StringtoUpperCase(String string, Locale locale) Indirection forString.toUpperCase(Locale).static Stringuncapitalize(String string)
-
Method Details
-
toLowerCase
Indirection forString.toLowerCase(Locale)with a standardLocaleto prevent accidents. SeeCaseHelpertype description for details.- Parameters:
string- is theString.- Returns:
- the result of
String.toLowerCase(Locale). - Since:
- 4.0.0
-
toLowerCase
Indirection forString.toLowerCase(Locale).- Parameters:
string- is theString.locale- is theLocale.- Returns:
- the result of
String.toLowerCase(Locale).
-
toUpperCase
Indirection forString.toUpperCase(Locale)with a standardLocale.USto prevent accidents. SeeCaseHelpertype description for details.- Parameters:
string- is theString.- Returns:
- the result of
String.toUpperCase(Locale).
-
toUpperCase
Indirection forString.toUpperCase(Locale).- Parameters:
string- is theString.locale- is theLocale.- Returns:
- the result of
String.toUpperCase(Locale).
-
capitalize
-
uncapitalize
-