[−][src]Struct icu_locid::LanguageIdentifier
LanguageIdentifier
is a core struct representing a Unicode BCP47 Language Identifier
.
Examples
use icu_locid::LanguageIdentifier; let li: LanguageIdentifier = "en-US".parse() .expect("Failed to parse."); assert_eq!(li.language, "en"); assert_eq!(li.script, None); assert_eq!(li.region.unwrap(), "US"); assert_eq!(li.variants.len(), 0); assert_eq!(li, "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::LanguageIdentifier; let li: LanguageIdentifier = "eN_latn_Us-Valencia".parse() .expect("Failed to parse."); assert_eq!(li.language, "en"); assert_eq!(li.script.unwrap(), "Latn"); assert_eq!(li.region.unwrap(), "US"); assert_eq!(li.variants.get(0).unwrap(), "valencia");
Fields
language: Language
Language subtag of the LanguageIdentifier
script: Option<Script>
Script subtag of the LanguageIdentifier
region: Option<Region>
Region subtag of the LanguageIdentifier
variants: Variants
Variant subtags of the LanguageIdentifier
Implementations
impl LanguageIdentifier
[src]
pub fn from_bytes(v: &[u8]) -> Result<Self, ParserError>
[src]
A constructor which takes a utf8 slice, parses it and
produces a well-formed LanguageIdentifier
.
Examples
use icu_locid::LanguageIdentifier; let li = LanguageIdentifier::from_bytes(b"en-US") .expect("Parsing failed."); assert_eq!(li.to_string(), "en-US");
pub fn from_locale_bytes(v: &[u8]) -> Result<Self, ParserError>
[src]
A constructor which takes a utf8 slice which may contain extension keys,
parses it and produces a well-formed LanguageIdentifier
.
Examples
use icu_locid::LanguageIdentifier; let li = LanguageIdentifier::from_locale_bytes(b"en-US-x-posix") .expect("Parsing failed."); assert_eq!(li.to_string(), "en-US");
This method should be used for input that may be a locale identifier. All extensions will be lost.
pub fn canonicalize<S: AsRef<[u8]>>(input: S) -> Result<String, ParserError>
[src]
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::LanguageIdentifier; assert_eq!(LanguageIdentifier::canonicalize("pL_latn_pl"), Ok("pl-Latn-PL".to_string()));
Trait Implementations
impl Clone for LanguageIdentifier
[src]
fn clone(&self) -> LanguageIdentifier
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for LanguageIdentifier
[src]
impl Default for LanguageIdentifier
[src]
fn default() -> LanguageIdentifier
[src]
impl Display for LanguageIdentifier
[src]
impl Eq for LanguageIdentifier
[src]
impl From<LanguageIdentifier> for Locale
[src]
fn from(id: LanguageIdentifier) -> Self
[src]
impl From<Locale> for LanguageIdentifier
[src]
impl FromStr for LanguageIdentifier
[src]
type Err = ParserError
The associated error which can be returned from parsing.
fn from_str(source: &str) -> Result<Self, Self::Err>
[src]
impl Hash for LanguageIdentifier
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl Ord for LanguageIdentifier
[src]
fn cmp(&self, other: &LanguageIdentifier) -> 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 LanguageIdentifier
[src]
impl PartialEq<LanguageIdentifier> for LanguageIdentifier
[src]
fn eq(&self, other: &LanguageIdentifier) -> bool
[src]
fn ne(&self, other: &LanguageIdentifier) -> bool
[src]
impl PartialEq<str> for LanguageIdentifier
[src]
impl PartialOrd<LanguageIdentifier> for LanguageIdentifier
[src]
fn partial_cmp(&self, other: &LanguageIdentifier) -> Option<Ordering>
[src]
fn lt(&self, other: &LanguageIdentifier) -> bool
[src]
fn le(&self, other: &LanguageIdentifier) -> bool
[src]
fn gt(&self, other: &LanguageIdentifier) -> bool
[src]
fn ge(&self, other: &LanguageIdentifier) -> bool
[src]
impl StructuralEq for LanguageIdentifier
[src]
impl StructuralPartialEq for LanguageIdentifier
[src]
Auto Trait Implementations
impl RefUnwindSafe for LanguageIdentifier
impl Send for LanguageIdentifier
impl Sync for LanguageIdentifier
impl Unpin for LanguageIdentifier
impl UnwindSafe for LanguageIdentifier
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> 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>,