Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions components/locale_core/src/extensions/unicode/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,29 @@ impl Attributes {
{
self.deref().iter().map(|t| t.as_str()).try_for_each(f)
}

/// Extends the `Attributes` with values from another `Attributes`.
///
/// # Example
///
/// ```
/// use icu::locale::extensions::unicode::Attributes;
///
/// let mut attrs: Attributes = "foobar-foobaz".parse().unwrap();
/// let attrs2: Attributes = "foobar-fooqux".parse().unwrap();
///
/// attrs.extend(attrs2);
///
/// assert_eq!(attrs, "foobar-foobaz-fooqux".parse().unwrap());
/// ```
#[cfg(feature = "alloc")]
pub fn extend(&mut self, other: Attributes) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub fn extend(&mut self, other: Attributes) {
pub fn extend_from_attributes(&mut self, other: Attributes) {

for attr in other.0 {
if let Err(idx) = self.binary_search(&attr) {
self.0.insert(idx, attr);
}
}
}
}

/// ✨ *Enabled with the `alloc` Cargo feature.*
Expand Down
21 changes: 21 additions & 0 deletions components/locale_core/src/extensions/unicode/keywords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,27 @@ impl Keywords {
Ok(())
}

/// Extends the `Keywords` with values from another `Keywords`.
///
/// # Example
///
/// ```
/// use icu::locale::extensions::unicode::Keywords;
///
/// let mut kw: Keywords = "ab-cd-ca-buddhist".parse().unwrap();
/// let kw2: Keywords = "ca-gregory-hc-h12".parse().unwrap();
///
/// kw.extend(kw2);
///
/// assert_eq!(kw, "ab-cd-ca-gregory-hc-h12".parse().unwrap());
/// ```
#[cfg(feature = "alloc")]
pub fn extend(&mut self, other: Keywords) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub fn extend(&mut self, other: Keywords) {
pub fn extend_from_keywords(&mut self, other: Keywords) {

for (key, value) in other.0 {
self.0.insert(key, value);
}
}

/// This needs to be its own method to help with type inference in helpers.rs
#[cfg(test)]
pub(crate) fn from_tuple_vec(v: Vec<(Key, Value)>) -> Self {
Expand Down
20 changes: 20 additions & 0 deletions components/locale_core/src/extensions/unicode/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,26 @@ impl Unicode {
}
Ok(())
}

/// Extends the `Unicode` with values from another `Unicode`.
///
/// # Example
///
/// ```
/// use icu::locale::extensions::unicode::Unicode;
///
/// let mut ue: Unicode = "u-foobar-ca-buddhist".parse().unwrap();
/// let ue2: Unicode = "u-ca-gregory-hc-h12".parse().unwrap();
///
/// ue.extend(ue2);
///
/// assert_eq!(ue, "u-foobar-ca-gregory-hc-h12".parse().unwrap());
/// ```
#[cfg(feature = "alloc")]
pub fn extend(&mut self, other: Unicode) {
self.keywords.extend(other.keywords);
self.attributes.extend(other.attributes);
}
}

/// ✨ *Enabled with the `alloc` Cargo feature.*
Expand Down
2 changes: 1 addition & 1 deletion components/locale_core/src/preferences/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
//!
//! # Preferences Merging
//!
//! In traditional internatonalization APIs, the argument passed to constructors is a locale.
//! In traditional internationalization APIs, the argument passed to constructors is a locale.
//! ICU4X changes this paradigm by accepting a `Preferences`, which can be extracted from a [`Locale`] and combined with
//! other `Preferences`s provided by the environment.
//!
Expand Down