// 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 ). use core::cmp::Ordering; use core::str::FromStr; use crate::ordering::SubtagOrderingResult; use crate::parser::{ get_subtag_iterator, parse_language_identifier, parse_language_identifier_with_single_variant, ParserError, ParserMode, }; use crate::subtags; use alloc::string::String; use alloc::string::ToString; /// A core struct representing a [`Unicode BCP47 Language Identifier`]. /// /// # Examples /// /// ``` /// use icu::locid::{subtags::*, LanguageIdentifier}; /// /// let li: LanguageIdentifier = "en-US".parse().expect("Failed to parse."); /// /// assert_eq!(li.language, "en".parse::().unwrap()); /// assert_eq!(li.script, None); /// assert_eq!(li.region.unwrap(), "US".parse::().unwrap()); /// assert_eq!(li.variants.len(), 0); /// assert_eq!(li.to_string(), "en-US"); /// ``` /// /// # Parsing /// /// Unicode recognizes three levels of standard conformance for any language identifier: /// /// * *well-formed* - syntactically correct /// * *valid* - well-formed and only uses registered language, region, script and variant subtags... /// * *canonical* - valid and no deprecated codes or structure. /// /// At the moment parsing normalizes a well-formed language identifier converting /// `_` separators to `-` and adjusting casing to conform to the Unicode standard. /// /// Any bogus subtags will cause the parsing to fail with an error. /// No subtag validation is performed. /// /// # Examples /// /// ``` /// use icu::locid::{subtags::*, LanguageIdentifier}; /// /// let li: LanguageIdentifier = /// "eN_latn_Us-Valencia".parse().expect("Failed to parse."); /// /// assert_eq!(li.language, "en".parse::().unwrap()); /// assert_eq!(li.script, "Latn".parse::