From 5aa8c99adfc7a72d0bc14143d53cdf6bcae65651 Mon Sep 17 00:00:00 2001 From: Younies Mahmoud Date: Tue, 18 Feb 2025 18:42:15 +0100 Subject: [PATCH] Rename `fdf` to `formatter` in decimal formatting examples and benchmarks (#6150) --- components/decimal/README.md | 18 +++++++++--------- .../decimal/benches/fixed_decimal_format.rs | 6 +++--- components/decimal/src/grouper.rs | 4 ++-- components/decimal/src/lib.rs | 18 +++++++++--------- components/decimal/src/options.rs | 6 +++--- components/decimal/src/parts.rs | 6 +++--- components/decimal/src/provider.rs | 6 +++--- 7 files changed, 32 insertions(+), 32 deletions(-) diff --git a/components/decimal/README.md b/components/decimal/README.md index 3edeef8ab82..6b02e43bf13 100644 --- a/components/decimal/README.md +++ b/components/decimal/README.md @@ -20,15 +20,15 @@ use icu::decimal::DecimalFormatter; use icu::locale::locale; use writeable::assert_writeable_eq; -let df = DecimalFormatter::try_new( +let formatter = DecimalFormatter::try_new( locale!("bn").into(), Default::default(), ) .expect("locale should be present"); -let fixed_decimal = Decimal::from(1000007); +let decimal = Decimal::from(1000007); -assert_writeable_eq!(df.format(&fixed_decimal), "১০,০০,০০৭"); +assert_writeable_eq!(formatter.format(&decimal), "১০,০০,০০৭"); ``` ### Format a number with digits after the decimal separator @@ -39,17 +39,17 @@ use icu::decimal::DecimalFormatter; use icu::locale::Locale; use writeable::assert_writeable_eq; -let df = +let formatter = DecimalFormatter::try_new(Default::default(), Default::default()) .expect("locale should be present"); -let fixed_decimal = { +let decimal = { let mut decimal = Decimal::from(200050); decimal.multiply_pow10(-2); decimal }; -assert_writeable_eq!(df.format(&fixed_decimal), "2,000.50"); +assert_writeable_eq!(formatter.format(&decimal), "2,000.50"); ``` ### Format a number using an alternative numbering system @@ -62,15 +62,15 @@ use icu::decimal::DecimalFormatter; use icu::locale::locale; use writeable::assert_writeable_eq; -let fdf = DecimalFormatter::try_new( +let formatter = DecimalFormatter::try_new( locale!("th-u-nu-thai").into(), Default::default(), ) .expect("locale should be present"); -let fixed_decimal = Decimal::from(1000007); +let decimal = Decimal::from(1000007); -assert_writeable_eq!(fdf.format(&fixed_decimal), "๑,๐๐๐,๐๐๗"); +assert_writeable_eq!(formatter.format(&decimal), "๑,๐๐๐,๐๐๗"); ``` [`DecimalFormatter`]: DecimalFormatter diff --git a/components/decimal/benches/fixed_decimal_format.rs b/components/decimal/benches/fixed_decimal_format.rs index 98c6e0436f7..414330ba087 100644 --- a/components/decimal/benches/fixed_decimal_format.rs +++ b/components/decimal/benches/fixed_decimal_format.rs @@ -32,10 +32,10 @@ fn overview_bench(c: &mut Criterion) { b.iter(|| { // This benchmark demonstrates the performance of the format function on 1000 numbers // ranging from -1e9 to 1e9. - let fdf = DecimalFormatter::try_new(prefs, options).unwrap(); + let formatter = DecimalFormatter::try_new(prefs, options).unwrap(); for &num in &nums { - let fd = Decimal::from(black_box(num)); - fdf.format_to_string(&fd); + let decimal = Decimal::from(black_box(num)); + formatter.format_to_string(&decimal); } }); }); diff --git a/components/decimal/src/grouper.rs b/components/decimal/src/grouper.rs index 88ee789016d..830625d310e 100644 --- a/components/decimal/src/grouper.rs +++ b/components/decimal/src/grouper.rs @@ -201,9 +201,9 @@ fn test_grouper() { grouping_strategy: Some(cas.strategy), ..Default::default() }; - let fdf = + let formatter = DecimalFormatter::try_new_unstable(&provider, Default::default(), options).unwrap(); - let actual = fdf.format(&dec); + let actual = formatter.format(&dec); assert_writeable_eq!(actual, cas.expected[i], "{:?}", cas); } } diff --git a/components/decimal/src/lib.rs b/components/decimal/src/lib.rs index ca502ffc506..630e47e8f30 100644 --- a/components/decimal/src/lib.rs +++ b/components/decimal/src/lib.rs @@ -20,15 +20,15 @@ //! use icu::locale::locale; //! use writeable::assert_writeable_eq; //! -//! let df = DecimalFormatter::try_new( +//! let formatter = DecimalFormatter::try_new( //! locale!("bn").into(), //! Default::default(), //! ) //! .expect("locale should be present"); //! -//! let fixed_decimal = Decimal::from(1000007); +//! let decimal = Decimal::from(1000007); //! -//! assert_writeable_eq!(df.format(&fixed_decimal), "১০,০০,০০৭"); +//! assert_writeable_eq!(formatter.format(&decimal), "১০,০০,০০৭"); //! ``` //! //! ## Format a number with digits after the decimal separator @@ -39,17 +39,17 @@ //! use icu::locale::Locale; //! use writeable::assert_writeable_eq; //! -//! let df = +//! let formatter = //! DecimalFormatter::try_new(Default::default(), Default::default()) //! .expect("locale should be present"); //! -//! let fixed_decimal = { +//! let decimal = { //! let mut decimal = Decimal::from(200050); //! decimal.multiply_pow10(-2); //! decimal //! }; //! -//! assert_writeable_eq!(df.format(&fixed_decimal), "2,000.50"); +//! assert_writeable_eq!(formatter.format(&decimal), "2,000.50"); //! ``` //! //! ## Format a number using an alternative numbering system @@ -62,15 +62,15 @@ //! use icu::locale::locale; //! use writeable::assert_writeable_eq; //! -//! let fdf = DecimalFormatter::try_new( +//! let formatter = DecimalFormatter::try_new( //! locale!("th-u-nu-thai").into(), //! Default::default(), //! ) //! .expect("locale should be present"); //! -//! let fixed_decimal = Decimal::from(1000007); +//! let decimal = Decimal::from(1000007); //! -//! assert_writeable_eq!(fdf.format(&fixed_decimal), "๑,๐๐๐,๐๐๗"); +//! assert_writeable_eq!(formatter.format(&decimal), "๑,๐๐๐,๐๐๗"); //! ``` //! //! [`DecimalFormatter`]: DecimalFormatter diff --git a/components/decimal/src/options.rs b/components/decimal/src/options.rs index a4c94105867..0fe7739d880 100644 --- a/components/decimal/src/options.rs +++ b/components/decimal/src/options.rs @@ -36,14 +36,14 @@ impl From for DecimalFormatterOptions { /// let locale = Default::default(); /// let mut options: options::DecimalFormatterOptions = Default::default(); /// options.grouping_strategy = Some(options::GroupingStrategy::Min2); -/// let df = DecimalFormatter::try_new(locale, options) +/// let formatter = DecimalFormatter::try_new(locale, options) /// .expect("locale should be present"); /// /// let one_thousand = 1000.into(); -/// assert_writeable_eq!(df.format(&one_thousand), "1000"); +/// assert_writeable_eq!(formatter.format(&one_thousand), "1000"); /// /// let ten_thousand = 10000.into(); -/// assert_writeable_eq!(df.format(&ten_thousand), "10,000"); +/// assert_writeable_eq!(formatter.format(&ten_thousand), "10,000"); /// ``` #[non_exhaustive] #[derive(Debug, Eq, PartialEq, Clone, Copy, Hash, Default)] diff --git a/components/decimal/src/parts.rs b/components/decimal/src/parts.rs index 66135d4784f..58003ef7da9 100644 --- a/components/decimal/src/parts.rs +++ b/components/decimal/src/parts.rs @@ -12,17 +12,17 @@ //! use icu::locale::locale; //! use writeable::assert_writeable_parts_eq; //! -//! let df = DecimalFormatter::try_new( +//! let formatter = DecimalFormatter::try_new( //! locale!("en").into(), //! Default::default(), //! ) //! .unwrap(); //! -//! let fixed_decimal = "-987654.321".parse().unwrap(); +//! let decimal = "-987654.321".parse().unwrap(); //! //! // Missing data is filled in on a best-effort basis, and an error is signaled. //! assert_writeable_parts_eq!( -//! df.format(&fixed_decimal), +//! formatter.format(&decimal), //! "-987,654.321", //! [ //! (0, 1, parts::MINUS_SIGN), diff --git a/components/decimal/src/provider.rs b/components/decimal/src/provider.rs index 39a6c74ce92..aa5875d108f 100644 --- a/components/decimal/src/provider.rs +++ b/components/decimal/src/provider.rs @@ -50,7 +50,7 @@ //! numbering_system: RefCell::new(None), //! }; //! -//! let df = DecimalFormatter::try_new_unstable( +//! let formatter = DecimalFormatter::try_new_unstable( //! &provider, //! locale!("th").into(), //! Default::default(), @@ -59,7 +59,7 @@ //! //! assert_eq!(provider.numbering_system.borrow().as_ref().map(|x| x.as_str()), Some("latn")); //! -//! let df = DecimalFormatter::try_new_unstable( +//! let formatter = DecimalFormatter::try_new_unstable( //! &provider, //! locale!("th-u-nu-thai").into(), //! Default::default(), @@ -68,7 +68,7 @@ //! //! assert_eq!(provider.numbering_system.borrow().as_ref().map(|x| x.as_str()), Some("thai")); //! -//! let df = DecimalFormatter::try_new_unstable( +//! let formatter = DecimalFormatter::try_new_unstable( //! &provider, //! locale!("th-u-nu-adlm").into(), //! Default::default(),