Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/unicode/localematcher.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // © 2019 and later: Unicode, Inc. and others.
0002 // License & terms of use: http://www.unicode.org/copyright.html
0003 
0004 // localematcher.h
0005 // created: 2019may08 Markus W. Scherer
0006 
0007 #ifndef __LOCALEMATCHER_H__
0008 #define __LOCALEMATCHER_H__
0009 
0010 #include "unicode/utypes.h"
0011 
0012 #if U_SHOW_CPLUSPLUS_API
0013 
0014 #include "unicode/locid.h"
0015 #include "unicode/stringpiece.h"
0016 #include "unicode/uobject.h"
0017 
0018 /**
0019  * \file
0020  * \brief C++ API: Locale matcher: User's desired locales vs. application's supported locales.
0021  */
0022 
0023 /**
0024  * Builder option for whether the language subtag or the script subtag is most important.
0025  *
0026  * @see LocaleMatcher::Builder#setFavorSubtag(ULocMatchFavorSubtag)
0027  * @stable ICU 65
0028  */
0029 enum ULocMatchFavorSubtag {
0030     /**
0031      * Language differences are most important, then script differences, then region differences.
0032      * (This is the default behavior.)
0033      *
0034      * @stable ICU 65
0035      */
0036     ULOCMATCH_FAVOR_LANGUAGE,
0037     /**
0038      * Makes script differences matter relatively more than language differences.
0039      *
0040      * @stable ICU 65
0041      */
0042     ULOCMATCH_FAVOR_SCRIPT
0043 };
0044 #ifndef U_IN_DOXYGEN
0045 typedef enum ULocMatchFavorSubtag ULocMatchFavorSubtag;
0046 #endif
0047 
0048 /**
0049  * Builder option for whether all desired locales are treated equally or
0050  * earlier ones are preferred.
0051  *
0052  * @see LocaleMatcher::Builder#setDemotionPerDesiredLocale(ULocMatchDemotion)
0053  * @stable ICU 65
0054  */
0055 enum ULocMatchDemotion {
0056     /**
0057      * All desired locales are treated equally.
0058      *
0059      * @stable ICU 65
0060      */
0061     ULOCMATCH_DEMOTION_NONE,
0062     /**
0063      * Earlier desired locales are preferred.
0064      *
0065      * <p>From each desired locale to the next,
0066      * the distance to any supported locale is increased by an additional amount
0067      * which is at least as large as most region mismatches.
0068      * A later desired locale has to have a better match with some supported locale
0069      * due to more than merely having the same region subtag.
0070      *
0071      * <p>For example: <code>Supported={en, sv}  desired=[en-GB, sv]</code>
0072      * yields <code>Result(en-GB, en)</code> because
0073      * with the demotion of sv its perfect match is no better than
0074      * the region distance between the earlier desired locale en-GB and en=en-US.
0075      *
0076      * <p>Notes:
0077      * <ul>
0078      *   <li>In some cases, language and/or script differences can be as small as
0079      *       the typical region difference. (Example: sr-Latn vs. sr-Cyrl)
0080      *   <li>It is possible for certain region differences to be larger than usual,
0081      *       and larger than the demotion.
0082      *       (As of CLDR 35 there is no such case, but
0083      *        this is possible in future versions of the data.)
0084      * </ul>
0085      *
0086      * @stable ICU 65
0087      */
0088     ULOCMATCH_DEMOTION_REGION
0089 };
0090 #ifndef U_IN_DOXYGEN
0091 typedef enum ULocMatchDemotion ULocMatchDemotion;
0092 #endif
0093 
0094 /**
0095  * Builder option for whether to include or ignore one-way (fallback) match data.
0096  * The LocaleMatcher uses CLDR languageMatch data which includes fallback (oneway=true) entries.
0097  * Sometimes it is desirable to ignore those.
0098  *
0099  * <p>For example, consider a web application with the UI in a given language,
0100  * with a link to another, related web app.
0101  * The link should include the UI language, and the target server may also use
0102  * the client’s Accept-Language header data.
0103  * The target server has its own list of supported languages.
0104  * One may want to favor UI language consistency, that is,
0105  * if there is a decent match for the original UI language, we want to use it,
0106  * but not if it is merely a fallback.
0107  *
0108  * @see LocaleMatcher::Builder#setDirection(ULocMatchDirection)
0109  * @stable ICU 67
0110  */
0111 enum ULocMatchDirection {
0112     /**
0113      * Locale matching includes one-way matches such as Breton→French. (default)
0114      *
0115      * @stable ICU 67
0116      */
0117     ULOCMATCH_DIRECTION_WITH_ONE_WAY,
0118     /**
0119      * Locale matching limited to two-way matches including e.g. Danish↔Norwegian
0120      * but ignoring one-way matches.
0121      *
0122      * @stable ICU 67
0123      */
0124     ULOCMATCH_DIRECTION_ONLY_TWO_WAY
0125 };
0126 #ifndef U_IN_DOXYGEN
0127 typedef enum ULocMatchDirection ULocMatchDirection;
0128 #endif
0129 
0130 struct UHashtable;
0131 
0132 U_NAMESPACE_BEGIN
0133 
0134 struct LSR;
0135 
0136 class LocaleDistance;
0137 class LocaleLsrIterator;
0138 class UVector;
0139 class XLikelySubtags;
0140 
0141 /**
0142  * Immutable class that picks the best match between a user's desired locales and
0143  * an application's supported locales.
0144  * Movable but not copyable.
0145  *
0146  * <p>Example:
0147  * <pre>
0148  * UErrorCode errorCode = U_ZERO_ERROR;
0149  * LocaleMatcher matcher = LocaleMatcher::Builder().setSupportedLocales("fr, en-GB, en").build(errorCode);
0150  * Locale *bestSupported = matcher.getBestLocale(Locale.US, errorCode);  // "en"
0151  * </pre>
0152  *
0153  * <p>A matcher takes into account when languages are close to one another,
0154  * such as Danish and Norwegian,
0155  * and when regional variants are close, like en-GB and en-AU as opposed to en-US.
0156  *
0157  * <p>If there are multiple supported locales with the same (language, script, region)
0158  * likely subtags, then the current implementation returns the first of those locales.
0159  * It ignores variant subtags (except for pseudolocale variants) and extensions.
0160  * This may change in future versions.
0161  *
0162  * <p>For example, the current implementation does not distinguish between
0163  * de, de-DE, de-Latn, de-1901, de-u-co-phonebk.
0164  *
0165  * <p>If you prefer one equivalent locale over another, then provide only the preferred one,
0166  * or place it earlier in the list of supported locales.
0167  *
0168  * <p>Otherwise, the order of supported locales may have no effect on the best-match results.
0169  * The current implementation compares each desired locale with supported locales
0170  * in the following order:
0171  * 1. Default locale, if supported;
0172  * 2. CLDR "paradigm locales" like en-GB and es-419;
0173  * 3. other supported locales.
0174  * This may change in future versions.
0175  *
0176  * <p>Often a product will just need one matcher instance, built with the languages
0177  * that it supports. However, it may want multiple instances with different
0178  * default languages based on additional information, such as the domain.
0179  *
0180  * <p>This class is not intended for public subclassing.
0181  *
0182  * @stable ICU 65
0183  */
0184 class U_COMMON_API LocaleMatcher : public UMemory {
0185 public:
0186     /**
0187      * Data for the best-matching pair of a desired and a supported locale.
0188      * Movable but not copyable.
0189      *
0190      * @stable ICU 65
0191      */
0192     class U_COMMON_API Result : public UMemory {
0193     public:
0194         /**
0195          * Move constructor; might modify the source.
0196          * This object will have the same contents that the source object had.
0197          *
0198          * @param src Result to move contents from.
0199          * @stable ICU 65
0200          */
0201         Result(Result &&src) noexcept;
0202 
0203         /**
0204          * Destructor.
0205          *
0206          * @stable ICU 65
0207          */
0208         ~Result();
0209 
0210         /**
0211          * Move assignment; might modify the source.
0212          * This object will have the same contents that the source object had.
0213          *
0214          * @param src Result to move contents from.
0215          * @stable ICU 65
0216          */
0217         Result &operator=(Result &&src) noexcept;
0218 
0219         /**
0220          * Returns the best-matching desired locale.
0221          * nullptr if the list of desired locales is empty or if none matched well enough.
0222          *
0223          * @return the best-matching desired locale, or nullptr.
0224          * @stable ICU 65
0225          */
0226         inline const Locale *getDesiredLocale() const { return desiredLocale; }
0227 
0228         /**
0229          * Returns the best-matching supported locale.
0230          * If none matched well enough, this is the default locale.
0231          * The default locale is nullptr if Builder::setNoDefaultLocale() was called,
0232          * or if the list of supported locales is empty and no explicit default locale is set.
0233          *
0234          * @return the best-matching supported locale, or nullptr.
0235          * @stable ICU 65
0236          */
0237         inline const Locale *getSupportedLocale() const { return supportedLocale; }
0238 
0239         /**
0240          * Returns the index of the best-matching desired locale in the input Iterable order.
0241          * -1 if the list of desired locales is empty or if none matched well enough.
0242          *
0243          * @return the index of the best-matching desired locale, or -1.
0244          * @stable ICU 65
0245          */
0246         inline int32_t getDesiredIndex() const { return desiredIndex; }
0247 
0248         /**
0249          * Returns the index of the best-matching supported locale in the
0250          * constructor’s or builder’s input order (“set” Collection plus “added” locales).
0251          * If the matcher was built from a locale list string, then the iteration order is that
0252          * of a LocalePriorityList built from the same string.
0253          * -1 if the list of supported locales is empty or if none matched well enough.
0254          *
0255          * @return the index of the best-matching supported locale, or -1.
0256          * @stable ICU 65
0257          */
0258         inline int32_t getSupportedIndex() const { return supportedIndex; }
0259 
0260         /**
0261          * Takes the best-matching supported locale and adds relevant fields of the
0262          * best-matching desired locale, such as the -t- and -u- extensions.
0263          * May replace some fields of the supported locale.
0264          * The result is the locale that should be used for date and number formatting, collation, etc.
0265          * Returns the root locale if getSupportedLocale() returns nullptr.
0266          *
0267          * <p>Example: desired=ar-SA-u-nu-latn, supported=ar-EG, resolved locale=ar-SA-u-nu-latn
0268          *
0269          * @return a locale combining the best-matching desired and supported locales.
0270          * @stable ICU 65
0271          */
0272         Locale makeResolvedLocale(UErrorCode &errorCode) const;
0273 
0274     private:
0275         Result(const Locale *desired, const Locale *supported,
0276                int32_t desIndex, int32_t suppIndex, UBool owned) :
0277                 desiredLocale(desired), supportedLocale(supported),
0278                 desiredIndex(desIndex), supportedIndex(suppIndex),
0279                 desiredIsOwned(owned) {}
0280 
0281         Result(const Result &other) = delete;
0282         Result &operator=(const Result &other) = delete;
0283 
0284         const Locale *desiredLocale;
0285         const Locale *supportedLocale;
0286         int32_t desiredIndex;
0287         int32_t supportedIndex;
0288         UBool desiredIsOwned;
0289 
0290         friend class LocaleMatcher;
0291     };
0292 
0293     /**
0294      * LocaleMatcher builder.
0295      * Movable but not copyable.
0296      *
0297      * @stable ICU 65
0298      */
0299     class U_COMMON_API Builder : public UMemory {
0300     public:
0301         /**
0302          * Constructs a builder used in chaining parameters for building a LocaleMatcher.
0303          *
0304          * @return a new Builder object
0305          * @stable ICU 65
0306          */
0307         Builder() {}
0308 
0309         /**
0310          * Move constructor; might modify the source.
0311          * This builder will have the same contents that the source builder had.
0312          *
0313          * @param src Builder to move contents from.
0314          * @stable ICU 65
0315          */
0316         Builder(Builder &&src) noexcept;
0317 
0318         /**
0319          * Destructor.
0320          *
0321          * @stable ICU 65
0322          */
0323         ~Builder();
0324 
0325         /**
0326          * Move assignment; might modify the source.
0327          * This builder will have the same contents that the source builder had.
0328          *
0329          * @param src Builder to move contents from.
0330          * @stable ICU 65
0331          */
0332         Builder &operator=(Builder &&src) noexcept;
0333 
0334         /**
0335          * Parses an Accept-Language string
0336          * (<a href="https://tools.ietf.org/html/rfc2616#section-14.4">RFC 2616 Section 14.4</a>),
0337          * such as "af, en, fr;q=0.9", and sets the supported locales accordingly.
0338          * Allows whitespace in more places but does not allow "*".
0339          * Clears any previously set/added supported locales first.
0340          *
0341          * @param locales the Accept-Language string of locales to set
0342          * @return this Builder object
0343          * @stable ICU 65
0344          */
0345         Builder &setSupportedLocalesFromListString(StringPiece locales);
0346 
0347         /**
0348          * Copies the supported locales, preserving iteration order.
0349          * Clears any previously set/added supported locales first.
0350          * Duplicates are allowed, and are not removed.
0351          *
0352          * @param locales the list of locale
0353          * @return this Builder object
0354          * @stable ICU 65
0355          */
0356         Builder &setSupportedLocales(Locale::Iterator &locales);
0357 
0358         /**
0359          * Copies the supported locales from the begin/end range, preserving iteration order.
0360          * Clears any previously set/added supported locales first.
0361          * Duplicates are allowed, and are not removed.
0362          *
0363          * Each of the iterator parameter values must be an
0364          * input iterator whose value is convertible to const Locale &.
0365          *
0366          * @param begin Start of range.
0367          * @param end Exclusive end of range.
0368          * @return this Builder object
0369          * @stable ICU 65
0370          */
0371         template<typename Iter>
0372         Builder &setSupportedLocales(Iter begin, Iter end) {
0373             if (U_FAILURE(errorCode_)) { return *this; }
0374             clearSupportedLocales();
0375             while (begin != end) {
0376                 addSupportedLocale(*begin++);
0377             }
0378             return *this;
0379         }
0380 
0381         /**
0382          * Copies the supported locales from the begin/end range, preserving iteration order.
0383          * Calls the converter to convert each *begin to a Locale or const Locale &.
0384          * Clears any previously set/added supported locales first.
0385          * Duplicates are allowed, and are not removed.
0386          *
0387          * Each of the iterator parameter values must be an
0388          * input iterator whose value is convertible to const Locale &.
0389          *
0390          * @param begin Start of range.
0391          * @param end Exclusive end of range.
0392          * @param converter Converter from *begin to const Locale & or compatible.
0393          * @return this Builder object
0394          * @stable ICU 65
0395          */
0396         template<typename Iter, typename Conv>
0397         Builder &setSupportedLocalesViaConverter(Iter begin, Iter end, Conv converter) {
0398             if (U_FAILURE(errorCode_)) { return *this; }
0399             clearSupportedLocales();
0400             while (begin != end) {
0401                 addSupportedLocale(converter(*begin++));
0402             }
0403             return *this;
0404         }
0405 
0406         /**
0407          * Adds another supported locale.
0408          * Duplicates are allowed, and are not removed.
0409          *
0410          * @param locale another locale
0411          * @return this Builder object
0412          * @stable ICU 65
0413          */
0414         Builder &addSupportedLocale(const Locale &locale);
0415 
0416         /**
0417          * Sets no default locale.
0418          * There will be no explicit or implicit default locale.
0419          * If there is no good match, then the matcher will return nullptr for the
0420          * best supported locale.
0421          *
0422          * @stable ICU 68
0423          */
0424         Builder &setNoDefaultLocale();
0425 
0426         /**
0427          * Sets the default locale; if nullptr, or if it is not set explicitly,
0428          * then the first supported locale is used as the default locale.
0429          * There is no default locale at all (nullptr will be returned instead)
0430          * if setNoDefaultLocale() is called.
0431          *
0432          * @param defaultLocale the default locale (will be copied)
0433          * @return this Builder object
0434          * @stable ICU 65
0435          */
0436         Builder &setDefaultLocale(const Locale *defaultLocale);
0437 
0438         /**
0439          * If ULOCMATCH_FAVOR_SCRIPT, then the language differences are smaller than script
0440          * differences.
0441          * This is used in situations (such as maps) where
0442          * it is better to fall back to the same script than a similar language.
0443          *
0444          * @param subtag the subtag to favor
0445          * @return this Builder object
0446          * @stable ICU 65
0447          */
0448         Builder &setFavorSubtag(ULocMatchFavorSubtag subtag);
0449 
0450         /**
0451          * Option for whether all desired locales are treated equally or
0452          * earlier ones are preferred (this is the default).
0453          *
0454          * @param demotion the demotion per desired locale to set.
0455          * @return this Builder object
0456          * @stable ICU 65
0457          */
0458         Builder &setDemotionPerDesiredLocale(ULocMatchDemotion demotion);
0459 
0460         /**
0461          * Option for whether to include or ignore one-way (fallback) match data.
0462          * By default, they are included.
0463          *
0464          * @param matchDirection the match direction to set.
0465          * @return this Builder object
0466          * @stable ICU 67
0467          */
0468         Builder &setDirection(ULocMatchDirection matchDirection) {
0469             if (U_SUCCESS(errorCode_)) {
0470                 direction_ = matchDirection;
0471             }
0472             return *this;
0473         }
0474 
0475         /**
0476          * Sets the maximum distance for an acceptable match.
0477          * The matcher will return a match for a pair of locales only if
0478          * they match at least as well as the pair given here.
0479          *
0480          * For example, setMaxDistance(en-US, en-GB) limits matches to ones where the
0481          * (desired, support) locales have a distance no greater than a region subtag difference.
0482          * This is much stricter than the CLDR default.
0483          *
0484          * The details of locale matching are subject to changes in
0485          * CLDR data and in the algorithm.
0486          * Specifying a maximum distance in relative terms via a sample pair of locales
0487          * insulates from changes that affect all distance metrics similarly,
0488          * but some changes will necessarily affect relative distances between
0489          * different pairs of locales.
0490          *
0491          * @param desired the desired locale for distance comparison.
0492          * @param supported the supported locale for distance comparison.
0493          * @return this Builder object
0494          * @stable ICU 68
0495          */
0496         Builder &setMaxDistance(const Locale &desired, const Locale &supported);
0497 
0498         /**
0499          * Sets the UErrorCode if an error occurred while setting parameters.
0500          * Preserves older error codes in the outErrorCode.
0501          *
0502          * @param outErrorCode Set to an error code if it does not contain one already
0503          *                  and an error occurred while setting parameters.
0504          *                  Otherwise unchanged.
0505          * @return true if U_FAILURE(outErrorCode)
0506          * @stable ICU 65
0507          */
0508         UBool copyErrorTo(UErrorCode &outErrorCode) const;
0509 
0510         /**
0511          * Builds and returns a new locale matcher.
0512          * This builder can continue to be used.
0513          *
0514          * @param errorCode ICU error code. Its input value must pass the U_SUCCESS() test,
0515          *                  or else the function returns immediately. Check for U_FAILURE()
0516          *                  on output or use with function chaining. (See User Guide for details.)
0517          * @return LocaleMatcher
0518          * @stable ICU 65
0519          */
0520         LocaleMatcher build(UErrorCode &errorCode) const;
0521 
0522     private:
0523         friend class LocaleMatcher;
0524 
0525         Builder(const Builder &other) = delete;
0526         Builder &operator=(const Builder &other) = delete;
0527 
0528         void clearSupportedLocales();
0529         bool ensureSupportedLocaleVector();
0530 
0531         UErrorCode errorCode_ = U_ZERO_ERROR;
0532         UVector *supportedLocales_ = nullptr;
0533         int32_t thresholdDistance_ = -1;
0534         ULocMatchDemotion demotion_ = ULOCMATCH_DEMOTION_REGION;
0535         Locale *defaultLocale_ = nullptr;
0536         bool withDefault_ = true;
0537         ULocMatchFavorSubtag favor_ = ULOCMATCH_FAVOR_LANGUAGE;
0538         ULocMatchDirection direction_ = ULOCMATCH_DIRECTION_WITH_ONE_WAY;
0539         Locale *maxDistanceDesired_ = nullptr;
0540         Locale *maxDistanceSupported_ = nullptr;
0541     };
0542 
0543     // FYI No public LocaleMatcher constructors in C++; use the Builder.
0544 
0545     /**
0546      * Move copy constructor; might modify the source.
0547      * This matcher will have the same settings that the source matcher had.
0548      * @param src source matcher
0549      * @stable ICU 65
0550      */
0551     LocaleMatcher(LocaleMatcher &&src) noexcept;
0552 
0553     /**
0554      * Destructor.
0555      * @stable ICU 65
0556      */
0557     ~LocaleMatcher();
0558 
0559     /**
0560      * Move assignment operator; might modify the source.
0561      * This matcher will have the same settings that the source matcher had.
0562      * The behavior is undefined if *this and src are the same object.
0563      * @param src source matcher
0564      * @return *this
0565      * @stable ICU 65
0566      */
0567     LocaleMatcher &operator=(LocaleMatcher &&src) noexcept;
0568 
0569     /**
0570      * Returns the supported locale which best matches the desired locale.
0571      *
0572      * @param desiredLocale Typically a user's language.
0573      * @param errorCode ICU error code. Its input value must pass the U_SUCCESS() test,
0574      *                  or else the function returns immediately. Check for U_FAILURE()
0575      *                  on output or use with function chaining. (See User Guide for details.)
0576      * @return the best-matching supported locale.
0577      * @stable ICU 65
0578      */
0579     const Locale *getBestMatch(const Locale &desiredLocale, UErrorCode &errorCode) const;
0580 
0581     /**
0582      * Returns the supported locale which best matches one of the desired locales.
0583      *
0584      * @param desiredLocales Typically a user's languages, in order of preference (descending).
0585      * @param errorCode ICU error code. Its input value must pass the U_SUCCESS() test,
0586      *                  or else the function returns immediately. Check for U_FAILURE()
0587      *                  on output or use with function chaining. (See User Guide for details.)
0588      * @return the best-matching supported locale.
0589      * @stable ICU 65
0590      */
0591     const Locale *getBestMatch(Locale::Iterator &desiredLocales, UErrorCode &errorCode) const;
0592 
0593     /**
0594      * Parses an Accept-Language string
0595      * (<a href="https://tools.ietf.org/html/rfc2616#section-14.4">RFC 2616 Section 14.4</a>),
0596      * such as "af, en, fr;q=0.9",
0597      * and returns the supported locale which best matches one of the desired locales.
0598      * Allows whitespace in more places but does not allow "*".
0599      *
0600      * @param desiredLocaleList Typically a user's languages, as an Accept-Language string.
0601      * @param errorCode ICU error code. Its input value must pass the U_SUCCESS() test,
0602      *                  or else the function returns immediately. Check for U_FAILURE()
0603      *                  on output or use with function chaining. (See User Guide for details.)
0604      * @return the best-matching supported locale.
0605      * @stable ICU 65
0606      */
0607     const Locale *getBestMatchForListString(StringPiece desiredLocaleList, UErrorCode &errorCode) const;
0608 
0609     /**
0610      * Returns the best match between the desired locale and the supported locales.
0611      * If the result's desired locale is not nullptr, then it is the address of the input locale.
0612      * It has not been cloned.
0613      *
0614      * @param desiredLocale Typically a user's language.
0615      * @param errorCode ICU error code. Its input value must pass the U_SUCCESS() test,
0616      *                  or else the function returns immediately. Check for U_FAILURE()
0617      *                  on output or use with function chaining. (See User Guide for details.)
0618      * @return the best-matching pair of the desired and a supported locale.
0619      * @stable ICU 65
0620      */
0621     Result getBestMatchResult(const Locale &desiredLocale, UErrorCode &errorCode) const;
0622 
0623     /**
0624      * Returns the best match between the desired and supported locales.
0625      * If the result's desired locale is not nullptr, then it is a clone of
0626      * the best-matching desired locale. The Result object owns the clone.
0627      *
0628      * @param desiredLocales Typically a user's languages, in order of preference (descending).
0629      * @param errorCode ICU error code. Its input value must pass the U_SUCCESS() test,
0630      *                  or else the function returns immediately. Check for U_FAILURE()
0631      *                  on output or use with function chaining. (See User Guide for details.)
0632      * @return the best-matching pair of a desired and a supported locale.
0633      * @stable ICU 65
0634      */
0635     Result getBestMatchResult(Locale::Iterator &desiredLocales, UErrorCode &errorCode) const;
0636 
0637     /**
0638      * Returns true if the pair of locales matches acceptably.
0639      * This is influenced by Builder options such as setDirection(), setFavorSubtag(),
0640      * and setMaxDistance().
0641      *
0642      * @param desired The desired locale.
0643      * @param supported The supported locale.
0644      * @param errorCode ICU error code. Its input value must pass the U_SUCCESS() test,
0645      *                  or else the function returns immediately. Check for U_FAILURE()
0646      *                  on output or use with function chaining. (See User Guide for details.)
0647      * @return true if the pair of locales matches acceptably.
0648      * @stable ICU 68
0649      */
0650     UBool isMatch(const Locale &desired, const Locale &supported, UErrorCode &errorCode) const;
0651 
0652 #ifndef U_HIDE_INTERNAL_API
0653     /**
0654      * Returns a fraction between 0 and 1, where 1 means that the languages are a
0655      * perfect match, and 0 means that they are completely different.
0656      *
0657      * <p>This is mostly an implementation detail, and the precise values may change over time.
0658      * The implementation may use either the maximized forms or the others ones, or both.
0659      * The implementation may or may not rely on the forms to be consistent with each other.
0660      *
0661      * <p>Callers should construct and use a matcher rather than match pairs of locales directly.
0662      *
0663      * @param desired Desired locale.
0664      * @param supported Supported locale.
0665      * @param errorCode ICU error code. Its input value must pass the U_SUCCESS() test,
0666      *                  or else the function returns immediately. Check for U_FAILURE()
0667      *                  on output or use with function chaining. (See User Guide for details.)
0668      * @return value between 0 and 1, inclusive.
0669      * @internal (has a known user)
0670      */
0671     double internalMatch(const Locale &desired, const Locale &supported, UErrorCode &errorCode) const;
0672 #endif  // U_HIDE_INTERNAL_API
0673 
0674 private:
0675     LocaleMatcher(const Builder &builder, UErrorCode &errorCode);
0676     LocaleMatcher(const LocaleMatcher &other) = delete;
0677     LocaleMatcher &operator=(const LocaleMatcher &other) = delete;
0678 
0679     int32_t putIfAbsent(const LSR &lsr, int32_t i, int32_t suppLength, UErrorCode &errorCode);
0680 
0681     int32_t getBestSuppIndex(LSR desiredLSR, LocaleLsrIterator *remainingIter, UErrorCode &errorCode) const;
0682 
0683     const XLikelySubtags &likelySubtags;
0684     const LocaleDistance &localeDistance;
0685     int32_t thresholdDistance;
0686     int32_t demotionPerDesiredLocale;
0687     ULocMatchFavorSubtag favorSubtag;
0688     ULocMatchDirection direction;
0689 
0690     // These are in input order.
0691     const Locale ** supportedLocales;
0692     LSR *lsrs;
0693     int32_t supportedLocalesLength;
0694     // These are in preference order: 1. Default locale 2. paradigm locales 3. others.
0695     UHashtable *supportedLsrToIndex;  // Map<LSR, Integer>
0696     // Array versions of the supportedLsrToIndex keys and values.
0697     // The distance lookup loops over the supportedLSRs and returns the index of the best match.
0698     const LSR **supportedLSRs;
0699     int32_t *supportedIndexes;
0700     int32_t supportedLSRsLength;
0701     Locale *ownedDefaultLocale;
0702     const Locale *defaultLocale;
0703 };
0704 
0705 U_NAMESPACE_END
0706 
0707 #endif  // U_SHOW_CPLUSPLUS_API
0708 #endif  // __LOCALEMATCHER_H__