-
Notifications
You must be signed in to change notification settings - Fork 176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use pattern in icu_decimal
#5385
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
#![allow(clippy::exhaustive_enums)] | ||
|
||
use alloc::borrow::Cow; | ||
use icu_pattern::SinglePlaceholderPattern; | ||
use icu_provider::prelude::*; | ||
|
||
#[cfg(feature = "compiled_data")] | ||
|
@@ -46,30 +47,6 @@ const _: () = { | |
/// The latest minimum set of markers required by this component. | ||
pub const MARKERS: &[DataMarkerInfo] = &[DecimalSymbolsV1Marker::INFO]; | ||
|
||
/// A collection of strings to affix to a decimal number. | ||
/// | ||
/// <div class="stab unstable"> | ||
/// 🚧 This code is considered unstable; it may change at any time, in breaking or non-breaking ways, | ||
/// including in SemVer minor releases. While the serde representation of data structs is guaranteed | ||
/// to be stable, their Rust representation might not be. Use with caution. | ||
/// </div> | ||
#[derive(Debug, PartialEq, Clone, yoke::Yokeable, zerofrom::ZeroFrom)] | ||
#[cfg_attr( | ||
feature = "datagen", | ||
derive(serde::Serialize, databake::Bake), | ||
databake(path = icu_decimal::provider), | ||
)] | ||
#[cfg_attr(feature = "serde", derive(serde::Deserialize))] | ||
pub struct AffixesV1<'data> { | ||
/// String to prepend before the decimal number. | ||
#[cfg_attr(feature = "serde", serde(borrow))] | ||
pub prefix: Cow<'data, str>, | ||
|
||
/// String to append after the decimal number. | ||
#[cfg_attr(feature = "serde", serde(borrow))] | ||
pub suffix: Cow<'data, str>, | ||
} | ||
|
||
/// A collection of settings expressing where to put grouping separators in a decimal number. | ||
/// For example, `1,000,000` has two grouping separators, positioned along every 3 digits. | ||
/// | ||
|
@@ -117,13 +94,13 @@ pub struct GroupingSizesV1 { | |
)] | ||
#[cfg_attr(feature = "serde", derive(serde::Deserialize))] | ||
pub struct DecimalSymbolsV1<'data> { | ||
/// Prefix and suffix to apply when a negative sign is needed. | ||
/// Pattern to apply when a negative sign is needed. | ||
#[cfg_attr(feature = "serde", serde(borrow))] | ||
pub minus_sign_affixes: AffixesV1<'data>, | ||
pub minus_sign_pattern: Option<SinglePlaceholderPattern<Cow<'data, str>>>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Question: why did you make it an |
||
|
||
/// Prefix and suffix to apply when a plus sign is needed. | ||
/// Pattern to apply when a plus sign is needed. | ||
#[cfg_attr(feature = "serde", serde(borrow))] | ||
pub plus_sign_affixes: AffixesV1<'data>, | ||
pub plus_sign_pattern: Option<SinglePlaceholderPattern<Cow<'data, str>>>, | ||
|
||
/// Character used to separate the integer and fraction parts of the number. | ||
#[cfg_attr(feature = "serde", serde(borrow))] | ||
|
@@ -141,17 +118,18 @@ pub struct DecimalSymbolsV1<'data> { | |
pub digits: [char; 10], | ||
} | ||
|
||
/// The value used if [`DecimalSymbolsV1::minus_sign_pattern`] is empty. | ||
pub static NEGATIVE_DEFAULT: SinglePlaceholderPattern<Cow<'static, str>> = | ||
SinglePlaceholderPattern::from_store_unchecked(Cow::Borrowed("\x02-")); | ||
/// The value used if [`DecimalSymbolsV1::plus_sign_pattern`] is empty. | ||
pub static POSITIVE_DEFAULT: SinglePlaceholderPattern<Cow<'static, str>> = | ||
SinglePlaceholderPattern::from_store_unchecked(Cow::Borrowed("\x02+")); | ||
|
||
impl Default for DecimalSymbolsV1<'static> { | ||
fn default() -> Self { | ||
Self { | ||
minus_sign_affixes: AffixesV1 { | ||
prefix: Cow::Borrowed("-"), | ||
suffix: Cow::Borrowed(""), | ||
}, | ||
plus_sign_affixes: AffixesV1 { | ||
prefix: Cow::Borrowed("+"), | ||
suffix: Cow::Borrowed(""), | ||
}, | ||
minus_sign_pattern: None, | ||
plus_sign_pattern: None, | ||
decimal_separator: ".".into(), | ||
grouping_separator: ",".into(), | ||
grouping_sizes: GroupingSizesV1 { | ||
|
Large diffs are not rendered by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
strictly speaking this should use a pattern type that requires exactly one placeholder
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When you make
.suffix()
return anOption
, you can debug_assert that it isSome
.