Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into decimaldigits
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Nov 15, 2024
2 parents e8eaea9 + 36d97cd commit 2df57b9
Show file tree
Hide file tree
Showing 30 changed files with 406 additions and 192 deletions.
12 changes: 8 additions & 4 deletions components/datetime/src/external_loaders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ impl FixedDecimalFormatterLoader for ExternalLoaderCompiledData {
locale: &DataLocale,
options: FixedDecimalFormatterOptions,
) -> Result<FixedDecimalFormatter, DataError> {
FixedDecimalFormatter::try_new(locale, options)
let temp_loc = locale.clone().into_locale();
FixedDecimalFormatter::try_new(temp_loc.into(), options)
}
}

Expand All @@ -64,7 +65,8 @@ where
locale: &DataLocale,
options: FixedDecimalFormatterOptions,
) -> Result<FixedDecimalFormatter, DataError> {
FixedDecimalFormatter::try_new_with_any_provider(self.0, locale, options)
let temp_loc = locale.clone().into_locale();
FixedDecimalFormatter::try_new_with_any_provider(self.0, temp_loc.into(), options)
}
}

Expand Down Expand Up @@ -93,7 +95,8 @@ where
locale: &DataLocale,
options: FixedDecimalFormatterOptions,
) -> Result<FixedDecimalFormatter, DataError> {
FixedDecimalFormatter::try_new_with_buffer_provider(self.0, locale, options)
let temp_loc = locale.clone().into_locale();
FixedDecimalFormatter::try_new_with_buffer_provider(self.0, temp_loc.into(), options)
}
}

Expand Down Expand Up @@ -123,7 +126,8 @@ where
locale: &DataLocale,
options: FixedDecimalFormatterOptions,
) -> Result<FixedDecimalFormatter, DataError> {
FixedDecimalFormatter::try_new_unstable(self.0, locale, options)
let temp_loc = locale.clone().into_locale();
FixedDecimalFormatter::try_new_unstable(self.0, temp_loc.into(), options)
}
}

