Skip to content

feat(currency): Add accounting formatting and relax constructor validation#8177

Open
younies wants to merge 9 commits into
unicode-org:mainfrom
younies:currency-accounting
Open

feat(currency): Add accounting formatting and relax constructor validation#8177
younies wants to merge 9 commits into
unicode-org:mainfrom
younies:currency-accounting

Conversation

@younies

@younies younies commented Jul 3, 2026

Copy link
Copy Markdown
Member

This PR addresses what was left in #8066 and adds support for accounting currency formatting.

Changelog

  1. Relaxed Formatter Validation: Removed the strict validation in CurrencyFormatter and CompactCurrencyFormatter constructors that required the standard pattern to be present. This allows the formatters to initialize and rely on runtime fallback.
  2. Accounting Formatting:
    • Added Accounting variant to CurrencyUsage enum.
    • Updated CurrencyEssentials::name_and_pattern to retrieve accounting patterns (accounting_positive, accounting_negative, etc.) when CurrencyUsage::Accounting is selected.
    • Updated formatters to pass self.options.usage to name_and_pattern.
  3. GIGO Fallback:
    • Implemented GIGO fallback in standard_pattern to return FALLBACK_PATTERN ("{0} {1}") if the pattern is missing (due to corrupt data), with a debug_assert! in debug builds.
    • Updated positive pattern getters to return non-optional &DoublePlaceholderPattern.
  4. Datagen:
    • Updated datagen fallback for accounting_alpha_next_to_number_positive to standard_alpha_next_to_number.
    • Regenerated the baked data.
  5. Tests:
    • Added tests for accounting formatting in format.rs.
    • Added a test for FALLBACK_PATTERN in essentials.rs.

Diff Base: currency-plural-patterns (which is stacked on currency-cash-formatting #8175)

TAG=agy
CONV=f08dbbb0-24e0-4da6-a2f8-f6a19ba2c8b5

@younies younies requested review from a team, Manishearth, robertbastian and sffc as code owners July 3, 2026 15:18
@younies younies force-pushed the currency-accounting branch from 983286a to 7420977 Compare July 5, 2026 09:15
younies added a commit to younies/icu4x that referenced this pull request Jul 5, 2026
@younies younies force-pushed the currency-accounting branch from 7420977 to 38c8dbf Compare July 5, 2026 09:54
younies added a commit to younies/icu4x that referenced this pull request Jul 5, 2026
@younies younies force-pushed the currency-accounting branch from 38c8dbf to 48b5344 Compare July 5, 2026 10:00
younies added a commit to younies/icu4x that referenced this pull request Jul 5, 2026
@younies younies force-pushed the currency-accounting branch from 48b5344 to e0dac35 Compare July 5, 2026 10:15
younies added a commit to younies/icu4x that referenced this pull request Jul 5, 2026
@younies younies force-pushed the currency-accounting branch from e0dac35 to 085f6cb Compare July 5, 2026 10:27
younies added a commit to younies/icu4x that referenced this pull request Jul 6, 2026
@younies younies force-pushed the currency-accounting branch from 085f6cb to 371a6fe Compare July 6, 2026 15:05
younies added a commit to younies/icu4x that referenced this pull request Jul 6, 2026
@younies younies force-pushed the currency-accounting branch from 371a6fe to 00e4244 Compare July 6, 2026 15:17
younies added a commit to younies/icu4x that referenced this pull request Jul 6, 2026
@younies younies force-pushed the currency-accounting branch from 00e4244 to ebd85e7 Compare July 6, 2026 15:34
younies added a commit to younies/icu4x that referenced this pull request Jul 6, 2026
@younies younies force-pushed the currency-accounting branch from ebd85e7 to e59f92c Compare July 6, 2026 15:39
younies added a commit to younies/icu4x that referenced this pull request Jul 6, 2026
@younies younies force-pushed the currency-accounting branch from e59f92c to de33b9b Compare July 6, 2026 15:49
younies added a commit to younies/icu4x that referenced this pull request Jul 6, 2026
@younies younies force-pushed the currency-accounting branch from de33b9b to 84608eb Compare July 6, 2026 16:40
younies added 6 commits July 7, 2026 19:00
…mat_sign logic

Extract the common format_sign logic from the match arms in format_fixed_decimal
to avoid duplication, as suggested in PR review.

TAG=agy
CONV=b42e69df-8afe-401b-aedf-7af6a5c30a76
Document that `u8::MAX` is used as a sentinel value in
`standard_fractions_index` and `standard_next_to_alpha_fractions_index`
when the precision matches the default, and the formatter should
fall back to the default currency fractions.

TAG=agy
CONV=7e0f7c07-a527-44f4-8ebe-270520b5881c
@younies younies force-pushed the currency-accounting branch from 84608eb to e68dc25 Compare July 7, 2026 19:15
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.

1 participant