From 00b596b76342d958b873bebf3b399a0dbd1af80b Mon Sep 17 00:00:00 2001 From: Younies Mahmoud Date: Tue, 20 Aug 2024 12:21:42 +0200 Subject: [PATCH] Refactor: Update `CompactCount` to use `PluralCategory` enum (#5401) --- components/experimental/Cargo.toml | 2 +- .../dimension/provider/compact_count_ule.rs | 16 +++++++------- .../dimension/provider/currency_compact.rs | 7 +++--- provider/source/src/currency/compact.rs | 22 +++++++++---------- 4 files changed, 23 insertions(+), 24 deletions(-) diff --git a/components/experimental/Cargo.toml b/components/experimental/Cargo.toml index 15837b20907..4dd191d8374 100644 --- a/components/experimental/Cargo.toml +++ b/components/experimental/Cargo.toml @@ -69,7 +69,7 @@ icu_normalizer_data = { workspace = true } [features] default = ["compiled_data"] compiled_data = ["dep:icu_experimental_data", "icu_decimal/compiled_data", "icu_list/compiled_data", "icu_plurals/compiled_data", "icu_properties/compiled_data", "icu_normalizer/compiled_data"] -datagen = ["serde", "std", "dep:databake", "zerovec/databake", "zerotrie/databake", "tinystr/databake", "icu_collections/databake", "std", "log", "icu_pattern/databake"] +datagen = ["serde", "std", "dep:databake", "zerovec/databake", "zerotrie/databake", "tinystr/databake", "icu_collections/databake", "std", "log", "icu_pattern/databake", "icu_plurals/datagen"] ryu = ["fixed_decimal/ryu"] serde = ["dep:serde", "zerovec/serde", "potential_utf/serde", "tinystr/serde", "icu_collections/serde", "icu_decimal/serde", "icu_list/serde", "icu_pattern/serde", "icu_plurals/serde", "icu_provider/serde", "zerotrie/serde"] std = ["fixed_decimal/std", "icu_decimal/std", "icu_pattern/std", "icu_plurals/std", "icu_provider/std", "icu_locale_core/std"] diff --git a/components/experimental/src/dimension/provider/compact_count_ule.rs b/components/experimental/src/dimension/provider/compact_count_ule.rs index cafb6ff052d..ec29a110d2a 100644 --- a/components/experimental/src/dimension/provider/compact_count_ule.rs +++ b/components/experimental/src/dimension/provider/compact_count_ule.rs @@ -2,10 +2,10 @@ // called LICENSE at the top level of the ICU4X source tree // (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). +use crate::dimension::provider::currency_compact::CompactCount; +use icu_plurals::PluralCategory; use zerovec::ule::{AsULE, ZeroVecError, ULE}; -use super::{count::Count, currency_compact::CompactCount}; - /// [`CompactCountULE`] is a type optimized for efficient storing and /// deserialization of [`CompactCount`] using the `ZeroVec` model. /// @@ -65,12 +65,12 @@ impl AsULE for CompactCount { #[inline] fn from_unaligned(unaligned: Self::ULE) -> Self { let count = match unaligned.0 & 0b0000_0111 { - 0 => Count::Zero, - 1 => Count::One, - 2 => Count::Two, - 3 => Count::Few, - 4 => Count::Many, - 5 => Count::Other, + 0 => PluralCategory::Zero, + 1 => PluralCategory::One, + 2 => PluralCategory::Two, + 3 => PluralCategory::Few, + 4 => PluralCategory::Many, + 5 => PluralCategory::Other, _ => unreachable!(), }; match unaligned.0 & 0b1000_0000 { diff --git a/components/experimental/src/dimension/provider/currency_compact.rs b/components/experimental/src/dimension/provider/currency_compact.rs index 4e2a00485e6..5e720efe6d4 100644 --- a/components/experimental/src/dimension/provider/currency_compact.rs +++ b/components/experimental/src/dimension/provider/currency_compact.rs @@ -9,11 +9,10 @@ //! //! Read more about data providers: [`icu_provider`] +use icu_plurals::PluralCategory; use icu_provider::prelude::*; use zerovec::ZeroMap; -use super::count::Count; - /// Currency Compact V1 data struct. #[icu_provider::data_struct(marker(ShortCurrencyCompactV1Marker, "currency/compact@1"))] #[derive(Debug, Clone, Default, PartialEq)] @@ -47,6 +46,6 @@ pub struct ShortCurrencyCompactV1<'data> { )] #[repr(u8)] pub enum CompactCount { - Standard(Count), - AlphaNextToNumber(Count), + Standard(PluralCategory), + AlphaNextToNumber(PluralCategory), } diff --git a/provider/source/src/currency/compact.rs b/provider/source/src/currency/compact.rs index e86f4510fac..6cb8fe12b5b 100644 --- a/provider/source/src/currency/compact.rs +++ b/provider/source/src/currency/compact.rs @@ -8,8 +8,8 @@ use crate::SourceDataProvider; use std::collections::HashSet; -use icu::experimental::dimension::provider::count::Count; use icu::experimental::dimension::provider::currency_compact::*; +use icu::plurals::PluralCategory; use icu_provider::prelude::*; use icu_provider::DataProvider; use zerovec::ZeroMap; @@ -64,12 +64,12 @@ impl DataProvider for SourceDataProvider { }; let count = match count_str { - "zero" => Count::Zero, - "one" => Count::One, - "two" => Count::Two, - "few" => Count::Few, - "many" => Count::Many, - "other" => Count::Other, + "zero" => PluralCategory::Zero, + "one" => PluralCategory::One, + "two" => PluralCategory::Two, + "few" => PluralCategory::Few, + "many" => PluralCategory::Many, + "other" => PluralCategory::Other, _ => return Err(DataErrorKind::IdentifierNotFound.into_error()), }; @@ -130,11 +130,11 @@ fn test_basic() { let en_patterns = &en.payload.get().to_owned().compact_patterns; assert_eq!( - en_patterns.get(&(3, CompactCount::Standard(Count::One))), + en_patterns.get(&(3, CompactCount::Standard(PluralCategory::One))), Some("¤0K") ); assert_eq!( - en_patterns.get(&(3, CompactCount::AlphaNextToNumber(Count::One))), + en_patterns.get(&(3, CompactCount::AlphaNextToNumber(PluralCategory::One))), Some("¤ 0K") ); @@ -148,11 +148,11 @@ fn test_basic() { let ja_patterns = &ja.payload.get().to_owned().compact_patterns; assert_eq!( - ja_patterns.get(&(4, CompactCount::Standard(Count::Other))), + ja_patterns.get(&(4, CompactCount::Standard(PluralCategory::Other))), Some("¤0万") ); assert_eq!( - ja_patterns.get(&(4, CompactCount::AlphaNextToNumber(Count::Other))), + ja_patterns.get(&(4, CompactCount::AlphaNextToNumber(PluralCategory::Other))), Some("¤\u{a0}0万") ); }