diff --git a/components/casemap/benches/casemap.rs b/components/casemap/benches/casemap.rs index 7314bece065..f339907aa15 100644 --- a/components/casemap/benches/casemap.rs +++ b/components/casemap/benches/casemap.rs @@ -28,7 +28,7 @@ fn overview_bench(c: &mut Criterion) { c.bench_function("icu_casemap/titlecase_segment", |b| { b.iter(|| { for s in TEST_STRING_EN.split(' ') { - black_box(casemapper.titlecase_segment_legacy_to_string( + black_box(casemapper.titlecase_segment_with_only_case_data_to_string( black_box(s), &root, Default::default(), diff --git a/components/casemap/src/casemapper.rs b/components/casemap/src/casemapper.rs index 8c2c76abc8c..f55489af2f1 100644 --- a/components/casemap/src/casemapper.rs +++ b/components/casemap/src/casemapper.rs @@ -7,7 +7,7 @@ use crate::provider::data::MappingKind; use crate::provider::CaseMapV1; use crate::provider::CaseMapV1Marker; use crate::set::ClosureSink; -use crate::titlecase::{HeadAdjustment, TailCasing, TitlecaseOptions}; +use crate::titlecase::{LeadingAdjustment, TitlecaseOptions, TrailingCase}; use alloc::string::String; use icu_locid::LanguageIdentifier; use icu_provider::prelude::*; @@ -111,7 +111,7 @@ impl CaseMapper { src, CaseMapLocale::from_langid(langid), MappingKind::Lower, - TailCasing::default(), + TrailingCase::default(), ) } @@ -131,12 +131,13 @@ impl CaseMapper { src, CaseMapLocale::from_langid(langid), MappingKind::Upper, - TailCasing::default(), + TrailingCase::default(), ) } /// Returns the full titlecase mapping of the given string as a [`Writeable`], treating - /// the string as a single segment (and thus only titlecasing the beginning of it). + /// the string as a single segment (and thus only titlecasing the beginning of it). Performs + /// the specified leading adjustment behavior from the options without loading additional data. /// /// This should typically be used as a lower-level helper to construct the titlecasing operation desired /// by the application, for example one can titlecase on a per-word basis by mixing this with @@ -146,16 +147,18 @@ impl CaseMapper { /// as a `LanguageIdentifier` (usually the `id` field of the `Locale`) if available, or /// `Default::default()` for the root locale. /// - /// This function performs legacy head adjustment behavior when [`HeadAdjustment::Adjust`] is set. See + /// This function performs "adjust to cased" leading adjustment behavior when [`LeadingAdjustment::Auto`] or [`LeadingAdjustment::ToCased`] + /// is set. Auto mode is not able to pick the "adjust to letter/number/symbol" behavior as this type does not load + /// the data to do so, use [`TitlecaseMapper`] if such behavior is desired. See /// the docs of [`TitlecaseMapper`] for more information on what this means. There is no difference between /// the behavior of this function and the equivalent ones on [`TitlecaseMapper`] when the head adjustment mode - /// is [`HeadAdjustment::NoAdjust`]. + /// is [`LeadingAdjustment::None`]. /// - /// See [`Self::titlecase_segment_legacy_to_string()`] for the equivalent convenience function that returns a String, + /// See [`Self::titlecase_segment_with_only_case_data_to_string()`] for the equivalent convenience function that returns a String, /// as well as for an example. /// /// [`TitlecaseMapper`]: crate::TitlecaseMapper - pub fn titlecase_segment_legacy<'a>( + pub fn titlecase_segment_with_only_case_data<'a>( &'a self, src: &'a str, langid: &LanguageIdentifier, @@ -164,9 +167,9 @@ impl CaseMapper { self.titlecase_segment_with_adjustment(src, langid, options, |data, ch| data.is_cased(ch)) } - /// Helper to support different head adjustment behaviors, - /// `char_is_head` is a function that returns true for a character that is allowed to be the - /// titlecase head, when `head_adjustment = Adjust` + /// Helper to support different leading adjustment behaviors, + /// `char_is_lead` is a function that returns true for a character that is allowed to be the + /// first relevant character in a titlecasing string, when `leading_adjustment != None` /// /// We return a concrete type instead of `impl Trait` so the return value can be mixed with that of other calls /// to this function with different closures @@ -175,12 +178,12 @@ impl CaseMapper { src: &'a str, langid: &LanguageIdentifier, options: TitlecaseOptions, - char_is_head: impl Fn(&CaseMapV1, char) -> bool, + char_is_lead: impl Fn(&CaseMapV1, char) -> bool, ) -> StringAndWriteable> { let data = self.data.get(); - let (head, rest) = match options.head_adjustment { - HeadAdjustment::Adjust => { - let first_cased = src.char_indices().find(|(_i, ch)| char_is_head(data, *ch)); + let (head, rest) = match options.leading_adjustment { + LeadingAdjustment::Auto | LeadingAdjustment::ToCased => { + let first_cased = src.char_indices().find(|(_i, ch)| char_is_lead(data, *ch)); if let Some((first_cased, _ch)) = first_cased { ( src.get(..first_cased).unwrap_or(""), @@ -190,13 +193,13 @@ impl CaseMapper { (src, "") } } - HeadAdjustment::NoAdjust => ("", src), + LeadingAdjustment::None => ("", src), }; let writeable = data.full_helper_writeable::( rest, CaseMapLocale::from_langid(langid), MappingKind::Title, - options.tail_casing, + options.trailing_case, ); StringAndWriteable { string: head, @@ -215,7 +218,7 @@ impl CaseMapper { src, CaseMapLocale::Root, MappingKind::Fold, - TailCasing::default(), + TrailingCase::default(), ) } @@ -232,7 +235,7 @@ impl CaseMapper { src, CaseMapLocale::Turkish, MappingKind::Fold, - TailCasing::default(), + TrailingCase::default(), ) } @@ -299,8 +302,12 @@ impl CaseMapper { self.uppercase(src, langid).write_to_string().into_owned() } - /// Returns the full titlecase mapping of the given string as a String, treating - /// the string as a single segment (and thus only titlecasing the beginning of it). + /// Returns the full titlecase mapping of the given string as a [`Writeable`], treating + /// the string as a single segment (and thus only titlecasing the beginning of it). Performs + /// the specified leading adjustment behavior from the options without loading additional data. + /// + /// Note that [`TitlecaseMapper`] has better behavior, most users should consider using + /// it instead. This method primarily exists for people who care about the amount of data being loaded. /// /// This should typically be used as a lower-level helper to construct the titlecasing operation desired /// by the application, for example one can titlecase on a per-word basis by mixing this with @@ -310,12 +317,14 @@ impl CaseMapper { /// as a `LanguageIdentifier` (usually the `id` field of the `Locale`) if available, or /// `Default::default()` for the root locale. /// - /// This function performs legacy head adjustment behavior when [`HeadAdjustment::Adjust`] is set. See + /// This function performs "adjust to cased" leading adjustment behavior when [`LeadingAdjustment::Auto`] or [`LeadingAdjustment::ToCased`] + /// is set. Auto mode is not able to pick the "adjust to letter/number/symbol" behavior as this type does not load + /// the data to do so, use [`TitlecaseMapper`] if such behavior is desired. See /// the docs of [`TitlecaseMapper`] for more information on what this means. There is no difference between /// the behavior of this function and the equivalent ones on [`TitlecaseMapper`] when the head adjustment mode - /// is [`HeadAdjustment::NoAdjust`]. + /// is [`LeadingAdjustment::None`]. /// - /// See [`Self::titlecase_segment_legacy()`] for the equivalent lower-level function that returns a [`Writeable`] + /// See [`Self::titlecase_segment_with_only_case_data()`] for the equivalent lower-level function that returns a [`Writeable`] /// /// # Examples /// @@ -330,30 +339,30 @@ impl CaseMapper { /// /// // note that the subsequent words are not titlecased, this function assumes /// // that the entire string is a single segment and only titlecases at the beginning. - /// assert_eq!(cm.titlecase_segment_legacy_to_string("hEllO WorLd", &root, default_options), "Hello world"); - /// assert_eq!(cm.titlecase_segment_legacy_to_string("Γειά σου Κόσμε", &root, default_options), "Γειά σου κόσμε"); - /// assert_eq!(cm.titlecase_segment_legacy_to_string("नमस्ते दुनिया", &root, default_options), "नमस्ते दुनिया"); - /// assert_eq!(cm.titlecase_segment_legacy_to_string("Привет мир", &root, default_options), "Привет мир"); + /// assert_eq!(cm.titlecase_segment_with_only_case_data_to_string("hEllO WorLd", &root, default_options), "Hello world"); + /// assert_eq!(cm.titlecase_segment_with_only_case_data_to_string("Γειά σου Κόσμε", &root, default_options), "Γειά σου κόσμε"); + /// assert_eq!(cm.titlecase_segment_with_only_case_data_to_string("नमस्ते दुनिया", &root, default_options), "नमस्ते दुनिया"); + /// assert_eq!(cm.titlecase_segment_with_only_case_data_to_string("Привет мир", &root, default_options), "Привет мир"); /// /// // Some behavior is language-sensitive - /// assert_eq!(cm.titlecase_segment_legacy_to_string("istanbul", &root, default_options), "Istanbul"); - /// assert_eq!(cm.titlecase_segment_legacy_to_string("istanbul", &langid!("tr"), default_options), "İstanbul"); // Turkish dotted i + /// assert_eq!(cm.titlecase_segment_with_only_case_data_to_string("istanbul", &root, default_options), "Istanbul"); + /// assert_eq!(cm.titlecase_segment_with_only_case_data_to_string("istanbul", &langid!("tr"), default_options), "İstanbul"); // Turkish dotted i /// - /// assert_eq!(cm.titlecase_segment_legacy_to_string("և Երևանի", &root, default_options), "Եւ երևանի"); - /// assert_eq!(cm.titlecase_segment_legacy_to_string("և Երևանի", &langid!("hy"), default_options), "Եվ երևանի"); // Eastern Armenian ech-yiwn ligature + /// assert_eq!(cm.titlecase_segment_with_only_case_data_to_string("և Երևանի", &root, default_options), "Եւ երևանի"); + /// assert_eq!(cm.titlecase_segment_with_only_case_data_to_string("և Երևանի", &langid!("hy"), default_options), "Եվ երևանի"); // Eastern Armenian ech-yiwn ligature /// - /// assert_eq!(cm.titlecase_segment_legacy_to_string("ijkdijk", &root, default_options), "Ijkdijk"); - /// assert_eq!(cm.titlecase_segment_legacy_to_string("ijkdijk", &langid!("nl"), default_options), "IJkdijk"); // Dutch IJ digraph + /// assert_eq!(cm.titlecase_segment_with_only_case_data_to_string("ijkdijk", &root, default_options), "Ijkdijk"); + /// assert_eq!(cm.titlecase_segment_with_only_case_data_to_string("ijkdijk", &langid!("nl"), default_options), "IJkdijk"); // Dutch IJ digraph /// ``` /// /// [`TitlecaseMapper`]: crate::TitlecaseMapper - pub fn titlecase_segment_legacy_to_string( + pub fn titlecase_segment_with_only_case_data_to_string( &self, src: &str, langid: &LanguageIdentifier, options: TitlecaseOptions, ) -> String { - self.titlecase_segment_legacy(src, langid, options) + self.titlecase_segment_with_only_case_data(src, langid, options) .write_to_string() .into_owned() } @@ -621,13 +630,17 @@ mod tests { ); // but the YPOGEGRAMMENI should not titlecase assert_eq!( - cm.titlecase_segment_legacy_to_string("α\u{0313}\u{0345}", &root, default_options), + cm.titlecase_segment_with_only_case_data_to_string( + "α\u{0313}\u{0345}", + &root, + default_options + ), "Α\u{0313}\u{0345}" ); // U+1F80 GREEK SMALL LETTER ALPHA WITH PSILI AND YPOGEGRAMMENI assert_eq!( - cm.titlecase_segment_legacy_to_string("ᾀ", &root, default_options), + cm.titlecase_segment_with_only_case_data_to_string("ᾀ", &root, default_options), "ᾈ" ); assert_eq!(cm.uppercase_to_string("ᾀ", &root), "ἈΙ"); @@ -635,7 +648,7 @@ mod tests { // U+1FFC GREEK CAPITAL LETTER OMEGA WITH PROSGEGRAMMENI assert_eq!(cm.lowercase_to_string("ῼ", &root), "ῳ"); assert_eq!( - cm.titlecase_segment_legacy_to_string("ῼ", &root, default_options), + cm.titlecase_segment_with_only_case_data_to_string("ῼ", &root, default_options), "ῼ" ); assert_eq!(cm.uppercase_to_string("ῼ", &root), "ΩΙ"); @@ -643,7 +656,7 @@ mod tests { // U+1F98 GREEK CAPITAL LETTER ETA WITH PSILI AND PROSGEGRAMMENI assert_eq!(cm.lowercase_to_string("ᾘ", &root), "ᾐ"); assert_eq!( - cm.titlecase_segment_legacy_to_string("ᾘ", &root, default_options), + cm.titlecase_segment_with_only_case_data_to_string("ᾘ", &root, default_options), "ᾘ" ); assert_eq!(cm.uppercase_to_string("ᾘ", &root), "ἨΙ"); @@ -651,7 +664,7 @@ mod tests { // U+1FB2 GREEK SMALL LETTER ALPHA WITH VARIA AND YPOGEGRAMMENI assert_eq!(cm.lowercase_to_string("ᾲ", &root), "ᾲ"); assert_eq!( - cm.titlecase_segment_legacy_to_string("ᾲ", &root, default_options), + cm.titlecase_segment_with_only_case_data_to_string("ᾲ", &root, default_options), "Ὰ\u{345}" ); assert_eq!(cm.uppercase_to_string("ᾲ", &root), "ᾺΙ"); @@ -667,11 +680,11 @@ mod tests { assert_eq!(cm.lowercase_to_string("İ", &tr), "i"); assert_eq!(cm.lowercase_to_string("İ", &az), "i"); assert_eq!( - cm.titlecase_segment_legacy_to_string("İ", &tr, default_options), + cm.titlecase_segment_with_only_case_data_to_string("İ", &tr, default_options), "İ" ); assert_eq!( - cm.titlecase_segment_legacy_to_string("İ", &az, default_options), + cm.titlecase_segment_with_only_case_data_to_string("İ", &az, default_options), "İ" ); assert_eq!(cm.uppercase_to_string("İ", &tr), "İ"); @@ -681,11 +694,11 @@ mod tests { assert_eq!(cm.lowercase_to_string("I\u{0307}", &tr), "i"); assert_eq!(cm.lowercase_to_string("I\u{0307}", &az), "i"); assert_eq!( - cm.titlecase_segment_legacy_to_string("I\u{0307}", &tr, default_options), + cm.titlecase_segment_with_only_case_data_to_string("I\u{0307}", &tr, default_options), "I\u{0307}" ); assert_eq!( - cm.titlecase_segment_legacy_to_string("I\u{0307}", &az, default_options), + cm.titlecase_segment_with_only_case_data_to_string("I\u{0307}", &az, default_options), "I\u{0307}" ); assert_eq!(cm.uppercase_to_string("I\u{0307}", &tr), "I\u{0307}"); @@ -695,11 +708,11 @@ mod tests { assert_eq!(cm.lowercase_to_string("I", &tr), "ı"); assert_eq!(cm.lowercase_to_string("I", &az), "ı"); assert_eq!( - cm.titlecase_segment_legacy_to_string("I", &tr, default_options), + cm.titlecase_segment_with_only_case_data_to_string("I", &tr, default_options), "I" ); assert_eq!( - cm.titlecase_segment_legacy_to_string("I", &az, default_options), + cm.titlecase_segment_with_only_case_data_to_string("I", &az, default_options), "I" ); assert_eq!(cm.uppercase_to_string("I", &tr), "I"); @@ -709,11 +722,11 @@ mod tests { assert_eq!(cm.lowercase_to_string("i", &tr), "i"); assert_eq!(cm.lowercase_to_string("i", &az), "i"); assert_eq!( - cm.titlecase_segment_legacy_to_string("i", &tr, default_options), + cm.titlecase_segment_with_only_case_data_to_string("i", &tr, default_options), "İ" ); assert_eq!( - cm.titlecase_segment_legacy_to_string("i", &az, default_options), + cm.titlecase_segment_with_only_case_data_to_string("i", &az, default_options), "İ" ); assert_eq!(cm.uppercase_to_string("i", &tr), "İ"); diff --git a/components/casemap/src/internals.rs b/components/casemap/src/internals.rs index b24c3572b67..ddee7219273 100644 --- a/components/casemap/src/internals.rs +++ b/components/casemap/src/internals.rs @@ -11,7 +11,7 @@ use crate::provider::data::{DotType, MappingKind}; use crate::provider::exception_helpers::ExceptionSlot; use crate::provider::{CaseMapUnfoldV1, CaseMapV1}; use crate::set::ClosureSink; -use crate::titlecase::TailCasing; +use crate::titlecase::TrailingCase; use core::fmt; use icu_locid::LanguageIdentifier; use writeable::Writeable; @@ -54,7 +54,7 @@ pub(crate) struct FullCaseWriteable<'a, const IS_TITLE_CONTEXT: bool> { src: &'a str, locale: CaseMapLocale, mapping: MappingKind, - titlecase_tail_casing: TailCasing, + titlecase_tail_casing: TrailingCase, } impl<'a, const IS_TITLE_CONTEXT: bool> Writeable for FullCaseWriteable<'a, IS_TITLE_CONTEXT> { @@ -68,7 +68,7 @@ impl<'a, const IS_TITLE_CONTEXT: bool> Writeable for FullCaseWriteable<'a, IS_TI self.data .full_helper::(c, context, self.locale, mapping, sink)?; if IS_TITLE_CONTEXT { - if self.titlecase_tail_casing == TailCasing::Lowercase { + if self.titlecase_tail_casing == TrailingCase::Lower { mapping = MappingKind::Lower; } else { break; @@ -76,7 +76,7 @@ impl<'a, const IS_TITLE_CONTEXT: bool> Writeable for FullCaseWriteable<'a, IS_TI } } // Write the rest of the string - if IS_TITLE_CONTEXT && self.titlecase_tail_casing == TailCasing::PreserveCase { + if IS_TITLE_CONTEXT && self.titlecase_tail_casing == TrailingCase::Unchanged { sink.write_str(iter.as_str())?; } Ok(()) @@ -516,7 +516,7 @@ impl<'data> CaseMapV1<'data> { src: &'a str, locale: CaseMapLocale, mapping: MappingKind, - titlecase_tail_casing: TailCasing, + titlecase_tail_casing: TrailingCase, ) -> FullCaseWriteable<'a, IS_TITLE_CONTEXT> { // Ensure that they are either both true or both false, i.e. an XNOR operation debug_assert!(!(IS_TITLE_CONTEXT ^ (mapping == MappingKind::Title))); diff --git a/components/casemap/src/titlecase.rs b/components/casemap/src/titlecase.rs index 874e9d1ff7a..8f5cbe0693a 100644 --- a/components/casemap/src/titlecase.rs +++ b/components/casemap/src/titlecase.rs @@ -13,30 +13,97 @@ use icu_properties::{GeneralCategory, GeneralCategoryGroup, PropertiesError}; use icu_provider::prelude::*; use writeable::Writeable; -/// How to handle the rest of the string once the head of the -/// string has been titlecased. See docs of [`TitlecaseMapper`] for examples. +/// How to handle the rest of the string once the beginning of the +/// string has been titlecased. +/// +/// # Examples +/// +/// ```rust +/// use icu_casemap::TitlecaseMapper; +/// use icu_casemap::titlecase::{TrailingCase, TitlecaseOptions}; +/// use icu_locid::langid; +/// +/// let cm = TitlecaseMapper::new(); +/// let root = langid!("und"); +/// +/// let default_options = Default::default(); +/// let mut preserve_case: TitlecaseOptions = Default::default(); +/// preserve_case.trailing_case = TrailingCase::Unchanged; +/// +/// // Exhibits trailing case when set: +/// assert_eq!(cm.titlecase_segment_to_string("spOngeBoB", &root, default_options), "Spongebob"); +/// assert_eq!(cm.titlecase_segment_to_string("spOngeBoB", &root, preserve_case), "SpOngeBoB"); +/// ``` #[non_exhaustive] #[derive(Copy, Clone, Default, PartialEq, Eq, Hash, Debug)] -pub enum TailCasing { +pub enum TrailingCase { + /// Preserve the casing of the rest of the string ("spoNgEBoB" -> "SpoNgEBoB") + Unchanged, /// Lowercase the rest of the string ("spoNgEBoB" -> "Spongebob") #[default] - Lowercase, - /// Preserve the casing of the rest of the string ("spoNgEBoB" -> "SpoNgEBoB") - PreserveCase, + Lower, } -/// Whether to start casing at the beginning of the string or at the first -/// relevant character. See docs of [`TitlecaseMapper`] for examples. +/// Where to start casing the string. +/// +/// [`TitlecaseMapper`] by default performs "leading adjustment", where it searches for the first "relevant" character +/// in the string before initializing the actual titlecasing. For example, it will skip punctuation at the beginning +/// of a string, allowing for strings like `'twas` or `«hello»` to be appropriately titlecased. +/// +/// Opinions on exactly what is a "relevant" character may differ. In "adjust to cased" mode the first cased character is considered "relevant", +/// whereas in the "auto" mode, it is the first character that is a letter, number, symbol, or private use character. This means +/// that the strings `49ers` and `«丰(abc)»` will titlecase in "adjust to cased" mode to `49Ers` and `«丰(Abc)»`, whereas in the "auto" mode they stay unchanged. +/// This difference largely matters for things that mix numbers and letters, or mix writing systems, within a single segment. +/// +/// # Examples +/// +/// ```rust +/// use icu_casemap::TitlecaseMapper; +/// use icu_casemap::titlecase::{LeadingAdjustment, TitlecaseOptions}; +/// use icu_locid::langid; +/// +/// let cm = TitlecaseMapper::new(); +/// let root = langid!("und"); +/// +/// let default_options = Default::default(); // head adjustment set to Auto +/// let mut no_adjust: TitlecaseOptions = Default::default(); +/// let mut adjust_to_cased: TitlecaseOptions = Default::default(); +/// no_adjust.leading_adjustment = LeadingAdjustment::None; +/// adjust_to_cased.leading_adjustment = LeadingAdjustment::ToCased; +/// +/// // Exhibits leading adjustment when set: +/// assert_eq!(cm.titlecase_segment_to_string("«hello»", &root, default_options), "«Hello»"); +/// assert_eq!(cm.titlecase_segment_to_string("«hello»", &root, adjust_to_cased), "«Hello»"); +/// assert_eq!(cm.titlecase_segment_to_string("«hello»", &root, no_adjust), "«hello»"); +/// +/// // Only changed in adjust-to-cased mode: +/// assert_eq!(cm.titlecase_segment_to_string("丰(abc)", &root, default_options), "丰(abc)"); +/// assert_eq!(cm.titlecase_segment_to_string("丰(abc)", &root, adjust_to_cased), "丰(Abc)"); +/// assert_eq!(cm.titlecase_segment_to_string("丰(abc)", &root, no_adjust), "丰(abc)"); +/// +/// // Only changed in adjust-to-cased mode: +/// assert_eq!(cm.titlecase_segment_to_string("49ers", &root, default_options), "49ers"); +/// assert_eq!(cm.titlecase_segment_to_string("49ers", &root, adjust_to_cased), "49Ers"); +/// assert_eq!(cm.titlecase_segment_to_string("49ers", &root, no_adjust), "49ers"); +/// ``` #[non_exhaustive] #[derive(Copy, Clone, Default, PartialEq, Eq, Hash, Debug)] -pub enum HeadAdjustment { - /// Adjust the string to the first relevant character before beginning to apply casing - /// ("'twixt" -> "'Twixt") - #[default] - Adjust, +pub enum LeadingAdjustment { /// Start titlecasing immediately, even if the character is not one that is relevant for casing /// ("'twixt" -> "'twixt", "twixt" -> "Twixt") - NoAdjust, + None, + /// Adjust the string to the first relevant character before beginning to apply casing + /// ("'twixt" -> "'Twixt"). "Relevant" character is picked by best available algorithm, + /// by default will adjust to first letter, number, symbol, or private use character, + /// but if no data is available (e.g. this API is being called via [`CaseMapper::titlecase_segment_with_only_case_data()`]), + /// then may be equivalent to "adjust to cased". + /// + /// This is the default + #[default] + Auto, + /// Adjust the string to the first cased character before beginning to apply casing + /// ("'twixt" -> "'Twixt") + ToCased, } /// Various options for controlling titlecasing @@ -47,29 +114,25 @@ pub enum HeadAdjustment { pub struct TitlecaseOptions { /// How to handle the rest of the string once the head of the /// string has been titlecased - pub tail_casing: TailCasing, + pub trailing_case: TrailingCase, /// Whether to start casing at the beginning of the string or at the first /// relevant character. - pub head_adjustment: HeadAdjustment, + pub leading_adjustment: LeadingAdjustment, } /// A wrapper around [`CaseMapper`] that can compute titlecasing stuff, and is able to load additional data /// to support the non-legacy "head adjustment" behavior. /// /// -/// By default, [`Self::titlecase_segment()`] and [`Self::titlecase_segment_to_string()`] perform "head adjustment", +/// By default, [`Self::titlecase_segment()`] and [`Self::titlecase_segment_to_string()`] perform "leading adjustment", /// where they wait till the first relevant character to begin titlecasing. For example, in the string `'twixt`, the apostrophe /// is ignored because the word starts at the first "t", which will get titlecased (producing `'Twixt`). Other punctuation will /// also be ignored, like in the string `«hello»`, which will get titlecased to `«Hello»`. /// -/// Opinions on exactly what is a "relevant" character may differ. In "legacy" mode the first cased character is considered "relevant", -/// whereas in the normal mode, it is the first character that is a letter, number, symbol, or private use character. This means -/// that the strings `49ers` and `«丰(abc)»` will titlecase to `49Ers` and `«丰(Abc)»`, whereas in the normal mode they stay unchanged. -/// This difference largely matters for things that mix numbers and letters, or mix writing systems, within a single segment. -/// -/// The normal mode requires additional data; which is the purpose of this being a separate type. +/// This is a separate type from [`CaseMapper`] because it loads the additional data +/// required by [`LeadingAdjustment::Auto`] to perform the best possible leading adjustment. /// -/// If you are planning on only using [`HeadAdjustment::NoAdjust`], consider using [`CaseMapper`] directly; this +/// If you are planning on only using [`LeadingAdjustment::None`] or [`LeadingAdjustment::ToCased`], consider using [`CaseMapper`] directly; this /// type will have no additional behavior. /// /// # Examples @@ -103,36 +166,6 @@ pub struct TitlecaseOptions { /// assert_eq!(cm.titlecase_segment_to_string("ijkdijk", &langid!("nl"), default_options), "IJkdijk"); // Dutch IJ digraph /// ``` /// -/// Head adjustment behaviors: -/// -/// ```rust -/// use icu_casemap::TitlecaseMapper; -/// use icu_casemap::titlecase::{HeadAdjustment, TitlecaseOptions}; -/// use icu_locid::langid; -/// -/// let cm_normal = TitlecaseMapper::new(); -/// let cm_legacy = TitlecaseMapper::new_legacy(); -/// let root = langid!("und"); -/// -/// let default_options = Default::default(); -/// let mut no_adjust: TitlecaseOptions = Default::default(); -/// no_adjust.head_adjustment = HeadAdjustment::NoAdjust; -/// -/// // Exhibits head adjustment when set: -/// assert_eq!(cm_normal.titlecase_segment_to_string("«hello»", &root, default_options), "«Hello»"); -/// assert_eq!(cm_legacy.titlecase_segment_to_string("«hello»", &root, default_options), "«Hello»"); -/// assert_eq!(cm_normal.titlecase_segment_to_string("«hello»", &root, no_adjust), "«hello»"); -/// -/// // Only changed in legacy mode: -/// assert_eq!(cm_normal.titlecase_segment_to_string("丰(abc)", &root, default_options), "丰(abc)"); -/// assert_eq!(cm_legacy.titlecase_segment_to_string("丰(abc)", &root, default_options), "丰(Abc)"); -/// assert_eq!(cm_normal.titlecase_segment_to_string("丰(abc)", &root, no_adjust), "丰(abc)"); -/// -/// // Only changed in legacy mode: -/// assert_eq!(cm_normal.titlecase_segment_to_string("49ers", &root, default_options), "49ers"); -/// assert_eq!(cm_legacy.titlecase_segment_to_string("49ers", &root, default_options), "49Ers"); -/// assert_eq!(cm_normal.titlecase_segment_to_string("49ers", &root, no_adjust), "49ers"); -/// ``` ///
/// 🚧 This code is experimental; it may change at any time, in breaking or non-breaking ways, /// including in SemVer minor releases. It can be enabled with the "experimental" Cargo feature @@ -142,12 +175,11 @@ pub struct TitlecaseOptions { #[derive(Clone, Debug)] pub struct TitlecaseMapper { cm: CM, - gc: Option>, + gc: CodePointMapData, } impl TitlecaseMapper { - /// A constructor which creates a [`TitlecaseMapper`] using compiled data, with the normal (non-legacy) head adjustment behavior. - /// See struct docs on [`TitlecaseMapper`] for more information on head adjustment behavior and usage examples. + /// A constructor which creates a [`TitlecaseMapper`] using compiled data /// /// ✨ *Enabled with the `compiled_data` Cargo feature.* /// @@ -156,20 +188,7 @@ impl TitlecaseMapper { pub const fn new() -> Self { Self { cm: CaseMapper::new(), - gc: Some(icu_properties::maps::general_category().static_to_owned()), - } - } - /// A constructor which creates a [`TitlecaseMapper`] using compiled data, with the legacy head adjustment behavior. - /// See struct docs on [`TitlecaseMapper`] for more information on head adjustment behavior and usage examples. - /// - /// ✨ *Enabled with the `compiled_data` Cargo feature.* - /// - /// [📚 Help choosing a constructor](icu_provider::constructors) - #[cfg(feature = "compiled_data")] - pub const fn new_legacy() -> Self { - Self { - cm: CaseMapper::new(), - gc: None, + gc: icu_properties::maps::general_category().static_to_owned(), } } @@ -182,15 +201,6 @@ impl TitlecaseMapper { try_new_unstable, Self, ]); - icu_provider::gen_any_buffer_data_constructors!(locale: skip, options: skip, error: DataError, - #[cfg(skip)] - functions: [ - new_legacy, - try_new_legacy_with_any_provider, - try_new_legacy_with_buffer_provider, - try_new_legacy_unstable, - Self, - ]); #[doc = icu_provider::gen_any_buffer_unstable_docs!(UNSTABLE, Self::new)] pub fn try_new_unstable

(provider: &P) -> Result @@ -198,22 +208,12 @@ impl TitlecaseMapper { P: DataProvider + DataProvider + ?Sized, { let cm = CaseMapper::try_new_unstable(provider)?; - let gc = Some( - icu_properties::maps::load_general_category(provider).map_err(|e| { - let PropertiesError::PropDataLoad(e) = e else { unreachable!() }; - e - })?, - ); + let gc = icu_properties::maps::load_general_category(provider).map_err(|e| { + let PropertiesError::PropDataLoad(e) = e else { unreachable!() }; + e + })?; Ok(Self { cm, gc }) } - #[doc = icu_provider::gen_any_buffer_unstable_docs!(UNSTABLE, Self::new)] - pub fn try_new_legacy_unstable

(provider: &P) -> Result - where - P: DataProvider + ?Sized, - { - let cm = CaseMapper::try_new_unstable(provider)?; - Ok(Self { cm, gc: None }) - } } // We use Borrow, not AsRef, since we want the blanket impl on T @@ -229,8 +229,7 @@ impl> TitlecaseMapper { ]); /// A constructor which creates a [`TitlecaseMapper`] from an existing [`CaseMapper`] - /// (either owned or as a reference) and compiled data, with the normal (non-legacy) head adjustment behavior. - /// See struct docs on [`TitlecaseMapper`] for more information on head adjustment behavior. + /// (either owned or as a reference) and compiled data /// /// ✨ *Enabled with the `compiled_data` Cargo feature.* /// @@ -239,20 +238,10 @@ impl> TitlecaseMapper { pub const fn new_with_mapper(casemapper: CM) -> Self { Self { cm: casemapper, - gc: Some(icu_properties::maps::general_category().static_to_owned()), - } - } - /// A constructor which creates a [`TitlecaseMapper`] from an existing [`CaseMapper`] - /// (either owned or as a reference), with the legacy head adjustment behavior. - /// See struct docs on [`TitlecaseMapper`] for more information on head adjustment behavior. - /// - /// [📚 Help choosing a constructor](icu_provider::constructors) - pub const fn new_with_mapper_legacy(casemapper: CM) -> Self { - Self { - cm: casemapper, - gc: None, + gc: icu_properties::maps::general_category().static_to_owned(), } } + /// Construct this object to wrap an existing CaseMapper (or a reference to one), loading additional data as needed. /// #[doc = icu_provider::gen_any_buffer_unstable_docs!(UNSTABLE, Self::new_with_mapper)] @@ -260,12 +249,10 @@ impl> TitlecaseMapper { where P: DataProvider + DataProvider + ?Sized, { - let gc = Some( - icu_properties::maps::load_general_category(provider).map_err(|e| { - let PropertiesError::PropDataLoad(e) = e else { unreachable!() }; - e - })?, - ); + let gc = icu_properties::maps::load_general_category(provider).map_err(|e| { + let PropertiesError::PropDataLoad(e) = e else { unreachable!() }; + e + })?; Ok(Self { cm: casemapper, gc }) } @@ -288,7 +275,7 @@ impl> TitlecaseMapper { langid: &LanguageIdentifier, options: TitlecaseOptions, ) -> impl Writeable + 'a { - if let Some(gc) = self.gc.as_ref() { + if options.leading_adjustment == LeadingAdjustment::Auto { // letter, number, symbol, or private use code point const HEAD_GROUPS: GeneralCategoryGroup = GeneralCategoryGroup::Letter .union(GeneralCategoryGroup::Number) @@ -297,7 +284,7 @@ impl> TitlecaseMapper { self.cm .as_ref() .titlecase_segment_with_adjustment(src, langid, options, |_data, ch| { - HEAD_GROUPS.contains(gc.as_borrowed().get(ch)) + HEAD_GROUPS.contains(self.gc.as_borrowed().get(ch)) }) } else { self.cm @@ -350,11 +337,11 @@ impl> TitlecaseMapper { /// assert_eq!(cm.titlecase_segment_to_string("ijkdijk", &langid!("nl"), default_options), "IJkdijk"); // Dutch IJ digraph /// ``` /// - /// Head adjustment behaviors: + /// Leading adjustment behaviors: /// /// ```rust /// use icu_casemap::TitlecaseMapper; - /// use icu_casemap::titlecase::{HeadAdjustment, TitlecaseOptions}; + /// use icu_casemap::titlecase::{LeadingAdjustment, TitlecaseOptions}; /// use icu_locid::langid; /// /// let cm = TitlecaseMapper::new(); @@ -362,9 +349,9 @@ impl> TitlecaseMapper { /// /// let default_options = Default::default(); /// let mut no_adjust: TitlecaseOptions = Default::default(); - /// no_adjust.head_adjustment = HeadAdjustment::NoAdjust; + /// no_adjust.leading_adjustment = LeadingAdjustment::None; /// - /// // Exhibits head adjustment when set: + /// // Exhibits leading adjustment when set: /// assert_eq!(cm.titlecase_segment_to_string("«hello»", &root, default_options), "«Hello»"); /// assert_eq!(cm.titlecase_segment_to_string("«hello»", &root, no_adjust), "«hello»"); /// @@ -379,7 +366,7 @@ impl> TitlecaseMapper { /// /// ```rust /// use icu_casemap::TitlecaseMapper; - /// use icu_casemap::titlecase::{TailCasing, TitlecaseOptions}; + /// use icu_casemap::titlecase::{TrailingCase, TitlecaseOptions}; /// use icu_locid::langid; /// /// let cm = TitlecaseMapper::new(); @@ -387,9 +374,9 @@ impl> TitlecaseMapper { /// /// let default_options = Default::default(); /// let mut preserve_case: TitlecaseOptions = Default::default(); - /// preserve_case.tail_casing = TailCasing::PreserveCase; + /// preserve_case.trailing_case = TrailingCase::Unchanged; /// - /// // Exhibits head adjustment when set: + /// // Exhibits trailing case when set: /// assert_eq!(cm.titlecase_segment_to_string("spOngeBoB", &root, default_options), "Spongebob"); /// assert_eq!(cm.titlecase_segment_to_string("spOngeBoB", &root, preserve_case), "SpOngeBoB"); /// ``` diff --git a/components/casemap/tests/conversions.rs b/components/casemap/tests/conversions.rs index 893d701ca45..e2ac0d3ebbb 100644 --- a/components/casemap/tests/conversions.rs +++ b/components/casemap/tests/conversions.rs @@ -209,27 +209,27 @@ fn test_armenian() { let ew = "և"; let yerevan = "Երևանի"; assert_eq!( - cm.titlecase_segment_legacy_to_string(ew, &root, default_options), + cm.titlecase_segment_with_only_case_data_to_string(ew, &root, default_options), "Եւ" ); assert_eq!( - cm.titlecase_segment_legacy_to_string(yerevan, &root, default_options), + cm.titlecase_segment_with_only_case_data_to_string(yerevan, &root, default_options), "Երևանի" ); assert_eq!( - cm.titlecase_segment_legacy_to_string(ew, &east, default_options), + cm.titlecase_segment_with_only_case_data_to_string(ew, &east, default_options), "Եվ" ); assert_eq!( - cm.titlecase_segment_legacy_to_string(yerevan, &east, default_options), + cm.titlecase_segment_with_only_case_data_to_string(yerevan, &east, default_options), "Երևանի" ); assert_eq!( - cm.titlecase_segment_legacy_to_string(ew, &west, default_options), + cm.titlecase_segment_with_only_case_data_to_string(ew, &west, default_options), "Եւ" ); assert_eq!( - cm.titlecase_segment_legacy_to_string(yerevan, &west, default_options), + cm.titlecase_segment_with_only_case_data_to_string(yerevan, &west, default_options), "Երևանի" ); } @@ -241,105 +241,105 @@ fn test_dutch() { let default_options = Default::default(); assert_eq!( - cm.titlecase_segment_legacy_to_string("ijssel", &nl, default_options), + cm.titlecase_segment_with_only_case_data_to_string("ijssel", &nl, default_options), "IJssel" ); assert_eq!( - cm.titlecase_segment_legacy_to_string("igloo", &nl, default_options), + cm.titlecase_segment_with_only_case_data_to_string("igloo", &nl, default_options), "Igloo" ); assert_eq!( - cm.titlecase_segment_legacy_to_string("IJMUIDEN", &nl, default_options), + cm.titlecase_segment_with_only_case_data_to_string("IJMUIDEN", &nl, default_options), "IJmuiden" ); assert_eq!( - cm.titlecase_segment_legacy_to_string("ij", &nl, default_options), + cm.titlecase_segment_with_only_case_data_to_string("ij", &nl, default_options), "IJ" ); assert_eq!( - cm.titlecase_segment_legacy_to_string("IJ", &nl, default_options), + cm.titlecase_segment_with_only_case_data_to_string("IJ", &nl, default_options), "IJ" ); assert_eq!( - cm.titlecase_segment_legacy_to_string("íj́", &nl, default_options), + cm.titlecase_segment_with_only_case_data_to_string("íj́", &nl, default_options), "ÍJ́" ); assert_eq!( - cm.titlecase_segment_legacy_to_string("ÍJ́", &nl, default_options), + cm.titlecase_segment_with_only_case_data_to_string("ÍJ́", &nl, default_options), "ÍJ́" ); assert_eq!( - cm.titlecase_segment_legacy_to_string("íJ́", &nl, default_options), + cm.titlecase_segment_with_only_case_data_to_string("íJ́", &nl, default_options), "ÍJ́" ); assert_eq!( - cm.titlecase_segment_legacy_to_string("Ij́", &nl, default_options), + cm.titlecase_segment_with_only_case_data_to_string("Ij́", &nl, default_options), "Ij́" ); assert_eq!( - cm.titlecase_segment_legacy_to_string("ij́", &nl, default_options), + cm.titlecase_segment_with_only_case_data_to_string("ij́", &nl, default_options), "Ij́" ); assert_eq!( - cm.titlecase_segment_legacy_to_string("ïj́", &nl, default_options), + cm.titlecase_segment_with_only_case_data_to_string("ïj́", &nl, default_options), "Ïj́" ); assert_eq!( - cm.titlecase_segment_legacy_to_string("íj\u{0308}", &nl, default_options), + cm.titlecase_segment_with_only_case_data_to_string("íj\u{0308}", &nl, default_options), "Íj\u{0308}" ); assert_eq!( - cm.titlecase_segment_legacy_to_string("íj́\u{1D16E}", &nl, default_options), + cm.titlecase_segment_with_only_case_data_to_string("íj́\u{1D16E}", &nl, default_options), "Íj́\u{1D16E}" ); assert_eq!( - cm.titlecase_segment_legacy_to_string("íj\u{1ABE}", &nl, default_options), + cm.titlecase_segment_with_only_case_data_to_string("íj\u{1ABE}", &nl, default_options), "Íj\u{1ABE}" ); assert_eq!( - cm.titlecase_segment_legacy_to_string("ijabc", &nl, default_options), + cm.titlecase_segment_with_only_case_data_to_string("ijabc", &nl, default_options), "IJabc" ); assert_eq!( - cm.titlecase_segment_legacy_to_string("IJabc", &nl, default_options), + cm.titlecase_segment_with_only_case_data_to_string("IJabc", &nl, default_options), "IJabc" ); assert_eq!( - cm.titlecase_segment_legacy_to_string("íj́abc", &nl, default_options), + cm.titlecase_segment_with_only_case_data_to_string("íj́abc", &nl, default_options), "ÍJ́abc" ); assert_eq!( - cm.titlecase_segment_legacy_to_string("ÍJ́abc", &nl, default_options), + cm.titlecase_segment_with_only_case_data_to_string("ÍJ́abc", &nl, default_options), "ÍJ́abc" ); assert_eq!( - cm.titlecase_segment_legacy_to_string("íJ́abc", &nl, default_options), + cm.titlecase_segment_with_only_case_data_to_string("íJ́abc", &nl, default_options), "ÍJ́abc" ); assert_eq!( - cm.titlecase_segment_legacy_to_string("Ij́abc", &nl, default_options), + cm.titlecase_segment_with_only_case_data_to_string("Ij́abc", &nl, default_options), "Ij́abc" ); assert_eq!( - cm.titlecase_segment_legacy_to_string("ij́abc", &nl, default_options), + cm.titlecase_segment_with_only_case_data_to_string("ij́abc", &nl, default_options), "Ij́abc" ); assert_eq!( - cm.titlecase_segment_legacy_to_string("ïj́abc", &nl, default_options), + cm.titlecase_segment_with_only_case_data_to_string("ïj́abc", &nl, default_options), "Ïj́abc" ); assert_eq!( - cm.titlecase_segment_legacy_to_string("íjabc\u{0308}", &nl, default_options), + cm.titlecase_segment_with_only_case_data_to_string("íjabc\u{0308}", &nl, default_options), "Íjabc\u{0308}" ); assert_eq!( - cm.titlecase_segment_legacy_to_string("íj́abc\u{1D16E}", &nl, default_options), + cm.titlecase_segment_with_only_case_data_to_string("íj́abc\u{1D16E}", &nl, default_options), "ÍJ́abc\u{1D16E}" ); assert_eq!( - cm.titlecase_segment_legacy_to_string("íjabc\u{1ABE}", &nl, default_options), + cm.titlecase_segment_with_only_case_data_to_string("íjabc\u{1ABE}", &nl, default_options), "Íjabc\u{1ABE}" ); } diff --git a/ffi/diplomat/c/include/ICU4XCaseMapper.h b/ffi/diplomat/c/include/ICU4XCaseMapper.h index bdec1d4b267..aef264f7225 100644 --- a/ffi/diplomat/c/include/ICU4XCaseMapper.h +++ b/ffi/diplomat/c/include/ICU4XCaseMapper.h @@ -31,7 +31,7 @@ diplomat_result_void_ICU4XError ICU4XCaseMapper_lowercase(const ICU4XCaseMapper* diplomat_result_void_ICU4XError ICU4XCaseMapper_uppercase(const ICU4XCaseMapper* self, const char* s_data, size_t s_len, const ICU4XLocale* locale, DiplomatWriteable* write); -diplomat_result_void_ICU4XError ICU4XCaseMapper_titlecase_segment_legacy_v1(const ICU4XCaseMapper* self, const char* s_data, size_t s_len, const ICU4XLocale* locale, ICU4XTitlecaseOptionsV1 options, DiplomatWriteable* write); +diplomat_result_void_ICU4XError ICU4XCaseMapper_titlecase_segment_with_only_case_data_v1(const ICU4XCaseMapper* self, const char* s_data, size_t s_len, const ICU4XLocale* locale, ICU4XTitlecaseOptionsV1 options, DiplomatWriteable* write); diplomat_result_void_ICU4XError ICU4XCaseMapper_fold(const ICU4XCaseMapper* self, const char* s_data, size_t s_len, DiplomatWriteable* write); diff --git a/ffi/diplomat/c/include/ICU4XHeadAdjustment.h b/ffi/diplomat/c/include/ICU4XLeadingAdjustment.h similarity index 51% rename from ffi/diplomat/c/include/ICU4XHeadAdjustment.h rename to ffi/diplomat/c/include/ICU4XLeadingAdjustment.h index 305e0e165bd..91647188edf 100644 --- a/ffi/diplomat/c/include/ICU4XHeadAdjustment.h +++ b/ffi/diplomat/c/include/ICU4XLeadingAdjustment.h @@ -1,5 +1,5 @@ -#ifndef ICU4XHeadAdjustment_H -#define ICU4XHeadAdjustment_H +#ifndef ICU4XLeadingAdjustment_H +#define ICU4XLeadingAdjustment_H #include #include #include @@ -10,10 +10,11 @@ namespace capi { #endif -typedef enum ICU4XHeadAdjustment { - ICU4XHeadAdjustment_Adjust = 0, - ICU4XHeadAdjustment_NoAdjust = 1, -} ICU4XHeadAdjustment; +typedef enum ICU4XLeadingAdjustment { + ICU4XLeadingAdjustment_Auto = 0, + ICU4XLeadingAdjustment_None = 1, + ICU4XLeadingAdjustment_ToCased = 2, +} ICU4XLeadingAdjustment; #ifdef __cplusplus } // namespace capi #endif @@ -22,7 +23,7 @@ namespace capi { extern "C" { #endif -void ICU4XHeadAdjustment_destroy(ICU4XHeadAdjustment* self); +void ICU4XLeadingAdjustment_destroy(ICU4XLeadingAdjustment* self); #ifdef __cplusplus } // extern "C" diff --git a/ffi/diplomat/c/include/ICU4XTitlecaseMapper.h b/ffi/diplomat/c/include/ICU4XTitlecaseMapper.h index e1ed6d9b7ee..04debefbf9d 100644 --- a/ffi/diplomat/c/include/ICU4XTitlecaseMapper.h +++ b/ffi/diplomat/c/include/ICU4XTitlecaseMapper.h @@ -26,8 +26,6 @@ extern "C" { diplomat_result_box_ICU4XTitlecaseMapper_ICU4XError ICU4XTitlecaseMapper_create(const ICU4XDataProvider* provider); -diplomat_result_box_ICU4XTitlecaseMapper_ICU4XError ICU4XTitlecaseMapper_create_legacy(const ICU4XDataProvider* provider); - diplomat_result_void_ICU4XError ICU4XTitlecaseMapper_titlecase_segment_v1(const ICU4XTitlecaseMapper* self, const char* s_data, size_t s_len, const ICU4XLocale* locale, ICU4XTitlecaseOptionsV1 options, DiplomatWriteable* write); void ICU4XTitlecaseMapper_destroy(ICU4XTitlecaseMapper* self); diff --git a/ffi/diplomat/c/include/ICU4XTitlecaseOptionsV1.h b/ffi/diplomat/c/include/ICU4XTitlecaseOptionsV1.h index ca78b796c9c..a8281885600 100644 --- a/ffi/diplomat/c/include/ICU4XTitlecaseOptionsV1.h +++ b/ffi/diplomat/c/include/ICU4XTitlecaseOptionsV1.h @@ -6,21 +6,21 @@ #include #include "diplomat_runtime.h" -#include "ICU4XHeadAdjustment.h" -#include "ICU4XTailCasing.h" +#include "ICU4XLeadingAdjustment.h" +#include "ICU4XTrailingCase.h" #ifdef __cplusplus namespace capi { #endif typedef struct ICU4XTitlecaseOptionsV1 { - ICU4XHeadAdjustment head_adjustment; - ICU4XTailCasing tail_casing; + ICU4XLeadingAdjustment leading_adjustment; + ICU4XTrailingCase trailing_case; } ICU4XTitlecaseOptionsV1; #ifdef __cplusplus } // namespace capi #endif -#include "ICU4XHeadAdjustment.h" -#include "ICU4XTailCasing.h" +#include "ICU4XLeadingAdjustment.h" +#include "ICU4XTrailingCase.h" #ifdef __cplusplus namespace capi { extern "C" { diff --git a/ffi/diplomat/c/include/ICU4XTailCasing.h b/ffi/diplomat/c/include/ICU4XTrailingCase.h similarity index 58% rename from ffi/diplomat/c/include/ICU4XTailCasing.h rename to ffi/diplomat/c/include/ICU4XTrailingCase.h index 580420a434c..d8957e00884 100644 --- a/ffi/diplomat/c/include/ICU4XTailCasing.h +++ b/ffi/diplomat/c/include/ICU4XTrailingCase.h @@ -1,5 +1,5 @@ -#ifndef ICU4XTailCasing_H -#define ICU4XTailCasing_H +#ifndef ICU4XTrailingCase_H +#define ICU4XTrailingCase_H #include #include #include @@ -10,10 +10,10 @@ namespace capi { #endif -typedef enum ICU4XTailCasing { - ICU4XTailCasing_Lowercase = 0, - ICU4XTailCasing_PreserveCase = 1, -} ICU4XTailCasing; +typedef enum ICU4XTrailingCase { + ICU4XTrailingCase_Lower = 0, + ICU4XTrailingCase_Unchanged = 1, +} ICU4XTrailingCase; #ifdef __cplusplus } // namespace capi #endif @@ -22,7 +22,7 @@ namespace capi { extern "C" { #endif -void ICU4XTailCasing_destroy(ICU4XTailCasing* self); +void ICU4XTrailingCase_destroy(ICU4XTrailingCase* self); #ifdef __cplusplus } // extern "C" diff --git a/ffi/diplomat/cpp/docs/source/casemap_ffi.rst b/ffi/diplomat/cpp/docs/source/casemap_ffi.rst index 969b870ef14..051eb1038b0 100644 --- a/ffi/diplomat/cpp/docs/source/casemap_ffi.rst +++ b/ffi/diplomat/cpp/docs/source/casemap_ffi.rst @@ -69,22 +69,22 @@ See the `Rust documentation for uppercase `__ for more information. - .. cpp:function:: template diplomat::result titlecase_segment_legacy_v1_to_writeable(const std::string_view s, const ICU4XLocale& locale, ICU4XTitlecaseOptionsV1 options, W& write) const + .. cpp:function:: template diplomat::result titlecase_segment_with_only_case_data_v1_to_writeable(const std::string_view s, const ICU4XLocale& locale, ICU4XTitlecaseOptionsV1 options, W& write) const - Returns the full titlecase mapping of the given string, using legacy head adjustment behavior (if head adjustment is enabled in the options) + Returns the full titlecase mapping of the given string, performing head adjustment without loading additional data. (if head adjustment is enabled in the options) The ``v1`` refers to the version of the options struct, which may change as we add more options - See the `Rust documentation for titlecase_segment_legacy `__ for more information. + See the `Rust documentation for titlecase_segment_with_only_case_data `__ for more information. - .. cpp:function:: diplomat::result titlecase_segment_legacy_v1(const std::string_view s, const ICU4XLocale& locale, ICU4XTitlecaseOptionsV1 options) const + .. cpp:function:: diplomat::result titlecase_segment_with_only_case_data_v1(const std::string_view s, const ICU4XLocale& locale, ICU4XTitlecaseOptionsV1 options) const - Returns the full titlecase mapping of the given string, using legacy head adjustment behavior (if head adjustment is enabled in the options) + Returns the full titlecase mapping of the given string, performing head adjustment without loading additional data. (if head adjustment is enabled in the options) The ``v1`` refers to the version of the options struct, which may change as we add more options - See the `Rust documentation for titlecase_segment_legacy `__ for more information. + See the `Rust documentation for titlecase_segment_with_only_case_data `__ for more information. .. cpp:function:: template diplomat::result fold_to_writeable(const std::string_view s, W& write) const @@ -173,23 +173,16 @@ See the `Rust documentation for simple_fold_turkic `__ for more information. -.. cpp:enum-struct:: ICU4XHeadAdjustment +.. cpp:enum-struct:: ICU4XLeadingAdjustment - See the `Rust documentation for HeadAdjustment `__ for more information. + See the `Rust documentation for LeadingAdjustment `__ for more information. - .. cpp:enumerator:: Adjust + .. cpp:enumerator:: Auto - .. cpp:enumerator:: NoAdjust + .. cpp:enumerator:: None -.. cpp:enum-struct:: ICU4XTailCasing - - See the `Rust documentation for TailCasing `__ for more information. - - - .. cpp:enumerator:: Lowercase - - .. cpp:enumerator:: PreserveCase + .. cpp:enumerator:: ToCased .. cpp:class:: ICU4XTitlecaseMapper @@ -203,15 +196,6 @@ See the `Rust documentation for new `__ for more information. - .. cpp:function:: static diplomat::result create_legacy(const ICU4XDataProvider& provider) - - Construct a new ``ICU4XTitlecaseMapper`` instance with legacy head-adjustment behavior - - Behaves identically to using ``titlecase_segment_legacy`` on ``CaseMapper`` - - See the `Rust documentation for new_legacy `__ for more information. - - .. cpp:function:: template diplomat::result titlecase_segment_v1_to_writeable(const std::string_view s, const ICU4XLocale& locale, ICU4XTitlecaseOptionsV1 options, W& write) const Returns the full titlecase mapping of the given string @@ -235,11 +219,20 @@ See the `Rust documentation for TitlecaseOptions `__ for more information. - .. cpp:member:: ICU4XHeadAdjustment head_adjustment + .. cpp:member:: ICU4XLeadingAdjustment leading_adjustment - .. cpp:member:: ICU4XTailCasing tail_casing + .. cpp:member:: ICU4XTrailingCase trailing_case .. cpp:function:: static ICU4XTitlecaseOptionsV1 default_options() See the `Rust documentation for default `__ for more information. + +.. cpp:enum-struct:: ICU4XTrailingCase + + See the `Rust documentation for TrailingCase `__ for more information. + + + .. cpp:enumerator:: Lower + + .. cpp:enumerator:: Unchanged diff --git a/ffi/diplomat/cpp/examples/casemapping/test.cpp b/ffi/diplomat/cpp/examples/casemapping/test.cpp index 6e7bd335ccd..3559c5435d9 100644 --- a/ffi/diplomat/cpp/examples/casemapping/test.cpp +++ b/ffi/diplomat/cpp/examples/casemapping/test.cpp @@ -34,7 +34,7 @@ int main() { return 1; } - out = cm.titlecase_segment_legacy_v1("hEllO WorLd", und, tc_options).ok().value(); + out = cm.titlecase_segment_with_only_case_data_v1("hEllO WorLd", und, tc_options).ok().value(); std::cout << "Titlecased value is " << out << std::endl; if (out != "Hello world") { std::cout << "Output does not match expected output" << std::endl; diff --git a/ffi/diplomat/cpp/include/ICU4XCaseMapper.h b/ffi/diplomat/cpp/include/ICU4XCaseMapper.h index bdec1d4b267..aef264f7225 100644 --- a/ffi/diplomat/cpp/include/ICU4XCaseMapper.h +++ b/ffi/diplomat/cpp/include/ICU4XCaseMapper.h @@ -31,7 +31,7 @@ diplomat_result_void_ICU4XError ICU4XCaseMapper_lowercase(const ICU4XCaseMapper* diplomat_result_void_ICU4XError ICU4XCaseMapper_uppercase(const ICU4XCaseMapper* self, const char* s_data, size_t s_len, const ICU4XLocale* locale, DiplomatWriteable* write); -diplomat_result_void_ICU4XError ICU4XCaseMapper_titlecase_segment_legacy_v1(const ICU4XCaseMapper* self, const char* s_data, size_t s_len, const ICU4XLocale* locale, ICU4XTitlecaseOptionsV1 options, DiplomatWriteable* write); +diplomat_result_void_ICU4XError ICU4XCaseMapper_titlecase_segment_with_only_case_data_v1(const ICU4XCaseMapper* self, const char* s_data, size_t s_len, const ICU4XLocale* locale, ICU4XTitlecaseOptionsV1 options, DiplomatWriteable* write); diplomat_result_void_ICU4XError ICU4XCaseMapper_fold(const ICU4XCaseMapper* self, const char* s_data, size_t s_len, DiplomatWriteable* write); diff --git a/ffi/diplomat/cpp/include/ICU4XCaseMapper.hpp b/ffi/diplomat/cpp/include/ICU4XCaseMapper.hpp index bd8b863c263..a3e3a541a7c 100644 --- a/ffi/diplomat/cpp/include/ICU4XCaseMapper.hpp +++ b/ffi/diplomat/cpp/include/ICU4XCaseMapper.hpp @@ -71,24 +71,26 @@ class ICU4XCaseMapper { diplomat::result uppercase(const std::string_view s, const ICU4XLocale& locale) const; /** - * Returns the full titlecase mapping of the given string, using legacy head adjustment behavior + * Returns the full titlecase mapping of the given string, performing head adjustment without + * loading additional data. * (if head adjustment is enabled in the options) * * The `v1` refers to the version of the options struct, which may change as we add more options * - * See the [Rust documentation for `titlecase_segment_legacy`](https://docs.rs/icu/latest/icu/casemap/struct.CaseMapper.html#method.titlecase_segment_legacy) for more information. + * See the [Rust documentation for `titlecase_segment_with_only_case_data`](https://docs.rs/icu/latest/icu/casemap/struct.CaseMapper.html#method.titlecase_segment_with_only_case_data) for more information. */ - template diplomat::result titlecase_segment_legacy_v1_to_writeable(const std::string_view s, const ICU4XLocale& locale, ICU4XTitlecaseOptionsV1 options, W& write) const; + template diplomat::result titlecase_segment_with_only_case_data_v1_to_writeable(const std::string_view s, const ICU4XLocale& locale, ICU4XTitlecaseOptionsV1 options, W& write) const; /** - * Returns the full titlecase mapping of the given string, using legacy head adjustment behavior + * Returns the full titlecase mapping of the given string, performing head adjustment without + * loading additional data. * (if head adjustment is enabled in the options) * * The `v1` refers to the version of the options struct, which may change as we add more options * - * See the [Rust documentation for `titlecase_segment_legacy`](https://docs.rs/icu/latest/icu/casemap/struct.CaseMapper.html#method.titlecase_segment_legacy) for more information. + * See the [Rust documentation for `titlecase_segment_with_only_case_data`](https://docs.rs/icu/latest/icu/casemap/struct.CaseMapper.html#method.titlecase_segment_with_only_case_data) for more information. */ - diplomat::result titlecase_segment_legacy_v1(const std::string_view s, const ICU4XLocale& locale, ICU4XTitlecaseOptionsV1 options) const; + diplomat::result titlecase_segment_with_only_case_data_v1(const std::string_view s, const ICU4XLocale& locale, ICU4XTitlecaseOptionsV1 options) const; /** * Case-folds the characters in the given string @@ -260,10 +262,10 @@ inline diplomat::result ICU4XCaseMapper::uppercase(cons } return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string)); } -template inline diplomat::result ICU4XCaseMapper::titlecase_segment_legacy_v1_to_writeable(const std::string_view s, const ICU4XLocale& locale, ICU4XTitlecaseOptionsV1 options, W& write) const { +template inline diplomat::result ICU4XCaseMapper::titlecase_segment_with_only_case_data_v1_to_writeable(const std::string_view s, const ICU4XLocale& locale, ICU4XTitlecaseOptionsV1 options, W& write) const { ICU4XTitlecaseOptionsV1 diplomat_wrapped_struct_options = options; capi::DiplomatWriteable write_writer = diplomat::WriteableTrait::Construct(write); - auto diplomat_result_raw_out_value = capi::ICU4XCaseMapper_titlecase_segment_legacy_v1(this->inner.get(), s.data(), s.size(), locale.AsFFI(), capi::ICU4XTitlecaseOptionsV1{ .head_adjustment = static_cast(diplomat_wrapped_struct_options.head_adjustment), .tail_casing = static_cast(diplomat_wrapped_struct_options.tail_casing) }, &write_writer); + auto diplomat_result_raw_out_value = capi::ICU4XCaseMapper_titlecase_segment_with_only_case_data_v1(this->inner.get(), s.data(), s.size(), locale.AsFFI(), capi::ICU4XTitlecaseOptionsV1{ .leading_adjustment = static_cast(diplomat_wrapped_struct_options.leading_adjustment), .trailing_case = static_cast(diplomat_wrapped_struct_options.trailing_case) }, &write_writer); diplomat::result diplomat_result_out_value; if (diplomat_result_raw_out_value.is_ok) { diplomat_result_out_value = diplomat::Ok(std::monostate()); @@ -272,11 +274,11 @@ template inline diplomat::result ICU4XCa } return diplomat_result_out_value; } -inline diplomat::result ICU4XCaseMapper::titlecase_segment_legacy_v1(const std::string_view s, const ICU4XLocale& locale, ICU4XTitlecaseOptionsV1 options) const { +inline diplomat::result ICU4XCaseMapper::titlecase_segment_with_only_case_data_v1(const std::string_view s, const ICU4XLocale& locale, ICU4XTitlecaseOptionsV1 options) const { ICU4XTitlecaseOptionsV1 diplomat_wrapped_struct_options = options; std::string diplomat_writeable_string; capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); - auto diplomat_result_raw_out_value = capi::ICU4XCaseMapper_titlecase_segment_legacy_v1(this->inner.get(), s.data(), s.size(), locale.AsFFI(), capi::ICU4XTitlecaseOptionsV1{ .head_adjustment = static_cast(diplomat_wrapped_struct_options.head_adjustment), .tail_casing = static_cast(diplomat_wrapped_struct_options.tail_casing) }, &diplomat_writeable_out); + auto diplomat_result_raw_out_value = capi::ICU4XCaseMapper_titlecase_segment_with_only_case_data_v1(this->inner.get(), s.data(), s.size(), locale.AsFFI(), capi::ICU4XTitlecaseOptionsV1{ .leading_adjustment = static_cast(diplomat_wrapped_struct_options.leading_adjustment), .trailing_case = static_cast(diplomat_wrapped_struct_options.trailing_case) }, &diplomat_writeable_out); diplomat::result diplomat_result_out_value; if (diplomat_result_raw_out_value.is_ok) { diplomat_result_out_value = diplomat::Ok(std::monostate()); diff --git a/ffi/diplomat/cpp/include/ICU4XHeadAdjustment.hpp b/ffi/diplomat/cpp/include/ICU4XHeadAdjustment.hpp deleted file mode 100644 index 80f14218e3f..00000000000 --- a/ffi/diplomat/cpp/include/ICU4XHeadAdjustment.hpp +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef ICU4XHeadAdjustment_HPP -#define ICU4XHeadAdjustment_HPP -#include -#include -#include -#include -#include -#include -#include -#include "diplomat_runtime.hpp" - -#include "ICU4XHeadAdjustment.h" - - - -/** - * - * - * See the [Rust documentation for `HeadAdjustment`](https://docs.rs/icu/latest/icu/casemap/titlecase/enum.HeadAdjustment.html) for more information. - */ -enum struct ICU4XHeadAdjustment { - Adjust = 0, - NoAdjust = 1, -}; - -#endif diff --git a/ffi/diplomat/cpp/include/ICU4XHeadAdjustment.h b/ffi/diplomat/cpp/include/ICU4XLeadingAdjustment.h similarity index 51% rename from ffi/diplomat/cpp/include/ICU4XHeadAdjustment.h rename to ffi/diplomat/cpp/include/ICU4XLeadingAdjustment.h index 305e0e165bd..91647188edf 100644 --- a/ffi/diplomat/cpp/include/ICU4XHeadAdjustment.h +++ b/ffi/diplomat/cpp/include/ICU4XLeadingAdjustment.h @@ -1,5 +1,5 @@ -#ifndef ICU4XHeadAdjustment_H -#define ICU4XHeadAdjustment_H +#ifndef ICU4XLeadingAdjustment_H +#define ICU4XLeadingAdjustment_H #include #include #include @@ -10,10 +10,11 @@ namespace capi { #endif -typedef enum ICU4XHeadAdjustment { - ICU4XHeadAdjustment_Adjust = 0, - ICU4XHeadAdjustment_NoAdjust = 1, -} ICU4XHeadAdjustment; +typedef enum ICU4XLeadingAdjustment { + ICU4XLeadingAdjustment_Auto = 0, + ICU4XLeadingAdjustment_None = 1, + ICU4XLeadingAdjustment_ToCased = 2, +} ICU4XLeadingAdjustment; #ifdef __cplusplus } // namespace capi #endif @@ -22,7 +23,7 @@ namespace capi { extern "C" { #endif -void ICU4XHeadAdjustment_destroy(ICU4XHeadAdjustment* self); +void ICU4XLeadingAdjustment_destroy(ICU4XLeadingAdjustment* self); #ifdef __cplusplus } // extern "C" diff --git a/ffi/diplomat/cpp/include/ICU4XLeadingAdjustment.hpp b/ffi/diplomat/cpp/include/ICU4XLeadingAdjustment.hpp new file mode 100644 index 00000000000..6258dda55c7 --- /dev/null +++ b/ffi/diplomat/cpp/include/ICU4XLeadingAdjustment.hpp @@ -0,0 +1,27 @@ +#ifndef ICU4XLeadingAdjustment_HPP +#define ICU4XLeadingAdjustment_HPP +#include +#include +#include +#include +#include +#include +#include +#include "diplomat_runtime.hpp" + +#include "ICU4XLeadingAdjustment.h" + + + +/** + * + * + * See the [Rust documentation for `LeadingAdjustment`](https://docs.rs/icu/latest/icu/casemap/titlecase/enum.LeadingAdjustment.html) for more information. + */ +enum struct ICU4XLeadingAdjustment { + Auto = 0, + None = 1, + ToCased = 2, +}; + +#endif diff --git a/ffi/diplomat/cpp/include/ICU4XTailCasing.hpp b/ffi/diplomat/cpp/include/ICU4XTailCasing.hpp deleted file mode 100644 index 8e0937ab09e..00000000000 --- a/ffi/diplomat/cpp/include/ICU4XTailCasing.hpp +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef ICU4XTailCasing_HPP -#define ICU4XTailCasing_HPP -#include -#include -#include -#include -#include -#include -#include -#include "diplomat_runtime.hpp" - -#include "ICU4XTailCasing.h" - - - -/** - * - * - * See the [Rust documentation for `TailCasing`](https://docs.rs/icu/latest/icu/casemap/titlecase/enum.TailCasing.html) for more information. - */ -enum struct ICU4XTailCasing { - Lowercase = 0, - PreserveCase = 1, -}; - -#endif diff --git a/ffi/diplomat/cpp/include/ICU4XTitlecaseMapper.h b/ffi/diplomat/cpp/include/ICU4XTitlecaseMapper.h index e1ed6d9b7ee..04debefbf9d 100644 --- a/ffi/diplomat/cpp/include/ICU4XTitlecaseMapper.h +++ b/ffi/diplomat/cpp/include/ICU4XTitlecaseMapper.h @@ -26,8 +26,6 @@ extern "C" { diplomat_result_box_ICU4XTitlecaseMapper_ICU4XError ICU4XTitlecaseMapper_create(const ICU4XDataProvider* provider); -diplomat_result_box_ICU4XTitlecaseMapper_ICU4XError ICU4XTitlecaseMapper_create_legacy(const ICU4XDataProvider* provider); - diplomat_result_void_ICU4XError ICU4XTitlecaseMapper_titlecase_segment_v1(const ICU4XTitlecaseMapper* self, const char* s_data, size_t s_len, const ICU4XLocale* locale, ICU4XTitlecaseOptionsV1 options, DiplomatWriteable* write); void ICU4XTitlecaseMapper_destroy(ICU4XTitlecaseMapper* self); diff --git a/ffi/diplomat/cpp/include/ICU4XTitlecaseMapper.hpp b/ffi/diplomat/cpp/include/ICU4XTitlecaseMapper.hpp index b0fc7dca8de..462bc635d0d 100644 --- a/ffi/diplomat/cpp/include/ICU4XTitlecaseMapper.hpp +++ b/ffi/diplomat/cpp/include/ICU4XTitlecaseMapper.hpp @@ -41,15 +41,6 @@ class ICU4XTitlecaseMapper { */ static diplomat::result create(const ICU4XDataProvider& provider); - /** - * Construct a new `ICU4XTitlecaseMapper` instance with legacy head-adjustment behavior - * - * Behaves identically to using `titlecase_segment_legacy` on `CaseMapper` - * - * See the [Rust documentation for `new_legacy`](https://docs.rs/icu/latest/icu/casemap/struct.TitlecaseMapper.html#method.new_legacy) for more information. - */ - static diplomat::result create_legacy(const ICU4XDataProvider& provider); - /** * Returns the full titlecase mapping of the given string * @@ -91,20 +82,10 @@ inline diplomat::result ICU4XTitlecaseMapper:: } return diplomat_result_out_value; } -inline diplomat::result ICU4XTitlecaseMapper::create_legacy(const ICU4XDataProvider& provider) { - auto diplomat_result_raw_out_value = capi::ICU4XTitlecaseMapper_create_legacy(provider.AsFFI()); - diplomat::result diplomat_result_out_value; - if (diplomat_result_raw_out_value.is_ok) { - diplomat_result_out_value = diplomat::Ok(std::move(ICU4XTitlecaseMapper(diplomat_result_raw_out_value.ok))); - } else { - diplomat_result_out_value = diplomat::Err(std::move(static_cast(diplomat_result_raw_out_value.err))); - } - return diplomat_result_out_value; -} template inline diplomat::result ICU4XTitlecaseMapper::titlecase_segment_v1_to_writeable(const std::string_view s, const ICU4XLocale& locale, ICU4XTitlecaseOptionsV1 options, W& write) const { ICU4XTitlecaseOptionsV1 diplomat_wrapped_struct_options = options; capi::DiplomatWriteable write_writer = diplomat::WriteableTrait::Construct(write); - auto diplomat_result_raw_out_value = capi::ICU4XTitlecaseMapper_titlecase_segment_v1(this->inner.get(), s.data(), s.size(), locale.AsFFI(), capi::ICU4XTitlecaseOptionsV1{ .head_adjustment = static_cast(diplomat_wrapped_struct_options.head_adjustment), .tail_casing = static_cast(diplomat_wrapped_struct_options.tail_casing) }, &write_writer); + auto diplomat_result_raw_out_value = capi::ICU4XTitlecaseMapper_titlecase_segment_v1(this->inner.get(), s.data(), s.size(), locale.AsFFI(), capi::ICU4XTitlecaseOptionsV1{ .leading_adjustment = static_cast(diplomat_wrapped_struct_options.leading_adjustment), .trailing_case = static_cast(diplomat_wrapped_struct_options.trailing_case) }, &write_writer); diplomat::result diplomat_result_out_value; if (diplomat_result_raw_out_value.is_ok) { diplomat_result_out_value = diplomat::Ok(std::monostate()); @@ -117,7 +98,7 @@ inline diplomat::result ICU4XTitlecaseMapper::titlecase ICU4XTitlecaseOptionsV1 diplomat_wrapped_struct_options = options; std::string diplomat_writeable_string; capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); - auto diplomat_result_raw_out_value = capi::ICU4XTitlecaseMapper_titlecase_segment_v1(this->inner.get(), s.data(), s.size(), locale.AsFFI(), capi::ICU4XTitlecaseOptionsV1{ .head_adjustment = static_cast(diplomat_wrapped_struct_options.head_adjustment), .tail_casing = static_cast(diplomat_wrapped_struct_options.tail_casing) }, &diplomat_writeable_out); + auto diplomat_result_raw_out_value = capi::ICU4XTitlecaseMapper_titlecase_segment_v1(this->inner.get(), s.data(), s.size(), locale.AsFFI(), capi::ICU4XTitlecaseOptionsV1{ .leading_adjustment = static_cast(diplomat_wrapped_struct_options.leading_adjustment), .trailing_case = static_cast(diplomat_wrapped_struct_options.trailing_case) }, &diplomat_writeable_out); diplomat::result diplomat_result_out_value; if (diplomat_result_raw_out_value.is_ok) { diplomat_result_out_value = diplomat::Ok(std::monostate()); diff --git a/ffi/diplomat/cpp/include/ICU4XTitlecaseOptionsV1.h b/ffi/diplomat/cpp/include/ICU4XTitlecaseOptionsV1.h index ca78b796c9c..a8281885600 100644 --- a/ffi/diplomat/cpp/include/ICU4XTitlecaseOptionsV1.h +++ b/ffi/diplomat/cpp/include/ICU4XTitlecaseOptionsV1.h @@ -6,21 +6,21 @@ #include #include "diplomat_runtime.h" -#include "ICU4XHeadAdjustment.h" -#include "ICU4XTailCasing.h" +#include "ICU4XLeadingAdjustment.h" +#include "ICU4XTrailingCase.h" #ifdef __cplusplus namespace capi { #endif typedef struct ICU4XTitlecaseOptionsV1 { - ICU4XHeadAdjustment head_adjustment; - ICU4XTailCasing tail_casing; + ICU4XLeadingAdjustment leading_adjustment; + ICU4XTrailingCase trailing_case; } ICU4XTitlecaseOptionsV1; #ifdef __cplusplus } // namespace capi #endif -#include "ICU4XHeadAdjustment.h" -#include "ICU4XTailCasing.h" +#include "ICU4XLeadingAdjustment.h" +#include "ICU4XTrailingCase.h" #ifdef __cplusplus namespace capi { extern "C" { diff --git a/ffi/diplomat/cpp/include/ICU4XTitlecaseOptionsV1.hpp b/ffi/diplomat/cpp/include/ICU4XTitlecaseOptionsV1.hpp index 8f06128b31a..756c036e430 100644 --- a/ffi/diplomat/cpp/include/ICU4XTitlecaseOptionsV1.hpp +++ b/ffi/diplomat/cpp/include/ICU4XTitlecaseOptionsV1.hpp @@ -11,8 +11,8 @@ #include "ICU4XTitlecaseOptionsV1.h" -#include "ICU4XHeadAdjustment.hpp" -#include "ICU4XTailCasing.hpp" +#include "ICU4XLeadingAdjustment.hpp" +#include "ICU4XTrailingCase.hpp" struct ICU4XTitlecaseOptionsV1; @@ -23,8 +23,8 @@ struct ICU4XTitlecaseOptionsV1; */ struct ICU4XTitlecaseOptionsV1 { public: - ICU4XHeadAdjustment head_adjustment; - ICU4XTailCasing tail_casing; + ICU4XLeadingAdjustment leading_adjustment; + ICU4XTrailingCase trailing_case; /** * @@ -37,6 +37,6 @@ struct ICU4XTitlecaseOptionsV1 { inline ICU4XTitlecaseOptionsV1 ICU4XTitlecaseOptionsV1::default_options() { capi::ICU4XTitlecaseOptionsV1 diplomat_raw_struct_out_value = capi::ICU4XTitlecaseOptionsV1_default_options(); - return ICU4XTitlecaseOptionsV1{ .head_adjustment = std::move(static_cast(diplomat_raw_struct_out_value.head_adjustment)), .tail_casing = std::move(static_cast(diplomat_raw_struct_out_value.tail_casing)) }; + return ICU4XTitlecaseOptionsV1{ .leading_adjustment = std::move(static_cast(diplomat_raw_struct_out_value.leading_adjustment)), .trailing_case = std::move(static_cast(diplomat_raw_struct_out_value.trailing_case)) }; } #endif diff --git a/ffi/diplomat/cpp/include/ICU4XTailCasing.h b/ffi/diplomat/cpp/include/ICU4XTrailingCase.h similarity index 58% rename from ffi/diplomat/cpp/include/ICU4XTailCasing.h rename to ffi/diplomat/cpp/include/ICU4XTrailingCase.h index 580420a434c..d8957e00884 100644 --- a/ffi/diplomat/cpp/include/ICU4XTailCasing.h +++ b/ffi/diplomat/cpp/include/ICU4XTrailingCase.h @@ -1,5 +1,5 @@ -#ifndef ICU4XTailCasing_H -#define ICU4XTailCasing_H +#ifndef ICU4XTrailingCase_H +#define ICU4XTrailingCase_H #include #include #include @@ -10,10 +10,10 @@ namespace capi { #endif -typedef enum ICU4XTailCasing { - ICU4XTailCasing_Lowercase = 0, - ICU4XTailCasing_PreserveCase = 1, -} ICU4XTailCasing; +typedef enum ICU4XTrailingCase { + ICU4XTrailingCase_Lower = 0, + ICU4XTrailingCase_Unchanged = 1, +} ICU4XTrailingCase; #ifdef __cplusplus } // namespace capi #endif @@ -22,7 +22,7 @@ namespace capi { extern "C" { #endif -void ICU4XTailCasing_destroy(ICU4XTailCasing* self); +void ICU4XTrailingCase_destroy(ICU4XTrailingCase* self); #ifdef __cplusplus } // extern "C" diff --git a/ffi/diplomat/cpp/include/ICU4XTrailingCase.hpp b/ffi/diplomat/cpp/include/ICU4XTrailingCase.hpp new file mode 100644 index 00000000000..efe0e485601 --- /dev/null +++ b/ffi/diplomat/cpp/include/ICU4XTrailingCase.hpp @@ -0,0 +1,26 @@ +#ifndef ICU4XTrailingCase_HPP +#define ICU4XTrailingCase_HPP +#include +#include +#include +#include +#include +#include +#include +#include "diplomat_runtime.hpp" + +#include "ICU4XTrailingCase.h" + + + +/** + * + * + * See the [Rust documentation for `TrailingCase`](https://docs.rs/icu/latest/icu/casemap/titlecase/enum.TrailingCase.html) for more information. + */ +enum struct ICU4XTrailingCase { + Lower = 0, + Unchanged = 1, +}; + +#endif diff --git a/ffi/diplomat/js/docs/source/casemap_ffi.rst b/ffi/diplomat/js/docs/source/casemap_ffi.rst index 6f818d87b87..7af7654d112 100644 --- a/ffi/diplomat/js/docs/source/casemap_ffi.rst +++ b/ffi/diplomat/js/docs/source/casemap_ffi.rst @@ -55,13 +55,13 @@ See the `Rust documentation for uppercase `__ for more information. - .. js:method:: titlecase_segment_legacy_v1(s, locale, options) + .. js:method:: titlecase_segment_with_only_case_data_v1(s, locale, options) - Returns the full titlecase mapping of the given string, using legacy head adjustment behavior (if head adjustment is enabled in the options) + Returns the full titlecase mapping of the given string, performing head adjustment without loading additional data. (if head adjustment is enabled in the options) The ``v1`` refers to the version of the options struct, which may change as we add more options - See the `Rust documentation for titlecase_segment_legacy `__ for more information. + See the `Rust documentation for titlecase_segment_with_only_case_data `__ for more information. .. js:method:: fold(s) @@ -136,14 +136,9 @@ See the `Rust documentation for simple_fold_turkic `__ for more information. -.. js:class:: ICU4XHeadAdjustment +.. js:class:: ICU4XLeadingAdjustment - See the `Rust documentation for HeadAdjustment `__ for more information. - - -.. js:class:: ICU4XTailCasing - - See the `Rust documentation for TailCasing `__ for more information. + See the `Rust documentation for LeadingAdjustment `__ for more information. .. js:class:: ICU4XTitlecaseMapper @@ -158,15 +153,6 @@ See the `Rust documentation for new `__ for more information. - .. js:function:: create_legacy(provider) - - Construct a new ``ICU4XTitlecaseMapper`` instance with legacy head-adjustment behavior - - Behaves identically to using ``titlecase_segment_legacy`` on ``CaseMapper`` - - See the `Rust documentation for new_legacy `__ for more information. - - .. js:method:: titlecase_segment_v1(s, locale, options) Returns the full titlecase mapping of the given string @@ -181,11 +167,16 @@ See the `Rust documentation for TitlecaseOptions `__ for more information. - .. js:attribute:: head_adjustment + .. js:attribute:: leading_adjustment - .. js:attribute:: tail_casing + .. js:attribute:: trailing_case .. js:function:: default_options() See the `Rust documentation for default `__ for more information. + +.. js:class:: ICU4XTrailingCase + + See the `Rust documentation for TrailingCase `__ for more information. + diff --git a/ffi/diplomat/js/include/ICU4XCaseMapper.d.ts b/ffi/diplomat/js/include/ICU4XCaseMapper.d.ts index c6084068cb9..eb472c809bf 100644 --- a/ffi/diplomat/js/include/ICU4XCaseMapper.d.ts +++ b/ffi/diplomat/js/include/ICU4XCaseMapper.d.ts @@ -41,14 +41,14 @@ export class ICU4XCaseMapper { /** - * Returns the full titlecase mapping of the given string, using legacy head adjustment behavior (if head adjustment is enabled in the options) + * Returns the full titlecase mapping of the given string, performing head adjustment without loading additional data. (if head adjustment is enabled in the options) * The `v1` refers to the version of the options struct, which may change as we add more options - * See the {@link https://docs.rs/icu/latest/icu/casemap/struct.CaseMapper.html#method.titlecase_segment_legacy Rust documentation for `titlecase_segment_legacy`} for more information. + * See the {@link https://docs.rs/icu/latest/icu/casemap/struct.CaseMapper.html#method.titlecase_segment_with_only_case_data Rust documentation for `titlecase_segment_with_only_case_data`} for more information. * @throws {@link FFIError}<{@link ICU4XError}> */ - titlecase_segment_legacy_v1(s: string, locale: ICU4XLocale, options: ICU4XTitlecaseOptionsV1): string | never; + titlecase_segment_with_only_case_data_v1(s: string, locale: ICU4XLocale, options: ICU4XTitlecaseOptionsV1): string | never; /** diff --git a/ffi/diplomat/js/include/ICU4XCaseMapper.js b/ffi/diplomat/js/include/ICU4XCaseMapper.js index d5d4edf05b8..b6bf60bdda9 100644 --- a/ffi/diplomat/js/include/ICU4XCaseMapper.js +++ b/ffi/diplomat/js/include/ICU4XCaseMapper.js @@ -1,8 +1,8 @@ import wasm from "./diplomat-wasm.mjs" import * as diplomatRuntime from "./diplomat-runtime.js" import { ICU4XError_js_to_rust, ICU4XError_rust_to_js } from "./ICU4XError.js" -import { ICU4XHeadAdjustment_js_to_rust, ICU4XHeadAdjustment_rust_to_js } from "./ICU4XHeadAdjustment.js" -import { ICU4XTailCasing_js_to_rust, ICU4XTailCasing_rust_to_js } from "./ICU4XTailCasing.js" +import { ICU4XLeadingAdjustment_js_to_rust, ICU4XLeadingAdjustment_rust_to_js } from "./ICU4XLeadingAdjustment.js" +import { ICU4XTrailingCase_js_to_rust, ICU4XTrailingCase_rust_to_js } from "./ICU4XTrailingCase.js" const ICU4XCaseMapper_box_destroy_registry = new FinalizationRegistry(underlying => { wasm.ICU4XCaseMapper_destroy(underlying); @@ -79,14 +79,14 @@ export class ICU4XCaseMapper { return diplomat_out; } - titlecase_segment_legacy_v1(arg_s, arg_locale, arg_options) { + titlecase_segment_with_only_case_data_v1(arg_s, arg_locale, arg_options) { const buf_arg_s = diplomatRuntime.DiplomatBuf.str(wasm, arg_s); - const field_head_adjustment_arg_options = arg_options["head_adjustment"]; - const field_tail_casing_arg_options = arg_options["tail_casing"]; + const field_leading_adjustment_arg_options = arg_options["leading_adjustment"]; + const field_trailing_case_arg_options = arg_options["trailing_case"]; const diplomat_out = diplomatRuntime.withWriteable(wasm, (writeable) => { return (() => { const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XCaseMapper_titlecase_segment_legacy_v1(diplomat_receive_buffer, this.underlying, buf_arg_s.ptr, buf_arg_s.size, arg_locale.underlying, ICU4XHeadAdjustment_js_to_rust[field_head_adjustment_arg_options], ICU4XTailCasing_js_to_rust[field_tail_casing_arg_options], writeable); + wasm.ICU4XCaseMapper_titlecase_segment_with_only_case_data_v1(diplomat_receive_buffer, this.underlying, buf_arg_s.ptr, buf_arg_s.size, arg_locale.underlying, ICU4XLeadingAdjustment_js_to_rust[field_leading_adjustment_arg_options], ICU4XTrailingCase_js_to_rust[field_trailing_case_arg_options], writeable); const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); if (is_ok) { const ok_value = {}; diff --git a/ffi/diplomat/js/include/ICU4XHeadAdjustment.d.ts b/ffi/diplomat/js/include/ICU4XHeadAdjustment.d.ts deleted file mode 100644 index dde042ad06b..00000000000 --- a/ffi/diplomat/js/include/ICU4XHeadAdjustment.d.ts +++ /dev/null @@ -1,13 +0,0 @@ - -/** - - * See the {@link https://docs.rs/icu/latest/icu/casemap/titlecase/enum.HeadAdjustment.html Rust documentation for `HeadAdjustment`} for more information. - */ -export enum ICU4XHeadAdjustment { - /** - */ - Adjust = 'Adjust', - /** - */ - NoAdjust = 'NoAdjust', -} \ No newline at end of file diff --git a/ffi/diplomat/js/include/ICU4XHeadAdjustment.js b/ffi/diplomat/js/include/ICU4XHeadAdjustment.js deleted file mode 100644 index b2eff0aff08..00000000000 --- a/ffi/diplomat/js/include/ICU4XHeadAdjustment.js +++ /dev/null @@ -1,17 +0,0 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.js" - -export const ICU4XHeadAdjustment_js_to_rust = { - "Adjust": 0, - "NoAdjust": 1, -}; - -export const ICU4XHeadAdjustment_rust_to_js = { - [0]: "Adjust", - [1]: "NoAdjust", -}; - -export const ICU4XHeadAdjustment = { - "Adjust": "Adjust", - "NoAdjust": "NoAdjust", -}; diff --git a/ffi/diplomat/js/include/ICU4XLeadingAdjustment.d.ts b/ffi/diplomat/js/include/ICU4XLeadingAdjustment.d.ts new file mode 100644 index 00000000000..b170cdb94b6 --- /dev/null +++ b/ffi/diplomat/js/include/ICU4XLeadingAdjustment.d.ts @@ -0,0 +1,16 @@ + +/** + + * See the {@link https://docs.rs/icu/latest/icu/casemap/titlecase/enum.LeadingAdjustment.html Rust documentation for `LeadingAdjustment`} for more information. + */ +export enum ICU4XLeadingAdjustment { + /** + */ + Auto = 'Auto', + /** + */ + None = 'None', + /** + */ + ToCased = 'ToCased', +} \ No newline at end of file diff --git a/ffi/diplomat/js/include/ICU4XLeadingAdjustment.js b/ffi/diplomat/js/include/ICU4XLeadingAdjustment.js new file mode 100644 index 00000000000..e57aa259ac4 --- /dev/null +++ b/ffi/diplomat/js/include/ICU4XLeadingAdjustment.js @@ -0,0 +1,20 @@ +import wasm from "./diplomat-wasm.mjs" +import * as diplomatRuntime from "./diplomat-runtime.js" + +export const ICU4XLeadingAdjustment_js_to_rust = { + "Auto": 0, + "None": 1, + "ToCased": 2, +}; + +export const ICU4XLeadingAdjustment_rust_to_js = { + [0]: "Auto", + [1]: "None", + [2]: "ToCased", +}; + +export const ICU4XLeadingAdjustment = { + "Auto": "Auto", + "None": "None", + "ToCased": "ToCased", +}; diff --git a/ffi/diplomat/js/include/ICU4XTailCasing.d.ts b/ffi/diplomat/js/include/ICU4XTailCasing.d.ts deleted file mode 100644 index e3a4cee2011..00000000000 --- a/ffi/diplomat/js/include/ICU4XTailCasing.d.ts +++ /dev/null @@ -1,13 +0,0 @@ - -/** - - * See the {@link https://docs.rs/icu/latest/icu/casemap/titlecase/enum.TailCasing.html Rust documentation for `TailCasing`} for more information. - */ -export enum ICU4XTailCasing { - /** - */ - Lowercase = 'Lowercase', - /** - */ - PreserveCase = 'PreserveCase', -} \ No newline at end of file diff --git a/ffi/diplomat/js/include/ICU4XTailCasing.js b/ffi/diplomat/js/include/ICU4XTailCasing.js deleted file mode 100644 index e2c043205c6..00000000000 --- a/ffi/diplomat/js/include/ICU4XTailCasing.js +++ /dev/null @@ -1,17 +0,0 @@ -import wasm from "./diplomat-wasm.mjs" -import * as diplomatRuntime from "./diplomat-runtime.js" - -export const ICU4XTailCasing_js_to_rust = { - "Lowercase": 0, - "PreserveCase": 1, -}; - -export const ICU4XTailCasing_rust_to_js = { - [0]: "Lowercase", - [1]: "PreserveCase", -}; - -export const ICU4XTailCasing = { - "Lowercase": "Lowercase", - "PreserveCase": "PreserveCase", -}; diff --git a/ffi/diplomat/js/include/ICU4XTitlecaseMapper.d.ts b/ffi/diplomat/js/include/ICU4XTitlecaseMapper.d.ts index 1c14ddec875..dc2f41f8669 100644 --- a/ffi/diplomat/js/include/ICU4XTitlecaseMapper.d.ts +++ b/ffi/diplomat/js/include/ICU4XTitlecaseMapper.d.ts @@ -19,17 +19,6 @@ export class ICU4XTitlecaseMapper { */ static create(provider: ICU4XDataProvider): ICU4XTitlecaseMapper | never; - /** - - * Construct a new `ICU4XTitlecaseMapper` instance with legacy head-adjustment behavior - - * Behaves identically to using `titlecase_segment_legacy` on `CaseMapper` - - * See the {@link https://docs.rs/icu/latest/icu/casemap/struct.TitlecaseMapper.html#method.new_legacy Rust documentation for `new_legacy`} for more information. - * @throws {@link FFIError}<{@link ICU4XError}> - */ - static create_legacy(provider: ICU4XDataProvider): ICU4XTitlecaseMapper | never; - /** * Returns the full titlecase mapping of the given string diff --git a/ffi/diplomat/js/include/ICU4XTitlecaseMapper.js b/ffi/diplomat/js/include/ICU4XTitlecaseMapper.js index 81974fc3876..c25bf087022 100644 --- a/ffi/diplomat/js/include/ICU4XTitlecaseMapper.js +++ b/ffi/diplomat/js/include/ICU4XTitlecaseMapper.js @@ -1,8 +1,8 @@ import wasm from "./diplomat-wasm.mjs" import * as diplomatRuntime from "./diplomat-runtime.js" import { ICU4XError_js_to_rust, ICU4XError_rust_to_js } from "./ICU4XError.js" -import { ICU4XHeadAdjustment_js_to_rust, ICU4XHeadAdjustment_rust_to_js } from "./ICU4XHeadAdjustment.js" -import { ICU4XTailCasing_js_to_rust, ICU4XTailCasing_rust_to_js } from "./ICU4XTailCasing.js" +import { ICU4XLeadingAdjustment_js_to_rust, ICU4XLeadingAdjustment_rust_to_js } from "./ICU4XLeadingAdjustment.js" +import { ICU4XTrailingCase_js_to_rust, ICU4XTrailingCase_rust_to_js } from "./ICU4XTrailingCase.js" const ICU4XTitlecaseMapper_box_destroy_registry = new FinalizationRegistry(underlying => { wasm.ICU4XTitlecaseMapper_destroy(underlying); @@ -35,31 +35,14 @@ export class ICU4XTitlecaseMapper { })(); } - static create_legacy(arg_provider) { - return (() => { - const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XTitlecaseMapper_create_legacy(diplomat_receive_buffer, arg_provider.underlying); - const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); - if (is_ok) { - const ok_value = new ICU4XTitlecaseMapper(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []); - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - return ok_value; - } else { - const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)]; - wasm.diplomat_free(diplomat_receive_buffer, 5, 4); - throw new diplomatRuntime.FFIError(throw_value); - } - })(); - } - titlecase_segment_v1(arg_s, arg_locale, arg_options) { const buf_arg_s = diplomatRuntime.DiplomatBuf.str(wasm, arg_s); - const field_head_adjustment_arg_options = arg_options["head_adjustment"]; - const field_tail_casing_arg_options = arg_options["tail_casing"]; + const field_leading_adjustment_arg_options = arg_options["leading_adjustment"]; + const field_trailing_case_arg_options = arg_options["trailing_case"]; const diplomat_out = diplomatRuntime.withWriteable(wasm, (writeable) => { return (() => { const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XTitlecaseMapper_titlecase_segment_v1(diplomat_receive_buffer, this.underlying, buf_arg_s.ptr, buf_arg_s.size, arg_locale.underlying, ICU4XHeadAdjustment_js_to_rust[field_head_adjustment_arg_options], ICU4XTailCasing_js_to_rust[field_tail_casing_arg_options], writeable); + wasm.ICU4XTitlecaseMapper_titlecase_segment_v1(diplomat_receive_buffer, this.underlying, buf_arg_s.ptr, buf_arg_s.size, arg_locale.underlying, ICU4XLeadingAdjustment_js_to_rust[field_leading_adjustment_arg_options], ICU4XTrailingCase_js_to_rust[field_trailing_case_arg_options], writeable); const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); if (is_ok) { const ok_value = {}; diff --git a/ffi/diplomat/js/include/ICU4XTitlecaseOptionsV1.d.ts b/ffi/diplomat/js/include/ICU4XTitlecaseOptionsV1.d.ts index afd8a95824b..949043ecace 100644 --- a/ffi/diplomat/js/include/ICU4XTitlecaseOptionsV1.d.ts +++ b/ffi/diplomat/js/include/ICU4XTitlecaseOptionsV1.d.ts @@ -1,13 +1,13 @@ -import { ICU4XHeadAdjustment } from "./ICU4XHeadAdjustment"; -import { ICU4XTailCasing } from "./ICU4XTailCasing"; +import { ICU4XLeadingAdjustment } from "./ICU4XLeadingAdjustment"; +import { ICU4XTrailingCase } from "./ICU4XTrailingCase"; /** * See the {@link https://docs.rs/icu/latest/icu/casemap/titlecase/struct.TitlecaseOptions.html Rust documentation for `TitlecaseOptions`} for more information. */ export class ICU4XTitlecaseOptionsV1 { - head_adjustment: ICU4XHeadAdjustment; - tail_casing: ICU4XTailCasing; + leading_adjustment: ICU4XLeadingAdjustment; + trailing_case: ICU4XTrailingCase; /** diff --git a/ffi/diplomat/js/include/ICU4XTitlecaseOptionsV1.js b/ffi/diplomat/js/include/ICU4XTitlecaseOptionsV1.js index 4fae1055638..e1325f6abc2 100644 --- a/ffi/diplomat/js/include/ICU4XTitlecaseOptionsV1.js +++ b/ffi/diplomat/js/include/ICU4XTitlecaseOptionsV1.js @@ -1,12 +1,12 @@ import wasm from "./diplomat-wasm.mjs" import * as diplomatRuntime from "./diplomat-runtime.js" -import { ICU4XHeadAdjustment_js_to_rust, ICU4XHeadAdjustment_rust_to_js } from "./ICU4XHeadAdjustment.js" -import { ICU4XTailCasing_js_to_rust, ICU4XTailCasing_rust_to_js } from "./ICU4XTailCasing.js" +import { ICU4XLeadingAdjustment_js_to_rust, ICU4XLeadingAdjustment_rust_to_js } from "./ICU4XLeadingAdjustment.js" +import { ICU4XTrailingCase_js_to_rust, ICU4XTrailingCase_rust_to_js } from "./ICU4XTrailingCase.js" export class ICU4XTitlecaseOptionsV1 { constructor(underlying) { - this.head_adjustment = ICU4XHeadAdjustment_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, underlying)]; - this.tail_casing = ICU4XTailCasing_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, underlying + 4)]; + this.leading_adjustment = ICU4XLeadingAdjustment_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, underlying)]; + this.trailing_case = ICU4XTrailingCase_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, underlying + 4)]; } static default_options() { diff --git a/ffi/diplomat/js/include/ICU4XTrailingCase.d.ts b/ffi/diplomat/js/include/ICU4XTrailingCase.d.ts new file mode 100644 index 00000000000..efd1abe7298 --- /dev/null +++ b/ffi/diplomat/js/include/ICU4XTrailingCase.d.ts @@ -0,0 +1,13 @@ + +/** + + * See the {@link https://docs.rs/icu/latest/icu/casemap/titlecase/enum.TrailingCase.html Rust documentation for `TrailingCase`} for more information. + */ +export enum ICU4XTrailingCase { + /** + */ + Lower = 'Lower', + /** + */ + Unchanged = 'Unchanged', +} \ No newline at end of file diff --git a/ffi/diplomat/js/include/ICU4XTrailingCase.js b/ffi/diplomat/js/include/ICU4XTrailingCase.js new file mode 100644 index 00000000000..66307178429 --- /dev/null +++ b/ffi/diplomat/js/include/ICU4XTrailingCase.js @@ -0,0 +1,17 @@ +import wasm from "./diplomat-wasm.mjs" +import * as diplomatRuntime from "./diplomat-runtime.js" + +export const ICU4XTrailingCase_js_to_rust = { + "Lower": 0, + "Unchanged": 1, +}; + +export const ICU4XTrailingCase_rust_to_js = { + [0]: "Lower", + [1]: "Unchanged", +}; + +export const ICU4XTrailingCase = { + "Lower": "Lower", + "Unchanged": "Unchanged", +}; diff --git a/ffi/diplomat/js/include/index.d.ts b/ffi/diplomat/js/include/index.d.ts index 958d691df25..a771d389f4e 100644 --- a/ffi/diplomat/js/include/index.d.ts +++ b/ffi/diplomat/js/include/index.d.ts @@ -53,7 +53,6 @@ export { ICU4XGraphemeClusterSegmenter } from './ICU4XGraphemeClusterSegmenter.j export { ICU4XGregorianDateFormatter } from './ICU4XGregorianDateFormatter.js'; export { ICU4XGregorianDateTimeFormatter } from './ICU4XGregorianDateTimeFormatter.js'; export { ICU4XGregorianZonedDateTimeFormatter } from './ICU4XGregorianZonedDateTimeFormatter.js'; -export { ICU4XHeadAdjustment } from './ICU4XHeadAdjustment.js'; export { ICU4XIsoDate } from './ICU4XIsoDate.js'; export { ICU4XIsoDateTime } from './ICU4XIsoDateTime.js'; export { ICU4XIsoTimeZoneFormat } from './ICU4XIsoTimeZoneFormat.js'; @@ -62,6 +61,7 @@ export { ICU4XIsoTimeZoneOptions } from './ICU4XIsoTimeZoneOptions.js'; export { ICU4XIsoTimeZoneSecondDisplay } from './ICU4XIsoTimeZoneSecondDisplay.js'; export { ICU4XIsoWeekday } from './ICU4XIsoWeekday.js'; export { ICU4XLanguageDisplay } from './ICU4XLanguageDisplay.js'; +export { ICU4XLeadingAdjustment } from './ICU4XLeadingAdjustment.js'; export { ICU4XLineBreakIteratorLatin1 } from './ICU4XLineBreakIteratorLatin1.js'; export { ICU4XLineBreakIteratorUtf16 } from './ICU4XLineBreakIteratorUtf16.js'; export { ICU4XLineBreakIteratorUtf8 } from './ICU4XLineBreakIteratorUtf8.js'; @@ -99,13 +99,13 @@ export { ICU4XSentenceBreakIteratorLatin1 } from './ICU4XSentenceBreakIteratorLa export { ICU4XSentenceBreakIteratorUtf16 } from './ICU4XSentenceBreakIteratorUtf16.js'; export { ICU4XSentenceBreakIteratorUtf8 } from './ICU4XSentenceBreakIteratorUtf8.js'; export { ICU4XSentenceSegmenter } from './ICU4XSentenceSegmenter.js'; -export { ICU4XTailCasing } from './ICU4XTailCasing.js'; export { ICU4XTime } from './ICU4XTime.js'; export { ICU4XTimeFormatter } from './ICU4XTimeFormatter.js'; export { ICU4XTimeLength } from './ICU4XTimeLength.js'; export { ICU4XTimeZoneFormatter } from './ICU4XTimeZoneFormatter.js'; export { ICU4XTitlecaseMapper } from './ICU4XTitlecaseMapper.js'; export { ICU4XTitlecaseOptionsV1 } from './ICU4XTitlecaseOptionsV1.js'; +export { ICU4XTrailingCase } from './ICU4XTrailingCase.js'; export { ICU4XTransformResult } from './ICU4XTransformResult.js'; export { ICU4XUnicodeSetData } from './ICU4XUnicodeSetData.js'; export { ICU4XWeekCalculator } from './ICU4XWeekCalculator.js'; diff --git a/ffi/diplomat/js/include/index.js b/ffi/diplomat/js/include/index.js index db2bcd9135b..ddab134f0ec 100644 --- a/ffi/diplomat/js/include/index.js +++ b/ffi/diplomat/js/include/index.js @@ -53,7 +53,6 @@ export { ICU4XGraphemeClusterSegmenter } from './ICU4XGraphemeClusterSegmenter.j export { ICU4XGregorianDateFormatter } from './ICU4XGregorianDateFormatter.js'; export { ICU4XGregorianDateTimeFormatter } from './ICU4XGregorianDateTimeFormatter.js'; export { ICU4XGregorianZonedDateTimeFormatter } from './ICU4XGregorianZonedDateTimeFormatter.js'; -export { ICU4XHeadAdjustment } from './ICU4XHeadAdjustment.js'; export { ICU4XIsoDate } from './ICU4XIsoDate.js'; export { ICU4XIsoDateTime } from './ICU4XIsoDateTime.js'; export { ICU4XIsoTimeZoneFormat } from './ICU4XIsoTimeZoneFormat.js'; @@ -62,6 +61,7 @@ export { ICU4XIsoTimeZoneOptions } from './ICU4XIsoTimeZoneOptions.js'; export { ICU4XIsoTimeZoneSecondDisplay } from './ICU4XIsoTimeZoneSecondDisplay.js'; export { ICU4XIsoWeekday } from './ICU4XIsoWeekday.js'; export { ICU4XLanguageDisplay } from './ICU4XLanguageDisplay.js'; +export { ICU4XLeadingAdjustment } from './ICU4XLeadingAdjustment.js'; export { ICU4XLineBreakIteratorLatin1 } from './ICU4XLineBreakIteratorLatin1.js'; export { ICU4XLineBreakIteratorUtf16 } from './ICU4XLineBreakIteratorUtf16.js'; export { ICU4XLineBreakIteratorUtf8 } from './ICU4XLineBreakIteratorUtf8.js'; @@ -99,13 +99,13 @@ export { ICU4XSentenceBreakIteratorLatin1 } from './ICU4XSentenceBreakIteratorLa export { ICU4XSentenceBreakIteratorUtf16 } from './ICU4XSentenceBreakIteratorUtf16.js'; export { ICU4XSentenceBreakIteratorUtf8 } from './ICU4XSentenceBreakIteratorUtf8.js'; export { ICU4XSentenceSegmenter } from './ICU4XSentenceSegmenter.js'; -export { ICU4XTailCasing } from './ICU4XTailCasing.js'; export { ICU4XTime } from './ICU4XTime.js'; export { ICU4XTimeFormatter } from './ICU4XTimeFormatter.js'; export { ICU4XTimeLength } from './ICU4XTimeLength.js'; export { ICU4XTimeZoneFormatter } from './ICU4XTimeZoneFormatter.js'; export { ICU4XTitlecaseMapper } from './ICU4XTitlecaseMapper.js'; export { ICU4XTitlecaseOptionsV1 } from './ICU4XTitlecaseOptionsV1.js'; +export { ICU4XTrailingCase } from './ICU4XTrailingCase.js'; export { ICU4XTransformResult } from './ICU4XTransformResult.js'; export { ICU4XUnicodeSetData } from './ICU4XUnicodeSetData.js'; export { ICU4XWeekCalculator } from './ICU4XWeekCalculator.js'; diff --git a/ffi/diplomat/src/casemap.rs b/ffi/diplomat/src/casemap.rs index 48919fb303d..cc20ccccec1 100644 --- a/ffi/diplomat/src/casemap.rs +++ b/ffi/diplomat/src/casemap.rs @@ -11,28 +11,29 @@ pub mod ffi { }; use alloc::boxed::Box; use diplomat_runtime::DiplomatWriteable; - use icu_casemap::titlecase::{HeadAdjustment, TailCasing}; + use icu_casemap::titlecase::{LeadingAdjustment, TrailingCase}; use icu_casemap::{CaseMapCloser, CaseMapper, TitlecaseMapper}; use writeable::Writeable; - #[diplomat::enum_convert(HeadAdjustment, needs_wildcard)] - #[diplomat::rust_link(icu::casemap::titlecase::HeadAdjustment, Enum)] - pub enum ICU4XHeadAdjustment { - Adjust, - NoAdjust, + #[diplomat::enum_convert(LeadingAdjustment, needs_wildcard)] + #[diplomat::rust_link(icu::casemap::titlecase::LeadingAdjustment, Enum)] + pub enum ICU4XLeadingAdjustment { + Auto, + None, + ToCased, } - #[diplomat::enum_convert(TailCasing, needs_wildcard)] - #[diplomat::rust_link(icu::casemap::titlecase::TailCasing, Enum)] - pub enum ICU4XTailCasing { - Lowercase, - PreserveCase, + #[diplomat::enum_convert(TrailingCase, needs_wildcard)] + #[diplomat::rust_link(icu::casemap::titlecase::TrailingCase, Enum)] + pub enum ICU4XTrailingCase { + Lower, + Unchanged, } #[diplomat::rust_link(icu::casemap::titlecase::TitlecaseOptions, Struct)] pub struct ICU4XTitlecaseOptionsV1 { - pub head_adjustment: ICU4XHeadAdjustment, - pub tail_casing: ICU4XTailCasing, + pub leading_adjustment: ICU4XLeadingAdjustment, + pub trailing_case: ICU4XTrailingCase, } impl ICU4XTitlecaseOptionsV1 { @@ -40,8 +41,8 @@ pub mod ffi { pub fn default_options() -> ICU4XTitlecaseOptionsV1 { // named default_options to avoid keyword clashes Self { - head_adjustment: ICU4XHeadAdjustment::Adjust, - tail_casing: ICU4XTailCasing::Lowercase, + leading_adjustment: ICU4XLeadingAdjustment::Auto, + trailing_case: ICU4XTrailingCase::Lower, } } } @@ -98,17 +99,21 @@ pub mod ffi { Ok(()) } - /// Returns the full titlecase mapping of the given string, using legacy head adjustment behavior + /// Returns the full titlecase mapping of the given string, performing head adjustment without + /// loading additional data. /// (if head adjustment is enabled in the options) /// /// The `v1` refers to the version of the options struct, which may change as we add more options - #[diplomat::rust_link(icu::casemap::CaseMapper::titlecase_segment_legacy, FnInStruct)] #[diplomat::rust_link( - icu::casemap::CaseMapper::titlecase_segment_legacy_to_string, + icu::casemap::CaseMapper::titlecase_segment_with_only_case_data, + FnInStruct + )] + #[diplomat::rust_link( + icu::casemap::CaseMapper::titlecase_segment_with_only_case_data_to_string, FnInStruct, hidden )] - pub fn titlecase_segment_legacy_v1( + pub fn titlecase_segment_with_only_case_data_v1( &self, s: &str, locale: &ICU4XLocale, @@ -120,7 +125,7 @@ pub mod ffi { core::str::from_utf8(s.as_bytes()) .map_err(|e| ICU4XError::DataIoError.log_original(&e))?; self.0 - .titlecase_segment_legacy(s, &locale.0.id, options.into()) + .titlecase_segment_with_only_case_data(s, &locale.0.id, options.into()) .write_to(write)?; Ok(()) @@ -290,25 +295,6 @@ pub mod ffi { provider, )?))) } - /// Construct a new `ICU4XTitlecaseMapper` instance with legacy head-adjustment behavior - /// - /// Behaves identically to using `titlecase_segment_legacy` on `CaseMapper` - #[diplomat::rust_link(icu::casemap::TitlecaseMapper::new_legacy, FnInStruct)] - #[diplomat::rust_link( - icu::casemap::TitlecaseMapper::new_legacy_with_mapper, - FnInStruct, - hidden - )] - pub fn create_legacy( - provider: &ICU4XDataProvider, - ) -> Result, ICU4XError> { - Ok(Box::new(ICU4XTitlecaseMapper(call_constructor!( - TitlecaseMapper::new [r => Ok(r)], - TitlecaseMapper::try_new_with_any_provider, - TitlecaseMapper::try_new_with_buffer_provider, - provider, - )?))) - } /// Returns the full titlecase mapping of the given string /// @@ -343,8 +329,8 @@ impl From for TitlecaseOptions { fn from(other: ffi::ICU4XTitlecaseOptionsV1) -> Self { let mut ret = Self::default(); - ret.head_adjustment = other.head_adjustment.into(); - ret.tail_casing = other.tail_casing.into(); + ret.leading_adjustment = other.leading_adjustment.into(); + ret.trailing_case = other.trailing_case.into(); ret } }