Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Titlecasing renames #3843

Merged
merged 13 commits into from
Aug 11, 2023
2 changes: 1 addition & 1 deletion components/casemap/benches/casemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
111 changes: 62 additions & 49 deletions components/casemap/src/casemapper.rs

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions components/casemap/src/internals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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> {
Expand All @@ -68,15 +68,15 @@ impl<'a, const IS_TITLE_CONTEXT: bool> Writeable for FullCaseWriteable<'a, IS_TI
self.data
.full_helper::<IS_TITLE_CONTEXT, W>(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;
}
}
}
// 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(())
Expand Down Expand Up @@ -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)));
Expand Down
233 changes: 110 additions & 123 deletions components/casemap/src/titlecase.rs

Large diffs are not rendered by default.

62 changes: 31 additions & 31 deletions components/casemap/tests/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
"Երևանի"
);
}
Expand All @@ -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}"
);
}
Expand Down
2 changes: 1 addition & 1 deletion ffi/diplomat/c/include/ICU4XCaseMapper.h

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

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

2 changes: 0 additions & 2 deletions ffi/diplomat/c/include/ICU4XTitlecaseMapper.h

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

12 changes: 6 additions & 6 deletions ffi/diplomat/c/include/ICU4XTitlecaseOptionsV1.h

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

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

Loading
Loading