Expand Down
2 changes: 1 addition & 1 deletion components/datetime/src/format/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ mod tests {
let mut fixed_decimal_format_options = FixedDecimalFormatterOptions::default();
fixed_decimal_format_options.grouping_strategy = GroupingStrategy::Never;
let fixed_decimal_format = FixedDecimalFormatter::try_new(
&icu_locale_core::locale!("en").into(),
icu_locale_core::locale!("en").into(),
fixed_decimal_format_options,
)
.unwrap();
Expand Down
6 changes: 3 additions & 3 deletions components/decimal/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion components/decimal/benches/fixed_decimal_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ fn triangular_nums(range: f64) -> Vec<isize> {

fn overview_bench(c: &mut Criterion) {
let nums = triangular_nums(1e9);

c.bench_function("icu_decimal/overview", |b| {
b.iter(|| {
// This benchmark demonstrates the performance of the format function on 1000 numbers
Expand Down
2 changes: 1 addition & 1 deletion components/decimal/examples/code_line_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const LINES_REMOVED_ADDED: [(i64, i64); 5] = [
];

fn main() {
let fdf = FixedDecimalFormatter::try_new(&locale!("bn").into(), Default::default())
let fdf = FixedDecimalFormatter::try_new(locale!("bn").into(), Default::default())
.expect("locale should be present");

for (removed, added) in LINES_REMOVED_ADDED {
Expand Down
2 changes: 1 addition & 1 deletion components/decimal/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ mod tests {
#[test]
pub fn test_es_mx() {
let locale = locale!("es-MX").into();
let fmt = FixedDecimalFormatter::try_new(&locale, Default::default()).unwrap();
let fmt = FixedDecimalFormatter::try_new(locale, Default::default()).unwrap();
let fd = "12345.67".parse().unwrap();
assert_writeable_eq!(fmt.format(&fd), "12,345.67");
}
Expand Down
2 changes: 1 addition & 1 deletion components/decimal/src/grouper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ fn test_grouper() {
};
let fdf = FixedDecimalFormatter::try_new_unstable(
&provider.as_downcasting(),
&Default::default(),
Default::default(),
options,
)
.unwrap();
Expand Down
36 changes: 27 additions & 9 deletions components/decimal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
//! use writeable::assert_writeable_eq;
//!
//! let fdf = FixedDecimalFormatter::try_new(
//! &locale!("bn").into(),
//! locale!("bn").into(),
//! Default::default(),
//! )
//! .expect("locale should be present");
Expand All @@ -40,7 +40,7 @@
//! use writeable::assert_writeable_eq;
//!
//! let fdf =
//! FixedDecimalFormatter::try_new(&Default::default(), Default::default())
//! FixedDecimalFormatter::try_new(Default::default(), Default::default())
//! .expect("locale should be present");
//!
//! let fixed_decimal = FixedDecimal::from(200050).multiplied_pow10(-2);
Expand All @@ -60,7 +60,7 @@
//! use writeable::assert_writeable_eq;
//!
//! let fdf = FixedDecimalFormatter::try_new(
//! &locale!("th-u-nu-thai").into(),
//! locale!("th-u-nu-thai").into(),
//! Default::default(),
//! )
//! .expect("locale should be present");
Expand Down Expand Up @@ -101,12 +101,24 @@ pub use format::FormattedFixedDecimal;
use alloc::string::String;
use fixed_decimal::FixedDecimal;
use icu_locale_core::locale;
use icu_locale_core::preferences::{
define_preferences, extensions::unicode::keywords::NumberingSystem,
};
use icu_provider::prelude::*;
use size_test_macro::size_test;
use writeable::Writeable;

size_test!(FixedDecimalFormatter, fixed_decimal_formatter_size, 104);

define_preferences!(
/// The preferences for fixed decimal formatting.
FixedDecimalFormatterPreferences,
{
/// Numbering System. Corresponds to the `-u-nu` in Unicode Locale Identifier.
numbering_system: NumberingSystem
}
);

/// A formatter for [`FixedDecimal`], rendering decimal digits in an i18n-friendly way.
///
/// [`FixedDecimalFormatter`] supports:
Expand Down Expand Up @@ -135,7 +147,7 @@ impl AsRef<FixedDecimalFormatter> for FixedDecimalFormatter {

impl FixedDecimalFormatter {
icu_provider::gen_any_buffer_data_constructors!(
(locale, options: options::FixedDecimalFormatterOptions) -> error: DataError,
(prefs: FixedDecimalFormatterPreferences, options: options::FixedDecimalFormatterOptions) -> error: DataError,
/// Creates a new [`FixedDecimalFormatter`] from compiled data and an options bag.
);

Expand All @@ -146,16 +158,22 @@ impl FixedDecimalFormatter {
+ ?Sized,
>(
provider: &D,
locale: &DataLocale,
prefs: FixedDecimalFormatterPreferences,
options: options::FixedDecimalFormatterOptions,
) -> Result<Self, DataError> {
let locale = DataLocale::from_preferences_locale::<provider::DecimalSymbolsV2Marker>(
prefs.locale_prefs,
);
let nu: &str = prefs
.numbering_system
.as_ref()
.map(|s| s.as_str())
.unwrap_or("");
let symbols: DataPayload<provider::DecimalSymbolsV2Marker> = provider
.load(DataRequest {
id: DataIdentifierBorrowed::for_marker_attributes_and_locale(
DataMarkerAttributes::from_str_or_panic(
locale.get_single_unicode_ext("nu").unwrap_or_default(),
),
locale,
DataMarkerAttributes::from_str_or_panic(nu),
&locale,
),
..Default::default()
})?
Expand Down
2 changes: 1 addition & 1 deletion components/decimal/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl From<GroupingStrategy> for FixedDecimalFormatterOptions {
/// let locale = Default::default();
/// let mut options: options::FixedDecimalFormatterOptions = Default::default();
/// options.grouping_strategy = options::GroupingStrategy::Min2;
/// let fdf = FixedDecimalFormatter::try_new(&locale, options)
/// let fdf = FixedDecimalFormatter::try_new(locale, options)
/// .expect("locale should be present");
///
/// let one_thousand = 1000.into();
Expand Down
2 changes: 1 addition & 1 deletion components/experimental/src/compactdecimal/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl FormattedCompactDecimal<'_> {
/// use writeable::assert_writeable_eq;
///
/// let short_english = CompactDecimalFormatter::try_new_short(
/// &locale!("en").into(),
/// locale!("en").into(),
/// Default::default(),
/// )
/// .unwrap();
Expand Down
Loading

0 comments on commit 2df57b9

Please sign in to comment.