Go to the documentation of this file.
7 #ifndef __LOCALEMATCHER_H__
8 #define __LOCALEMATCHER_H__
12 #if U_SHOW_CPLUSPLUS_API
23 #ifndef U_FORCE_HIDE_DRAFT_API
138 class LocaleDistance;
139 class LocaleLsrIterator;
141 class XLikelySubtags;
221 #ifndef U_HIDE_DRAFT_API
276 #endif // U_HIDE_DRAFT_API
280 int32_t desIndex, int32_t suppIndex,
UBool owned) :
281 desiredLocale(desired), supportedLocale(supported),
282 desiredIndex(desIndex), supportedIndex(suppIndex),
283 desiredIsOwned(owned) {}
288 const Locale *desiredLocale;
289 const Locale *supportedLocale;
290 int32_t desiredIndex;
291 int32_t supportedIndex;
292 UBool desiredIsOwned;
339 #ifndef U_HIDE_DRAFT_API
377 template<
typename Iter>
379 if (
U_FAILURE(errorCode_)) {
return *
this; }
380 clearSupportedLocales();
381 while (begin != end) {
382 addSupportedLocale(*begin++);
402 template<
typename Iter,
typename Conv>
404 if (
U_FAILURE(errorCode_)) {
return *
this; }
405 clearSupportedLocales();
406 while (begin != end) {
407 addSupportedLocale(converter(*begin++));
464 direction_ = direction;
492 #endif // U_HIDE_DRAFT_API
500 void clearSupportedLocales();
501 bool ensureSupportedLocaleVector();
504 UVector *supportedLocales_ =
nullptr;
505 int32_t thresholdDistance_ = -1;
507 Locale *defaultLocale_ =
nullptr;
538 #ifndef U_HIDE_DRAFT_API
606 #endif // U_HIDE_DRAFT_API
608 #ifndef U_HIDE_INTERNAL_API
628 #endif // U_HIDE_INTERNAL_API
635 int32_t putIfAbsent(
const LSR &lsr, int32_t i, int32_t suppLength,
UErrorCode &errorCode);
637 int32_t getBestSuppIndex(LSR desiredLSR, LocaleLsrIterator *remainingIter,
UErrorCode &errorCode)
const;
639 const XLikelySubtags &likelySubtags;
640 const LocaleDistance &localeDistance;
641 int32_t thresholdDistance;
642 int32_t demotionPerDesiredLocale;
647 const Locale ** supportedLocales;
649 int32_t supportedLocalesLength;
654 const LSR **supportedLSRs;
655 int32_t *supportedIndexes;
656 int32_t supportedLSRsLength;
657 Locale *ownedDefaultLocale;
658 const Locale *defaultLocale;
663 #endif // U_FORCE_HIDE_DRAFT_API
664 #endif // U_SHOW_CPLUSPLUS_API
665 #endif // __LOCALEMATCHER_H__
struct UHashtable UHashtable
@ ULOCMATCH_DIRECTION_ONLY_TWO_WAY
Locale matching limited to two-way matches including e.g.
LocaleMatcher build(UErrorCode &errorCode) const
Builds and returns a new locale matcher.
Data for the best-matching pair of a desired and a supported locale.
Basic definitions for ICU, for both C and C++ APIs.
ULocMatchDemotion
Builder option for whether all desired locales are treated equally or earlier ones are preferred.
int8_t UBool
The ICU boolean type.
Builder & addSupportedLocale(const Locale &locale)
Adds another supported locale.
int32_t getSupportedIndex() const
Returns the index of the best-matching supported locale in the constructor’s or builder’s input order...
LocaleMatcher(LocaleMatcher &&src) U_NOEXCEPT
Move copy constructor; might modify the source.
Builder & setDirection(ULocMatchDirection direction)
Option for whether to include or ignore one-way (fallback) match data.
#define U_COMMON_API
Set to export library symbols from inside the common library, and to import them from outside.
const Locale * getBestMatchForListString(StringPiece desiredLocaleList, UErrorCode &errorCode) const
Parses an Accept-Language string (RFC 2616 Section 14.4), such as "af, en, fr;q=0....
LocaleMatcher & operator=(LocaleMatcher &&src) U_NOEXCEPT
Move assignment operator; might modify the source.
Builder(Builder &&src) U_NOEXCEPT
Move constructor; might modify the source.
UBool copyErrorTo(UErrorCode &outErrorCode) const
Sets the UErrorCode if an error occurred while setting parameters.
C++ API: StringPiece: Read-only byte string wrapper class.
Builder & setSupportedLocalesFromListString(StringPiece locales)
Parses an Accept-Language string (RFC 2616 Section 14.4), such as "af, en, fr;q=0....
Result & operator=(Result &&src) U_NOEXCEPT
Move assignment; might modify the source.
const Locale * getDesiredLocale() const
Returns the best-matching desired locale.
Builder()
Constructs a builder used in chaining parameters for building a LocaleMatcher.
#define U_FAILURE(x)
Does the error code indicate a failure?
A Locale iterator interface similar to a Java Iterator<Locale>.
ULocMatchFavorSubtag
Builder option for whether the language subtag or the script subtag is most important.
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Builder & setDefaultLocale(const Locale *defaultLocale)
Sets the default locale; if nullptr, or if it is not set explicitly, then the first supported locale ...
@ ULOCMATCH_DEMOTION_NONE
All desired locales are treated equally.
UMemory is the common ICU base class.
ULocMatchDirection
Builder option for whether to include or ignore one-way (fallback) match data.
const Locale * getSupportedLocale() const
Returns the best-matching supported locale.
const Locale * getBestMatch(const Locale &desiredLocale, UErrorCode &errorCode) const
Returns the supported locale which best matches the desired locale.
Builder & setSupportedLocales(Locale::Iterator &locales)
Copies the supported locales, preserving iteration order.
Builder & setDemotionPerDesiredLocale(ULocMatchDemotion demotion)
Option for whether all desired locales are treated equally or earlier ones are preferred (this is the...
Builder & setSupportedLocales(Iter begin, Iter end)
Copies the supported locales from the begin/end range, preserving iteration order.
Builder & setSupportedLocalesViaConverter(Iter begin, Iter end, Conv converter)
Copies the supported locales from the begin/end range, preserving iteration order.
@ U_ZERO_ERROR
No error, no warning.
Builder & operator=(Builder &&src) U_NOEXCEPT
Move assignment; might modify the source.
Locale makeResolvedLocale(UErrorCode &errorCode) const
Takes the best-matching supported locale and adds relevant fields of the best-matching desired locale...
@ ULOCMATCH_FAVOR_LANGUAGE
Language differences are most important, then script differences, then region differences.
#define U_SUCCESS(x)
Does the error code indicate success?
const Locale * getBestMatch(Locale::Iterator &desiredLocales, UErrorCode &errorCode) const
Returns the supported locale which best matches one of the desired locales.
Immutable class that picks the best match between a user's desired locales and an application's suppo...
Builder & setFavorSubtag(ULocMatchFavorSubtag subtag)
If ULOCMATCH_FAVOR_SCRIPT, then the language differences are smaller than script differences.
Result getBestMatchResult(Locale::Iterator &desiredLocales, UErrorCode &errorCode) const
Returns the best match between the desired and supported locales.
double internalMatch(const Locale &desired, const Locale &supported, UErrorCode &errorCode) const
Returns a fraction between 0 and 1, where 1 means that the languages are a perfect match,...
~LocaleMatcher()
Destructor.
int32_t getDesiredIndex() const
Returns the index of the best-matching desired locale in the input Iterable order.
@ ULOCMATCH_FAVOR_SCRIPT
Makes script differences matter relatively more than language differences.
Result getBestMatchResult(const Locale &desiredLocale, UErrorCode &errorCode) const
Returns the best match between the desired locale and the supported locales.
C++ API: Locale ID object.
C++ API: Common ICU base class UObject.
A string-like object that points to a sized piece of memory.
@ ULOCMATCH_DIRECTION_WITH_ONE_WAY
Locale matching includes one-way matches such as Breton→French.
A Locale object represents a specific geographical, political, or cultural region.
@ ULOCMATCH_DEMOTION_REGION
Earlier desired locales are preferred.
Result(Result &&src) U_NOEXCEPT
Move constructor; might modify the source.