[−][src]Struct icu::locid::Locale
Locale
is a core struct representing a Unicode Locale Identifier
.
A locale is made of two parts:
- Unicode Language Identifier
- A set of Unicode Extensions
Locale
exposes all of the same fields and methods as LanguageIdentifier
, and
on top of that is able to parse, manipulate and serialize unicode extension fields.
Examples
use icu_locid::Locale; use icu_locid::extensions::unicode::{Key, Value}; let loc: Locale = "en-US-u-ca-buddhist".parse() .expect("Failed to parse."); assert_eq!(loc.language, "en"); assert_eq!(loc.script, None); assert_eq!(loc.region, Some("US".parse().unwrap())); assert_eq!(loc.variants.len(), 0); assert_eq!(loc, "en-US-u-ca-buddhist"); let key: Key = "ca".parse().expect("Parsing key failed."); let value: Value = "buddhist".parse().expect("Parsing value failed."); assert_eq!(loc.extensions.unicode.keywords.get(key), Some(&value));
Parsing
Unicode recognizes three levels of standard conformance for a locale:
- well-formed - syntactically correct
- valid - well-formed and only uses registered language subtags, extensions, keywords, types...
- canonical - valid and no deprecated codes or structure.
At the moment parsing normalizes a well-formed locale 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::Locale; let loc: Locale = "eN_latn_Us-Valencia_u-hC-H12".parse() .expect("Failed to parse."); assert_eq!(loc.language, "en"); assert_eq!(loc.script, Some("Latn".parse().unwrap())); assert_eq!(loc.region, Some("US".parse().unwrap())); assert_eq!(loc.variants.get(0).unwrap(), "valencia");
Fields
language: Language
Language subtag of the Locale
script: Option<Script>
Script subtag of the Locale
region: Option<Region>
Region subtag of the Locale
variants: Variants
Variant subtags of the Locale
extensions: Extensions
Implementations
impl Locale
[src]
pub fn from_bytes(v: &[u8]) -> Result<Locale, ParserError>
[src]
A constructor which takes a utf8 slice, parses it and
produces a well-formed Locale
.
Examples
use icu_locid::Locale; let loc = Locale::from_bytes("en-US-u-hc-h12".as_bytes()) .expect("Parsing failed."); assert_eq!(loc.to_string(), "en-US-u-hc-h12");
pub fn canonicalize<S>(input: S) -> Result<String, ParserError> where
S: AsRef<[u8]>,
[src]
S: AsRef<[u8]>,
This is a best-effort operation that performs all available levels of canonicalization.
At the moment the operation will normalize casing and the separator, but in the future it may also validate and update from deprecated subtags to canonical ones.
Examples
use icu_locid::Locale; assert_eq!(Locale::canonicalize("pL_latn_pl-U-HC-H12"), Ok("pl-Latn-PL-u-hc-h12".to_string()));
Trait Implementations
impl Clone for Locale
[src]
impl Debug for Locale
[src]
impl Default for Locale
[src]
impl Display for Locale
[src]
impl Eq for Locale
[src]
impl From<LanguageIdentifier> for Locale
[src]
fn from(id: LanguageIdentifier) -> Locale
[src]
impl From<Locale> for LanguageIdentifier
[src]
fn from(loc: Locale) -> LanguageIdentifier
[src]
impl FromStr for Locale
[src]
type Err = ParserError
The associated error which can be returned from parsing.
fn from_str(source: &str) -> Result<Locale, <Locale as FromStr>::Err>
[src]
impl Hash for Locale
[src]
fn hash<__H>(&self, state: &mut __H) where
__H: Hasher,
[src]
__H: Hasher,
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl Ord for Locale
[src]
fn cmp(&self, other: &Locale) -> Ordering
[src]
#[must_use]fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn clamp(self, min: Self, max: Self) -> Self
[src]
impl<'_> PartialEq<&'_ str> for Locale
[src]
impl PartialEq<Locale> for Locale
[src]
impl PartialEq<str> for Locale
[src]
impl PartialOrd<Locale> for Locale
[src]
fn partial_cmp(&self, other: &Locale) -> Option<Ordering>
[src]
fn lt(&self, other: &Locale) -> bool
[src]
fn le(&self, other: &Locale) -> bool
[src]
fn gt(&self, other: &Locale) -> bool
[src]
fn ge(&self, other: &Locale) -> bool
[src]
impl StructuralEq for Locale
[src]
impl StructuralPartialEq for Locale
[src]
Auto Trait Implementations
impl RefUnwindSafe for Locale
impl Send for Locale
impl Sync for Locale
impl Unpin for Locale
impl UnwindSafe for Locale
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Downcast for T where
T: Any,
T: Any,
fn into_any(self: Box<T>) -> Box<dyn Any + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
fn as_any(&self) -> &(dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
impl<T> DowncastSync for T where
T: Send + Sync + Any,
T: Send + Sync + Any,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,