Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from runtime parsing to compile time parsing #2406

Merged
merged 2 commits into from
Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions components/calendar/src/any_calendar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ use core::fmt;
/// There are many ways of constructing an AnyCalendar'd date:
/// ```
/// use icu::calendar::{AnyCalendar, AnyCalendarKind, DateTime, japanese::Japanese, types::Time};
/// use icu::locid::Locale;
/// use icu::locid::{Locale,locale};
pdogr marked this conversation as resolved.
Show resolved Hide resolved
/// # use std::str::FromStr;
/// # use std::rc::Rc;
/// # use std::convert::TryInto;
///
/// let provider = icu_testdata::get_provider();
///
/// let locale = Locale::from_str("en-u-ca-japanese").unwrap(); // English with the Japanese calendar
/// let locale = locale!("en-u-ca-japanese"); // English with the Japanese calendar
///
/// let calendar = AnyCalendar::try_new_for_locale_with_buffer_provider(&provider, &(&locale).into())
/// .expect("constructing AnyCalendar failed");
Expand Down
12 changes: 6 additions & 6 deletions components/datetime/src/any/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ use icu_provider::DataLocale;
/// ```
/// use icu::calendar::{any_calendar::AnyCalendar, Date, Gregorian};
/// use icu::datetime::{options::length, DateFormatter};
/// use icu::locid::Locale;
/// use icu::locid::{Locale, locale};
/// use std::str::FromStr;
///
/// let provider = icu_testdata::get_provider();
///
/// let length = length::Date::Medium;
///
/// let df = DateFormatter::try_new_with_buffer_provider(&provider, &Locale::from_str("en-u-ca-gregory").unwrap().into(), length)
/// let df = DateFormatter::try_new_with_buffer_provider(&provider, &locale!("en-u-ca-gregory").into(), length)
/// .expect("Failed to create TypedDateFormatter instance.");
///
/// let date = Date::new_gregorian_date(2020, 9, 1)
Expand Down Expand Up @@ -101,14 +101,14 @@ impl DateFormatter {
/// ```
/// use icu::calendar::{any_calendar::AnyCalendar, Date, Gregorian};
/// use icu::datetime::{options::length, DateFormatter};
/// use icu::locid::Locale;
/// use icu::locid::{Locale, locale};
/// use icu_provider::any::DynamicDataProviderAnyMarkerWrap;
/// use std::str::FromStr;
///
/// let provider = icu_testdata::get_provider();
///
/// let length = length::Date::Medium;
/// let locale = Locale::from_str("en-u-ca-gregory").unwrap();
/// let locale: Locale = locale!("en-u-ca-gregory");
pdogr marked this conversation as resolved.
Show resolved Hide resolved
///
/// let df = DateFormatter::try_new_with_buffer_provider(&provider, &locale.into(), length)
/// .expect("Failed to create TypedDateFormatter instance.");
Expand Down Expand Up @@ -149,14 +149,14 @@ impl DateFormatter {
/// ```
/// use icu::calendar::{any_calendar::AnyCalendar, Date, Gregorian};
/// use icu::datetime::{options::length, DateFormatter};
/// use icu::locid::Locale;
/// use icu::locid::{Locale, locale};
/// use icu_provider::any::DynamicDataProviderAnyMarkerWrap;
/// use std::str::FromStr;
///
/// let provider = icu_testdata::get_provider();
///
/// let length = length::Date::Medium;
/// let locale = Locale::from_str("en-u-ca-gregory").unwrap();
/// let locale: Locale = locale!("en-u-ca-gregory");
///
/// let df = DateFormatter::try_new_unstable(&provider, &locale.into(), length)
/// .expect("Failed to create TypedDateFormatter instance.");
Expand Down
22 changes: 11 additions & 11 deletions components/datetime/src/any/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ use icu_provider::DataLocale;
/// ```
/// use icu::calendar::DateTime;
/// use icu::datetime::{options::length, DateTimeFormatter};
/// use icu::locid::Locale;
/// use icu::locid::{Locale, locale};
/// use std::str::FromStr;
///
/// let provider = icu_testdata::get_provider();
///
/// let mut options = length::Bag::from_date_time_style(length::Date::Medium, length::Time::Short);
///
/// let dtf = DateTimeFormatter::try_new_with_buffer_provider(&provider, &Locale::from_str("en-u-ca-gregory").unwrap().into(), options.into())
/// let dtf = DateTimeFormatter::try_new_with_buffer_provider(&provider, &locale!("en-u-ca-gregory").into(), options.into())
/// .expect("Failed to create DateTimeFormatter instance.");
///
/// let datetime = DateTime::new_gregorian_datetime(2020, 9, 1, 12, 34, 28)
Expand All @@ -59,14 +59,14 @@ use icu_provider::DataLocale;
/// ```
/// use icu::calendar::{AnyCalendar, AnyCalendarKind, DateTime, types::Time};
/// use icu::datetime::{options::length, DateTimeFormatter};
/// use icu::locid::Locale;
/// use icu::locid::{Locale, locale};
/// # use std::str::FromStr;
/// # use std::rc::Rc;
/// # use std::convert::TryInto;
///
/// let provider = icu_testdata::get_provider();
///
/// let locale = Locale::from_str("en-u-ca-japanese").unwrap(); // English with the Japanese calendar
/// let locale: Locale = locale!("en-u-ca-japanese"); // English with the Japanese calendar
///
/// let calendar = AnyCalendar::try_new_for_locale_with_buffer_provider(&provider, &(&locale).into())
/// .expect("constructing AnyCalendar failed");
Expand Down Expand Up @@ -149,14 +149,14 @@ impl DateTimeFormatter {
/// ```
/// use icu::calendar::DateTime;
/// use icu::datetime::{options::length, DateTimeFormatter};
/// use icu::locid::Locale;
/// use icu::locid::{Locale, locale};
/// use icu_provider::any::DynamicDataProviderAnyMarkerWrap;
/// use std::str::FromStr;
///
/// let provider = icu_testdata::get_provider();
///
/// let mut options = length::Bag::from_date_time_style(length::Date::Medium, length::Time::Short);
/// let locale = Locale::from_str("en-u-ca-gregory").unwrap();
/// let locale: Locale = locale!("en-u-ca-gregory");
///
/// let dtf = DateTimeFormatter::try_new_with_buffer_provider(&provider, &locale.into(), options.into())
/// .expect("Failed to create TypedDateTimeFormatter instance.");
Expand Down Expand Up @@ -197,14 +197,14 @@ impl DateTimeFormatter {
/// ```
/// use icu::calendar::DateTime;
/// use icu::datetime::{options::length, DateTimeFormatter};
/// use icu::locid::Locale;
/// use icu::locid::{Locale, locale};
/// use icu_provider::any::DynamicDataProviderAnyMarkerWrap;
/// use std::str::FromStr;
///
/// let provider = icu_testdata::get_provider();
///
/// let mut options = length::Bag::from_date_time_style(length::Date::Medium, length::Time::Short);
/// let locale = Locale::from_str("en-u-ca-gregory").unwrap();
/// let locale: Locale = locale!("en-u-ca-gregory");
///
/// let dtf = DateTimeFormatter::try_new_unstable(&provider, &locale.into(), options.into())
/// .expect("Failed to create TypedDateTimeFormatter instance.");
Expand Down Expand Up @@ -338,7 +338,7 @@ impl DateTimeFormatter {
/// let provider = icu_testdata::get_provider();
///
/// let length = length::Date::Medium;
/// let locale = Locale::from_str("en-u-ca-gregory").unwrap();
/// let locale: Locale = locale!("en-u-ca-gregory");
///
/// let df = DateFormatter::try_new_with_buffer_provider(&provider, &locale.into(), length)
/// .expect("Failed to create TypedDateFormatter instance.");
Expand Down Expand Up @@ -444,15 +444,15 @@ where {
/// options::{components, length},
/// DateTimeFormatter, DateTimeFormatterOptions,
/// };
/// use icu::locid::Locale;
/// use icu::locid::{Locale, locale};
/// use std::str::FromStr;
///
/// let options = length::Bag::from_date_style(length::Date::Medium).into();
///
/// let provider = icu_testdata::get_provider();
/// let dtf = DateTimeFormatter::try_new_with_buffer_provider(
/// &provider,
/// &Locale::from_str("en-u-ca-gregory").unwrap().into(),
/// &locale!("en-u-ca-gregory").into(),
/// options
/// )
/// .expect("Failed to create TypedDateTimeFormatter instance.");
Expand Down
12 changes: 6 additions & 6 deletions components/datetime/src/any/zoned_datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ impl ZonedDateTimeFormatter {
/// use icu::datetime::options::length;
/// use icu::datetime::mock::parse_zoned_gregorian_from_str;
/// use icu::datetime::{DateTimeFormatterOptions, ZonedDateTimeFormatter};
/// use icu::locid::Locale;
/// use icu::locid::{Locale, locale};
/// use icu::datetime::TimeZoneFormatterOptions;
/// use std::str::FromStr;
///
/// let provider = icu_testdata::get_provider();
///
/// let options = length::Bag::from_date_time_style(length::Date::Medium, length::Time::Long).into();
/// let locale = Locale::from_str("en-u-ca-gregory").unwrap();
/// let locale: Locale = locale!("en-u-ca-gregory");
///
/// let zdtf = ZonedDateTimeFormatter::try_new_unstable(
/// &provider,
Expand Down Expand Up @@ -260,14 +260,14 @@ impl ZonedDateTimeFormatter {
/// use icu::datetime::options::length;
/// use icu::datetime::mock::parse_zoned_gregorian_from_str;
/// use icu::datetime::{DateTimeFormatterOptions, ZonedDateTimeFormatter};
/// use icu::locid::Locale;
/// use icu::locid::{Locale, locale};
/// use icu::datetime::TimeZoneFormatterOptions;
/// use std::str::FromStr;
///
/// let provider = icu_testdata::get_baked_provider();
///
/// let options = length::Bag::from_date_time_style(length::Date::Medium, length::Time::Long).into();
/// let locale = Locale::from_str("en-u-ca-gregory").unwrap();
/// let locale: Locale = locale!("en-u-ca-gregory");
///
/// let zdtf = ZonedDateTimeFormatter::try_new_with_any_provider(
/// &provider,
Expand Down Expand Up @@ -316,14 +316,14 @@ impl ZonedDateTimeFormatter {
/// use icu::datetime::options::length;
/// use icu::datetime::mock::parse_zoned_gregorian_from_str;
/// use icu::datetime::{DateTimeFormatterOptions, ZonedDateTimeFormatter};
/// use icu::locid::Locale;
/// use icu::locid::{Locale, locale};
/// use icu::datetime::TimeZoneFormatterOptions;
/// use std::str::FromStr;
///
/// let provider = icu_testdata::get_provider();
///
/// let options = length::Bag::from_date_time_style(length::Date::Medium, length::Time::Long).into();
/// let locale = Locale::from_str("en").unwrap();
/// let locale: Locale = locale!("en");
///
/// let zdtf = ZonedDateTimeFormatter::try_new_with_buffer_provider(
/// &provider,
Expand Down
5 changes: 3 additions & 2 deletions components/locid/src/extensions/transform/fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ impl Fields {
/// ```
/// use icu::locid::extensions::transform::Fields;
/// use icu::locid::Locale;
/// use icu::locid::locale;
///
/// let loc1 = Locale::from_bytes(b"und-t-h0-hybrid").unwrap();
/// let loc2 = Locale::from_bytes(b"und-u-ca-buddhist").unwrap();
/// let loc1:Locale = Locale::from_bytes(b"und-t-h0-hybrid").unwrap();
/// let loc2:Locale = locale!("und-u-ca-buddhist");
///
/// assert!(!loc1.extensions.transform.fields.is_empty());
/// assert!(loc2.extensions.transform.fields.is_empty());
Expand Down
11 changes: 6 additions & 5 deletions components/locid/src/extensions/unicode/keywords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,10 @@ impl Keywords {
/// ```
/// use icu::locid::extensions::unicode::Keywords;
/// use icu::locid::Locale;
/// use icu::locid::locale;
///
/// let loc1 = Locale::from_bytes(b"und-t-h0-hybrid").unwrap();
/// let loc2 = Locale::from_bytes(b"und-u-ca-buddhist").unwrap();
/// let loc2 = locale!("und-u-ca-buddhist");
///
/// assert!(loc1.extensions.unicode.keywords.is_empty());
/// assert!(!loc2.extensions.unicode.keywords.is_empty());
Expand Down Expand Up @@ -327,25 +328,25 @@ impl Keywords {
/// # Examples
///
/// ```
/// use icu::locid::Locale;
/// use icu::locid::{Locale, locale};
/// use icu::locid::extensions::unicode::Keywords;
/// use std::cmp::Ordering;
///
/// let subtags: &[&[u8]] = &[&*b"ca", &*b"buddhist"];
///
/// let kwds = "und-u-ca-buddhist".parse::<Locale>().unwrap().extensions.unicode.keywords;
/// let kwds = locale!("und-u-ca-buddhist").extensions.unicode.keywords;
/// assert_eq!(
/// Ordering::Equal,
/// kwds.strict_cmp_iter(subtags.iter().copied()).end()
/// );
///
/// let kwds = "und".parse::<Locale>().unwrap().extensions.unicode.keywords;
/// let kwds = locale!("und").extensions.unicode.keywords;
/// assert_eq!(
/// Ordering::Less,
/// kwds.strict_cmp_iter(subtags.iter().copied()).end()
/// );
///
/// let kwds = "und-u-nu-latn".parse::<Locale>().unwrap().extensions.unicode.keywords;
/// let kwds = locale!("und-u-nu-latn").extensions.unicode.keywords;
/// assert_eq!(
/// Ordering::Greater,
/// kwds.strict_cmp_iter(subtags.iter().copied()).end()
Expand Down
8 changes: 4 additions & 4 deletions components/locid/src/locale.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,24 +204,24 @@ impl Locale {
/// # Examples
///
/// ```
/// use icu::locid::Locale;
/// use icu::locid::{Locale, locale};
/// use std::cmp::Ordering;
///
/// let subtags: &[&[u8]] = &[&*b"ca", &*b"ES", &*b"valencia", &*b"u", &*b"ca", &*b"hebrew"];
///
/// let loc = "ca-ES-valencia-u-ca-hebrew".parse::<Locale>().unwrap();
/// let loc: Locale = locale!("ca-ES-valencia-u-ca-hebrew");
/// assert_eq!(
/// Ordering::Equal,
/// loc.strict_cmp_iter(subtags.iter().copied()).end()
/// );
///
/// let loc = "ca-ES-valencia".parse::<Locale>().unwrap();
/// let loc: Locale = locale!("ca-ES-valencia");
/// assert_eq!(
/// Ordering::Less,
/// loc.strict_cmp_iter(subtags.iter().copied()).end()
/// );
///
/// let loc = "ca-ES-valencia-u-nu-arab".parse::<Locale>().unwrap();
/// let loc: Locale = locale!("ca-ES-valencia-u-nu-arab");
/// assert_eq!(
/// Ordering::Greater,
/// loc.strict_cmp_iter(subtags.iter().copied()).end()
Expand Down
11 changes: 4 additions & 7 deletions provider/adapters/src/fallback/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ pub struct LocaleFallbackConfig {
/// config.priority = FallbackPriority::Language;
/// let key_fallbacker = fallbacker.for_config(config);
/// let mut fallback_iterator = key_fallbacker.fallback_for(
/// icu_locid::Locale::from_bytes(b"ca-ES-valencia")
/// .unwrap()
/// icu_locid::locale!("ca-ES-valencia")
/// .into(),
/// );
///
Expand Down Expand Up @@ -109,8 +108,7 @@ pub struct LocaleFallbackConfig {
/// config.priority = FallbackPriority::Region;
/// let key_fallbacker = fallbacker.for_config(config);
/// let mut fallback_iterator = key_fallbacker.fallback_for(
/// icu_locid::Locale::from_bytes(b"ca-ES-valencia")
/// .unwrap()
/// icu_locid::locale!("ca-ES-valencia")
/// .into(),
/// );
///
Expand Down Expand Up @@ -142,8 +140,7 @@ pub struct LocaleFallbackConfig {
/// config.extension_key = Some(icu_locid::extensions_unicode_key!("nu"));
/// let key_fallbacker = fallbacker.for_config(config);
/// let mut fallback_iterator = key_fallbacker.fallback_for(
/// icu_locid::Locale::from_bytes(b"ar-EG-u-nu-latn")
/// .unwrap()
/// icu_locid::locale!("ar-EG-u-nu-latn")
/// .into(),
/// );
///
Expand Down Expand Up @@ -264,7 +261,7 @@ impl LocaleFallbacker {
/// let fallbacker = LocaleFallbacker::try_new_with_buffer_provider(&provider).expect("data");
/// let key_fallbacker = fallbacker.for_key(FooV1Marker::KEY);
/// let mut fallback_iterator = key_fallbacker
/// .fallback_for(icu_locid::Locale::from_bytes(b"en-GB").unwrap().into());
/// .fallback_for(icu_locid::locale!("en-GB").into());
///
/// // Run the algorithm and check the results.
/// assert_eq!(fallback_iterator.get().to_string(), "en-GB");
Expand Down