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

Bump Diplomat and use DiplomatChar #4349

Merged
merged 7 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.lock

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

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,10 @@ icu_benchmark_macros = { path = "tools/benchmark/macros" }

# The version here can either be a `version = ".."` spec or `git = "https://github.com/rust-diplomat/diplomat", rev = ".."`
# Diplomat must be published preceding a new ICU4X release but may use git versions in between
diplomat = { git = "https://github.com/rust-diplomat/diplomat.git", rev = "7e0482c03ad2406e49bcc77795622c632d4cfed6" }
diplomat-runtime = { git = "https://github.com/rust-diplomat/diplomat.git", rev = "7e0482c03ad2406e49bcc77795622c632d4cfed6" }
diplomat_core = { git = "https://github.com/rust-diplomat/diplomat.git", rev = "7e0482c03ad2406e49bcc77795622c632d4cfed6" }
diplomat-tool = { git = "https://github.com/rust-diplomat/diplomat.git", rev = "7e0482c03ad2406e49bcc77795622c632d4cfed6" }
diplomat = { git = "https://github.com/rust-diplomat/diplomat.git", rev = "f545acf50629b6f2135adca374507b717a821cd8" }
diplomat-runtime = { git = "https://github.com/rust-diplomat/diplomat.git", rev = "f545acf50629b6f2135adca374507b717a821cd8" }
diplomat_core = { git = "https://github.com/rust-diplomat/diplomat.git", rev = "f545acf50629b6f2135adca374507b717a821cd8" }
diplomat-tool = { git = "https://github.com/rust-diplomat/diplomat.git", rev = "f545acf50629b6f2135adca374507b717a821cd8" }

