Struct unic_locale_impl::extensions::UnicodeExtensionList
source · pub struct UnicodeExtensionList { /* private fields */ }
Expand description
A list of Unicode BCP47 U Extensions
as defined in Unicode Locale Identifier
specification.
Unicode extensions provide subtags that specify language and/or locale-based behavior
or refinements to language tags, according to work done by the Unicode Consortium.
(See RFC 6067
for details).
§Examples
use unic_locale_impl::Locale;
let mut loc: Locale = "de-u-hc-h12-ca-buddhist".parse()
.expect("Parsing failed.");
assert_eq!(loc.extensions.unicode.keyword("ca")
.expect("Getting keyword failed.")
.collect::<Vec<_>>(),
&["buddhist"]);
Implementations§
source§impl UnicodeExtensionList
impl UnicodeExtensionList
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true
if there are no keywords and no attributes in
the UnicodeExtensionList
.
§Examples
use unic_locale_impl::Locale;
let mut loc: Locale = "en-US-u-foo".parse()
.expect("Parsing failed.");
assert_eq!(loc.extensions.unicode.is_empty(), false);
sourcepub fn keyword<S: AsRef<[u8]>>(
&self,
key: S
) -> Result<impl ExactSizeIterator<Item = &str>, LocaleError>
pub fn keyword<S: AsRef<[u8]>>( &self, key: S ) -> Result<impl ExactSizeIterator<Item = &str>, LocaleError>
Returns the value of keyword in the UnicodeExtensionList
.
§Examples
use unic_locale_impl::Locale;
let mut loc: Locale = "en-US-u-ca-buddhist".parse()
.expect("Parsing failed.");
assert_eq!(loc.extensions.unicode.keyword("ca")
.expect("Getting keyword failed.")
.collect::<Vec<_>>(),
&["buddhist"]);
// Here keyword with key "aa" is not available
assert_eq!(loc.extensions.unicode.keyword("aa")
.expect("Getting keyword failed.")
.len(),
0);
sourcepub fn keyword_keys(&self) -> impl ExactSizeIterator<Item = &str>
pub fn keyword_keys(&self) -> impl ExactSizeIterator<Item = &str>
Returns an iterator over all keys in the UnicodeExtensionList
.
§Examples
use unic_locale_impl::Locale;
let mut loc: Locale = "en-US-u-ca-buddhist-nu-thai".parse()
.expect("Parsing failed.");
assert_eq!(loc.extensions.unicode.keyword_keys().collect::<Vec<_>>(),
&["ca", "nu"]);
sourcepub fn set_keyword<S: AsRef<[u8]>>(
&mut self,
key: S,
value: &[S]
) -> Result<(), LocaleError>
pub fn set_keyword<S: AsRef<[u8]>>( &mut self, key: S, value: &[S] ) -> Result<(), LocaleError>
Adds a keyword to the UnicodeExtensionList
or sets value for key if
keyword is already included in the UnicodeExtensionList
.
§Examples
use unic_locale_impl::Locale;
let mut loc: Locale = "en-US".parse()
.expect("Parsing failed.");
loc.extensions.unicode.set_keyword("ca", &["buddhist"])
.expect("Setting keyword failed.");
assert_eq!(loc.to_string(), "en-US-u-ca-buddhist");
loc.extensions.unicode.set_keyword("ca", &["chinese"])
.expect("Setting keyword failed.");
assert_eq!(loc.to_string(), "en-US-u-ca-chinese");
sourcepub fn remove_keyword<S: AsRef<[u8]>>(
&mut self,
key: S
) -> Result<bool, LocaleError>
pub fn remove_keyword<S: AsRef<[u8]>>( &mut self, key: S ) -> Result<bool, LocaleError>
Removes a keyword from the UnicodeExtensionList
.
Returns true
if keyword was included in the UnicodeExtensionList
before removal.
§Examples
use unic_locale_impl::Locale;
let mut loc: Locale = "en-US-u-ca-buddhist".parse()
.expect("Parsing failed.");
assert_eq!(loc.extensions.unicode.remove_keyword("ca")
.expect("Removing tag failed."),
true);
assert_eq!(loc.to_string(), "en-US");
sourcepub fn clear_keywords(&mut self)
pub fn clear_keywords(&mut self)
Clears all keywords from the UnicodeExtensionList
.
§Examples
use unic_locale_impl::Locale;
let mut loc: Locale = "en-US-u-ca-buddhist".parse()
.expect("Parsing failed.");
loc.extensions.unicode.clear_keywords();
assert_eq!(loc.to_string(), "en-US");
sourcepub fn has_attribute<S: AsRef<[u8]>>(
&self,
attribute: S
) -> Result<bool, LocaleError>
pub fn has_attribute<S: AsRef<[u8]>>( &self, attribute: S ) -> Result<bool, LocaleError>
Returns true
if attribute is included in the UnicodeExtensionList
.
§Examples
use unic_locale_impl::Locale;
let mut loc: Locale = "en-US-u-foo".parse()
.expect("Parsing failed.");
assert_eq!(loc.extensions.unicode.has_attribute("foo")
.expect("Getting attribute failed."),
true);
sourcepub fn attributes(&self) -> impl ExactSizeIterator<Item = &str>
pub fn attributes(&self) -> impl ExactSizeIterator<Item = &str>
Returns an iterator over all attributes in the UnicodeExtensionList
.
§Examples
use unic_locale_impl::Locale;
let mut loc: Locale = "en-US-u-foo-bar".parse()
.expect("Parsing failed.");
assert_eq!(loc.extensions.unicode.attributes().collect::<Vec<_>>(),
&["bar", "foo"]);
sourcepub fn set_attribute<S: AsRef<[u8]>>(
&mut self,
attribute: S
) -> Result<(), LocaleError>
pub fn set_attribute<S: AsRef<[u8]>>( &mut self, attribute: S ) -> Result<(), LocaleError>
Sets an attribute on the UnicodeExtensionList
.
§Examples
use unic_locale_impl::Locale;
let mut loc: Locale = "en-US".parse()
.expect("Parsing failed.");
loc.extensions.unicode.set_attribute("foo")
.expect("Setting attribute failed.");
assert_eq!(loc.to_string(), "en-US-u-foo");
sourcepub fn remove_attribute<S: AsRef<[u8]>>(
&mut self,
attribute: S
) -> Result<bool, LocaleError>
pub fn remove_attribute<S: AsRef<[u8]>>( &mut self, attribute: S ) -> Result<bool, LocaleError>
Removes an attribute from the UnicodeExtensionList
.
Returns true
if attribute was included in the UnicodeExtensionList
before removal.
§Examples
use unic_locale_impl::Locale;
let mut loc: Locale = "en-US-u-foo".parse()
.expect("Parsing failed.");
assert_eq!(loc.extensions.unicode.remove_attribute("foo")
.expect("Removing attribute failed."),
true);
assert_eq!(loc.to_string(), "en-US");
sourcepub fn clear_attributes(&mut self)
pub fn clear_attributes(&mut self)
Clears all attributes from the UnicodeExtensionList
.
§Examples
use unic_locale_impl::Locale;
let mut loc: Locale = "en-US-u-foo".parse()
.expect("Parsing failed.");
loc.extensions.unicode.clear_attributes();
assert_eq!(loc.to_string(), "en-US");
Trait Implementations§
source§impl Clone for UnicodeExtensionList
impl Clone for UnicodeExtensionList
source§fn clone(&self) -> UnicodeExtensionList
fn clone(&self) -> UnicodeExtensionList
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for UnicodeExtensionList
impl Debug for UnicodeExtensionList
source§impl Default for UnicodeExtensionList
impl Default for UnicodeExtensionList
source§fn default() -> UnicodeExtensionList
fn default() -> UnicodeExtensionList
source§impl Display for UnicodeExtensionList
impl Display for UnicodeExtensionList
source§impl Hash for UnicodeExtensionList
impl Hash for UnicodeExtensionList
source§impl Ord for UnicodeExtensionList
impl Ord for UnicodeExtensionList
source§fn cmp(&self, other: &UnicodeExtensionList) -> Ordering
fn cmp(&self, other: &UnicodeExtensionList) -> 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 UnicodeExtensionList
impl PartialEq for UnicodeExtensionList
source§fn eq(&self, other: &UnicodeExtensionList) -> bool
fn eq(&self, other: &UnicodeExtensionList) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd for UnicodeExtensionList
impl PartialOrd for UnicodeExtensionList
source§fn partial_cmp(&self, other: &UnicodeExtensionList) -> Option<Ordering>
fn partial_cmp(&self, other: &UnicodeExtensionList) -> 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