Skip to content

Commit

Permalink
Datagen for neo Weekdays
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Oct 20, 2023
1 parent ed21356 commit 7298538
Show file tree
Hide file tree
Showing 14 changed files with 840 additions and 7 deletions.
5 changes: 5 additions & 0 deletions components/datetime/data/data/macros.rs

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

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions components/datetime/data/data/mod.rs

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

5 changes: 5 additions & 0 deletions components/datetime/src/provider/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ const _: () = {
icu_datetime_data::impl_time_zone_generic_short_v1!(Baked);
icu_datetime_data::impl_time_zone_specific_long_v1!(Baked);
icu_datetime_data::impl_time_zone_specific_short_v1!(Baked);

#[cfg(feature = "experimental")]
icu_datetime_data::impl_weekday_symbols_v1!(Baked);
};

#[cfg(feature = "datagen")]
Expand Down Expand Up @@ -128,4 +131,6 @@ pub const KEYS: &[DataKey] = &[
time_zones::TimeZoneFormatsV1Marker::KEY,
#[cfg(feature = "experimental")]
calendar::DateSkeletonPatternsV1Marker::KEY,
#[cfg(feature = "experimental")]
neo::WeekdaySymbolsV1Marker::KEY,
];
2 changes: 2 additions & 0 deletions components/datetime/src/provider/neo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ pub enum MonthSymbolsV1<'data> {
#[icu_provider::data_struct(
marker(WeekdaySymbolsV1Marker, "datetime/symbols/weekdays@1"),
marker(DayPeriodSymbolsV1Marker, "datetime/symbols/dayperiods@1"),
// We're not producing or using day symbols yet, but this is where they would go
marker(ChineseDaySymbolsV1Marker, "datetime/symbols/chinese/days@1"),
marker(DangiDaySymbolsV1Marker, "datetime/symbols/dangi/days@1"),
// for calendars that don't use day symbols
Expand Down
16 changes: 16 additions & 0 deletions components/locid/src/extensions/private/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,22 @@ impl Private {
Self(input.into())
}

/// A constructor which takes a single [`Subtag`].
///
/// # Examples
///
/// ```
/// use icu::locid::extensions::private::{Private, Subtag};
///
/// let subtag: Subtag = "foo".parse().expect("Failed to parse a Subtag.");
///
/// let private = Private::from_single(subtag);
/// assert_eq!(&private.to_string(), "x-foo");
/// ```
pub const fn new_single(input: Subtag) -> Self {
Self(ShortSlice::new_single(input))
}

/// Empties the [`Private`] list.
///
/// # Examples
Expand Down
11 changes: 11 additions & 0 deletions provider/core/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,17 @@ impl AuxiliaryKeys {
}
}

#[cfg(feature = "experimental")]
impl From<Subtag> for AuxiliaryKeys {
fn from(subtag: Subtag) -> Self {
Self {
value: AuxiliaryKeysInner::Stack(
TinyAsciiStr::from_bytes(&subtag.as_str().as_bytes()).unwrap(),
),
}
}
}

#[test]
fn test_data_locale_to_string() {
use icu_locid::locale;
Expand Down
12 changes: 7 additions & 5 deletions provider/datagen/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,11 +495,13 @@ fn select_locales_for_key(
result
.into_iter()
.chain(explicit.iter().cloned())
.filter(|locale| {
if implicit.contains(locale) {
.filter(|locale_orig| {
let mut locale = locale_orig.clone();
locale.remove_aux();
if implicit.contains(&locale) {
return true;
}
if explicit.contains(locale) {
if explicit.contains(&locale) {
return true;
}
if locale.is_langid_und() && include_und {
Expand All @@ -520,14 +522,14 @@ fn select_locales_for_key(
{
return false;
}
let mut iter = fallbacker_with_config.fallback_for(locale.clone());
let mut iter = fallbacker_with_config.fallback_for(locale);
while !iter.get().is_und() {
if explicit.contains(iter.get()) {
return true;
}
iter.step();
}
log::trace!("Filtered out: {key}/{locale}");
log::trace!("Filtered out: {key}/{locale_orig}"); // this will print aux keys too but it avoids a clone
false
})
.collect()
Expand Down
2 changes: 2 additions & 0 deletions provider/datagen/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ registry!(
icu_datetime::provider::calendar::RocDateSymbolsV1Marker = "datetime/roc/datesymbols@1",
icu_datetime::provider::calendar::TimeLengthsV1Marker = "datetime/timelengths@1",
icu_datetime::provider::calendar::TimeSymbolsV1Marker = "datetime/timesymbols@1",
// new datetime symbols stuff (unused so far)
icu_datetime::provider::neo::WeekdaySymbolsV1Marker = "datetime/symbols/weekdays@1",
icu_datetime::provider::time_zones::MetazoneGenericNamesLongV1Marker =
"time_zone/generic_long@1",
icu_datetime::provider::time_zones::MetazoneGenericNamesShortV1Marker =
Expand Down
67 changes: 67 additions & 0 deletions provider/datagen/src/transform/cldr/cldr_serde/ca.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,70 @@ pub struct LangDates {
}

pub type Resource = super::LocaleResource<LangDates>;

/// A length, for querying Contexts
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum Length {
Abbr,
Narrow,
Wide,
Short,
}

/// A context, for querying Contexts
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum Context {
Format,
Standalone,
}

impl<Symbols> Contexts<Symbols> {
/// Load
fn load_exact(&self, context: Context, length: Length) -> Option<&Symbols> {
use {Context::*, Length::*};

match (context, length) {
(Format, Abbr) => Some(&self.format.abbreviated),
(Format, Narrow) => Some(&self.format.narrow),
(Format, Wide) => Some(&self.format.wide),
(Format, Short) => self.format.short.as_ref(),
(Standalone, Abbr) => self
.stand_alone
.as_ref()
.and_then(|s| s.abbreviated.as_ref()),
(Standalone, Narrow) => self.stand_alone.as_ref().and_then(|s| s.narrow.as_ref()),
(Standalone, Wide) => self.stand_alone.as_ref().and_then(|s| s.wide.as_ref()),
(Standalone, Short) => self.stand_alone.as_ref().and_then(|s| s.short.as_ref()),
}
}

/// Load the data for a given context/length pair, performing horizontal fallback
/// if necessary
///
/// Horizontal fallback is performed as specified in
/// <https://unicode.org/reports/tr35/tr35-dates.html#months_days_quarters_eras>
///
/// I.e. missing `standalone`s fall back to `format`, missing `short` falls back to
/// `abbr`.
pub fn load(&self, context: Context, length: Length) -> &Symbols {
if context == Context::Standalone {
if let Some(sym) = self.load_exact(context, length) {
return sym;
}
// fall back to format
}

if let Some(sym) = self.load_exact(Context::Format, length) {
return sym;
}

// The only case where we reach this far without error is when we're looking
// for short lengths
debug_assert!(
length == Length::Short,
"Short is the only nullable format length!"
);

&self.format.abbreviated
}
}
1 change: 1 addition & 0 deletions provider/datagen/src/transform/cldr/datetime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use std::collections::HashMap;
use std::collections::HashSet;
use std::str::FromStr;

mod neo;
mod patterns;
mod skeletons;
mod symbols;
Expand Down
Loading

0 comments on commit 7298538

Please sign in to comment.