[][src]Struct unic_locale_impl::extensions::TransformExtensionList

pub struct TransformExtensionList { /* fields omitted */ }

A list of Unicode BCP47 T Extensions as defined in Unicode Locale Identifier specification.

Transform extension carries information about source language or script of transformed content, including content that has been transliterated, transcribed, or translated, or in some other way influenced by the source (See RFC 6497 for details).

Examples

use unic_locale_impl::{Locale, LanguageIdentifier};

let mut loc: Locale = "de-t-en-US-h0-hybrid".parse()
    .expect("Parsing failed.");

let en_us: LanguageIdentifier = "en-US".parse()
    .expect("Parsing failed.");

assert_eq!(loc.extensions.transform.tlang(), Some(&en_us));
assert_eq!(
    loc.extensions.transform.tfield("h0")
                            .expect("Getting tfield failed.")
                            .collect::<Vec<_>>(),
    &["hybrid"]
);

Methods

impl TransformExtensionList[src]

pub fn is_empty(&self) -> bool[src]

Returns true if there are no tfields and no tlang in the TransformExtensionList.

Examples

use unic_locale_impl::Locale;

let mut loc: Locale = "en-US-t-es-AR".parse()
    .expect("Parsing failed.");

assert_eq!(loc.extensions.transform.is_empty(), false);

pub fn tlang(&self) -> Option<&LanguageIdentifier>[src]

Gets tlang from the TransformExtensionList.

Examples

use unic_locale_impl::Locale;
use unic_langid_impl::LanguageIdentifier;

let mut loc: Locale = "en-US-t-es-AR".parse()
    .expect("Parsing failed.");

let tlang: LanguageIdentifier = "es-AR".parse()
    .expect("Parsing failed on tlang.");

assert_eq!(loc.extensions.transform.tlang(), Some(&tlang));

pub fn set_tlang(
    &mut self,
    tlang: LanguageIdentifier
) -> Result<(), LocaleError>
[src]

Sets tlang on the TransformExtensionList.

Examples

use unic_locale_impl::Locale;
use unic_langid_impl::LanguageIdentifier;

let mut loc: Locale = "en-US".parse()
    .expect("Parsing failed.");

let tlang: LanguageIdentifier = "es-AR".parse()
    .expect("Parsing failed on tlang.");

loc.extensions.transform.set_tlang(tlang)
    .expect("Setting tlang failed.");

assert_eq!(loc.to_string(), "en-US-t-es-AR");

pub fn clear_tlang(&mut self)[src]

Clears tlang on the TransformExtensionList.

Examples

use unic_locale_impl::Locale;
use unic_langid_impl::LanguageIdentifier;

let mut loc: Locale = "en-US-t-es-AR".parse()
    .expect("Parsing failed.");

loc.extensions.transform.clear_tlang();

assert_eq!(loc.to_string(), "en-US");

pub fn tfield<S: AsRef<[u8]>>(
    &self,
    tkey: S
) -> Result<impl ExactSizeIterator<Item = &str>, LocaleError>
[src]

Returns the tvalue of tfield in the TransformExtensionList.

Examples

use unic_locale_impl::Locale;

let mut loc: Locale = "en-US-t-k0-dvorak".parse()
    .expect("Parsing failed.");

assert_eq!(loc.extensions.transform.tfield("k0")
               .expect("Getting tfield failed.")
               .collect::<Vec<_>>(),
           &["dvorak"]);

// Here tfield with tkey "m0" is not available
assert_eq!(loc.extensions.transform.tfield("m0")
               .expect("Getting tfield failed.")
               .collect::<Vec<_>>()
               .is_empty(),
           true);

pub fn tfield_keys(&self) -> impl ExactSizeIterator<Item = &str>[src]

Returns an iterator over all tkeys in the TransformExtensionList.

Examples

use unic_locale_impl::Locale;

let mut loc: Locale = "en-US-t-k0-dvorak-h0-hybrid".parse()
    .expect("Parsing failed.");

assert_eq!(loc.extensions.transform.tfield_keys().collect::<Vec<_>>(),
           &["h0", "k0"]);

pub fn set_tfield<S: AsRef<[u8]>>(
    &mut self,
    tkey: S,
    tvalue: &[S]
) -> Result<(), LocaleError>
[src]

Adds a tfield to the TransformExtensionList or sets tvalue for tkey if tfield is already included in the TransformExtensionList.

Examples

use unic_locale_impl::Locale;

let mut loc: Locale = "en-US".parse()
    .expect("Parsing failed.");

loc.extensions.transform.set_tfield("k0", &["dvorak"])
    .expect("Setting tfield failed.");

assert_eq!(loc.to_string(), "en-US-t-k0-dvorak");

loc.extensions.transform.set_tfield("k0", &["colemak"])
    .expect("Setting tfield failed.");

assert_eq!(loc.to_string(), "en-US-t-k0-colemak");

pub fn remove_tfield<S: AsRef<[u8]>>(
    &mut self,
    tkey: S
) -> Result<bool, LocaleError>
[src]

Removes a tfield from the TransformExtensionList.

Returns true if tfield was included in the TransformExtensionList before removal.

Examples

use unic_locale_impl::Locale;

let mut loc: Locale = "en-US-t-k0-dvorak".parse()
    .expect("Parsing failed.");

assert_eq!(loc.extensions.transform.remove_tfield("k0")
               .expect("Removing tfield failed."),
           true);

assert_eq!(loc.to_string(), "en-US");

pub fn clear_tfields(&mut self)[src]

Clears all tfields from the TransformExtensionList.

Examples

use unic_locale_impl::Locale;

let mut loc: Locale = "en-US-t-k0-dvorak".parse()
    .expect("Parsing failed.");

loc.extensions.transform.clear_tfields();
assert_eq!(loc.to_string(), "en-US");

Trait Implementations

impl Clone for TransformExtensionList[src]

impl Debug for TransformExtensionList[src]

impl Default for TransformExtensionList[src]

impl Display for TransformExtensionList[src]

impl Eq for TransformExtensionList[src]

impl Hash for TransformExtensionList[src]

impl Ord for TransformExtensionList[src]

impl PartialEq<TransformExtensionList> for TransformExtensionList[src]

impl PartialOrd<TransformExtensionList> for TransformExtensionList[src]

impl StructuralEq for TransformExtensionList[src]

impl StructuralPartialEq for TransformExtensionList[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.