Skip to content

Commit

Permalink
Implements number formattign in terms of unumberformat.h
Browse files Browse the repository at this point in the history
There are some sharp corners around significant digit formatting,
which will need to be revisited.

Issue #152
  • Loading branch information
filmil committed Jul 24, 2020
1 parent e3aae10 commit 7a828c0
Show file tree
Hide file tree
Showing 4 changed files with 268 additions and 58 deletions.
34 changes: 16 additions & 18 deletions ecma402_traits/src/numberformat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use std::fmt;
/// See [Options] for the contents of the options. See the [NumberFormat::try_new]
/// for the use of the options.
pub mod options {

/// Controls whether short or long form display is used. Short is slightly
/// more economical with spacing. Only used when notation is Compact.
#[derive(Eq, PartialEq, Debug, Clone)]
Expand Down Expand Up @@ -150,8 +150,7 @@ pub mod options {
/// be concatenated with "-per-" to make a compound unit. There is no default value; if the
/// style is "unit", the unit property must be provided.
#[derive(Debug, Clone)]
pub struct Unit(String);

pub struct Unit(pub String);
}

/// The options set by the user at construction time. See discussion at the top level
Expand All @@ -163,21 +162,21 @@ pub mod options {
/// [tc39lf]: https://tc39.es/proposal-intl-number-format/#sec-Intl.NumberFormat
#[derive(Debug, Clone)]
pub struct Options {
pub compact_display: options::CompactDisplay,
pub compact_display: Option<options::CompactDisplay>,
pub currency: Option<options::Currency>,
pub currency_display: options::CurrencyDisplay,
pub currency_sign: options::CurrencySign,
pub notation: options::Notation,
pub numbering_system: options::NumberingSystem,
pub numbering_system: Option<options::NumberingSystem>,
pub sign_display: options::SignDisplay,
pub style: options::Style,
pub unit: Option<options::Unit>,

pub minimum_integer_digits: u8,
pub minimum_fraction_digits: u8,
pub maximum_fraction_digits: u8,
pub minimum_significant_digits: u8,
pub maximum_significant_digits: u8,
pub minimum_integer_digits: Option<u8>,
pub minimum_fraction_digits: Option<u8>,
pub maximum_fraction_digits: Option<u8>,
pub minimum_significant_digits: Option<u8>,
pub maximum_significant_digits: Option<u8>,
}

impl Default for Options {
Expand All @@ -187,20 +186,20 @@ impl Default for Options {
/// [tc39lf]: https://tc39.es/proposal-intl-list-format/#sec-Intl.ListFormat
fn default() -> Self {
Options {
compact_display: options::CompactDisplay::Short,
compact_display: None,
currency: None,
currency_display: options::CurrencyDisplay::Symbol,
currency_sign: options::CurrencySign::Standard,
notation: options::Notation::Standard,
sign_display: options::SignDisplay::Auto,
style: options::Style::Decimal,
unit: None,
numbering_system: Default::default(),
minimum_integer_digits: 1,
minimum_fraction_digits: 0,
maximum_fraction_digits: 3,
minimum_significant_digits: 1,
maximum_significant_digits: 21,
numbering_system: None,
minimum_integer_digits: None,
minimum_fraction_digits: None,
maximum_fraction_digits: None,
minimum_significant_digits: None,
maximum_significant_digits: None,
}
}
}
Expand Down Expand Up @@ -229,4 +228,3 @@ pub trait NumberFormat {
where
W: fmt::Write;
}

7 changes: 7 additions & 0 deletions rust_icu_ecma402/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ rust_icu_ustring = { path = "../rust_icu_ustring", version = "0.3.0", default-fe
rust_icu_ulistformatter = { path = "../rust_icu_ulistformatter", version = "0.3.0", default-features = false }
rust_icu_upluralrules = { path = "../rust_icu_upluralrules", version = "0.3.0", default-features = false }
rust_icu_unum = { path = "../rust_icu_unum", version = "0.3.0", default-features = false }
rust_icu_unumberformatter = { path = "../rust_icu_unumberformatter", version = "0.3.0", default-features = false }

[dev-dependencies]
anyhow = "1.0.25"
Expand All @@ -38,6 +39,7 @@ use-bindgen = [
"rust_icu_ulistformatter/use-bindgen",
"rust_icu_uloc/use-bindgen",
"rust_icu_unum/use-bindgen",
"rust_icu_unumberformatter/use-bindgen",
"rust_icu_upluralrules/use-bindgen",
"rust_icu_ustring/use-bindgen",
]
Expand All @@ -47,6 +49,7 @@ renaming = [
"rust_icu_ulistformatter/renaming",
"rust_icu_uloc/renaming",
"rust_icu_unum/renaming",
"rust_icu_unumberformatter/renaming",
"rust_icu_upluralrules/renaming",
"rust_icu_ustring/renaming",
]
Expand All @@ -56,6 +59,7 @@ icu_config = [
"rust_icu_ulistformatter/icu_config",
"rust_icu_uloc/icu_config",
"rust_icu_unum/icu_config",
"rust_icu_unumberformatter/icu_config",
"rust_icu_upluralrules/icu_config",
"rust_icu_ustring/icu_config",
]
Expand All @@ -65,6 +69,7 @@ icu_version_in_env = [
"rust_icu_ulistformatter/icu_version_in_env",
"rust_icu_uloc/icu_version_in_env",
"rust_icu_unum/icu_version_in_env",
"rust_icu_unumberformatter/icu_version_in_env",
"rust_icu_upluralrules/icu_version_in_env",
"rust_icu_ustring/icu_version_in_env",
]
Expand All @@ -74,6 +79,7 @@ icu_version_64_plus = [
"rust_icu_ulistformatter/icu_version_64_plus",
"rust_icu_uloc/icu_version_64_plus",
"rust_icu_unum/icu_version_64_plus",
"rust_icu_unumberformatter/icu_version_64_plus",
"rust_icu_upluralrules/icu_version_64_plus",
"rust_icu_ustring/icu_version_64_plus",
]
Expand All @@ -83,6 +89,7 @@ icu_version_67_plus = [
"rust_icu_ulistformatter/icu_version_67_plus",
"rust_icu_uloc/icu_version_67_plus",
"rust_icu_unum/icu_version_67_plus",
"rust_icu_unumberformatter/icu_version_67_plus",
"rust_icu_upluralrules/icu_version_67_plus",
"rust_icu_ustring/icu_version_67_plus",
]
Expand Down
Loading

0 comments on commit 7a828c0

Please sign in to comment.