1 // © 2019 and later: Unicode, Inc. and others. 2 // License & terms of use: http://www.unicode.org/copyright.html 3 4 // localematcher.h 5 // created: 2019may08 Markus W. Scherer 6 7 #ifndef __LOCALEMATCHER_H__ 8 #define __LOCALEMATCHER_H__ 9 10 #include "unicode/utypes.h" 11 12 #if U_SHOW_CPLUSPLUS_API 13 14 #include "unicode/locid.h" 15 #include "unicode/stringpiece.h" 16 #include "unicode/uobject.h" 17 18 /** 19 * \file 20 * \brief C++ API: Locale matcher: User's desired locales vs. application's supported locales. 21 */ 22 23 /** 24 * Builder option for whether the language subtag or the script subtag is most important. 25 * 26 * @see LocaleMatcher::Builder#setFavorSubtag(ULocMatchFavorSubtag) 27 * @stable ICU 65 28 */ 29 enum ULocMatchFavorSubtag { 30 /** 31 * Language differences are most important, then script differences, then region differences. 32 * (This is the default behavior.) 33 * 34 * @stable ICU 65 35 */ 36 ULOCMATCH_FAVOR_LANGUAGE, 37 /** 38 * Makes script differences matter relatively more than language differences. 39 * 40 * @stable ICU 65 41 */ 42 ULOCMATCH_FAVOR_SCRIPT 43 }; 44 #ifndef U_IN_DOXYGEN 45 typedef enum ULocMatchFavorSubtag ULocMatchFavorSubtag; 46 #endif 47 48 /** 49 * Builder option for whether all desired locales are treated equally or 50 * earlier ones are preferred. 51 * 52 * @see LocaleMatcher::Builder#setDemotionPerDesiredLocale(ULocMatchDemotion) 53 * @stable ICU 65 54 */ 55 enum ULocMatchDemotion { 56 /** 57 * All desired locales are treated equally. 58 * 59 * @stable ICU 65 60 */ 61 ULOCMATCH_DEMOTION_NONE, 62 /** 63 * Earlier desired locales are preferred. 64 * 65 * <p>From each desired locale to the next, 66 * the distance to any supported locale is increased by an additional amount 67 * which is at least as large as most region mismatches. 68 * A later desired locale has to have a better match with some supported locale 69 * due to more than merely having the same region subtag. 70 * 71 * <p>For example: <code>Supported={en, sv} desired=[en-GB, sv]</code> 72 * yields <code>Result(en-GB, en)</code> because 73 * with the demotion of sv its perfect match is no better than 74 * the region distance between the earlier desired locale en-GB and en=en-US. 75 * 76 * <p>Notes: 77 * <ul> 78 * <li>In some cases, language and/or script differences can be as small as 79 * the typical region difference. (Example: sr-Latn vs. sr-Cyrl) 80 * <li>It is possible for certain region differences to be larger than usual, 81 * and larger than the demotion. 82 * (As of CLDR 35 there is no such case, but 83 * this is possible in future versions of the data.) 84 * </ul> 85 * 86 * @stable ICU 65 87 */ 88 ULOCMATCH_DEMOTION_REGION 89 }; 90 #ifndef U_IN_DOXYGEN 91 typedef enum ULocMatchDemotion ULocMatchDemotion; 92 #endif 93 94 /** 95 * Builder option for whether to include or ignore one-way (fallback) match data. 96 * The LocaleMatcher uses CLDR languageMatch data which includes fallback (oneway=true) entries. 97 * Sometimes it is desirable to ignore those. 98 * 99 * <p>For example, consider a web application with the UI in a given language, 100 * with a link to another, related web app. 101 * The link should include the UI language, and the target server may also use 102 * the client’s Accept-Language header data. 103 * The target server has its own list of supported languages. 104 * One may want to favor UI language consistency, that is, 105 * if there is a decent match for the original UI language, we want to use it, 106 * but not if it is merely a fallback. 107 * 108 * @see LocaleMatcher::Builder#setDirection(ULocMatchDirection) 109 * @stable ICU 67 110 */ 111 enum ULocMatchDirection { 112 /** 113 * Locale matching includes one-way matches such as Breton→French. (default) 114 * 115 * @stable ICU 67 116 */ 117 ULOCMATCH_DIRECTION_WITH_ONE_WAY, 118 /** 119 * Locale matching limited to two-way matches including e.g. Danish↔Norwegian 120 * but ignoring one-way matches. 121 * 122 * @stable ICU 67 123 */ 124 ULOCMATCH_DIRECTION_ONLY_TWO_WAY 125 }; 126 #ifndef U_IN_DOXYGEN 127 typedef enum ULocMatchDirection ULocMatchDirection; 128 #endif 129 130 struct UHashtable; 131 132 U_NAMESPACE_BEGIN 133 134 struct LSR; 135 136 class LocaleDistance; 137 class LocaleLsrIterator; 138 class UVector; 139 class XLikelySubtags; 140 141 /** 142 * Immutable class that picks the best match between a user's desired locales and 143 * an application's supported locales. 144 * Movable but not copyable. 145 * 146 * <p>Example: 147 * <pre> 148 * UErrorCode errorCode = U_ZERO_ERROR; 149 * LocaleMatcher matcher = LocaleMatcher::Builder().setSupportedLocales("fr, en-GB, en").build(errorCode); 150 * Locale *bestSupported = matcher.getBestLocale(Locale.US, errorCode); // "en" 151 * </pre> 152 * 153 * <p>A matcher takes into account when languages are close to one another, 154 * such as Danish and Norwegian, 155 * and when regional variants are close, like en-GB and en-AU as opposed to en-US. 156 * 157 * <p>If there are multiple supported locales with the same (language, script, region) 158 * likely subtags, then the current implementation returns the first of those locales. 159 * It ignores variant subtags (except for pseudolocale variants) and extensions. 160 * This may change in future versions. 161 * 162 * <p>For example, the current implementation does not distinguish between 163 * de, de-DE, de-Latn, de-1901, de-u-co-phonebk. 164 * 165 * <p>If you prefer one equivalent locale over another, then provide only the preferred one, 166 * or place it earlier in the list of supported locales. 167 * 168 * <p>Otherwise, the order of supported locales may have no effect on the best-match results. 169 * The current implementation compares each desired locale with supported locales 170 * in the following order: 171 * 1. Default locale, if supported; 172 * 2. CLDR "paradigm locales" like en-GB and es-419; 173 * 3. other supported locales. 174 * This may change in future versions. 175 * 176 * <p>Often a product will just need one matcher instance, built with the languages 177 * that it supports. However, it may want multiple instances with different 178 * default languages based on additional information, such as the domain. 179 * 180 * <p>This class is not intended for public subclassing. 181 * 182 * @stable ICU 65 183 */ 184 class U_COMMON_API LocaleMatcher : public UMemory { 185 public: 186 /** 187 * Data for the best-matching pair of a desired and a supported locale. 188 * Movable but not copyable. 189 * 190 * @stable ICU 65 191 */ 192 class U_COMMON_API Result : public UMemory { 193 public: 194 /** 195 * Move constructor; might modify the source. 196 * This object will have the same contents that the source object had. 197 * 198 * @param src Result to move contents from. 199 * @stable ICU 65 200 */ 201 Result(Result &&src) U_NOEXCEPT; 202 203 /** 204 * Destructor. 205 * 206 * @stable ICU 65 207 */ 208 ~Result(); 209 210 /** 211 * Move assignment; might modify the source. 212 * This object will have the same contents that the source object had. 213 * 214 * @param src Result to move contents from. 215 * @stable ICU 65 216 */ 217 Result &operator=(Result &&src) U_NOEXCEPT; 218 219 /** 220 * Returns the best-matching desired locale. 221 * nullptr if the list of desired locales is empty or if none matched well enough. 222 * 223 * @return the best-matching desired locale, or nullptr. 224 * @stable ICU 65 225 */ getDesiredLocale()226 inline const Locale *getDesiredLocale() const { return desiredLocale; } 227 228 /** 229 * Returns the best-matching supported locale. 230 * If none matched well enough, this is the default locale. 231 * The default locale is nullptr if Builder::setNoDefaultLocale() was called, 232 * or if the list of supported locales is empty and no explicit default locale is set. 233 * 234 * @return the best-matching supported locale, or nullptr. 235 * @stable ICU 65 236 */ getSupportedLocale()237 inline const Locale *getSupportedLocale() const { return supportedLocale; } 238 239 /** 240 * Returns the index of the best-matching desired locale in the input Iterable order. 241 * -1 if the list of desired locales is empty or if none matched well enough. 242 * 243 * @return the index of the best-matching desired locale, or -1. 244 * @stable ICU 65 245 */ getDesiredIndex()246 inline int32_t getDesiredIndex() const { return desiredIndex; } 247 248 /** 249 * Returns the index of the best-matching supported locale in the 250 * constructor’s or builder’s input order (“set” Collection plus “added” locales). 251 * If the matcher was built from a locale list string, then the iteration order is that 252 * of a LocalePriorityList built from the same string. 253 * -1 if the list of supported locales is empty or if none matched well enough. 254 * 255 * @return the index of the best-matching supported locale, or -1. 256 * @stable ICU 65 257 */ getSupportedIndex()258 inline int32_t getSupportedIndex() const { return supportedIndex; } 259 260 /** 261 * Takes the best-matching supported locale and adds relevant fields of the 262 * best-matching desired locale, such as the -t- and -u- extensions. 263 * May replace some fields of the supported locale. 264 * The result is the locale that should be used for date and number formatting, collation, etc. 265 * Returns the root locale if getSupportedLocale() returns nullptr. 266 * 267 * <p>Example: desired=ar-SA-u-nu-latn, supported=ar-EG, resolved locale=ar-SA-u-nu-latn 268 * 269 * @return a locale combining the best-matching desired and supported locales. 270 * @stable ICU 65 271 */ 272 Locale makeResolvedLocale(UErrorCode &errorCode) const; 273 274 private: Result(const Locale * desired,const Locale * supported,int32_t desIndex,int32_t suppIndex,UBool owned)275 Result(const Locale *desired, const Locale *supported, 276 int32_t desIndex, int32_t suppIndex, UBool owned) : 277 desiredLocale(desired), supportedLocale(supported), 278 desiredIndex(desIndex), supportedIndex(suppIndex), 279 desiredIsOwned(owned) {} 280 281 Result(const Result &other) = delete; 282 Result &operator=(const Result &other) = delete; 283 284 const Locale *desiredLocale; 285 const Locale *supportedLocale; 286 int32_t desiredIndex; 287 int32_t supportedIndex; 288 UBool desiredIsOwned; 289 290 friend class LocaleMatcher; 291 }; 292 293 /** 294 * LocaleMatcher builder. 295 * Movable but not copyable. 296 * 297 * @stable ICU 65 298 */ 299 class U_COMMON_API Builder : public UMemory { 300 public: 301 /** 302 * Constructs a builder used in chaining parameters for building a LocaleMatcher. 303 * 304 * @return a new Builder object 305 * @stable ICU 65 306 */ Builder()307 Builder() {} 308 309 /** 310 * Move constructor; might modify the source. 311 * This builder will have the same contents that the source builder had. 312 * 313 * @param src Builder to move contents from. 314 * @stable ICU 65 315 */ 316 Builder(Builder &&src) U_NOEXCEPT; 317 318 /** 319 * Destructor. 320 * 321 * @stable ICU 65 322 */ 323 ~Builder(); 324 325 /** 326 * Move assignment; might modify the source. 327 * This builder will have the same contents that the source builder had. 328 * 329 * @param src Builder to move contents from. 330 * @stable ICU 65 331 */ 332 Builder &operator=(Builder &&src) U_NOEXCEPT; 333 334 /** 335 * Parses an Accept-Language string 336 * (<a href="https://tools.ietf.org/html/rfc2616#section-14.4">RFC 2616 Section 14.4</a>), 337 * such as "af, en, fr;q=0.9", and sets the supported locales accordingly. 338 * Allows whitespace in more places but does not allow "*". 339 * Clears any previously set/added supported locales first. 340 * 341 * @param locales the Accept-Language string of locales to set 342 * @return this Builder object 343 * @stable ICU 65 344 */ 345 Builder &setSupportedLocalesFromListString(StringPiece locales); 346 347 /** 348 * Copies the supported locales, preserving iteration order. 349 * Clears any previously set/added supported locales first. 350 * Duplicates are allowed, and are not removed. 351 * 352 * @param locales the list of locale 353 * @return this Builder object 354 * @stable ICU 65 355 */ 356 Builder &setSupportedLocales(Locale::Iterator &locales); 357 358 /** 359 * Copies the supported locales from the begin/end range, preserving iteration order. 360 * Clears any previously set/added supported locales first. 361 * Duplicates are allowed, and are not removed. 362 * 363 * Each of the iterator parameter values must be an 364 * input iterator whose value is convertible to const Locale &. 365 * 366 * @param begin Start of range. 367 * @param end Exclusive end of range. 368 * @return this Builder object 369 * @stable ICU 65 370 */ 371 template<typename Iter> setSupportedLocales(Iter begin,Iter end)372 Builder &setSupportedLocales(Iter begin, Iter end) { 373 if (U_FAILURE(errorCode_)) { return *this; } 374 clearSupportedLocales(); 375 while (begin != end) { 376 addSupportedLocale(*begin++); 377 } 378 return *this; 379 } 380 381 /** 382 * Copies the supported locales from the begin/end range, preserving iteration order. 383 * Calls the converter to convert each *begin to a Locale or const Locale &. 384 * Clears any previously set/added supported locales first. 385 * Duplicates are allowed, and are not removed. 386 * 387 * Each of the iterator parameter values must be an 388 * input iterator whose value is convertible to const Locale &. 389 * 390 * @param begin Start of range. 391 * @param end Exclusive end of range. 392 * @param converter Converter from *begin to const Locale & or compatible. 393 * @return this Builder object 394 * @stable ICU 65 395 */ 396 template<typename Iter, typename Conv> setSupportedLocalesViaConverter(Iter begin,Iter end,Conv converter)397 Builder &setSupportedLocalesViaConverter(Iter begin, Iter end, Conv converter) { 398 if (U_FAILURE(errorCode_)) { return *this; } 399 clearSupportedLocales(); 400 while (begin != end) { 401 addSupportedLocale(converter(*begin++)); 402 } 403 return *this; 404 } 405 406 /** 407 * Adds another supported locale. 408 * Duplicates are allowed, and are not removed. 409 * 410 * @param locale another locale 411 * @return this Builder object 412 * @stable ICU 65 413 */ 414 Builder &addSupportedLocale(const Locale &locale); 415 416 #ifndef U_HIDE_DRAFT_API 417 /** 418 * Sets no default locale. 419 * There will be no explicit or implicit default locale. 420 * If there is no good match, then the matcher will return nullptr for the 421 * best supported locale. 422 * 423 * @draft ICU 68 424 */ 425 Builder &setNoDefaultLocale(); 426 #endif // U_HIDE_DRAFT_API 427 428 /** 429 * Sets the default locale; if nullptr, or if it is not set explicitly, 430 * then the first supported locale is used as the default locale. 431 * There is no default locale at all (nullptr will be returned instead) 432 * if setNoDefaultLocale() is called. 433 * 434 * @param defaultLocale the default locale (will be copied) 435 * @return this Builder object 436 * @stable ICU 65 437 */ 438 Builder &setDefaultLocale(const Locale *defaultLocale); 439 440 /** 441 * If ULOCMATCH_FAVOR_SCRIPT, then the language differences are smaller than script 442 * differences. 443 * This is used in situations (such as maps) where 444 * it is better to fall back to the same script than a similar language. 445 * 446 * @param subtag the subtag to favor 447 * @return this Builder object 448 * @stable ICU 65 449 */ 450 Builder &setFavorSubtag(ULocMatchFavorSubtag subtag); 451 452 /** 453 * Option for whether all desired locales are treated equally or 454 * earlier ones are preferred (this is the default). 455 * 456 * @param demotion the demotion per desired locale to set. 457 * @return this Builder object 458 * @stable ICU 65 459 */ 460 Builder &setDemotionPerDesiredLocale(ULocMatchDemotion demotion); 461 462 /** 463 * Option for whether to include or ignore one-way (fallback) match data. 464 * By default, they are included. 465 * 466 * @param direction the match direction to set. 467 * @return this Builder object 468 * @stable ICU 67 469 */ setDirection(ULocMatchDirection direction)470 Builder &setDirection(ULocMatchDirection direction) { 471 if (U_SUCCESS(errorCode_)) { 472 direction_ = direction; 473 } 474 return *this; 475 } 476 477 #ifndef U_HIDE_DRAFT_API 478 /** 479 * Sets the maximum distance for an acceptable match. 480 * The matcher will return a match for a pair of locales only if 481 * they match at least as well as the pair given here. 482 * 483 * For example, setMaxDistance(en-US, en-GB) limits matches to ones where the 484 * (desired, support) locales have a distance no greater than a region subtag difference. 485 * This is much stricter than the CLDR default. 486 * 487 * The details of locale matching are subject to changes in 488 * CLDR data and in the algorithm. 489 * Specifying a maximum distance in relative terms via a sample pair of locales 490 * insulates from changes that affect all distance metrics similarly, 491 * but some changes will necessarily affect relative distances between 492 * different pairs of locales. 493 * 494 * @param desired the desired locale for distance comparison. 495 * @param supported the supported locale for distance comparison. 496 * @return this Builder object 497 * @draft ICU 68 498 */ 499 Builder &setMaxDistance(const Locale &desired, const Locale &supported); 500 #endif // U_HIDE_DRAFT_API 501 502 /** 503 * Sets the UErrorCode if an error occurred while setting parameters. 504 * Preserves older error codes in the outErrorCode. 505 * 506 * @param outErrorCode Set to an error code if it does not contain one already 507 * and an error occurred while setting parameters. 508 * Otherwise unchanged. 509 * @return true if U_FAILURE(outErrorCode) 510 * @stable ICU 65 511 */ 512 UBool copyErrorTo(UErrorCode &outErrorCode) const; 513 514 /** 515 * Builds and returns a new locale matcher. 516 * This builder can continue to be used. 517 * 518 * @param errorCode ICU error code. Its input value must pass the U_SUCCESS() test, 519 * or else the function returns immediately. Check for U_FAILURE() 520 * on output or use with function chaining. (See User Guide for details.) 521 * @return LocaleMatcher 522 * @stable ICU 65 523 */ 524 LocaleMatcher build(UErrorCode &errorCode) const; 525 526 private: 527 friend class LocaleMatcher; 528 529 Builder(const Builder &other) = delete; 530 Builder &operator=(const Builder &other) = delete; 531 532 void clearSupportedLocales(); 533 bool ensureSupportedLocaleVector(); 534 535 UErrorCode errorCode_ = U_ZERO_ERROR; 536 UVector *supportedLocales_ = nullptr; 537 int32_t thresholdDistance_ = -1; 538 ULocMatchDemotion demotion_ = ULOCMATCH_DEMOTION_REGION; 539 Locale *defaultLocale_ = nullptr; 540 bool withDefault_ = true; 541 ULocMatchFavorSubtag favor_ = ULOCMATCH_FAVOR_LANGUAGE; 542 ULocMatchDirection direction_ = ULOCMATCH_DIRECTION_WITH_ONE_WAY; 543 Locale *maxDistanceDesired_ = nullptr; 544 Locale *maxDistanceSupported_ = nullptr; 545 }; 546 547 // FYI No public LocaleMatcher constructors in C++; use the Builder. 548 549 /** 550 * Move copy constructor; might modify the source. 551 * This matcher will have the same settings that the source matcher had. 552 * @param src source matcher 553 * @stable ICU 65 554 */ 555 LocaleMatcher(LocaleMatcher &&src) U_NOEXCEPT; 556 557 /** 558 * Destructor. 559 * @stable ICU 65 560 */ 561 ~LocaleMatcher(); 562 563 /** 564 * Move assignment operator; might modify the source. 565 * This matcher will have the same settings that the source matcher had. 566 * The behavior is undefined if *this and src are the same object. 567 * @param src source matcher 568 * @return *this 569 * @stable ICU 65 570 */ 571 LocaleMatcher &operator=(LocaleMatcher &&src) U_NOEXCEPT; 572 573 /** 574 * Returns the supported locale which best matches the desired locale. 575 * 576 * @param desiredLocale Typically a user's language. 577 * @param errorCode ICU error code. Its input value must pass the U_SUCCESS() test, 578 * or else the function returns immediately. Check for U_FAILURE() 579 * on output or use with function chaining. (See User Guide for details.) 580 * @return the best-matching supported locale. 581 * @stable ICU 65 582 */ 583 const Locale *getBestMatch(const Locale &desiredLocale, UErrorCode &errorCode) const; 584 585 /** 586 * Returns the supported locale which best matches one of the desired locales. 587 * 588 * @param desiredLocales Typically a user's languages, in order of preference (descending). 589 * @param errorCode ICU error code. Its input value must pass the U_SUCCESS() test, 590 * or else the function returns immediately. Check for U_FAILURE() 591 * on output or use with function chaining. (See User Guide for details.) 592 * @return the best-matching supported locale. 593 * @stable ICU 65 594 */ 595 const Locale *getBestMatch(Locale::Iterator &desiredLocales, UErrorCode &errorCode) const; 596 597 /** 598 * Parses an Accept-Language string 599 * (<a href="https://tools.ietf.org/html/rfc2616#section-14.4">RFC 2616 Section 14.4</a>), 600 * such as "af, en, fr;q=0.9", 601 * and returns the supported locale which best matches one of the desired locales. 602 * Allows whitespace in more places but does not allow "*". 603 * 604 * @param desiredLocaleList Typically a user's languages, as an Accept-Language string. 605 * @param errorCode ICU error code. Its input value must pass the U_SUCCESS() test, 606 * or else the function returns immediately. Check for U_FAILURE() 607 * on output or use with function chaining. (See User Guide for details.) 608 * @return the best-matching supported locale. 609 * @stable ICU 65 610 */ 611 const Locale *getBestMatchForListString(StringPiece desiredLocaleList, UErrorCode &errorCode) const; 612 613 /** 614 * Returns the best match between the desired locale and the supported locales. 615 * If the result's desired locale is not nullptr, then it is the address of the input locale. 616 * It has not been cloned. 617 * 618 * @param desiredLocale Typically a user's language. 619 * @param errorCode ICU error code. Its input value must pass the U_SUCCESS() test, 620 * or else the function returns immediately. Check for U_FAILURE() 621 * on output or use with function chaining. (See User Guide for details.) 622 * @return the best-matching pair of the desired and a supported locale. 623 * @stable ICU 65 624 */ 625 Result getBestMatchResult(const Locale &desiredLocale, UErrorCode &errorCode) const; 626 627 /** 628 * Returns the best match between the desired and supported locales. 629 * If the result's desired locale is not nullptr, then it is a clone of 630 * the best-matching desired locale. The Result object owns the clone. 631 * 632 * @param desiredLocales Typically a user's languages, in order of preference (descending). 633 * @param errorCode ICU error code. Its input value must pass the U_SUCCESS() test, 634 * or else the function returns immediately. Check for U_FAILURE() 635 * on output or use with function chaining. (See User Guide for details.) 636 * @return the best-matching pair of a desired and a supported locale. 637 * @stable ICU 65 638 */ 639 Result getBestMatchResult(Locale::Iterator &desiredLocales, UErrorCode &errorCode) const; 640 641 #ifndef U_HIDE_DRAFT_API 642 /** 643 * Returns true if the pair of locales matches acceptably. 644 * This is influenced by Builder options such as setDirection(), setFavorSubtag(), 645 * and setMaxDistance(). 646 * 647 * @param desired The desired locale. 648 * @param supported The supported locale. 649 * @param errorCode ICU error code. Its input value must pass the U_SUCCESS() test, 650 * or else the function returns immediately. Check for U_FAILURE() 651 * on output or use with function chaining. (See User Guide for details.) 652 * @return true if the pair of locales matches acceptably. 653 * @draft ICU 68 654 */ 655 UBool isMatch(const Locale &desired, const Locale &supported, UErrorCode &errorCode) const; 656 #endif // U_HIDE_DRAFT_API 657 658 #ifndef U_HIDE_INTERNAL_API 659 /** 660 * Returns a fraction between 0 and 1, where 1 means that the languages are a 661 * perfect match, and 0 means that they are completely different. 662 * 663 * <p>This is mostly an implementation detail, and the precise values may change over time. 664 * The implementation may use either the maximized forms or the others ones, or both. 665 * The implementation may or may not rely on the forms to be consistent with each other. 666 * 667 * <p>Callers should construct and use a matcher rather than match pairs of locales directly. 668 * 669 * @param desired Desired locale. 670 * @param supported Supported locale. 671 * @param errorCode ICU error code. Its input value must pass the U_SUCCESS() test, 672 * or else the function returns immediately. Check for U_FAILURE() 673 * on output or use with function chaining. (See User Guide for details.) 674 * @return value between 0 and 1, inclusive. 675 * @internal (has a known user) 676 */ 677 double internalMatch(const Locale &desired, const Locale &supported, UErrorCode &errorCode) const; 678 #endif // U_HIDE_INTERNAL_API 679 680 private: 681 LocaleMatcher(const Builder &builder, UErrorCode &errorCode); 682 LocaleMatcher(const LocaleMatcher &other) = delete; 683 LocaleMatcher &operator=(const LocaleMatcher &other) = delete; 684 685 int32_t putIfAbsent(const LSR &lsr, int32_t i, int32_t suppLength, UErrorCode &errorCode); 686 687 int32_t getBestSuppIndex(LSR desiredLSR, LocaleLsrIterator *remainingIter, UErrorCode &errorCode) const; 688 689 const XLikelySubtags &likelySubtags; 690 const LocaleDistance &localeDistance; 691 int32_t thresholdDistance; 692 int32_t demotionPerDesiredLocale; 693 ULocMatchFavorSubtag favorSubtag; 694 ULocMatchDirection direction; 695 696 // These are in input order. 697 const Locale ** supportedLocales; 698 LSR *lsrs; 699 int32_t supportedLocalesLength; 700 // These are in preference order: 1. Default locale 2. paradigm locales 3. others. 701 UHashtable *supportedLsrToIndex; // Map<LSR, Integer> 702 // Array versions of the supportedLsrToIndex keys and values. 703 // The distance lookup loops over the supportedLSRs and returns the index of the best match. 704 const LSR **supportedLSRs; 705 int32_t *supportedIndexes; 706 int32_t supportedLSRsLength; 707 Locale *ownedDefaultLocale; 708 const Locale *defaultLocale; 709 }; 710 711 U_NAMESPACE_END 712 713 #endif // U_SHOW_CPLUSPLUS_API 714 #endif // __LOCALEMATCHER_H__ 715