From 7f6e6a2b11aeeb59a9c468c1a8dbb59e7f4736fa Mon Sep 17 00:00:00 2001 From: "Shane F. Carr" Date: Thu, 19 Dec 2024 18:20:26 -0800 Subject: [PATCH] generate-readmes --- components/decimal/README.md | 66 ++++++++++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 2 deletions(-) diff --git a/components/decimal/README.md b/components/decimal/README.md index 1170fb74f83..76ce034c677 100644 --- a/components/decimal/README.md +++ b/components/decimal/README.md @@ -54,8 +54,7 @@ assert_writeable_eq!(fdf.format(&fixed_decimal), "2,000.50"); #### Format a number using an alternative numbering system -Numbering systems specified in the `-u-nu` subtag will be followed as long as the locale has -symbols for that numbering system. +Numbering systems specified in the `-u-nu` subtag will be followed. ```rust use fixed_decimal::SignedFixedDecimal; @@ -74,6 +73,69 @@ let fixed_decimal = SignedFixedDecimal::from(1000007); assert_writeable_eq!(fdf.format(&fixed_decimal), "๑,๐๐๐,๐๐๗"); ``` +#### Get the resolved numbering system + +Inspect the data request to get the resolved numbering system (public but unstable): + +```rust +use icu_provider::prelude::*; +use icu::decimal::FixedDecimalFormatter; +use icu::decimal::provider::DecimalDigitsV1Marker; +use icu::locale::locale; +use std::any::TypeId; +use std::cell::RefCell; + +struct NumberingSystemInspectionProvider

{ + inner: P, + numbering_system: RefCell>>, +} + +impl DataProvider for NumberingSystemInspectionProvider

+where + M: DataMarker, + P: DataProvider, +{ + fn load(&self, req: DataRequest) -> Result, DataError> { + if TypeId::of::() == TypeId::of::() { + *self.numbering_system.try_borrow_mut().unwrap() = Some(req.id.marker_attributes.to_owned()); + } + self.inner.load(req) + } +} + +let provider = NumberingSystemInspectionProvider { + inner: icu::decimal::provider::Baked, + numbering_system: RefCell::new(None), +}; + +let fdf = FixedDecimalFormatter::try_new_unstable( + &provider, + locale!("th").into(), + Default::default(), +) +.unwrap(); + +assert_eq!(provider.numbering_system.borrow().as_ref().map(|x| x.as_str()), Some("latn")); + +let fdf = FixedDecimalFormatter::try_new_unstable( + &provider, + locale!("th-u-nu-thai").into(), + Default::default(), +) +.unwrap(); + +assert_eq!(provider.numbering_system.borrow().as_ref().map(|x| x.as_str()), Some("thai")); + +let fdf = FixedDecimalFormatter::try_new_unstable( + &provider, + locale!("th-u-nu-adlm").into(), + Default::default(), +) +.unwrap(); + +assert_eq!(provider.numbering_system.borrow().as_ref().map(|x| x.as_str()), Some("adlm")); +``` + [`FixedDecimalFormatter`]: FixedDecimalFormatter