ICU 72.1 72.1
|
LocaleMatcher builder. More...
#include <localematcher.h>
Public Member Functions | |
Builder () | |
Constructs a builder used in chaining parameters for building a LocaleMatcher. More... | |
Builder (Builder &&src) U_NOEXCEPT | |
Move constructor; might modify the source. More... | |
~Builder () | |
Destructor. More... | |
Builder & | operator= (Builder &&src) U_NOEXCEPT |
Move assignment; might modify the source. More... | |
Builder & | setSupportedLocalesFromListString (StringPiece locales) |
Parses an Accept-Language string (RFC 2616 Section 14.4), such as "af, en, fr;q=0.9", and sets the supported locales accordingly. More... | |
Builder & | setSupportedLocales (Locale::Iterator &locales) |
Copies the supported locales, preserving iteration order. More... | |
template<typename Iter > | |
Builder & | setSupportedLocales (Iter begin, Iter end) |
Copies the supported locales from the begin/end range, preserving iteration order. More... | |
template<typename Iter , typename Conv > | |
Builder & | setSupportedLocalesViaConverter (Iter begin, Iter end, Conv converter) |
Copies the supported locales from the begin/end range, preserving iteration order. More... | |
Builder & | addSupportedLocale (const Locale &locale) |
Adds another supported locale. More... | |
Builder & | setNoDefaultLocale () |
Sets no default locale. More... | |
Builder & | setDefaultLocale (const Locale *defaultLocale) |
Sets the default locale; if nullptr, or if it is not set explicitly, then the first supported locale is used as the default locale. More... | |
Builder & | setFavorSubtag (ULocMatchFavorSubtag subtag) |
If ULOCMATCH_FAVOR_SCRIPT, then the language differences are smaller than script differences. More... | |
Builder & | setDemotionPerDesiredLocale (ULocMatchDemotion demotion) |
Option for whether all desired locales are treated equally or earlier ones are preferred (this is the default). More... | |
Builder & | setDirection (ULocMatchDirection matchDirection) |
Option for whether to include or ignore one-way (fallback) match data. More... | |
Builder & | setMaxDistance (const Locale &desired, const Locale &supported) |
Sets the maximum distance for an acceptable match. More... | |
UBool | copyErrorTo (UErrorCode &outErrorCode) const |
Sets the UErrorCode if an error occurred while setting parameters. More... | |
LocaleMatcher | build (UErrorCode &errorCode) const |
Builds and returns a new locale matcher. More... | |
Friends | |
class | LocaleMatcher |
LocaleMatcher builder.
Movable but not copyable.
Definition at line 299 of file localematcher.h.
|
inline |
Constructs a builder used in chaining parameters for building a LocaleMatcher.
Definition at line 307 of file localematcher.h.
icu::LocaleMatcher::Builder::Builder | ( | Builder && | src | ) |
icu::LocaleMatcher::Builder::~Builder | ( | ) |
Destructor.
LocaleMatcher icu::LocaleMatcher::Builder::build | ( | UErrorCode & | errorCode | ) | const |
Builds and returns a new locale matcher.
This builder can continue to be used.
errorCode | ICU error code. Its input value must pass the U_SUCCESS() test, or else the function returns immediately. Check for U_FAILURE() on output or use with function chaining. (See User Guide for details.) |
UBool icu::LocaleMatcher::Builder::copyErrorTo | ( | UErrorCode & | outErrorCode | ) | const |
Sets the UErrorCode if an error occurred while setting parameters.
Preserves older error codes in the outErrorCode.
outErrorCode | Set to an error code if it does not contain one already and an error occurred while setting parameters. Otherwise unchanged. |
Sets the default locale; if nullptr, or if it is not set explicitly, then the first supported locale is used as the default locale.
There is no default locale at all (nullptr will be returned instead) if setNoDefaultLocale() is called.
defaultLocale | the default locale (will be copied) |
Builder & icu::LocaleMatcher::Builder::setDemotionPerDesiredLocale | ( | ULocMatchDemotion | demotion | ) |
|
inline |
Option for whether to include or ignore one-way (fallback) match data.
By default, they are included.
matchDirection | the match direction to set. |
Definition at line 468 of file localematcher.h.
References U_SUCCESS.
Builder & icu::LocaleMatcher::Builder::setFavorSubtag | ( | ULocMatchFavorSubtag | subtag | ) |
Builder & icu::LocaleMatcher::Builder::setMaxDistance | ( | const Locale & | desired, |
const Locale & | supported | ||
) |
Sets the maximum distance for an acceptable match.
The matcher will return a match for a pair of locales only if they match at least as well as the pair given here.
For example, setMaxDistance(en-US, en-GB) limits matches to ones where the (desired, support) locales have a distance no greater than a region subtag difference. This is much stricter than the CLDR default.
The details of locale matching are subject to changes in CLDR data and in the algorithm. Specifying a maximum distance in relative terms via a sample pair of locales insulates from changes that affect all distance metrics similarly, but some changes will necessarily affect relative distances between different pairs of locales.
desired | the desired locale for distance comparison. |
supported | the supported locale for distance comparison. |
Builder & icu::LocaleMatcher::Builder::setNoDefaultLocale | ( | ) |
Sets no default locale.
There will be no explicit or implicit default locale. If there is no good match, then the matcher will return nullptr for the best supported locale.
|
inline |
Copies the supported locales from the begin/end range, preserving iteration order.
Clears any previously set/added supported locales first. Duplicates are allowed, and are not removed.
Each of the iterator parameter values must be an input iterator whose value is convertible to const Locale &.
begin | Start of range. |
end | Exclusive end of range. |
Definition at line 372 of file localematcher.h.
References U_FAILURE.
Builder & icu::LocaleMatcher::Builder::setSupportedLocales | ( | Locale::Iterator & | locales | ) |
Builder & icu::LocaleMatcher::Builder::setSupportedLocalesFromListString | ( | StringPiece | locales | ) |
Parses an Accept-Language string (RFC 2616 Section 14.4), such as "af, en, fr;q=0.9", and sets the supported locales accordingly.
Allows whitespace in more places but does not allow "*". Clears any previously set/added supported locales first.
locales | the Accept-Language string of locales to set |
|
inline |
Copies the supported locales from the begin/end range, preserving iteration order.
Calls the converter to convert each *begin to a Locale or const Locale &. Clears any previously set/added supported locales first. Duplicates are allowed, and are not removed.
Each of the iterator parameter values must be an input iterator whose value is convertible to const Locale &.
begin | Start of range. |
end | Exclusive end of range. |
converter | Converter from *begin to const Locale & or compatible. |
Definition at line 397 of file localematcher.h.
References U_FAILURE.
|
friend |
Definition at line 523 of file localematcher.h.