Go to the documentation of this file.
7 #ifndef __LOCALEMATCHER_H__
8 #define __LOCALEMATCHER_H__
12 #if U_SHOW_CPLUSPLUS_API
94 #ifndef U_FORCE_HIDE_DRAFT_API
132 #endif // U_FORCE_HIDE_DRAFT_API
140 class LocaleDistance;
141 class LocaleLsrIterator;
143 class XLikelySubtags;
280 int32_t desIndex, int32_t suppIndex,
UBool owned) :
281 desiredLocale(desired), supportedLocale(supported),
282 desiredIndex(desIndex), supportedIndex(suppIndex),
283 desiredIsOwned(owned) {}
285 Result(
const Result &other) =
delete;
286 Result &operator=(
const Result &other) =
delete;
288 const Locale *desiredLocale;
289 const Locale *supportedLocale;
290 int32_t desiredIndex;
291 int32_t supportedIndex;
292 UBool desiredIsOwned;
375 template<
typename Iter>
377 if (
U_FAILURE(errorCode_)) {
return *
this; }
378 clearSupportedLocales();
379 while (begin != end) {
380 addSupportedLocale(*begin++);
400 template<
typename Iter,
typename Conv>
402 if (
U_FAILURE(errorCode_)) {
return *
this; }
403 clearSupportedLocales();
404 while (begin != end) {
405 addSupportedLocale(converter(*begin++));
420 #ifndef U_HIDE_DRAFT_API
430 #endif // U_HIDE_DRAFT_API
466 #ifndef U_HIDE_DRAFT_API
477 direction_ = direction;
481 #endif // U_HIDE_DRAFT_API
483 #ifndef U_HIDE_DRAFT_API
506 #endif // U_HIDE_DRAFT_API
538 void clearSupportedLocales();
539 bool ensureSupportedLocaleVector();
542 UVector *supportedLocales_ =
nullptr;
543 int32_t thresholdDistance_ = -1;
545 Locale *defaultLocale_ =
nullptr;
546 bool withDefault_ =
true;
549 Locale *maxDistanceDesired_ =
nullptr;
550 Locale *maxDistanceSupported_ =
nullptr;
631 Result getBestMatchResult(
const Locale &desiredLocale,
UErrorCode &errorCode)
const;
647 #ifndef U_HIDE_DRAFT_API
662 #endif // U_HIDE_DRAFT_API
664 #ifndef U_HIDE_INTERNAL_API
684 #endif // U_HIDE_INTERNAL_API
691 int32_t putIfAbsent(
const LSR &lsr, int32_t i, int32_t suppLength,
UErrorCode &errorCode);
693 int32_t getBestSuppIndex(LSR desiredLSR, LocaleLsrIterator *remainingIter,
UErrorCode &errorCode)
const;
695 const XLikelySubtags &likelySubtags;
696 const LocaleDistance &localeDistance;
697 int32_t thresholdDistance;
698 int32_t demotionPerDesiredLocale;
703 const Locale ** supportedLocales;
705 int32_t supportedLocalesLength;
710 const LSR **supportedLSRs;
711 int32_t *supportedIndexes;
712 int32_t supportedLSRsLength;
713 Locale *ownedDefaultLocale;
714 const Locale *defaultLocale;
719 #endif // U_SHOW_CPLUSPLUS_API
720 #endif // __LOCALEMATCHER_H__
struct UHashtable UHashtable
@ ULOCMATCH_DIRECTION_ONLY_TWO_WAY
Locale matching limited to two-way matches including e.g.
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, a signed-byte integer.
int32_t getSupportedIndex() const
Returns the index of the best-matching supported locale in the constructor’s or builder’s input order...
Builder & setDirection(ULocMatchDirection direction)
Option for whether to include or ignore one-way (fallback) match data.
C++ API: StringPiece: Read-only byte string wrapper class.
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.
@ 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.
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.
@ ULOCMATCH_FAVOR_LANGUAGE
Language differences are most important, then script differences, then region differences.
#define U_SUCCESS(x)
Does the error code indicate success?
Immutable class that picks the best match between a user's desired locales and an application's suppo...
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.
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.