Class LocaleParser
java.lang.Object
ch.tocco.nice2.textresources.api.locale.LocaleParser
Parses a Locale string into
Locale
objects.
Note: This class does not validate any ISO codes.-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionparseLocalesString
(String localesString) Works on a comma-separated list, for example "da, en-GB"@Nullable Locale
parseLocaleString
(@Nullable String localeString) @Nullable Locale
parseLocaleStringNoEx
(String localeString) Calls parseLocaleString() and swallows an IllegalArgumentException, returning null instead.void
Only standard rules allowed, but still no ISO code validation.
-
Constructor Details
-
LocaleParser
public LocaleParser()Creates a non-strict parser. -
LocaleParser
public LocaleParser(boolean strict)
-
-
Method Details
-
setToStrictMode
public void setToStrictMode()Only standard rules allowed, but still no ISO code validation.It is a shortcut for: setLanguageCountrySeparators("_") setCheckCase(true)
-
parseLocaleString
@Nullable public @Nullable Locale parseLocaleString(@Nullable @Nullable String localeString) throws IllegalArgumentException - Parameters:
localeString
- Trim it.- Returns:
- A locale, or null when input is empty or null.
- Throws:
IllegalArgumentException
- On invalid syntax, seesetToStrictMode()
.
-
parseLocaleStringNoEx
Calls parseLocaleString() and swallows an IllegalArgumentException, returning null instead.- Parameters:
localeString
- (trim it. may be null.)- Returns:
- a locale, or null on failure or invalid syntax.
-
parseLocalesString
Works on a comma-separated list, for example "da, en-GB"- Parameters:
localesString
- (may be null)- Returns:
- Ordered Set, may be empty
- Throws:
IllegalArgumentException
- on first parse or validation error
-