Skip to content

Commit

Permalink
Mapping functions between DateSymbolsV1, TimeSymbolsV1, and neo symbo…
Browse files Browse the repository at this point in the history
…ls (#4187)
  • Loading branch information
sffc authored Oct 21, 2023
1 parent a88ee84 commit e0849fd
Show file tree
Hide file tree
Showing 5 changed files with 628 additions and 5 deletions.
2 changes: 1 addition & 1 deletion components/datetime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ icu_calendar = { workspace = true }
icu_decimal = { workspace = true }
icu_locid = { workspace = true }
icu_plurals = { workspace = true }
icu_provider = { workspace = true, features = ["macros"] }
icu_provider = { workspace = true, features = ["macros", "experimental"] }
icu_timezone = { workspace = true }
smallvec = "1.6"
tinystr = { workspace = true, features = ["alloc", "zerovec"] }
Expand Down
21 changes: 21 additions & 0 deletions components/datetime/src/provider/calendar/symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,27 @@ macro_rules! symbols {
#[cfg_attr(feature = "serde", serde(borrow))]
pub stand_alone: Option<StandAloneWidthsV1<'data>>,
}

#[cfg(any(feature = "datagen", feature = "experimental"))]
impl<'data> ContextsV1<'data> {
/// Convenience function to return stand-alone abbreviated as an `Option<&>`.
pub(crate) fn stand_alone_abbreviated(&self) -> Option<&SymbolsV1<'data>> {
self.stand_alone.as_ref().and_then(|x| x.abbreviated.as_ref())
}
/// Convenience function to return stand-alone wide as an `Option<&>`.
pub(crate) fn stand_alone_wide(&self) -> Option<&SymbolsV1<'data>> {
self.stand_alone.as_ref().and_then(|x| x.wide.as_ref())
}
/// Convenience function to return stand-alone narrow as an `Option<&>`.
pub(crate) fn stand_alone_narrow(&self) -> Option<&SymbolsV1<'data>> {
self.stand_alone.as_ref().and_then(|x| x.narrow.as_ref())
}
/// Convenience function to return stand-alone short as an `Option<&>`.
#[allow(dead_code)] // not all symbols have a short variant
pub(crate) fn stand_alone_short(&self) -> Option<&SymbolsV1<'data>> {
self.stand_alone.as_ref().and_then(|x| x.short.as_ref())
}
}
}
};
}
Expand Down
8 changes: 4 additions & 4 deletions components/datetime/src/provider/neo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

mod adapter;

use crate::pattern::{self, runtime};
use icu_provider::prelude::*;
use tinystr::UnvalidatedTinyAsciiStr;
use zerovec::ule::UnvalidatedStr;
use zerovec::{VarZeroVec, ZeroMap};

/// Symbols used for representing the year name
Expand Down Expand Up @@ -45,10 +48,7 @@ use zerovec::{VarZeroVec, ZeroMap};
pub enum YearSymbolsV1<'data> {
/// This calendar uses eras with numeric years, this stores the era names mapped from
/// era code to the name
Eras(
#[cfg_attr(feature = "serde", serde(borrow))]
ZeroMap<'data, UnvalidatedTinyAsciiStr<16>, str>,
),
Eras(#[cfg_attr(feature = "serde", serde(borrow))] ZeroMap<'data, UnvalidatedStr, str>),
/// This calendar is cyclic (Chinese, Dangi), so it uses cyclic year names without any eras
Cyclic(#[cfg_attr(feature = "serde", serde(borrow))] VarZeroVec<'data, str>),
}
Expand Down
Loading

0 comments on commit e0849fd

Please sign in to comment.