diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-07 05:48:48 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-07 05:48:48 +0000 |
commit | ef24de24a82fe681581cc130f342363c47c0969a (patch) | |
tree | 0d494f7e1a38b95c92426f58fe6eaa877303a86c /vendor/icu_locid/src/extensions | |
parent | Releasing progress-linux version 1.74.1+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-ef24de24a82fe681581cc130f342363c47c0969a.tar.xz rustc-ef24de24a82fe681581cc130f342363c47c0969a.zip |
Merging upstream version 1.75.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/icu_locid/src/extensions')
-rw-r--r-- | vendor/icu_locid/src/extensions/other/mod.rs | 14 | ||||
-rw-r--r-- | vendor/icu_locid/src/extensions/other/subtag.rs | 5 | ||||
-rw-r--r-- | vendor/icu_locid/src/extensions/private/mod.rs | 16 | ||||
-rw-r--r-- | vendor/icu_locid/src/extensions/private/other.rs | 3 | ||||
-rw-r--r-- | vendor/icu_locid/src/extensions/transform/fields.rs | 23 | ||||
-rw-r--r-- | vendor/icu_locid/src/extensions/transform/key.rs | 3 | ||||
-rw-r--r-- | vendor/icu_locid/src/extensions/transform/mod.rs | 29 | ||||
-rw-r--r-- | vendor/icu_locid/src/extensions/transform/value.rs | 20 | ||||
-rw-r--r-- | vendor/icu_locid/src/extensions/unicode/attribute.rs | 6 | ||||
-rw-r--r-- | vendor/icu_locid/src/extensions/unicode/attributes.rs | 12 | ||||
-rw-r--r-- | vendor/icu_locid/src/extensions/unicode/key.rs | 3 | ||||
-rw-r--r-- | vendor/icu_locid/src/extensions/unicode/keywords.rs | 40 | ||||
-rw-r--r-- | vendor/icu_locid/src/extensions/unicode/mod.rs | 42 | ||||
-rw-r--r-- | vendor/icu_locid/src/extensions/unicode/value.rs | 24 |
14 files changed, 120 insertions, 120 deletions
diff --git a/vendor/icu_locid/src/extensions/other/mod.rs b/vendor/icu_locid/src/extensions/other/mod.rs index 44d5c9cf8..933128739 100644 --- a/vendor/icu_locid/src/extensions/other/mod.rs +++ b/vendor/icu_locid/src/extensions/other/mod.rs @@ -21,10 +21,12 @@ mod subtag; +use crate::helpers::ShortSlice; use crate::parser::ParserError; use crate::parser::SubtagIterator; use alloc::vec::Vec; -pub use subtag::Subtag; +#[doc(inline)] +pub use subtag::{subtag, Subtag}; /// A list of [`Other Use Extensions`] as defined in [`Unicode Locale /// Identifier`] specification. @@ -49,7 +51,7 @@ pub use subtag::Subtag; #[derive(Clone, PartialEq, Eq, Debug, Default, Hash, PartialOrd, Ord)] pub struct Other { ext: u8, - keys: Vec<Subtag>, + keys: ShortSlice<Subtag>, } impl Other { @@ -71,6 +73,10 @@ impl Other { /// assert_eq!(&other.to_string(), "a-foo-bar"); /// ``` pub fn from_vec_unchecked(ext: u8, keys: Vec<Subtag>) -> Self { + Self::from_short_slice_unchecked(ext, keys.into()) + } + + pub(crate) fn from_short_slice_unchecked(ext: u8, keys: ShortSlice<Subtag>) -> Self { assert!(ext.is_ascii_alphabetic()); Self { ext, keys } } @@ -78,7 +84,7 @@ impl Other { pub(crate) fn try_from_iter(ext: u8, iter: &mut SubtagIterator) -> Result<Self, ParserError> { debug_assert!(ext.is_ascii_alphabetic()); - let mut keys = Vec::new(); + let mut keys = ShortSlice::new(); while let Some(subtag) = iter.peek() { if !Subtag::valid_key(subtag) { break; @@ -89,7 +95,7 @@ impl Other { iter.next(); } - Ok(Self::from_vec_unchecked(ext, keys)) + Ok(Self::from_short_slice_unchecked(ext, keys)) } /// Gets the tag character for this extension as a &str. diff --git a/vendor/icu_locid/src/extensions/other/subtag.rs b/vendor/icu_locid/src/extensions/other/subtag.rs index ad4d6a0f2..03be56940 100644 --- a/vendor/icu_locid/src/extensions/other/subtag.rs +++ b/vendor/icu_locid/src/extensions/other/subtag.rs @@ -11,12 +11,13 @@ impl_tinystr_subtag!( /// # Examples /// /// ``` - /// use icu::locid::extensions_other_subtag as subtag; + /// use icu::locid::extensions::other::subtag; /// /// assert_eq!(subtag!("Foo").as_str(), "foo"); /// ``` Subtag, - extensions::other::Subtag, + extensions::other, + subtag, extensions_other_subtag, 2..=8, s, diff --git a/vendor/icu_locid/src/extensions/private/mod.rs b/vendor/icu_locid/src/extensions/private/mod.rs index 8382d166f..161d47f56 100644 --- a/vendor/icu_locid/src/extensions/private/mod.rs +++ b/vendor/icu_locid/src/extensions/private/mod.rs @@ -13,7 +13,7 @@ //! # Examples //! //! ``` -//! use icu::locid::extensions_private_subtag as subtag; +//! use icu::locid::extensions::private::subtag; //! use icu::locid::{locale, Locale}; //! //! let mut loc: Locale = "en-US-x-foo-faa".parse().expect("Parsing failed."); @@ -32,8 +32,10 @@ mod other; use alloc::vec::Vec; use core::ops::Deref; -pub use other::Subtag; +#[doc(inline)] +pub use other::{subtag, Subtag}; +use crate::helpers::ShortSlice; use crate::parser::ParserError; use crate::parser::SubtagIterator; @@ -58,7 +60,7 @@ use crate::parser::SubtagIterator; /// [`Private Use Extensions`]: https://unicode.org/reports/tr35/#pu_extensions /// [`Unicode Locale Identifier`]: https://unicode.org/reports/tr35/#Unicode_locale_identifier #[derive(Clone, PartialEq, Eq, Debug, Default, Hash, PartialOrd, Ord)] -pub struct Private(Vec<Subtag>); +pub struct Private(ShortSlice<Subtag>); impl Private { /// Returns a new empty list of private-use extensions. Same as [`default()`](Default::default()), but is `const`. @@ -72,7 +74,7 @@ impl Private { /// ``` #[inline] pub const fn new() -> Self { - Self(Vec::new()) + Self(ShortSlice::new()) } /// A constructor which takes a pre-sorted list of [`Subtag`]. @@ -89,7 +91,7 @@ impl Private { /// assert_eq!(&private.to_string(), "x-foo-bar"); /// ``` pub fn from_vec_unchecked(input: Vec<Subtag>) -> Self { - Self(input) + Self(input.into()) } /// Empties the [`Private`] list. @@ -116,9 +118,9 @@ impl Private { pub(crate) fn try_from_iter(iter: &mut SubtagIterator) -> Result<Self, ParserError> { let keys = iter .map(Subtag::try_from_bytes) - .collect::<Result<Vec<_>, _>>()?; + .collect::<Result<ShortSlice<_>, _>>()?; - Ok(Self::from_vec_unchecked(keys)) + Ok(Self(keys)) } pub(crate) fn for_each_subtag_str<E, F>(&self, f: &mut F) -> Result<(), E> diff --git a/vendor/icu_locid/src/extensions/private/other.rs b/vendor/icu_locid/src/extensions/private/other.rs index a91e12855..810ffa2f4 100644 --- a/vendor/icu_locid/src/extensions/private/other.rs +++ b/vendor/icu_locid/src/extensions/private/other.rs @@ -18,7 +18,8 @@ impl_tinystr_subtag!( /// assert_eq!(subtag1.as_str(), "foo"); /// ``` Subtag, - extensions::private::Subtag, + extensions::private, + subtag, extensions_private_subtag, 1..=8, s, diff --git a/vendor/icu_locid/src/extensions/transform/fields.rs b/vendor/icu_locid/src/extensions/transform/fields.rs index f08581a87..2f12de9d1 100644 --- a/vendor/icu_locid/src/extensions/transform/fields.rs +++ b/vendor/icu_locid/src/extensions/transform/fields.rs @@ -24,11 +24,10 @@ use super::Value; /// # Examples /// /// ``` -/// use icu::locid::extensions::transform::{Fields, Key, Value}; -/// use icu::locid::extensions_transform_key as key; +/// use icu::locid::extensions::transform::{key, Fields, Key, Value}; /// /// let value = "hybrid".parse::<Value>().expect("Failed to parse a Value."); -/// let fields = vec![(key!("h0"), value)].into_iter().collect::<Fields>(); +/// let fields = [(key!("h0"), value)].into_iter().collect::<Fields>(); /// /// assert_eq!(&fields.to_string(), "h0-hybrid"); /// ``` @@ -76,11 +75,10 @@ impl Fields { /// # Examples /// /// ``` - /// use icu::locid::extensions::transform::{Fields, Value}; - /// use icu::locid::extensions_transform_key as key; + /// use icu::locid::extensions::transform::{key, Fields, Value}; /// /// let value = "hybrid".parse::<Value>().expect("Failed to parse a Value."); - /// let mut fields = vec![(key!("h0"), value)].into_iter().collect::<Fields>(); + /// let mut fields = [(key!("h0"), value)].into_iter().collect::<Fields>(); /// /// assert_eq!(&fields.to_string(), "h0-hybrid"); /// @@ -102,7 +100,7 @@ impl Fields { /// /// let key: Key = "h0".parse().expect("Failed to parse a Key."); /// let value: Value = "hybrid".parse().expect("Failed to parse a Value."); - /// let mut fields: Fields = vec![(key, value)].into_iter().collect(); + /// let mut fields = [(key, value)].into_iter().collect::<Fields>(); /// /// let key: Key = "h0".parse().expect("Failed to parse a Key."); /// assert!(&fields.contains_key(&key)); @@ -121,11 +119,10 @@ impl Fields { /// # Examples /// /// ``` - /// use icu::locid::extensions::transform::{Fields, Key, Value}; - /// use icu::locid::extensions_transform_key as key; + /// use icu::locid::extensions::transform::{key, Fields, Key, Value}; /// /// let value = "hybrid".parse::<Value>().unwrap(); - /// let fields = vec![(key!("h0"), value.clone())] + /// let fields = [(key!("h0"), value.clone())] /// .into_iter() /// .collect::<Fields>(); /// @@ -144,9 +141,7 @@ impl Fields { /// # Examples /// /// ``` - /// use icu::locid::extensions::transform::Key; - /// use icu::locid::extensions::transform::Value; - /// use icu::locid::extensions_transform_key as key; + /// use icu::locid::extensions::transform::{key, Key, Value}; /// use icu::locid::Locale; /// /// let lower = "lower".parse::<Value>().expect("valid extension subtag"); @@ -169,7 +164,7 @@ impl Fields { /// # Examples /// /// ``` - /// use icu::locid::extensions_transform_key as key; + /// use icu::locid::extensions::transform::key; /// use icu::locid::Locale; /// /// let mut loc: Locale = "und-t-h0-hybrid-d0-hex-m0-xml".parse().unwrap(); diff --git a/vendor/icu_locid/src/extensions/transform/key.rs b/vendor/icu_locid/src/extensions/transform/key.rs index 5400988a1..afdb31d76 100644 --- a/vendor/icu_locid/src/extensions/transform/key.rs +++ b/vendor/icu_locid/src/extensions/transform/key.rs @@ -18,7 +18,8 @@ impl_tinystr_subtag!( /// assert_eq!(key1.as_str(), "k0"); /// ``` Key, - extensions::transform::Key, + extensions::transform, + key, extensions_transform_key, 2..=2, s, diff --git a/vendor/icu_locid/src/extensions/transform/mod.rs b/vendor/icu_locid/src/extensions/transform/mod.rs index 7b97d87f6..4156c5910 100644 --- a/vendor/icu_locid/src/extensions/transform/mod.rs +++ b/vendor/icu_locid/src/extensions/transform/mod.rs @@ -35,14 +35,15 @@ mod key; mod value; pub use fields::Fields; -pub use key::Key; +#[doc(inline)] +pub use key::{key, Key}; pub use value::Value; +use crate::helpers::ShortSlice; use crate::parser::SubtagIterator; use crate::parser::{parse_language_identifier_from_iter, ParserError, ParserMode}; use crate::subtags::Language; use crate::LanguageIdentifier; -use alloc::vec; use litemap::LiteMap; /// A list of [`Unicode BCP47 T Extensions`] as defined in [`Unicode Locale @@ -144,21 +145,24 @@ impl Transform { } let mut current_tkey = None; - let mut current_tvalue = vec![]; + let mut current_tvalue = ShortSlice::new(); + let mut has_current_tvalue = false; while let Some(subtag) = iter.peek() { if let Some(tkey) = current_tkey { if let Ok(val) = Value::parse_subtag(subtag) { - current_tvalue.push(val); + has_current_tvalue = true; + if let Some(val) = val { + current_tvalue.push(val); + } } else { - if current_tvalue.is_empty() { + if !has_current_tvalue { return Err(ParserError::InvalidExtension); } - tfields.try_insert( - tkey, - Value::from_vec_unchecked(current_tvalue.drain(..).flatten().collect()), - ); + tfields.try_insert(tkey, Value::from_short_slice_unchecked(current_tvalue)); current_tkey = None; + current_tvalue = ShortSlice::new(); + has_current_tvalue = false; continue; } } else if let Ok(tkey) = Key::try_from_bytes(subtag) { @@ -171,13 +175,10 @@ impl Transform { } if let Some(tkey) = current_tkey { - if current_tvalue.is_empty() { + if !has_current_tvalue { return Err(ParserError::InvalidExtension); } - tfields.try_insert( - tkey, - Value::from_vec_unchecked(current_tvalue.into_iter().flatten().collect()), - ); + tfields.try_insert(tkey, Value::from_short_slice_unchecked(current_tvalue)); } Ok(Self { diff --git a/vendor/icu_locid/src/extensions/transform/value.rs b/vendor/icu_locid/src/extensions/transform/value.rs index f908b0208..798e84793 100644 --- a/vendor/icu_locid/src/extensions/transform/value.rs +++ b/vendor/icu_locid/src/extensions/transform/value.rs @@ -2,9 +2,8 @@ // called LICENSE at the top level of the ICU4X source tree // (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). +use crate::helpers::ShortSlice; use crate::parser::{ParserError, SubtagIterator}; -use alloc::vec; -use alloc::vec::Vec; use core::ops::RangeInclusive; use core::str::FromStr; use tinystr::TinyAsciiStr; @@ -28,7 +27,7 @@ use tinystr::TinyAsciiStr; /// "no".parse::<Value>().expect_err("Invalid Value."); /// ``` #[derive(Debug, PartialEq, Eq, Clone, Hash, PartialOrd, Ord, Default)] -pub struct Value(Vec<TinyAsciiStr<{ *TYPE_LENGTH.end() }>>); +pub struct Value(ShortSlice<TinyAsciiStr<{ *TYPE_LENGTH.end() }>>); const TYPE_LENGTH: RangeInclusive<usize> = 3..=8; const TRUE_TVALUE: TinyAsciiStr<8> = tinystr::tinystr!(8, "true"); @@ -45,7 +44,7 @@ impl Value { /// let value = Value::try_from_bytes(b"hybrid").expect("Parsing failed."); /// ``` pub fn try_from_bytes(input: &[u8]) -> Result<Self, ParserError> { - let mut v = vec![]; + let mut v = ShortSlice::default(); let mut has_value = false; for subtag in SubtagIterator::new(input) { @@ -66,12 +65,14 @@ impl Value { Ok(Self(v)) } - pub(crate) fn from_vec_unchecked(input: Vec<TinyAsciiStr<{ *TYPE_LENGTH.end() }>>) -> Self { + pub(crate) fn from_short_slice_unchecked( + input: ShortSlice<TinyAsciiStr<{ *TYPE_LENGTH.end() }>>, + ) -> Self { Self(input) } pub(crate) fn is_type_subtag(t: &[u8]) -> bool { - TYPE_LENGTH.contains(&t.len()) && !t.iter().any(|c: &u8| !c.is_ascii_alphanumeric()) + TYPE_LENGTH.contains(&t.len()) && t.iter().all(u8::is_ascii_alphanumeric) } pub(crate) fn parse_subtag( @@ -122,9 +123,12 @@ fn test_writeable() { let foobar = "foobar".parse().unwrap(); assert_writeable_eq!(Value::default(), "true"); - assert_writeable_eq!(Value::from_vec_unchecked(vec![hybrid]), "hybrid"); assert_writeable_eq!( - Value::from_vec_unchecked(vec![hybrid, foobar]), + Value::from_short_slice_unchecked(vec![hybrid].into()), + "hybrid" + ); + assert_writeable_eq!( + Value::from_short_slice_unchecked(vec![hybrid, foobar].into()), "hybrid-foobar" ); } diff --git a/vendor/icu_locid/src/extensions/unicode/attribute.rs b/vendor/icu_locid/src/extensions/unicode/attribute.rs index ba4b70924..f6fc53e05 100644 --- a/vendor/icu_locid/src/extensions/unicode/attribute.rs +++ b/vendor/icu_locid/src/extensions/unicode/attribute.rs @@ -12,8 +12,7 @@ impl_tinystr_subtag!( /// # Examples /// /// ``` - /// use icu::locid::extensions::unicode::Attribute; - /// use icu::locid::extensions_unicode_attribute as attribute; + /// use icu::locid::extensions::unicode::{attribute, Attribute}; /// /// let attr: Attribute = /// "buddhist".parse().expect("Failed to parse an Attribute."); @@ -21,7 +20,8 @@ impl_tinystr_subtag!( /// assert_eq!(attr, attribute!("buddhist")); /// ``` Attribute, - extensions::unicode::Attribute, + extensions::unicode, + attribute, extensions_unicode_attribute, 3..=8, s, diff --git a/vendor/icu_locid/src/extensions/unicode/attributes.rs b/vendor/icu_locid/src/extensions/unicode/attributes.rs index e58fb04da..1cdaded30 100644 --- a/vendor/icu_locid/src/extensions/unicode/attributes.rs +++ b/vendor/icu_locid/src/extensions/unicode/attributes.rs @@ -4,6 +4,7 @@ use super::Attribute; +use crate::helpers::ShortSlice; use alloc::vec::Vec; use core::ops::Deref; @@ -30,7 +31,7 @@ use core::ops::Deref; /// assert_eq!(attributes.to_string(), "foobar-testing"); /// ``` #[derive(Default, Debug, PartialEq, Eq, Clone, Hash, PartialOrd, Ord)] -pub struct Attributes(Vec<Attribute>); +pub struct Attributes(ShortSlice<Attribute>); impl Attributes { /// Returns a new empty set of attributes. Same as [`default()`](Default::default()), but is `const`. @@ -44,7 +45,7 @@ impl Attributes { /// ``` #[inline] pub const fn new() -> Self { - Self(Vec::new()) + Self(ShortSlice::new()) } /// A constructor which takes a pre-sorted list of [`Attribute`] elements. @@ -68,6 +69,10 @@ impl Attributes { /// for the caller to use [`binary_search`](slice::binary_search) instead of [`sort`](slice::sort) /// and [`dedup`](Vec::dedup()). pub fn from_vec_unchecked(input: Vec<Attribute>) -> Self { + Self(input.into()) + } + + pub(crate) fn from_short_slice_unchecked(input: ShortSlice<Attribute>) -> Self { Self(input) } @@ -78,8 +83,7 @@ impl Attributes { /// # Examples /// /// ``` - /// use icu::locid::extensions::unicode::{Attribute, Attributes}; - /// use icu::locid::extensions_unicode_attribute as attribute; + /// use icu::locid::extensions::unicode::{attribute, Attribute, Attributes}; /// use writeable::assert_writeable_eq; /// /// let mut attributes = Attributes::from_vec_unchecked(vec![ diff --git a/vendor/icu_locid/src/extensions/unicode/key.rs b/vendor/icu_locid/src/extensions/unicode/key.rs index bdfdd4e5c..e008ffd5a 100644 --- a/vendor/icu_locid/src/extensions/unicode/key.rs +++ b/vendor/icu_locid/src/extensions/unicode/key.rs @@ -17,7 +17,8 @@ impl_tinystr_subtag!( /// assert!("ca".parse::<Key>().is_ok()); /// ``` Key, - extensions::unicode::Key, + extensions::unicode, + key, extensions_unicode_key, 2..=2, s, diff --git a/vendor/icu_locid/src/extensions/unicode/keywords.rs b/vendor/icu_locid/src/extensions/unicode/keywords.rs index 4e2fbae9a..c2839fa44 100644 --- a/vendor/icu_locid/src/extensions/unicode/keywords.rs +++ b/vendor/icu_locid/src/extensions/unicode/keywords.rs @@ -13,7 +13,7 @@ use crate::helpers::ShortSlice; use crate::ordering::SubtagOrderingResult; /// A list of [`Key`]-[`Value`] pairs representing functional information -/// about locale's internationnalization preferences. +/// about locale's internationalization preferences. /// /// Here are examples of fields used in Unicode: /// - `hc` - Hour Cycle (`h11`, `h12`, `h23`, `h24`) @@ -30,11 +30,11 @@ use crate::ordering::SubtagOrderingResult; /// /// ``` /// use icu::locid::{ -/// extensions::unicode::Keywords, extensions_unicode_key as key, -/// extensions_unicode_value as value, locale, +/// extensions::unicode::{key, value, Keywords}, +/// locale, /// }; /// -/// let keywords = vec![(key!("hc"), value!("h23"))] +/// let keywords = [(key!("hc"), value!("h23"))] /// .into_iter() /// .collect::<Keywords>(); /// @@ -45,7 +45,7 @@ use crate::ordering::SubtagOrderingResult; /// /// ``` /// use icu::locid::{ -/// extensions_unicode_key as key, extensions_unicode_value as value, +/// extensions::unicode::{key, value}, /// Locale, /// }; /// @@ -116,12 +116,9 @@ impl Keywords { /// # Examples /// /// ``` - /// use icu::locid::{ - /// extensions::unicode::Keywords, extensions_unicode_key as key, - /// extensions_unicode_value as value, - /// }; + /// use icu::locid::extensions::unicode::{key, value, Keywords}; /// - /// let keywords = vec![(key!("ca"), value!("gregory"))] + /// let keywords = [(key!("ca"), value!("gregory"))] /// .into_iter() /// .collect::<Keywords>(); /// @@ -141,12 +138,9 @@ impl Keywords { /// # Examples /// /// ``` - /// use icu::locid::{ - /// extensions::unicode::Keywords, extensions_unicode_key as key, - /// extensions_unicode_value as value, - /// }; + /// use icu::locid::extensions::unicode::{key, value, Keywords}; /// - /// let keywords = vec![(key!("ca"), value!("buddhist"))] + /// let keywords = [(key!("ca"), value!("buddhist"))] /// .into_iter() /// .collect::<Keywords>(); /// @@ -167,12 +161,9 @@ impl Keywords { /// # Examples /// /// ``` - /// use icu::locid::{ - /// extensions::unicode::Keywords, extensions_unicode_key as key, - /// extensions_unicode_value as value, - /// }; + /// use icu::locid::extensions::unicode::{key, value, Keywords}; /// - /// let mut keywords = vec![(key!("ca"), value!("buddhist"))] + /// let mut keywords = [(key!("ca"), value!("buddhist"))] /// .into_iter() /// .collect::<Keywords>(); /// @@ -196,10 +187,8 @@ impl Keywords { /// ``` /// use icu::locid::extensions::unicode::Key; /// use icu::locid::extensions::unicode::Value; + /// 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 = "und-u-hello-ca-buddhist-hc-h12" /// .parse() @@ -222,8 +211,7 @@ impl Keywords { /// # Examples /// /// ``` - /// use icu::locid::extensions::unicode::Key; - /// use icu::locid::extensions_unicode_key as key; + /// use icu::locid::extensions::unicode::{key, Key}; /// use icu::locid::Locale; /// /// let mut loc: Locale = "und-u-hello-ca-buddhist-hc-h12" @@ -258,7 +246,7 @@ impl Keywords { /// # Examples /// /// ``` - /// use icu::locid::extensions_unicode_key as key; + /// use icu::locid::extensions::unicode::key; /// use icu::locid::Locale; /// /// let mut loc: Locale = "und-u-ca-buddhist-hc-h12-ms-metric".parse().unwrap(); diff --git a/vendor/icu_locid/src/extensions/unicode/mod.rs b/vendor/icu_locid/src/extensions/unicode/mod.rs index 687a8c383..95f1a2d78 100644 --- a/vendor/icu_locid/src/extensions/unicode/mod.rs +++ b/vendor/icu_locid/src/extensions/unicode/mod.rs @@ -11,12 +11,8 @@ //! # Examples //! //! ``` +//! use icu::locid::extensions::unicode::{attribute, key, value, Unicode}; //! 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 loc: Locale = "en-US-u-foobar-hc-h12".parse().expect("Parsing failed."); //! @@ -36,13 +32,16 @@ mod key; mod keywords; mod value; -use alloc::vec; -pub use attribute::Attribute; +#[doc(inline)] +pub use attribute::{attribute, Attribute}; pub use attributes::Attributes; -pub use key::Key; +#[doc(inline)] +pub use key::{key, Key}; pub use keywords::Keywords; -pub use value::Value; +#[doc(inline)] +pub use value::{value, Value}; +use crate::helpers::ShortSlice; use crate::parser::ParserError; use crate::parser::SubtagIterator; use litemap::LiteMap; @@ -63,10 +62,8 @@ 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 loc: Locale = /// "de-u-hc-h12-ca-buddhist".parse().expect("Parsing failed."); @@ -138,11 +135,7 @@ impl Unicode { } pub(crate) fn try_from_iter(iter: &mut SubtagIterator) -> Result<Self, ParserError> { - let mut attributes = vec![]; - let mut keywords = LiteMap::new(); - - let mut current_keyword = None; - let mut current_type = vec![]; + let mut attributes = ShortSlice::new(); while let Some(subtag) = iter.peek() { if let Ok(attr) = Attribute::try_from_bytes(subtag) { @@ -155,17 +148,22 @@ impl Unicode { iter.next(); } + let mut keywords = LiteMap::new(); + + let mut current_keyword = None; + let mut current_value = ShortSlice::new(); + while let Some(subtag) = iter.peek() { let slen = subtag.len(); if slen == 2 { if let Some(kw) = current_keyword.take() { - keywords.try_insert(kw, Value::from_vec_unchecked(current_type)); - current_type = vec![]; + keywords.try_insert(kw, Value::from_short_slice_unchecked(current_value)); + current_value = ShortSlice::new(); } current_keyword = Some(Key::try_from_bytes(subtag)?); } else if current_keyword.is_some() { match Value::parse_subtag(subtag) { - Ok(Some(t)) => current_type.push(t), + Ok(Some(t)) => current_value.push(t), Ok(None) => {} Err(_) => break, } @@ -176,7 +174,7 @@ impl Unicode { } if let Some(kw) = current_keyword.take() { - keywords.try_insert(kw, Value::from_vec_unchecked(current_type)); + keywords.try_insert(kw, Value::from_short_slice_unchecked(current_value)); } // Ensure we've defined at least one attribute or keyword @@ -186,7 +184,7 @@ impl Unicode { Ok(Self { keywords: keywords.into(), - attributes: Attributes::from_vec_unchecked(attributes), + attributes: Attributes::from_short_slice_unchecked(attributes), }) } diff --git a/vendor/icu_locid/src/extensions/unicode/value.rs b/vendor/icu_locid/src/extensions/unicode/value.rs index f1b2402de..d935656a9 100644 --- a/vendor/icu_locid/src/extensions/unicode/value.rs +++ b/vendor/icu_locid/src/extensions/unicode/value.rs @@ -4,7 +4,6 @@ use crate::helpers::ShortSlice; use crate::parser::{ParserError, SubtagIterator}; -use alloc::vec::Vec; use core::ops::RangeInclusive; use core::str::FromStr; use tinystr::TinyAsciiStr; @@ -20,9 +19,7 @@ use tinystr::TinyAsciiStr; /// # Examples /// /// ``` -/// use icu::locid::{ -/// extensions::unicode::Value, extensions_unicode_value as value, -/// }; +/// use icu::locid::extensions::unicode::{value, Value}; /// use writeable::assert_writeable_eq; /// /// assert_writeable_eq!(value!("gregory"), "gregory"); @@ -52,7 +49,7 @@ impl Value { /// Value::try_from_bytes(b"buddhist").expect("Parsing failed."); /// ``` pub fn try_from_bytes(input: &[u8]) -> Result<Self, ParserError> { - let mut v = Vec::new(); + let mut v = ShortSlice::new(); if !input.is_empty() { for subtag in SubtagIterator::new(input) { @@ -62,7 +59,7 @@ impl Value { } } } - Ok(Self(v.into())) + Ok(Self(v)) } /// Const constructor for when the value contains only a single subtag. @@ -85,7 +82,7 @@ impl Value { #[doc(hidden)] pub fn as_tinystr_slice(&self) -> &[TinyAsciiStr<8>] { - self.0.as_slice() + &self.0 } #[doc(hidden)] @@ -105,8 +102,8 @@ impl Value { } } - pub(crate) fn from_vec_unchecked(input: Vec<TinyAsciiStr<8>>) -> Self { - Self(input.into()) + pub(crate) fn from_short_slice_unchecked(input: ShortSlice<TinyAsciiStr<8>>) -> Self { + Self(input) } #[doc(hidden)] @@ -140,7 +137,7 @@ impl Value { where F: FnMut(&str) -> Result<(), E>, { - self.0.as_slice().iter().map(|t| t.as_str()).try_for_each(f) + self.0.iter().map(TinyAsciiStr::as_str).try_for_each(f) } } @@ -161,10 +158,8 @@ impl_writeable_for_subtag_list!(Value, "islamic", "civil"); /// # 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 loc: Locale = "de-u-ca-buddhist".parse().unwrap(); /// @@ -176,6 +171,7 @@ impl_writeable_for_subtag_list!(Value, "islamic", "civil"); /// /// [`Value`]: crate::extensions::unicode::Value #[macro_export] +#[doc(hidden)] macro_rules! extensions_unicode_value { ($value:literal) => {{ // What we want: @@ -196,3 +192,5 @@ macro_rules! extensions_unicode_value { R }}; } +#[doc(inline)] +pub use extensions_unicode_value as value; |