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>(&self, key: S) -> Result<impl ExactSizeIterator, LocaleError>
pub fn keyword<S>(&self, key: S) -> Result<impl ExactSizeIterator, 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
pub fn keyword_keys(&self) -> impl ExactSizeIterator
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>(&mut self, key: S, value: &[S]) -> Result<(), LocaleError>
pub fn set_keyword<S>(&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>(&mut self, key: S) -> Result<bool, LocaleError>
pub fn remove_keyword<S>(&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>(&self, attribute: S) -> Result<bool, LocaleError>
pub fn has_attribute<S>(&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
pub fn attributes(&self) -> impl ExactSizeIterator
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>(&mut self, attribute: S) -> Result<(), LocaleError>
pub fn set_attribute<S>(&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>(&mut self, attribute: S) -> Result<bool, LocaleError>
pub fn remove_attribute<S>(&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 more