- java.lang.Object
-
- io.github.mmm.base.text.CaseHelper
-
public final class CaseHelper extends Object
Simple helper for case conversion liketoLowerCase(String)ortoUpperCase(String). This seems pointless in the first place but prevents typical programming mistakes. Many developers will expect that"HI".returnstoLowerCase()"hi". However, this is not always the case!String.toLowerCase()will actually dotoLowerCase(Locale.getDefault()). The latter operation is obviously aLocalesensitive operation and can behave differently depending on the givenLocale. So e.g. if yourLocaleis actually Turkish (tr_TRresp.tr-TR) the result of"HI".will actually betoLowerCase()"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 standardStringcase operations to prevent such mistakes and also to document this fact.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static 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).
-
-
-
Method Detail
-
toLowerCase
public static String toLowerCase(String string)
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
public static String toLowerCase(String string, Locale locale)
Indirection forString.toLowerCase(Locale).- Parameters:
string- is theString.locale- is theLocale.- Returns:
- the result of
String.toLowerCase(Locale).
-
toUpperCase
public static String toUpperCase(String string)
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
public static String toUpperCase(String string, Locale locale)
Indirection forString.toUpperCase(Locale).- Parameters:
string- is theString.locale- is theLocale.- Returns:
- the result of
String.toUpperCase(Locale).
-
-