Skip to content

Commit

Permalink
Move preferences to icu_locale_core (#5630)
Browse files Browse the repository at this point in the history
Fixes #5179
  • Loading branch information
robertbastian authored Oct 1, 2024
1 parent efac644 commit 79d1183
Show file tree
Hide file tree
Showing 40 changed files with 184 additions and 260 deletions.
8 changes: 0 additions & 8 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ members = [
"utils/fixed_decimal",
"utils/ixdtf",
"utils/litemap",
"utils/preferences",
"utils/resb",
"utils/env_preferences",
"utils/tinystr",
Expand Down
1 change: 1 addition & 0 deletions components/locale_core/src/extensions/unicode/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ pub use attributes::Attributes;
#[doc(inline)]
pub use key::{key, Key};
pub use keywords::Keywords;
#[doc(inline)]
pub use subdivision::{subdivision_suffix, SubdivisionId, SubdivisionSuffix};
#[doc(inline)]
pub use value::{value, Value};
Expand Down
1 change: 1 addition & 0 deletions components/locale_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ pub use parser::errors::ParseError;
pub mod extensions;
#[macro_use]
pub mod subtags;
pub mod preferences;
pub mod zerovec;

#[cfg(feature = "serde")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

/// TODO
//! TODO
pub mod unicode;
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#![allow(non_snake_case)]

use crate::extensions::unicode::enum_keyword;
use crate::preferences::extensions::unicode::enum_keyword;

// https://github.com/unicode-org/cldr/blob/main/common/bcp47/calendar.xml
enum_keyword!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

use crate::extensions::unicode::enum_keyword;
use crate::preferences::extensions::unicode::enum_keyword;

enum_keyword!(
/// TODO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

use crate::extensions::unicode::errors::PreferencesParseError;
use crate::extensions::unicode::struct_keyword;
use icu_locale_core::{extensions::unicode::Value, subtags::Subtag};
use crate::preferences::extensions::unicode::errors::PreferencesParseError;
use crate::preferences::extensions::unicode::struct_keyword;
use crate::{extensions::unicode::Value, subtags::Subtag};
use tinystr::TinyAsciiStr;

struct_keyword!(
Expand All @@ -22,7 +22,7 @@ struct_keyword!(
Err(PreferencesParseError::InvalidKeywordValue)
},
|input: CurrencyType| {
icu_locale_core::extensions::unicode::Value::from_subtag(Some(
crate::extensions::unicode::Value::from_subtag(Some(
Subtag::from_tinystr_unvalidated(input.0.resize()),
))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

use crate::extensions::unicode::enum_keyword;
use crate::preferences::extensions::unicode::enum_keyword;

enum_keyword!(
/// TODO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

use crate::extensions::unicode::errors::PreferencesParseError;
use crate::extensions::unicode::struct_keyword;
use crate::extensions::unicode::Value;
use crate::preferences::extensions::unicode::errors::PreferencesParseError;
use crate::preferences::extensions::unicode::struct_keyword;
use crate::subtags::Script;
use alloc::vec::Vec;
use core::str::FromStr;
use icu_locale_core::extensions::unicode::Value;
use icu_locale_core::subtags::Script;

struct_keyword!(
/// TODO
Expand All @@ -24,6 +24,6 @@ struct_keyword!(
.map(Self)
},
|input: DictionaryBreakScriptExclusions| {
icu_locale_core::extensions::unicode::Value::from_iter(input.0.into_iter().map(Into::into))
crate::extensions::unicode::Value::from_iter(input.0.into_iter().map(Into::into))
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

use crate::extensions::unicode::enum_keyword;
use crate::preferences::extensions::unicode::enum_keyword;

enum_keyword!(
/// TODO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

use crate::extensions::unicode::enum_keyword;
use crate::preferences::extensions::unicode::enum_keyword;

enum_keyword!(
/// TODO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

use crate::extensions::unicode::enum_keyword;
use crate::preferences::extensions::unicode::enum_keyword;

enum_keyword!(
/// TODO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

use crate::extensions::unicode::enum_keyword;
use crate::preferences::extensions::unicode::enum_keyword;

enum_keyword!(
/// TODO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

use crate::extensions::unicode::enum_keyword;
use crate::preferences::extensions::unicode::enum_keyword;

enum_keyword!(
/// TODO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

use crate::extensions::unicode::enum_keyword;
use crate::preferences::extensions::unicode::enum_keyword;

enum_keyword!(
/// TODO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

use crate::extensions::unicode::enum_keyword;
use crate::preferences::extensions::unicode::enum_keyword;

enum_keyword!(
/// TODO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

use crate::extensions::unicode::errors::PreferencesParseError;
use crate::extensions::unicode::struct_keyword;
use icu_locale_core::{extensions::unicode::Value, subtags::Subtag};
use crate::preferences::extensions::unicode::errors::PreferencesParseError;
use crate::preferences::extensions::unicode::struct_keyword;
use crate::{extensions::unicode::Value, subtags::Subtag};

struct_keyword!(
/// TODO
Expand All @@ -18,6 +18,6 @@ struct_keyword!(
.ok_or(PreferencesParseError::InvalidKeywordValue)
},
|input: NumberingSystem| {
icu_locale_core::extensions::unicode::Value::from_subtag(Some(input.0))
crate::extensions::unicode::Value::from_subtag(Some(input.0))
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

use crate::extensions::unicode::errors::PreferencesParseError;
use crate::extensions::unicode::struct_keyword;
use alloc::string::ToString;
use icu_locale_core::{
use crate::preferences::extensions::unicode::errors::PreferencesParseError;
use crate::preferences::extensions::unicode::struct_keyword;
use crate::{
extensions::unicode::{SubdivisionId, Value},
subtags::Subtag,
};
use alloc::string::ToString;

struct_keyword!(
/// TODO
Expand All @@ -30,9 +30,9 @@ struct_keyword!(
#[cfg(test)]
mod test {
use super::*;
use icu_locale_core::extensions::unicode;
use icu_locale_core::extensions::unicode::subdivision_suffix;
use icu_locale_core::subtags::region;
use crate::extensions::unicode;
use crate::extensions::unicode::subdivision_suffix;
use crate::subtags::region;

#[test]
fn region_override_test() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

use core::ops::Deref;

use crate::extensions::unicode::errors::PreferencesParseError;
use crate::extensions::unicode::struct_keyword;
use alloc::string::ToString;
use icu_locale_core::{
use crate::preferences::extensions::unicode::errors::PreferencesParseError;
use crate::preferences::extensions::unicode::struct_keyword;
use crate::{
extensions::unicode::{SubdivisionId, Value},
subtags::Subtag,
};
use alloc::string::ToString;

struct_keyword!(
/// TODO
Expand Down Expand Up @@ -40,9 +40,9 @@ impl Deref for RegionalSubdivision {
#[cfg(test)]
mod test {
use super::*;
use icu_locale_core::extensions::unicode;
use icu_locale_core::extensions::unicode::subdivision_suffix;
use icu_locale_core::subtags::region;
use crate::extensions::unicode;
use crate::extensions::unicode::subdivision_suffix;
use crate::subtags::region;

#[test]
fn region_subdivision_test() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

use crate::extensions::unicode::enum_keyword;
use crate::preferences::extensions::unicode::enum_keyword;

enum_keyword!(
/// TODO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

use crate::extensions::unicode::errors::PreferencesParseError;
use crate::extensions::unicode::struct_keyword;
use icu_locale_core::{extensions::unicode::Value, subtags::Subtag};
use crate::preferences::extensions::unicode::errors::PreferencesParseError;
use crate::preferences::extensions::unicode::struct_keyword;
use crate::{extensions::unicode::Value, subtags::Subtag};

struct_keyword!(
/// TODO
Expand All @@ -18,6 +18,6 @@ struct_keyword!(
.ok_or(PreferencesParseError::InvalidKeywordValue)
},
|input: TimeZoneShortId| {
icu_locale_core::extensions::unicode::Value::from_subtag(Some(input.0))
crate::extensions::unicode::Value::from_subtag(Some(input.0))
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

use crate::extensions::unicode::enum_keyword;
use crate::preferences::extensions::unicode::enum_keyword;

enum_keyword!(
/// TODO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ macro_rules! __enum_keyword {

impl $name {
/// TODO
pub fn extend_value(self, input: &mut icu_locale_core::extensions::unicode::Value) {
pub fn extend_value(self, input: &mut $crate::extensions::unicode::Value) {
match self {
$(
// This is circumventing a limitation of the macro_rules - we need to have a conditional
Expand All @@ -48,7 +48,7 @@ macro_rules! __enum_keyword {
// complaints.
#[allow(non_snake_case)]
Self::$variant $(($v2))? => {
input.push_subtag(icu_locale_core::subtags::subtag!($key));
input.push_subtag($crate::subtags::subtag!($key));

$(
if let Some(v2) = $v2 {
Expand All @@ -61,10 +61,10 @@ macro_rules! __enum_keyword {
}
}

impl TryFrom<icu_locale_core::extensions::unicode::Value> for $name {
type Error = $crate::extensions::unicode::errors::PreferencesParseError;
impl TryFrom<$crate::extensions::unicode::Value> for $name {
type Error = $crate::preferences::extensions::unicode::errors::PreferencesParseError;

fn try_from(mut s: icu_locale_core::extensions::unicode::Value) -> Result<Self, Self::Error> {
fn try_from(mut s: $crate::extensions::unicode::Value) -> Result<Self, Self::Error> {
let first_subtag = s.get_subtag(0).unwrap();
Ok(match first_subtag.as_str() {
$(
Expand All @@ -80,9 +80,9 @@ macro_rules! __enum_keyword {
}
}

impl From<$name> for icu_locale_core::extensions::unicode::Value {
fn from(input: $name) -> icu_locale_core::extensions::unicode::Value {
let mut result = icu_locale_core::extensions::unicode::Value::default();
impl From<$name> for $crate::extensions::unicode::Value {
fn from(input: $name) -> $crate::extensions::unicode::Value {
let mut result = $crate::extensions::unicode::Value::default();
input.extend_value(&mut result);
result
}
Expand All @@ -93,16 +93,16 @@ macro_rules! __enum_keyword {
}, $ext_key:literal) => {
$crate::__enum_keyword!($(#[$doc])* $name {$($key => $variant $(($v2) {$($subk => $subv),*})?),*});

impl $crate::PreferenceKey for $name {
fn unicode_extension_key() -> Option<icu_locale_core::extensions::unicode::Key> {
Some(icu_locale_core::extensions::unicode::key!($ext_key))
impl $crate::preferences::PreferenceKey for $name {
fn unicode_extension_key() -> Option<$crate::extensions::unicode::Key> {
Some($crate::extensions::unicode::key!($ext_key))
}

fn is_custom(&self) -> bool {
false
}

fn unicode_extension_value(&self) -> Option<icu_locale_core::extensions::unicode::Value> {
fn unicode_extension_value(&self) -> Option<$crate::extensions::unicode::Value> {
Some(self.clone().into())
}
}
Expand All @@ -113,8 +113,8 @@ pub use __enum_keyword as enum_keyword;
#[cfg(test)]
mod tests {
use super::*;
use crate::extensions::unicode;
use core::str::FromStr;
use icu_locale_core::extensions::unicode;

#[test]
fn enum_keywords_test() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@
mod enum_keyword;
mod struct_keyword;

#[doc(inline)]
pub use enum_keyword::{enum_keyword, enum_keyword_inner};
#[doc(inline)]
pub use struct_keyword::struct_keyword;
Loading

0 comments on commit 79d1183

Please sign in to comment.