Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Short Compact Currency Formatter Provider and Populate Associated Data #5361

Merged
merged 16 commits into from
Aug 15, 2024

Conversation

younies
Copy link
Member

@younies younies commented Aug 13, 2024

Tasks

In this PR, the following tasks are accomplished:

  1. Extracted the short compact currency formatter patterns from numbers.json.
  2. Implemented the ShortCompactCurrencyV1 struct.
  3. Populated both the bakeddata and testdata for ShortCompactCurrencyV1Marker.

@younies younies requested a review from sffc August 14, 2024 09:30
@younies younies marked this pull request as ready for review August 14, 2024 15:44
@younies younies requested review from robertbastian, Manishearth and a team as code owners August 14, 2024 15:44
@younies younies changed the title Implement the data provider for the compact currency formatting Implement Short Compact Currency Formatter Provider and Populate Associated Data Aug 14, 2024
/// `"1000-count-one-alt-alphaNextToNumber": "¤ 0K"`
/// -> key1 = 3, key2 = CompactCount::OneAlt, value = "¤ 0K"
#[cfg_attr(feature = "serde", serde(borrow))]
pub compact_patterns: ZeroMap2d<'data, i8, CompactCount, str>,
Copy link
Member

Choose a reason for hiding this comment

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

unless you need to do the lookup in two steps, prefer ZeroMap<(i8, CompactCount), str> over ZeroMap2d, as the 2d version has bigger metadata.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

fn try_from(value: &str) -> Result<Self, Self::Error> {
match value {
"zero" => Ok(CompactCount::Zero),
"zero-alt-alphaNextToNumber" => Ok(CompactCount::ZeroAlt),
Copy link
Member

Choose a reason for hiding this comment

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

this is highly CLDR-JSON specific and should live in icu_provider_source.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

/// CompactPattern `zero`.
Zero = 0,
/// Compact Pattern `zero` alternative.
ZeroAlt = 1,
Copy link
Member

Choose a reason for hiding this comment

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

how will the Alt data be accessed? Consider putting them behind a locale variant instead (i.e. en-gb-alt), instead of modelling them in the same data struct

Copy link
Member Author

Choose a reason for hiding this comment

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

done, we made it AlphaNextToNumber

@younies younies requested a review from robertbastian August 14, 2024 16:41
@@ -33,11 +33,9 @@ pub struct ShortCurrencyCompactV1<'data> {
/// `"1000-count-one-alt-alphaNextToNumber": "¤ 0K"`
/// -> key1 = 3, key2 = CompactCount::OneAlt, value = "¤ 0K"
#[cfg_attr(feature = "serde", serde(borrow))]
pub compact_patterns: ZeroMap2d<'data, i8, CompactCount, str>,
pub compact_patterns: ZeroMap<'data, (i8, CompactCount), str>,
Copy link
Member

Choose a reason for hiding this comment

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

you have 4 bits left in CompactCountULE, what's the range of the log10?

Copy link
Member Author

Choose a reason for hiding this comment

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

there is no limit for log10, but I think to put the limit 16 is kinda a low limit

Copy link
Member

Choose a reason for hiding this comment

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

yeah it'd be -8 to 7 as well.

@@ -46,56 +44,35 @@ pub struct ShortCurrencyCompactV1<'data> {
databake(path = icu_experimental::dimension::provider::currency_compact)
)]
#[repr(u8)]
pub enum CompactCount {
pub enum Count {
Copy link
Member

Choose a reason for hiding this comment

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

can you use an existing Count? This type exists at least twice already.

Copy link
Member Author

Choose a reason for hiding this comment

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

done and #5373

Copy link
Member

Choose a reason for hiding this comment

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

you just moved it?

@younies younies requested a review from robertbastian August 15, 2024 10:20
Copy link
Member

@robertbastian robertbastian left a comment

Choose a reason for hiding this comment

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

There are still things that I'd like addressed and I'm trusting you to follow up on them.

@@ -33,11 +33,9 @@ pub struct ShortCurrencyCompactV1<'data> {
/// `"1000-count-one-alt-alphaNextToNumber": "¤ 0K"`
/// -> key1 = 3, key2 = CompactCount::OneAlt, value = "¤ 0K"
#[cfg_attr(feature = "serde", serde(borrow))]
pub compact_patterns: ZeroMap2d<'data, i8, CompactCount, str>,
pub compact_patterns: ZeroMap<'data, (i8, CompactCount), str>,
Copy link
Member

Choose a reason for hiding this comment

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

yeah it'd be -8 to 7 as well.

@@ -46,56 +44,35 @@ pub struct ShortCurrencyCompactV1<'data> {
databake(path = icu_experimental::dimension::provider::currency_compact)
)]
#[repr(u8)]
pub enum CompactCount {
pub enum Count {
Copy link
Member

Choose a reason for hiding this comment

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

you just moved it?

@younies younies merged commit 34b087a into unicode-org:main Aug 15, 2024
28 checks passed
@younies younies deleted the currency-compact branch August 15, 2024 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants