summaryrefslogtreecommitdiffstats
path: root/vendor/icu_locid/src/extensions/unicode
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/icu_locid/src/extensions/unicode')
-rw-r--r--vendor/icu_locid/src/extensions/unicode/attributes.rs15
-rw-r--r--vendor/icu_locid/src/extensions/unicode/keywords.rs65
-rw-r--r--vendor/icu_locid/src/extensions/unicode/mod.rs46
-rw-r--r--vendor/icu_locid/src/extensions/unicode/value.rs33
4 files changed, 83 insertions, 76 deletions
diff --git a/vendor/icu_locid/src/extensions/unicode/attributes.rs b/vendor/icu_locid/src/extensions/unicode/attributes.rs
index 1f9536bfa..e58fb04da 100644
--- a/vendor/icu_locid/src/extensions/unicode/attributes.rs
+++ b/vendor/icu_locid/src/extensions/unicode/attributes.rs
@@ -79,18 +79,19 @@ impl Attributes {
///
/// ```
/// use icu::locid::extensions::unicode::{Attribute, Attributes};
+ /// use icu::locid::extensions_unicode_attribute as attribute;
+ /// use writeable::assert_writeable_eq;
///
- /// let attribute1: Attribute = "foobar".parse().expect("Parsing failed.");
- /// let attribute2: Attribute = "testing".parse().expect("Parsing failed.");
- /// let mut v = vec![attribute1, attribute2];
- ///
- /// let mut attributes: Attributes = Attributes::from_vec_unchecked(v);
+ /// let mut attributes = Attributes::from_vec_unchecked(vec![
+ /// attribute!("foobar"),
+ /// attribute!("testing"),
+ /// ]);
///
- /// assert_eq!(attributes.to_string(), "foobar-testing");
+ /// assert_writeable_eq!(attributes, "foobar-testing");
///
/// attributes.clear();
///
- /// assert_eq!(attributes.to_string(), "");
+ /// assert_writeable_eq!(attributes, "");
/// ```
pub fn clear(&mut self) -> Self {
core::mem::take(self)
diff --git a/vendor/icu_locid/src/extensions/unicode/keywords.rs b/vendor/icu_locid/src/extensions/unicode/keywords.rs
index dc9a15921..580cacaf1 100644
--- a/vendor/icu_locid/src/extensions/unicode/keywords.rs
+++ b/vendor/icu_locid/src/extensions/unicode/keywords.rs
@@ -29,11 +29,14 @@ use crate::ordering::SubtagOrderingResult;
/// Manually build up a [`Keywords`] object:
///
/// ```
-/// use icu::locid::extensions::unicode::{Key, Keywords, Value};
+/// use icu::locid::{
+/// extensions::unicode::Keywords, extensions_unicode_key as key,
+/// extensions_unicode_value as value, locale,
+/// };
///
-/// let key: Key = "hc".parse().expect("Failed to parse a Key.");
-/// let value: Value = "h23".parse().expect("Failed to parse a Value.");
-/// let keywords: Keywords = vec![(key, value)].into_iter().collect();
+/// let keywords = vec![(key!("hc"), value!("h23"))]
+/// .into_iter()
+/// .collect::<Keywords>();
///
/// assert_eq!(&keywords.to_string(), "hc-h23");
/// ```
@@ -113,15 +116,16 @@ impl Keywords {
/// # Examples
///
/// ```
- /// use icu::locid::extensions::unicode::{Key, Keywords, Value};
- /// use litemap::LiteMap;
+ /// use icu::locid::{
+ /// extensions::unicode::Keywords, extensions_unicode_key as key,
+ /// extensions_unicode_value as value,
+ /// };
///
- /// let key: Key = "ca".parse().expect("Failed to parse a Key.");
- /// let value: Value = "gregory".parse().expect("Failed to parse a Value.");
- /// let keywords: Keywords = vec![(key, value)].into_iter().collect();
+ /// let keywords = vec![(key!("ca"), value!("gregory"))]
+ /// .into_iter()
+ /// .collect::<Keywords>();
///
- /// let key: Key = "ca".parse().expect("Failed to parse a Key.");
- /// assert!(&keywords.contains_key(&key));
+ /// assert!(&keywords.contains_key(&key!("ca")));
/// ```
pub fn contains_key<Q>(&self, key: &Q) -> bool
where
@@ -137,17 +141,16 @@ impl Keywords {
/// # Examples
///
/// ```
- /// use icu::locid::extensions::unicode::{Key, Keywords, Value};
+ /// use icu::locid::{
+ /// extensions::unicode::Keywords, extensions_unicode_key as key,
+ /// extensions_unicode_value as value,
+ /// };
///
- /// let key: Key = "ca".parse().expect("Failed to parse a Key.");
- /// let value: Value = "buddhist".parse().expect("Failed to parse a Value.");
- /// let keywords: Keywords = vec![(key, value)].into_iter().collect();
+ /// let keywords = vec![(key!("ca"), value!("buddhist"))]
+ /// .into_iter()
+ /// .collect::<Keywords>();
///
- /// let key: Key = "ca".parse().expect("Failed to parse a Key.");
- /// assert_eq!(
- /// keywords.get(&key).map(|v| v.to_string()),
- /// Some("buddhist".to_string())
- /// );
+ /// assert_eq!(keywords.get(&key!("ca")), Some(&value!("buddhist")));
/// ```
pub fn get<Q>(&self, key: &Q) -> Option<&Value>
where
@@ -164,20 +167,19 @@ impl Keywords {
/// # Examples
///
/// ```
- /// use icu::locid::extensions::unicode::{Key, Keywords, Value};
+ /// use icu::locid::{
+ /// extensions::unicode::Keywords, extensions_unicode_key as key,
+ /// extensions_unicode_value as value,
+ /// };
///
- /// let key: Key = "ca".parse().expect("Failed to parse a Key.");
- /// let value: Value = "buddhist".parse().expect("Failed to parse a Value.");
- /// let mut keywords: Keywords = vec![(key, value)].into_iter().collect();
+ /// let mut keywords = vec![(key!("ca"), value!("buddhist"))]
+ /// .into_iter()
+ /// .collect::<Keywords>();
///
- /// let key: Key = "ca".parse().expect("Failed to parse a Key.");
- /// if let Some(value) = keywords.get_mut(&key) {
- /// *value = "gregory".parse().expect("Failed to parse a Value.");
+ /// if let Some(value) = keywords.get_mut(&key!("ca")) {
+ /// *value = value!("gregory");
/// }
- /// assert_eq!(
- /// keywords.get(&key).map(|v| v.to_string()),
- /// Some("gregory".to_string())
- /// );
+ /// assert_eq!(keywords.get(&key!("ca")), Some(&value!("gregory")));
/// ```
pub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut Value>
where
@@ -308,7 +310,6 @@ impl Keywords {
/// .extensions
/// .unicode
/// .keywords;
- /// assert_eq!(a, a_kwds.to_string());
/// assert!(a_kwds.strict_cmp(a.as_bytes()) == Ordering::Equal);
/// assert!(a_kwds.strict_cmp(b.as_bytes()) == Ordering::Less);
/// }
diff --git a/vendor/icu_locid/src/extensions/unicode/mod.rs b/vendor/icu_locid/src/extensions/unicode/mod.rs
index fabf1036c..687a8c383 100644
--- a/vendor/icu_locid/src/extensions/unicode/mod.rs
+++ b/vendor/icu_locid/src/extensions/unicode/mod.rs
@@ -11,21 +11,24 @@
//! # Examples
//!
//! ```
-//! use icu::locid::extensions::unicode::{Attribute, Key, Unicode, Value};
-//! use icu::locid::{LanguageIdentifier, Locale};
+//! use icu::locid::Locale;
+//! use icu::locid::{
+//! extensions::unicode::Unicode,
+//! extensions_unicode_attribute as attribute,
+//! extensions_unicode_key as key, extensions_unicode_value as value,
+//! };
//!
-//! let mut loc: Locale =
-//! "en-US-u-foobar-hc-h12".parse().expect("Parsing failed.");
+//! let loc: Locale = "en-US-u-foobar-hc-h12".parse().expect("Parsing failed.");
//!
-//! let key: Key = "hc".parse().expect("Parsing key failed.");
-//! let value: Value = "h12".parse().expect("Parsing value failed.");
-//! let attribute: Attribute =
-//! "foobar".parse().expect("Parsing attribute failed.");
-//!
-//! assert_eq!(loc.extensions.unicode.keywords.get(&key), Some(&value));
-//! assert!(loc.extensions.unicode.attributes.contains(&attribute));
-//!
-//! assert_eq!(&loc.extensions.unicode.to_string(), "-u-foobar-hc-h12");
+//! assert_eq!(
+//! loc.extensions.unicode.keywords.get(&key!("hc")),
+//! Some(&value!("h12"))
+//! );
+//! assert!(loc
+//! .extensions
+//! .unicode
+//! .attributes
+//! .contains(&attribute!("foobar")));
//! ```
mod attribute;
mod attributes;
@@ -60,15 +63,18 @@ use litemap::LiteMap;
/// # Examples
///
/// ```
-/// use icu::locid::extensions::unicode::{Key, Value};
/// use icu::locid::Locale;
+/// use icu::locid::{
+/// extensions_unicode_key as key, extensions_unicode_value as value,
+/// };
///
-/// let mut loc: Locale =
+/// let loc: Locale =
/// "de-u-hc-h12-ca-buddhist".parse().expect("Parsing failed.");
///
-/// let key: Key = "ca".parse().expect("Parsing key failed.");
-/// let value: Value = "buddhist".parse().expect("Parsing value failed.");
-/// assert_eq!(loc.extensions.unicode.keywords.get(&key), Some(&value));
+/// assert_eq!(
+/// loc.extensions.unicode.keywords.get(&key!("ca")),
+/// Some(&value!("buddhist"))
+/// );
/// ```
#[derive(Clone, PartialEq, Eq, Debug, Default, Hash, PartialOrd, Ord)]
#[allow(clippy::exhaustive_structs)] // spec-backed stable datastructure
@@ -205,7 +211,7 @@ impl writeable::Writeable for Unicode {
if self.is_empty() {
return Ok(());
}
- sink.write_str("-u")?;
+ sink.write_str("u")?;
if !self.attributes.is_empty() {
sink.write_char('-')?;
writeable::Writeable::write_to(&self.attributes, sink)?;
@@ -221,7 +227,7 @@ impl writeable::Writeable for Unicode {
if self.is_empty() {
return writeable::LengthHint::exact(0);
}
- let mut result = writeable::LengthHint::exact(2);
+ let mut result = writeable::LengthHint::exact(1);
if !self.attributes.is_empty() {
result += writeable::Writeable::writeable_length_hint(&self.attributes) + 1;
}
diff --git a/vendor/icu_locid/src/extensions/unicode/value.rs b/vendor/icu_locid/src/extensions/unicode/value.rs
index ce9982a4c..e6374372c 100644
--- a/vendor/icu_locid/src/extensions/unicode/value.rs
+++ b/vendor/icu_locid/src/extensions/unicode/value.rs
@@ -3,7 +3,7 @@
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).
use crate::helpers::ShortVec;
-use crate::parser::{get_subtag_iterator, ParserError};
+use crate::parser::{ParserError, SubtagIterator};
use alloc::vec::Vec;
use core::ops::RangeInclusive;
use core::str::FromStr;
@@ -20,20 +20,21 @@ use tinystr::TinyAsciiStr;
/// # Examples
///
/// ```
-/// use icu::locid::extensions::unicode::Value;
-///
-/// let value1: Value = "gregory".parse().expect("Failed to parse a Value.");
-/// let value2: Value =
-/// "islamic-civil".parse().expect("Failed to parse a Value.");
-/// let value3: Value = "true".parse().expect("Failed to parse a Value.");
+/// use icu::locid::{
+/// extensions::unicode::Value, extensions_unicode_value as value,
+/// };
+/// use writeable::assert_writeable_eq;
///
-/// assert_eq!(&value1.to_string(), "gregory");
-/// assert_eq!(&value2.to_string(), "islamic-civil");
+/// assert_writeable_eq!(value!("gregory"), "gregory");
+/// assert_writeable_eq!(
+/// "islamic-civil".parse::<Value>().unwrap(),
+/// "islamic-civil"
+/// );
///
-/// // The value "true" is special-cased to an empty value
-/// assert_eq!(&value3.to_string(), "");
+/// // The value "true" has the special, empty string representation
+/// assert_eq!(value!("true").to_string(), "");
/// ```
-#[derive(Debug, PartialEq, Eq, Clone, Hash, PartialOrd, Ord)]
+#[derive(Debug, PartialEq, Eq, Clone, Hash, PartialOrd, Ord, Default)]
pub struct Value(ShortVec<TinyAsciiStr<{ *VALUE_LENGTH.end() }>>);
const VALUE_LENGTH: RangeInclusive<usize> = 3..=8;
@@ -48,15 +49,13 @@ impl Value {
/// ```
/// use icu::locid::extensions::unicode::Value;
///
- /// let value = Value::try_from_bytes(b"buddhist").expect("Parsing failed.");
- ///
- /// assert_eq!(&value.to_string(), "buddhist");
+ /// Value::try_from_bytes(b"buddhist").expect("Parsing failed.");
/// ```
pub fn try_from_bytes(input: &[u8]) -> Result<Self, ParserError> {
let mut v = ShortVec::new();
if !input.is_empty() {
- for subtag in get_subtag_iterator(input) {
+ for subtag in SubtagIterator::new(input) {
let val = Self::subtag_from_bytes(subtag)?;
if let Some(val) = val {
v.push(val);
@@ -153,7 +152,7 @@ impl FromStr for Value {
}
}
-impl_writeable_for_tinystr_list!(Value, "", "islamic", "civil");
+impl_writeable_for_subtag_list!(Value, "islamic", "civil");
/// A macro allowing for compile-time construction of valid Unicode [`Value`] subtag.
///