diff --git a/components/decimal/README.md b/components/decimal/README.md index 76ce034c677..61e377e3670 100644 --- a/components/decimal/README.md +++ b/components/decimal/README.md @@ -52,7 +52,7 @@ let fixed_decimal = { assert_writeable_eq!(fdf.format(&fixed_decimal), "2,000.50"); ``` -#### Format a number using an alternative numbering system +### Format a number using an alternative numbering system Numbering systems specified in the `-u-nu` subtag will be followed. @@ -73,69 +73,6 @@ 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