//! Other Use Extensions is a list of extensions other than unicode, //! transform or private. //! //! Those extensions are treated as a pass-through, and no Unicode related //! behavior depends on them. //! //! The main struct for this extension is [`Other`] which is a list of [`Subtag`]s. //! //! # Examples //! //! ``` //! use icu::locid::extensions::other::Other; //! use icu::locid::Locale; //! //! let mut loc: Locale = "en-US-a-foo-faa".parse().expect("Parsing failed."); //! ```
mod subtag;
usecrate::parser::ParserError; usecrate::parser::SubtagIterator; usecrate::shortvec::ShortBoxSlice; use alloc::vec::Vec; #[doc(inline)] pubuse subtag::{subtag, Subtag};
/// A list of [`Other Use Extensions`] as defined in [`Unicode Locale /// Identifier`] specification. /// /// Those extensions are treated as a pass-through, and no Unicode related /// behavior depends on them. /// /// # Examples /// /// ``` /// use icu::locid::extensions::other::{Other, Subtag}; /// /// let subtag1: Subtag = "foo".parse().expect("Failed to parse a Subtag."); /// let subtag2: Subtag = "bar".parse().expect("Failed to parse a Subtag."); /// /// let other = Other::from_vec_unchecked(b'a', vec![subtag1, subtag2]); /// assert_eq!(&other.to_string(), "a-foo-bar"); /// ``` /// /// [`Other Use Extensions`]: https://unicode.org/reports/tr35/#other_extensions /// [`Unicode Locale Identifier`]: https://unicode.org/reports/tr35/#Unicode_locale_identifier #[derive(Clone, PartialEq, Eq, Debug, Default, Hash, PartialOrd, Ord)] pubstruct Other {
ext: u8,
keys: ShortBoxSlice<Subtag>,
}
impl Other { /// A constructor which takes a pre-sorted list of [`Subtag`]. /// /// # Panics /// /// Panics if `ext` is not ASCII alphabetic. /// /// # Examples /// /// ``` /// use icu::locid::extensions::other::{Other, Subtag}; /// /// let subtag1: Subtag = "foo".parse().expect("Failed to parse a Subtag."); /// let subtag2: Subtag = "bar".parse().expect("Failed to parse a Subtag."); /// /// let other = Other::from_vec_unchecked(b'a', vec![subtag1, subtag2]); /// assert_eq!(&other.to_string(), "a-foo-bar"); /// ``` pubfn from_vec_unchecked(ext: u8, keys: Vec<Subtag>) -> Self { Self::from_short_slice_unchecked(ext, keys.into())
}
/// Gets the tag character for this extension as a &str. /// /// # Examples /// /// ``` /// use icu::locid::Locale; /// /// let loc: Locale = "und-a-hello-world".parse().unwrap(); /// let other_ext = &loc.extensions.other[0]; /// assert_eq!(other_ext.get_ext_str(), "a"); /// ``` pubfn get_ext_str(&self) -> &str {
debug_assert!(self.ext.is_ascii_alphabetic()); unsafe { core::str::from_utf8_unchecked(core::slice::from_ref(&self.ext)) }
}
/// Gets the tag character for this extension as a char. /// /// # Examples /// /// ``` /// use icu::locid::Locale; /// /// let loc: Locale = "und-a-hello-world".parse().unwrap(); /// let other_ext = &loc.extensions.other[0]; /// assert_eq!(other_ext.get_ext(), 'a'); /// ``` pubfn get_ext(&self) -> char { self.ext as char
}
/// Gets the tag character for this extension as a byte. /// /// # Examples /// /// ``` /// use icu::locid::Locale; /// /// let loc: Locale = "und-a-hello-world".parse().unwrap(); /// let other_ext = &loc.extensions.other[0]; /// assert_eq!(other_ext.get_ext_byte(), b'a'); /// ``` pubfn get_ext_byte(&self) -> u8 { self.ext
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.