Struct unic_locale::extensions::TransformExtensionList
source · pub struct TransformExtensionList { /* private fields */ }
Expand description
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"]
);
Implementations§
source§impl TransformExtensionList
impl TransformExtensionList
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
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);
sourcepub fn tlang(&self) -> Option<&LanguageIdentifier>
pub fn tlang(&self) -> Option<&LanguageIdentifier>
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));
sourcepub fn set_tlang(
&mut self,
tlang: LanguageIdentifier
) -> Result<(), LocaleError>
pub fn set_tlang( &mut self, tlang: LanguageIdentifier ) -> Result<(), LocaleError>
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");
sourcepub fn clear_tlang(&mut self)
pub fn clear_tlang(&mut self)
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");
sourcepub fn tfield<S>(&self, tkey: S) -> Result<impl ExactSizeIterator, LocaleError>
pub fn tfield<S>(&self, tkey: S) -> Result<impl ExactSizeIterator, LocaleError>
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);
sourcepub fn tfield_keys(&self) -> impl ExactSizeIterator
pub fn tfield_keys(&self) -> impl ExactSizeIterator
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"]);
sourcepub fn set_tfield<S>(
&mut self,
tkey: S,
tvalue: &[S]
) -> Result<(), LocaleError>
pub fn set_tfield<S>( &mut self, tkey: S, tvalue: &[S] ) -> Result<(), LocaleError>
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");
sourcepub fn remove_tfield<S>(&mut self, tkey: S) -> Result<bool, LocaleError>
pub fn remove_tfield<S>(&mut self, tkey: S) -> Result<bool, LocaleError>
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");
sourcepub fn clear_tfields(&mut self)
pub fn clear_tfields(&mut self)
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§
source§impl Clone for TransformExtensionList
impl Clone for TransformExtensionList
source§fn clone(&self) -> TransformExtensionList
fn clone(&self) -> TransformExtensionList
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for TransformExtensionList
impl Debug for TransformExtensionList
source§impl Default for TransformExtensionList
impl Default for TransformExtensionList
source§fn default() -> TransformExtensionList
fn default() -> TransformExtensionList
source§impl Display for TransformExtensionList
impl Display for TransformExtensionList
source§impl Hash for TransformExtensionList
impl Hash for TransformExtensionList
source§impl Ord for TransformExtensionList
impl Ord for TransformExtensionList
source§fn cmp(&self, other: &TransformExtensionList) -> Ordering
fn cmp(&self, other: &TransformExtensionList) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl PartialEq for TransformExtensionList
impl PartialEq for TransformExtensionList
source§fn eq(&self, other: &TransformExtensionList) -> bool
fn eq(&self, other: &TransformExtensionList) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd for TransformExtensionList
impl PartialOrd for TransformExtensionList
source§fn partial_cmp(&self, other: &TransformExtensionList) -> Option<Ordering>
fn partial_cmp(&self, other: &TransformExtensionList) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more