- 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 aLocale
sensitive operation and can behave differently depending on the givenLocale
. So e.g. if yourLocale
is actually Turkish (tr_TR
resp.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 standardString
case 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 String
capitalize(String string)
static String
toLowerCase(String string)
Indirection forString.toLowerCase(Locale)
with a standardLocale
to prevent accidents.static String
toLowerCase(String string, Locale locale)
Indirection forString.toLowerCase(Locale)
.static String
toUpperCase(String string)
Indirection forString.toUpperCase(Locale)
with a standardLocale.US
to prevent accidents.static String
toUpperCase(String string, Locale locale)
Indirection forString.toUpperCase(Locale)
.
-
-
-
Method Detail
-
toLowerCase
public static String toLowerCase(String string)
Indirection forString.toLowerCase(Locale)
with a standardLocale
to prevent accidents. SeeCaseHelper
type 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.US
to prevent accidents. SeeCaseHelper
type 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)
.
-
-