Skip to content

Commit

Permalink
Merge branch 'main' into std
Browse files Browse the repository at this point in the history
  • Loading branch information
robertbastian committed Jul 5, 2024
2 parents b59b6dc + 0efc535 commit 1f082ce
Show file tree
Hide file tree
Showing 15,108 changed files with 58,088 additions and 58,188 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
88 changes: 44 additions & 44 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ members = [
# Provider
"provider/adapters",
"provider/baked",
"provider/bikeshed",
"provider/source",
"provider/blob",
"provider/core",
"provider/core/macros",
Expand Down Expand Up @@ -152,7 +152,7 @@ icu_harfbuzz = { version = "~0.2.0", path = "ffi/harfbuzz", default-features = f

# Provider
icu_provider_export = { version = "~1.5.0", path = "provider/export", default-features = false }
icu_datagen_bikeshed = { version = "~1.5.0", path = "provider/bikeshed", default-features = false }
icu_provider_source = { version = "~1.5.0", path = "provider/source", default-features = false }
icu_provider = { version = "~1.5.0", path = "provider/core", default-features = false }
icu_provider_macros = { version = "~1.5.0", path = "provider/core/macros", default-features = false }
icu_provider_adapters = { version = "~1.5.0", path = "provider/adapters", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion components/collator/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ fn test_vi() {
}

#[test]
// See DatagenProvider test_zh_non_baked for gb2312 and big5han tests
// See SourceDataProvider test_zh_non_baked for gb2312 and big5han tests
fn test_zh() {
// Note: ㄅ is Bopomofo.

Expand Down
14 changes: 1 addition & 13 deletions components/experimental/src/dimension/provider/units.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,7 @@ pub struct UnitsDisplayNameV1<'data> {
// TODO: use `MeasureUnit` for the units key instead of strings.
/// Contains the long width patterns for the units.
#[cfg_attr(feature = "serde", serde(borrow))]
pub long: ZeroMap<'data, Count, str>,

// TODO: store the pattern in a SinglePattern.
// TODO: use `MeasureUnit` for the units key instead of strings.
/// Contains the short width patterns for the units.
#[cfg_attr(feature = "serde", serde(borrow))]
pub short: ZeroMap<'data, Count, str>,

// TODO: store the pattern in a SinglePattern.
// TODO: use `MeasureUnit` for the units key instead of strings.
/// Contains the narrow width patterns for the units.
#[cfg_attr(feature = "serde", serde(borrow))]
pub narrow: ZeroMap<'data, Count, str>,
pub patterns: ZeroMap<'data, Count, str>,
}

// TODO: revise this.
Expand Down
17 changes: 9 additions & 8 deletions components/experimental/src/dimension/units/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ use writeable::Writeable;

use crate::alloc::borrow::ToOwned;
use crate::dimension::provider::units::{Count, UnitsDisplayNameV1};
use crate::dimension::units::options::{UnitsFormatterOptions, Width};

pub struct FormattedUnit<'l> {
pub(crate) value: &'l FixedDecimal,
pub(crate) unit: &'l str,
pub(crate) options: &'l UnitsFormatterOptions,
// TODO: review using options and essentials.
// pub(crate) _options: &'l UnitsFormatterOptions,
// pub(crate) essential: &'l UnitsEssentialsV1<'l>,
pub(crate) display_name: &'l UnitsDisplayNameV1<'l>,
pub(crate) fixed_decimal_formatter: &'l FixedDecimalFormatter,
Expand All @@ -35,12 +35,11 @@ impl<'l> Writeable for FormattedUnit<'l> {
let plural_category = self.plural_rules.category_for(self.value);
let count = Count::from(plural_category);
let mut unit_pattern = None;
let display_name = match self.options.width {
Width::Short => self.display_name.short.get(&count),
Width::Long => self.display_name.long.get(&count),
Width::Narrow => self.display_name.narrow.get(&count),
}
.unwrap_or_else(|| unit_pattern.insert("{0} ".to_owned() + self.unit));
let display_name = self
.display_name
.patterns
.get(&count)
.unwrap_or_else(|| unit_pattern.insert("{0} ".to_owned() + self.unit));

// TODO: once the patterns are implemented to be used in the data side, we do not need this.
let pattern =
Expand All @@ -60,6 +59,8 @@ fn test_basic() {
use writeable::Writeable;

use crate::dimension::units::formatter::UnitsFormatter;
use crate::dimension::units::options::UnitsFormatterOptions;
use crate::dimension::units::options::Width;

let locale = locale!("en-US").into();
let meter = "meter";
Expand Down
38 changes: 28 additions & 10 deletions components/experimental/src/dimension/units/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ use icu_decimal::FixedDecimalFormatter;
use icu_plurals::PluralRules;
use icu_provider::DataPayload;

use super::super::provider::units::UnitsDisplayNameV1Marker;
use super::format::FormattedUnit;
use super::options::UnitsFormatterOptions;
use super::options::{UnitsFormatterOptions, Width};
use crate::dimension::provider::units::UnitsDisplayNameV1Marker;
use icu_provider::prelude::*;
use smallvec::SmallVec;

extern crate alloc;

Expand All @@ -27,7 +28,7 @@ extern crate alloc;
pub struct UnitsFormatter {
/// Options bag for the units formatter to determine the behavior of the formatter.
/// for example: width of the units.
options: UnitsFormatterOptions,
_options: UnitsFormatterOptions,

// /// Essential data for the units formatter.
// essential: DataPayload<UnitsEssentialsV1Marker>,
Expand All @@ -53,6 +54,20 @@ impl UnitsFormatter {
]
);

// TODO: Remove this function once we have separate markers for different widths.
#[inline]
fn attribute(width: Width, unit: &str) -> SmallVec<[u8; 32]> {
let mut buffer: SmallVec<[u8; 32]> = SmallVec::new();
let length = match width {
Width::Short => "short-",
Width::Narrow => "narrow-",
Width::Long => "long-",
};
buffer.extend_from_slice(length.as_bytes());
buffer.extend_from_slice(unit.as_bytes());
buffer
}

/// Creates a new [`UnitsFormatter`] from compiled locale data and an options bag.
///
/// ✨ *Enabled with the `compiled_data` Cargo feature.*
Expand All @@ -69,8 +84,10 @@ impl UnitsFormatter {

let plural_rules = PluralRules::try_new_cardinal(locale)?;

let unit_attribute = DataMarkerAttributes::try_from_str(unit)
.map_err(|_| DataError::custom("Failed to parse unit"))?;
// TODO: Remove this allocation once we have separate markers for different widths.
let attribute = Self::attribute(options.width, unit);
let unit_attribute = DataMarkerAttributes::try_from_utf8(&attribute[..attribute.len()])
.map_err(|_| DataError::custom("Failed to create a data marker"))?;

let display_name = crate::provider::Baked
.load(DataRequest {
Expand All @@ -83,7 +100,7 @@ impl UnitsFormatter {
.payload;

Ok(Self {
options,
_options: options,
display_name,
fixed_decimal_formatter,
plural_rules,
Expand Down Expand Up @@ -111,8 +128,10 @@ impl UnitsFormatter {

let plural_rules = PluralRules::try_new_cardinal_unstable(provider, locale)?;

let unit_attribute = DataMarkerAttributes::try_from_str(unit)
.map_err(|_| DataError::custom("Failed to parse unit"))?;
// TODO: Remove this allocation once we have separate markers for different widths.
let attribute = Self::attribute(options.width, unit);
let unit_attribute = DataMarkerAttributes::try_from_utf8(&attribute[..attribute.len()])
.map_err(|_| DataError::custom("Failed to create a data marker"))?;

let display_name = provider
.load(DataRequest {
Expand All @@ -125,7 +144,7 @@ impl UnitsFormatter {
.payload;

Ok(Self {
options,
_options: options,
display_name,
fixed_decimal_formatter,
plural_rules,
Expand All @@ -141,7 +160,6 @@ impl UnitsFormatter {
FormattedUnit {
value,
unit,
options: &self.options,
display_name: self.display_name.get(),
fixed_decimal_formatter: &self.fixed_decimal_formatter,
plural_rules: &self.plural_rules,
Expand Down
24 changes: 0 additions & 24 deletions provider/bikeshed/README.md

This file was deleted.

This file was deleted.

Loading

0 comments on commit 1f082ce

Please sign in to comment.