// This file is part of ICU4X. For terms of use, please see the file // called LICENSE at the top level of the ICU4X source tree // (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). //! The collection of code for locale canonicalization. use crate::provider::*; use crate::LocaleTransformError; use alloc::vec::Vec; use core::cmp::Ordering; use crate::LocaleExpander; use crate::TransformResult; use icu_locid::subtags::{Language, Region, Script}; use icu_locid::{ extensions::unicode::key, subtags::{language, Variant, Variants}, LanguageIdentifier, Locale, }; use icu_provider::prelude::*; use tinystr::TinyAsciiStr; /// Implements the algorithm defined in *[UTS #35: Annex C, LocaleId Canonicalization]*. /// /// # Examples /// /// ``` /// use icu_locid::Locale; /// use icu_locid_transform::{LocaleCanonicalizer, TransformResult}; /// /// let lc = LocaleCanonicalizer::new(); /// /// let mut locale: Locale = "ja-Latn-fonipa-hepburn-heploc".parse().unwrap(); /// assert_eq!(lc.canonicalize(&mut locale), TransformResult::Modified); /// assert_eq!(locale, "ja-Latn-alalc97-fonipa".parse().unwrap()); /// ``` /// /// [UTS #35: Annex C, LocaleId Canonicalization]: http://unicode.org/reports/tr35/#LocaleId_Canonicalization #[derive(Debug)] pub struct LocaleCanonicalizer { /// Data to support canonicalization. aliases: DataPayload, /// Likely subtags implementation for delegation. expander: LocaleExpander, } #[inline] fn uts35_rule_matches<'a, I>( source: &Locale, language: Language, script: Option