# Size optimized builds
[profile.release-opt-size]
Expand Down
47 changes: 39 additions & 8 deletions components/collections/src/codepointinvlist/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,12 @@ impl CodePointInversionListBuilder {
/// let check = builder.build();
/// assert_eq!(check.iter_chars().next(), Some('B'));
pub fn remove_char(&mut self, c: char) {
let to_remove = c as u32;
self.remove(to_remove, to_remove + 1);
self.remove32(c as u32)
}

/// See [`Self::remove_char`]
pub fn remove32(&mut self, c: u32) {
self.remove(c, c + 1);
}

/// Remove the range of characters from the [`CodePointInversionListBuilder`]
Expand All @@ -241,6 +245,12 @@ impl CodePointInversionListBuilder {
self.remove(start, end);
}

/// See [`Self::remove_range`]
pub fn remove_range32(&mut self, range: &impl RangeBounds<u32>) {
let (start, end) = deconstruct_range(range);
self.remove(start, end);
}

/// Remove the [`CodePointInversionList`] from the [`CodePointInversionListBuilder`]
///
/// # Examples
Expand Down Expand Up @@ -281,9 +291,13 @@ impl CodePointInversionListBuilder {
/// assert_eq!(check.next(), None);
/// ```
pub fn retain_char(&mut self, c: char) {
let code_point = c as u32;
self.remove(0, code_point);
self.remove(code_point + 1, (char::MAX as u32) + 1);
self.retain32(c as u32)
}

/// See [`Self::retain_char`]
pub fn retain32(&mut self, c: u32) {
self.remove(0, c);
self.remove(c + 1, (char::MAX as u32) + 1);
}

/// Retain the range of characters located within the [`CodePointInversionListBuilder`]
Expand All @@ -307,6 +321,13 @@ impl CodePointInversionListBuilder {
self.remove(end, (char::MAX as u32) + 1);
}

/// See [`Self::retain_range`]
pub fn retain_range32(&mut self, range: &impl RangeBounds<u32>) {
let (start, end) = deconstruct_range(range);
self.remove(0, start);
self.remove(end, (char::MAX as u32) + 1);
}

/// Retain the elements in the specified set within the [`CodePointInversionListBuilder`]
///
/// # Examples
Expand Down Expand Up @@ -430,9 +451,12 @@ impl CodePointInversionListBuilder {
/// assert!(!check.contains('A'));
/// ```
pub fn complement_char(&mut self, c: char) {
let code_point = c as u32;
let to_complement = [code_point, code_point + 1];
self.complement_list(to_complement.iter().copied());
self.complement32(c as u32);
}

/// See [`Self::complement_char`]
pub fn complement32(&mut self, c: u32) {
self.complement_list([c, c + 1].into_iter());
}

/// Complements the range in the builder, adding any elements in the range if not in the builder, and
Expand All @@ -455,6 +479,13 @@ impl CodePointInversionListBuilder {
self.complement_list(to_complement.iter().copied());
}

/// See [`Self::complement_range`]
pub fn complement_range32(&mut self, range: &impl RangeBounds<u32>) {
let (start, end) = deconstruct_range(range);
let to_complement = [start, end];
self.complement_list(to_complement.iter().copied());
}

/// Complements the set in the builder, adding any elements in the set if not in the builder, and
/// removing them otherwise.
///
Expand Down
13 changes: 0 additions & 13 deletions ffi/capi/dart/package/lib/src/CanonicalCombiningClassMap.g.dart

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

11 changes: 0 additions & 11 deletions ffi/capi/dart/package/lib/src/CodePointMapData16.g.dart

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

11 changes: 0 additions & 11 deletions ffi/capi/dart/package/lib/src/CodePointMapData8.g.dart

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

1 change: 0 additions & 1 deletion ffi/capi/src/bidi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
pub mod ffi {
use alloc::boxed::Box;
use alloc::vec::Vec;
use diplomat_runtime::DiplomatWriteable;

use core::fmt::Write;
use icu_properties::bidi::BidiClassAdapter;
Expand Down
43 changes: 28 additions & 15 deletions ffi/capi/src/casemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ pub mod ffi {
errors::ffi::ICU4XError, locale::ffi::ICU4XLocale, provider::ffi::ICU4XDataProvider,
};
use alloc::boxed::Box;
use diplomat_runtime::DiplomatWriteable;
use icu_casemap::titlecase::{LeadingAdjustment, TrailingCase};
use icu_casemap::{CaseMapCloser, CaseMapper, TitlecaseMapper};
use writeable::Writeable;
Expand Down Expand Up @@ -176,10 +175,12 @@ pub mod ffi {
#[diplomat::rust_link(icu::casemap::CaseMapper::add_case_closure_to, FnInStruct)]
pub fn add_case_closure_to(
&self,
c: char,
c: DiplomatChar,
builder: &mut crate::collections_sets::ffi::ICU4XCodePointSetBuilder,
) {
self.0.add_case_closure_to(c, &mut builder.0)
if let Some(ch) = char::from_u32(c) {
self.0.add_case_closure_to(ch, &mut builder.0)
}
}

/// Returns the simple lowercase mapping of the given character.
Expand All @@ -188,8 +189,10 @@ pub mod ffi {
/// Full mappings, which can map one char to a string, are not included.
/// For full mappings, use `ICU4XCaseMapper::lowercase`.
#[diplomat::rust_link(icu::casemap::CaseMapper::simple_lowercase, FnInStruct)]
pub fn simple_lowercase(&self, ch: char) -> char {
self.0.simple_lowercase(ch)
pub fn simple_lowercase(&self, ch: DiplomatChar) -> DiplomatChar {
char::from_u32(ch)
.map(|ch| self.0.simple_lowercase(ch) as DiplomatChar)
.unwrap_or(ch)
}

/// Returns the simple uppercase mapping of the given character.
Expand All @@ -198,8 +201,10 @@ pub mod ffi {
/// Full mappings, which can map one char to a string, are not included.
/// For full mappings, use `ICU4XCaseMapper::uppercase`.
#[diplomat::rust_link(icu::casemap::CaseMapper::simple_uppercase, FnInStruct)]
pub fn simple_uppercase(&self, ch: char) -> char {
self.0.simple_uppercase(ch)
pub fn simple_uppercase(&self, ch: DiplomatChar) -> DiplomatChar {
char::from_u32(ch)
.map(|ch| self.0.simple_uppercase(ch) as DiplomatChar)
.unwrap_or(ch)
}

/// Returns the simple titlecase mapping of the given character.
Expand All @@ -208,25 +213,31 @@ pub mod ffi {
/// Full mappings, which can map one char to a string, are not included.
/// For full mappings, use `ICU4XCaseMapper::titlecase_segment`.
#[diplomat::rust_link(icu::casemap::CaseMapper::simple_titlecase, FnInStruct)]
pub fn simple_titlecase(&self, ch: char) -> char {
self.0.simple_titlecase(ch)
pub fn simple_titlecase(&self, ch: DiplomatChar) -> DiplomatChar {
char::from_u32(ch)
.map(|ch| self.0.simple_titlecase(ch) as DiplomatChar)
.unwrap_or(ch)
}

/// Returns the simple casefolding of the given character.
///
/// This function only implements simple folding.
/// For full folding, use `ICU4XCaseMapper::fold`.
#[diplomat::rust_link(icu::casemap::CaseMapper::simple_fold, FnInStruct)]
pub fn simple_fold(&self, ch: char) -> char {
self.0.simple_fold(ch)
pub fn simple_fold(&self, ch: DiplomatChar) -> DiplomatChar {
char::from_u32(ch)
.map(|ch| self.0.simple_fold(ch) as DiplomatChar)
.unwrap_or(ch)
}
/// Returns the simple casefolding of the given character in the Turkic locale
///
/// This function only implements simple folding.
/// For full folding, use `ICU4XCaseMapper::fold_turkic`.
#[diplomat::rust_link(icu::casemap::CaseMapper::simple_fold_turkic, FnInStruct)]
pub fn simple_fold_turkic(&self, ch: char) -> char {
self.0.simple_fold_turkic(ch)
pub fn simple_fold_turkic(&self, ch: DiplomatChar) -> DiplomatChar {
char::from_u32(ch)
.map(|ch| self.0.simple_fold_turkic(ch) as DiplomatChar)
.unwrap_or(ch)
}
}

Expand All @@ -253,10 +264,12 @@ pub mod ffi {
#[diplomat::rust_link(icu::casemap::CaseMapCloser::add_case_closure_to, FnInStruct)]
pub fn add_case_closure_to(
&self,
c: char,
c: DiplomatChar,
builder: &mut crate::collections_sets::ffi::ICU4XCodePointSetBuilder,
) {
self.0.add_case_closure_to(c, &mut builder.0)
if let Some(ch) = char::from_u32(c) {
self.0.add_case_closure_to(ch, &mut builder.0)
}
}

/// Finds all characters and strings which may casemap to `s` as their full case folding string
Expand Down
Loading