summaryrefslogtreecommitdiffstats
path: root/vendor/icu_list/src
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:48 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:48 +0000
commitef24de24a82fe681581cc130f342363c47c0969a (patch)
tree0d494f7e1a38b95c92426f58fe6eaa877303a86c /vendor/icu_list/src
parentReleasing progress-linux version 1.74.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-ef24de24a82fe681581cc130f342363c47c0969a.tar.xz
rustc-ef24de24a82fe681581cc130f342363c47c0969a.zip
Merging upstream version 1.75.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/icu_list/src')
-rw-r--r--vendor/icu_list/src/lib.rs15
-rw-r--r--vendor/icu_list/src/list_formatter.rs120
-rw-r--r--vendor/icu_list/src/provider/mod.rs35
-rw-r--r--vendor/icu_list/src/provider/serde_dfa.rs3
4 files changed, 133 insertions, 40 deletions
diff --git a/vendor/icu_list/src/lib.rs b/vendor/icu_list/src/lib.rs
index 9412a7fb9..931caf111 100644
--- a/vendor/icu_list/src/lib.rs
+++ b/vendor/icu_list/src/lib.rs
@@ -16,12 +16,11 @@
//! # use icu::locid::locale;
//! # use writeable::*;
//! #
-//! let list_formatter = ListFormatter::try_new_and_with_length_unstable(
-//! &icu_testdata::unstable(),
+//! let list_formatter = ListFormatter::try_new_and_with_length(
//! &locale!("es").into(),
//! ListLength::Wide,
//! )
-//! .expect("Data should load successfully");
+//! .expect("locale should be present");
//!
//! assert_writeable_eq!(
//! list_formatter.format(["España", "Suiza"].iter()),
@@ -42,12 +41,11 @@
//! # use icu::locid::locale;
//! # use writeable::*;
//! #
-//! let list_formatter = ListFormatter::try_new_or_with_length_unstable(
-//! &icu_testdata::unstable(),
+//! let list_formatter = ListFormatter::try_new_or_with_length(
//! &locale!("th").into(),
//! ListLength::Short,
//! )
-//! .expect("Data should load successfully");
+//! .expect("locale should be present");
//!
//! // We can use any Writeables as inputs
//! assert_writeable_eq!(list_formatter.format(1..=3), "1, 2 หรือ 3",);
@@ -60,12 +58,11 @@
//! # use icu::locid::locale;
//! # use writeable::*;
//! #
-//! let list_formatter = ListFormatter::try_new_unit_with_length_unstable(
-//! &icu_testdata::unstable(),
+//! let list_formatter = ListFormatter::try_new_unit_with_length(
//! &locale!("en").into(),
//! ListLength::Wide,
//! )
-//! .expect("Data should load successfully");
+//! .expect("locale should be present");
//!
//! assert_writeable_eq!(
//! list_formatter.format(["1ft", "2in"].iter()),
diff --git a/vendor/icu_list/src/list_formatter.rs b/vendor/icu_list/src/list_formatter.rs
index 5ef67c324..5ed635c2c 100644
--- a/vendor/icu_list/src/list_formatter.rs
+++ b/vendor/icu_list/src/list_formatter.rs
@@ -21,17 +21,35 @@ pub struct ListFormatter {
}
macro_rules! constructor {
- ($name: ident, $name_any: ident, $name_buffer: ident, $marker: ty, $doc: literal) => {
- #[doc = concat!("Creates a new [`ListFormatter`] that produces a ", $doc, "-type list.\n\nSee the [CLDR spec]",
- "(https://unicode.org/reports/tr35/tr35-general.html#ListPatterns) for an explanation of the different types.\n\n",
- "[📚 Help choosing a constructor](icu_provider::constructors)\n\n",
- "<div class=\"stab unstable\">⚠️ The bounds on this function may change over time, including in SemVer minor releases.</div>")]
- pub fn $name<D: DataProvider<$marker> + ?Sized>(
- data_provider: &D,
+ ($name: ident, $name_any: ident, $name_buffer: ident, $name_unstable: ident, $marker: ty, $doc: literal) => {
+ icu_provider::gen_any_buffer_data_constructors!(
+ locale: include,
+ style: ListLength,
+ error: ListError,
+ #[doc = concat!("Creates a new [`ListFormatter`] that produces a ", $doc, "-type list using compiled data.")]
+ ///
+ /// See the [CLDR spec](https://unicode.org/reports/tr35/tr35-general.html#ListPatterns) for
+ /// an explanation of the different types.
+ ///
+ /// ✨ *Enabled with the `compiled_data` Cargo feature.*
+ ///
+ /// [📚 Help choosing a constructor](icu_provider::constructors)
+ functions: [
+ $name,
+ $name_any,
+ $name_buffer,
+ $name_unstable,
+ Self
+ ]
+ );
+
+ #[doc = icu_provider::gen_any_buffer_unstable_docs!(UNSTABLE, Self::$name)]
+ pub fn $name_unstable(
+ provider: &(impl DataProvider<$marker> + ?Sized),
locale: &DataLocale,
length: ListLength,
) -> Result<Self, ListError> {
- let data = data_provider
+ let data = provider
.load(DataRequest {
locale,
metadata: Default::default(),
@@ -39,38 +57,31 @@ macro_rules! constructor {
.take_payload()?.cast();
Ok(Self { data, length })
}
- icu_provider::gen_any_buffer_constructors!(
- locale: include,
- style: ListLength,
- error: ListError,
- functions: [
- Self::$name,
- $name_any,
- $name_buffer
- ]
- );
};
}
impl ListFormatter {
constructor!(
- try_new_and_with_length_unstable,
+ try_new_and_with_length,
try_new_and_with_length_with_any_provider,
try_new_and_with_length_with_buffer_provider,
+ try_new_and_with_length_unstable,
AndListV1Marker,
"and"
);
constructor!(
- try_new_or_with_length_unstable,
+ try_new_or_with_length,
try_new_or_with_length_with_any_provider,
try_new_or_with_length_with_buffer_provider,
+ try_new_or_with_length_unstable,
OrListV1Marker,
"or"
);
constructor!(
- try_new_unit_with_length_unstable,
+ try_new_unit_with_length,
try_new_unit_with_length_with_any_provider,
try_new_unit_with_length_with_buffer_provider,
+ try_new_unit_with_length_unstable,
UnitListV1Marker,
"unit"
);
@@ -87,8 +98,7 @@ impl ListFormatter {
/// use icu::list::*;
/// # use icu::locid::locale;
/// # use writeable::*;
- /// let formatteur = ListFormatter::try_new_and_with_length_unstable(
- /// &icu_testdata::unstable(),
+ /// let formatteur = ListFormatter::try_new_and_with_length(
/// &locale!("fr").into(),
/// ListLength::Wide,
/// )
@@ -358,4 +368,68 @@ mod tests {
assert_writeable_eq!(formatter.format(["Beta", "Alpha"].iter()), "Beta :o Alpha");
}
+
+ macro_rules! test {
+ ($locale:literal, $type:ident, $(($input:expr, $output:literal),)+) => {
+ let f = ListFormatter::$type(
+ &icu::locid::locale!($locale).into(),
+ ListLength::Wide
+ ).unwrap();
+ $(
+ assert_writeable_eq!(f.format($input.iter()), $output);
+ )+
+ };
+ }
+
+ #[test]
+ fn test_basic() {
+ test!("fr", try_new_or_with_length, (["A", "B"], "A ou B"),);
+ }
+
+ #[test]
+ fn test_spanish() {
+ test!(
+ "es",
+ try_new_and_with_length,
+ (["x", "Mallorca"], "x y Mallorca"),
+ (["x", "Ibiza"], "x e Ibiza"),
+ (["x", "Hidalgo"], "x e Hidalgo"),
+ (["x", "Hierva"], "x y Hierva"),
+ );
+
+ test!(
+ "es",
+ try_new_or_with_length,
+ (["x", "Ibiza"], "x o Ibiza"),
+ (["x", "Okinawa"], "x u Okinawa"),
+ (["x", "8 más"], "x u 8 más"),
+ (["x", "8"], "x u 8"),
+ (["x", "87 más"], "x u 87 más"),
+ (["x", "87"], "x u 87"),
+ (["x", "11 más"], "x u 11 más"),
+ (["x", "11"], "x u 11"),
+ (["x", "110 más"], "x o 110 más"),
+ (["x", "110"], "x o 110"),
+ (["x", "11.000 más"], "x u 11.000 más"),
+ (["x", "11.000"], "x u 11.000"),
+ (["x", "11.000,92 más"], "x u 11.000,92 más"),
+ (["x", "11.000,92"], "x u 11.000,92"),
+ );
+
+ test!(
+ "es-AR",
+ try_new_and_with_length,
+ (["x", "Ibiza"], "x e Ibiza"),
+ );
+ }
+
+ #[test]
+ fn test_hebrew() {
+ test!(
+ "he",
+ try_new_and_with_length,
+ (["x", "יפו"], "x ויפו"),
+ (["x", "Ibiza"], "x ו‑Ibiza"),
+ );
+ }
}
diff --git a/vendor/icu_list/src/provider/mod.rs b/vendor/icu_list/src/provider/mod.rs
index 8438e956c..000234399 100644
--- a/vendor/icu_list/src/provider/mod.rs
+++ b/vendor/icu_list/src/provider/mod.rs
@@ -23,6 +23,29 @@ use icu_provider::DataMarker;
mod serde_dfa;
pub use serde_dfa::SerdeDFA;
+#[cfg(feature = "compiled_data")]
+#[derive(Debug)]
+/// Baked data
+///
+/// <div class="stab unstable">
+/// 🚧 This code is considered unstable; it may change at any time, in breaking or non-breaking ways,
+/// including in SemVer minor releases. In particular, the `DataProvider` implementations are only
+/// guaranteed to match with this version's `*_unstable` providers. Use with caution.
+/// </div>
+pub struct Baked;
+
+#[cfg(feature = "compiled_data")]
+const _: () = {
+ pub mod icu {
+ pub use crate as list;
+ pub use icu_locid_transform as locid_transform;
+ }
+ icu_list_data::make_provider!(Baked);
+ icu_list_data::impl_list_and_v1!(Baked);
+ icu_list_data::impl_list_or_v1!(Baked);
+ icu_list_data::impl_list_unit_v1!(Baked);
+};
+
/// Symbols and metadata required for [`ListFormatter`](crate::ListFormatter).
///
/// <div class="stab unstable">
@@ -35,7 +58,7 @@ pub use serde_dfa::SerdeDFA;
OrListV1Marker = "list/or@1",
UnitListV1Marker = "list/unit@1"
)]
-#[derive(Clone, Debug)]
+#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(
feature = "datagen",
derive(serde::Serialize, databake::Bake),
@@ -103,10 +126,10 @@ impl<'data> ListFormatterPatternsV1<'data> {
/// including in SemVer minor releases. While the serde representation of data structs is guaranteed
/// to be stable, their Rust representation might not be. Use with caution.
/// </div>
-#[derive(Clone, Debug, yoke::Yokeable, zerofrom::ZeroFrom)]
+#[derive(Clone, Debug, PartialEq, yoke::Yokeable, zerofrom::ZeroFrom)]
#[cfg_attr(
feature = "datagen",
- derive(PartialEq, serde::Serialize, databake::Bake),
+ derive(serde::Serialize, databake::Bake),
databake(path = icu_list::provider),
)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
@@ -129,10 +152,10 @@ pub struct ConditionalListJoinerPattern<'data> {
/// including in SemVer minor releases. While the serde representation of data structs is guaranteed
/// to be stable, their Rust representation might not be. Use with caution.
/// </div>
-#[derive(Clone, Debug, yoke::Yokeable, zerofrom::ZeroFrom)]
+#[derive(Clone, Debug, PartialEq, yoke::Yokeable, zerofrom::ZeroFrom)]
#[cfg_attr(
feature = "datagen",
- derive(PartialEq, serde::Serialize, databake::Bake),
+ derive(serde::Serialize, databake::Bake),
databake(path = icu_list::provider),
)]
pub struct SpecialCasePattern<'data> {
@@ -245,7 +268,7 @@ impl databake::Bake for ListJoinerPattern<'_> {
let string = (&*self.string).bake(env);
let index_1 = self.index_1.bake(env);
databake::quote! {
- ::icu_list::provider::ListJoinerPattern::from_parts(#string, #index_1)
+ icu_list::provider::ListJoinerPattern::from_parts(#string, #index_1)
}
}
}
diff --git a/vendor/icu_list/src/provider/serde_dfa.rs b/vendor/icu_list/src/provider/serde_dfa.rs
index 9be85fb18..4cde60d46 100644
--- a/vendor/icu_list/src/provider/serde_dfa.rs
+++ b/vendor/icu_list/src/provider/serde_dfa.rs
@@ -22,7 +22,6 @@ pub struct SerdeDFA<'data> {
pattern: Option<Cow<'data, str>>,
}
-#[cfg(feature = "datagen")]
impl PartialEq for SerdeDFA<'_> {
fn eq(&self, other: &Self) -> bool {
self.dfa_bytes == other.dfa_bytes
@@ -38,7 +37,7 @@ impl databake::Bake for SerdeDFA<'_> {
// Safe because of `to_bytes_little_endian`/`to_bytes_big_endian`'s invariant.
databake::quote! {
unsafe {
- ::icu_list::provider::SerdeDFA::from_dfa_bytes_unchecked(
+ icu_list::provider::SerdeDFA::from_dfa_bytes_unchecked(
if cfg!(target_endian = "little") {
#le_bytes
} else {