diff --git a/Cargo.lock b/Cargo.lock index 6e4be9d2b60..1218aa9762c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -796,7 +796,7 @@ dependencies = [ [[package]] name = "diplomat" version = "0.7.0" -source = "git+https://github.com/rust-diplomat/diplomat.git?rev=7e0482c03ad2406e49bcc77795622c632d4cfed6#7e0482c03ad2406e49bcc77795622c632d4cfed6" +source = "git+https://github.com/rust-diplomat/diplomat.git?rev=f545acf50629b6f2135adca374507b717a821cd8#f545acf50629b6f2135adca374507b717a821cd8" dependencies = [ "diplomat_core", "proc-macro2", @@ -814,7 +814,7 @@ dependencies = [ [[package]] name = "diplomat-runtime" version = "0.7.0" -source = "git+https://github.com/rust-diplomat/diplomat.git?rev=7e0482c03ad2406e49bcc77795622c632d4cfed6#7e0482c03ad2406e49bcc77795622c632d4cfed6" +source = "git+https://github.com/rust-diplomat/diplomat.git?rev=f545acf50629b6f2135adca374507b717a821cd8#f545acf50629b6f2135adca374507b717a821cd8" dependencies = [ "log", ] @@ -822,7 +822,7 @@ dependencies = [ [[package]] name = "diplomat-tool" version = "0.7.0" -source = "git+https://github.com/rust-diplomat/diplomat.git?rev=7e0482c03ad2406e49bcc77795622c632d4cfed6#7e0482c03ad2406e49bcc77795622c632d4cfed6" +source = "git+https://github.com/rust-diplomat/diplomat.git?rev=f545acf50629b6f2135adca374507b717a821cd8#f545acf50629b6f2135adca374507b717a821cd8" dependencies = [ "askama", "clap 3.2.25", @@ -842,7 +842,7 @@ dependencies = [ [[package]] name = "diplomat_core" version = "0.7.0" -source = "git+https://github.com/rust-diplomat/diplomat.git?rev=7e0482c03ad2406e49bcc77795622c632d4cfed6#7e0482c03ad2406e49bcc77795622c632d4cfed6" +source = "git+https://github.com/rust-diplomat/diplomat.git?rev=f545acf50629b6f2135adca374507b717a821cd8#f545acf50629b6f2135adca374507b717a821cd8" dependencies = [ "displaydoc", "lazy_static", diff --git a/Cargo.toml b/Cargo.toml index 58ba60f5d9b..a4470b7fe46 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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] diff --git a/components/collections/src/codepointinvlist/builder.rs b/components/collections/src/codepointinvlist/builder.rs index bd6ab9764cd..1c6e8d7abff 100644 --- a/components/collections/src/codepointinvlist/builder.rs +++ b/components/collections/src/codepointinvlist/builder.rs @@ -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`] @@ -241,6 +245,12 @@ impl CodePointInversionListBuilder { self.remove(start, end); } + /// See [`Self::remove_range`] + pub fn remove_range32(&mut self, range: &impl RangeBounds) { + let (start, end) = deconstruct_range(range); + self.remove(start, end); + } + /// Remove the [`CodePointInversionList`] from the [`CodePointInversionListBuilder`] /// /// # Examples @@ -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`] @@ -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) { + 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 @@ -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 @@ -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) { + 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. /// diff --git a/ffi/capi/dart/package/lib/src/CanonicalCombiningClassMap.g.dart b/ffi/capi/dart/package/lib/src/CanonicalCombiningClassMap.g.dart index e4c8879f979..0f9e3f6b71f 100644 --- a/ffi/capi/dart/package/lib/src/CanonicalCombiningClassMap.g.dart +++ b/ffi/capi/dart/package/lib/src/CanonicalCombiningClassMap.g.dart @@ -47,17 +47,4 @@ final class CanonicalCombiningClassMap implements ffi.Finalizable { static final _ICU4XCanonicalCombiningClassMap_get = _capi, ffi.Uint32)>>('ICU4XCanonicalCombiningClassMap_get') .asFunction, Rune)>(isLeaf: true); - - /// See the [Rust documentation for `get32`](https://docs.rs/icu/latest/icu/normalizer/properties/struct.CanonicalCombiningClassMap.html#method.get32) for more information. - /// - /// Additional information: [1](https://docs.rs/icu/latest/icu/properties/properties/struct.CanonicalCombiningClass.html) - int get32(int ch) { - final result = _ICU4XCanonicalCombiningClassMap_get32(_underlying, ch); - return result; - } - - // ignore: non_constant_identifier_names - static final _ICU4XCanonicalCombiningClassMap_get32 = - _capi, ffi.Uint32)>>('ICU4XCanonicalCombiningClassMap_get32') - .asFunction, int)>(isLeaf: true); } diff --git a/ffi/capi/dart/package/lib/src/CodePointMapData16.g.dart b/ffi/capi/dart/package/lib/src/CodePointMapData16.g.dart index e6f44255177..82e9315a4e1 100644 --- a/ffi/capi/dart/package/lib/src/CodePointMapData16.g.dart +++ b/ffi/capi/dart/package/lib/src/CodePointMapData16.g.dart @@ -36,17 +36,6 @@ final class CodePointMapData16 implements ffi.Finalizable { _capi, ffi.Uint32)>>('ICU4XCodePointMapData16_get') .asFunction, Rune)>(isLeaf: true); - /// Gets the value for a code point (specified as a 32 bit integer, in UTF-32) - int get32(int cp) { - final result = _ICU4XCodePointMapData16_get32(_underlying, cp); - return result; - } - - // ignore: non_constant_identifier_names - static final _ICU4XCodePointMapData16_get32 = - _capi, ffi.Uint32)>>('ICU4XCodePointMapData16_get32') - .asFunction, int)>(isLeaf: true); - /// Produces an iterator over ranges of code points that map to `value` /// /// See the [Rust documentation for `iter_ranges_for_value`](https://docs.rs/icu/latest/icu/properties/maps/struct.CodePointMapDataBorrowed.html#method.iter_ranges_for_value) for more information. diff --git a/ffi/capi/dart/package/lib/src/CodePointMapData8.g.dart b/ffi/capi/dart/package/lib/src/CodePointMapData8.g.dart index 7db9777e6e4..735487f3497 100644 --- a/ffi/capi/dart/package/lib/src/CodePointMapData8.g.dart +++ b/ffi/capi/dart/package/lib/src/CodePointMapData8.g.dart @@ -36,17 +36,6 @@ final class CodePointMapData8 implements ffi.Finalizable { _capi, ffi.Uint32)>>('ICU4XCodePointMapData8_get') .asFunction, Rune)>(isLeaf: true); - /// Gets the value for a code point (specified as a 32 bit integer, in UTF-32) - int get32(int cp) { - final result = _ICU4XCodePointMapData8_get32(_underlying, cp); - return result; - } - - // ignore: non_constant_identifier_names - static final _ICU4XCodePointMapData8_get32 = - _capi, ffi.Uint32)>>('ICU4XCodePointMapData8_get32') - .asFunction, int)>(isLeaf: true); - /// Converts a general category to its corresponding mask value /// /// Nonexistant general categories will map to the empty mask diff --git a/ffi/capi/src/bidi.rs b/ffi/capi/src/bidi.rs index cf4c8af98ba..5ef88476fd2 100644 --- a/ffi/capi/src/bidi.rs +++ b/ffi/capi/src/bidi.rs @@ -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; diff --git a/ffi/capi/src/casemap.rs b/ffi/capi/src/casemap.rs index cc20ccccec1..aa073a670d2 100644 --- a/ffi/capi/src/casemap.rs +++ b/ffi/capi/src/casemap.rs @@ -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; @@ -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. @@ -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. @@ -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. @@ -208,8 +213,10 @@ 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. @@ -217,16 +224,20 @@ pub mod ffi { /// 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) } } @@ -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 diff --git a/ffi/capi/src/collections_sets.rs b/ffi/capi/src/collections_sets.rs index 68ce1dfd1a2..9a003270e20 100644 --- a/ffi/capi/src/collections_sets.rs +++ b/ffi/capi/src/collections_sets.rs @@ -71,8 +71,8 @@ pub mod ffi { icu::collections::codepointinvlist::CodePointInversionListBuilder::add_char, FnInStruct )] - pub fn add_char(&mut self, ch: char) { - self.0.add_char(ch) + pub fn add_char(&mut self, ch: DiplomatChar) { + self.0.add_u32(ch) } /// Add a single u32 value to the set @@ -90,8 +90,8 @@ pub mod ffi { icu::collections::codepointinvlist::CodePointInversionListBuilder::add_range, FnInStruct )] - pub fn add_inclusive_range(&mut self, start: char, end: char) { - self.0.add_range(&(start..=end)) + pub fn add_inclusive_range(&mut self, start: DiplomatChar, end: DiplomatChar) { + self.0.add_range_u32(&(start..=end)) } /// Add an inclusive range of u32s to the set @@ -132,8 +132,13 @@ pub mod ffi { icu::collections::codepointinvlist::CodePointInversionListBuilder::remove_char, FnInStruct )] - pub fn remove_char(&mut self, ch: char) { - self.0.remove_char(ch) + #[diplomat::rust_link( + icu::collections::codepointinvlist::CodePointInversionListBuilder::remove32, + FnInStruct, + hidden + )] + pub fn remove_char(&mut self, ch: DiplomatChar) { + self.0.remove32(ch) } /// Remove an inclusive range of characters from the set @@ -141,8 +146,13 @@ pub mod ffi { icu::collections::codepointinvlist::CodePointInversionListBuilder::remove_range, FnInStruct )] - pub fn remove_inclusive_range(&mut self, start: char, end: char) { - self.0.remove_range(&(start..=end)) + #[diplomat::rust_link( + icu::collections::codepointinvlist::CodePointInversionListBuilder::remove_range32, + FnInStruct, + hidden + )] + pub fn remove_inclusive_range(&mut self, start: DiplomatChar, end: DiplomatChar) { + self.0.remove_range32(&(start..=end)) } /// Remove all elements that belong to the provided set from the set @@ -161,8 +171,13 @@ pub mod ffi { icu::collections::codepointinvlist::CodePointInversionListBuilder::retain_char, FnInStruct )] - pub fn retain_char(&mut self, ch: char) { - self.0.retain_char(ch) + #[diplomat::rust_link( + icu::collections::codepointinvlist::CodePointInversionListBuilder::retain32, + FnInStruct, + hidden + )] + pub fn retain_char(&mut self, ch: DiplomatChar) { + self.0.retain32(ch) } /// Removes all elements from the set except an inclusive range of characters f @@ -170,8 +185,13 @@ pub mod ffi { icu::collections::codepointinvlist::CodePointInversionListBuilder::retain_range, FnInStruct )] - pub fn retain_inclusive_range(&mut self, start: char, end: char) { - self.0.retain_range(&(start..=end)) + #[diplomat::rust_link( + icu::collections::codepointinvlist::CodePointInversionListBuilder::retain_range32, + FnInStruct, + hidden + )] + pub fn retain_inclusive_range(&mut self, start: DiplomatChar, end: DiplomatChar) { + self.0.retain_range32(&(start..=end)) } /// Removes all elements from the set except all elements in the provided set @@ -192,8 +212,13 @@ pub mod ffi { icu::collections::codepointinvlist::CodePointInversionListBuilder::complement_char, FnInStruct )] - pub fn complement_char(&mut self, ch: char) { - self.0.complement_char(ch) + #[diplomat::rust_link( + icu::collections::codepointinvlist::CodePointInversionListBuilder::complement32, + FnInStruct, + hidden + )] + pub fn complement_char(&mut self, ch: DiplomatChar) { + self.0.complement32(ch) } /// Complement an inclusive range of characters from the set @@ -203,8 +228,13 @@ pub mod ffi { icu::collections::codepointinvlist::CodePointInversionListBuilder::complement_range, FnInStruct )] - pub fn complement_inclusive_range(&mut self, start: char, end: char) { - self.0.complement_range(&(start..=end)) + #[diplomat::rust_link( + icu::collections::codepointinvlist::CodePointInversionListBuilder::complement_range32, + FnInStruct, + hidden + )] + pub fn complement_inclusive_range(&mut self, start: DiplomatChar, end: DiplomatChar) { + self.0.complement_range32(&(start..=end)) } /// Complement all elements that belong to the provided set from the set diff --git a/ffi/capi/src/data_struct.rs b/ffi/capi/src/data_struct.rs index d66e20b117b..15151089214 100644 --- a/ffi/capi/src/data_struct.rs +++ b/ffi/capi/src/data_struct.rs @@ -39,7 +39,7 @@ pub mod ffi { primary_group_size: u8, secondary_group_size: u8, min_group_size: u8, - digits: &[char], + digits: &[DiplomatChar], ) -> Result, ICU4XError> { use super::str_to_cow; use icu_decimal::provider::{ @@ -47,7 +47,9 @@ pub mod ffi { }; let digits = if digits.len() == 10 { let mut new_digits = ['\0'; 10]; - new_digits.copy_from_slice(digits); + for (old, new) in digits.iter().zip(new_digits.iter_mut()) { + *new = char::from_u32(*old).ok_or(ICU4XError::DataStructValidityError)?; + } new_digits } else { return Err(ICU4XError::DataStructValidityError); diff --git a/ffi/capi/src/displaynames.rs b/ffi/capi/src/displaynames.rs index eec14ed8393..f0744e994a4 100644 --- a/ffi/capi/src/displaynames.rs +++ b/ffi/capi/src/displaynames.rs @@ -8,7 +8,6 @@ pub mod ffi { use crate::locale::ffi::ICU4XLocale; use crate::provider::ffi::ICU4XDataProvider; use alloc::boxed::Box; - use diplomat_runtime::DiplomatWriteable; #[allow(unused_imports)] // feature-specific use icu_displaynames::{DisplayNamesOptions, Fallback, LanguageDisplay}; use icu_displaynames::{LocaleDisplayNamesFormatter, RegionDisplayNames}; diff --git a/ffi/capi/src/list.rs b/ffi/capi/src/list.rs index 278b12ffb5a..d2d15978372 100644 --- a/ffi/capi/src/list.rs +++ b/ffi/capi/src/list.rs @@ -10,7 +10,6 @@ pub mod ffi { use alloc::boxed::Box; use alloc::string::String; use alloc::vec::Vec; - use diplomat_runtime::DiplomatWriteable; use icu_list::{ListFormatter, ListLength}; use writeable::Writeable; diff --git a/ffi/capi/src/locale.rs b/ffi/capi/src/locale.rs index 07089cae65b..efb7366ec64 100644 --- a/ffi/capi/src/locale.rs +++ b/ffi/capi/src/locale.rs @@ -7,7 +7,6 @@ pub mod ffi { use crate::errors::ffi::ICU4XError; use alloc::boxed::Box; use core::str; - use diplomat_runtime::DiplomatWriteable; use icu_locid::extensions::unicode::Key; use icu_locid::subtags::{Language, Region, Script}; use icu_locid::Locale; diff --git a/ffi/capi/src/normalizer.rs b/ffi/capi/src/normalizer.rs index 13a1cf0292f..7b650e4a252 100644 --- a/ffi/capi/src/normalizer.rs +++ b/ffi/capi/src/normalizer.rs @@ -6,7 +6,6 @@ pub mod ffi { use crate::{errors::ffi::ICU4XError, provider::ffi::ICU4XDataProvider}; use alloc::boxed::Box; - use diplomat_runtime::DiplomatWriteable; use icu_normalizer::{ComposingNormalizer, DecomposingNormalizer}; #[diplomat::opaque] diff --git a/ffi/capi/src/normalizer_properties.rs b/ffi/capi/src/normalizer_properties.rs index dbb1dfbdbc1..33c80cb6f92 100644 --- a/ffi/capi/src/normalizer_properties.rs +++ b/ffi/capi/src/normalizer_properties.rs @@ -43,8 +43,8 @@ pub mod ffi { Struct, compact )] - pub fn get(&self, ch: char) -> u8 { - self.0.get(ch).0 + pub fn get(&self, ch: DiplomatChar) -> u8 { + self.0.get32(ch).0 } #[diplomat::rust_link( icu::normalizer::properties::CanonicalCombiningClassMap::get32, @@ -55,6 +55,7 @@ pub mod ffi { Struct, compact )] + #[diplomat::attr(dart, disable)] pub fn get32(&self, ch: u32) -> u8 { self.0.get32(ch).0 } @@ -87,8 +88,12 @@ pub mod ffi { icu::normalizer::properties::CanonicalComposition::compose, FnInStruct )] - pub fn compose(&self, starter: char, second: char) -> char { - self.0.compose(starter, second).unwrap_or('\0') + pub fn compose(&self, starter: DiplomatChar, second: DiplomatChar) -> DiplomatChar { + match (char::from_u32(starter), char::from_u32(second)) { + (Some(starter), Some(second)) => self.0.compose(starter, second), + _ => None, + } + .unwrap_or('\0') as DiplomatChar } } @@ -97,8 +102,8 @@ pub mod ffi { /// (which may or may not be the original one) #[diplomat::rust_link(icu::normalizer::properties::Decomposed, Enum)] pub struct ICU4XDecomposed { - first: char, - second: char, + first: DiplomatChar, + second: DiplomatChar, } /// The raw (non-recursive) canonical decomposition operation. @@ -127,17 +132,26 @@ pub mod ffi { icu::normalizer::properties::CanonicalDecomposition::decompose, FnInStruct )] - pub fn decompose(&self, c: char) -> ICU4XDecomposed { - match self.0.decompose(c) { - Decomposed::Default => ICU4XDecomposed { - first: c, - second: '\0', + pub fn decompose(&self, c: DiplomatChar) -> ICU4XDecomposed { + match char::from_u32(c) { + Some(c) => match self.0.decompose(c) { + Decomposed::Default => ICU4XDecomposed { + first: c as DiplomatChar, + second: '\0' as DiplomatChar, + }, + Decomposed::Singleton(s) => ICU4XDecomposed { + first: s as DiplomatChar, + second: '\0' as DiplomatChar, + }, + Decomposed::Expansion(first, second) => ICU4XDecomposed { + first: first as DiplomatChar, + second: second as DiplomatChar, + }, }, - Decomposed::Singleton(s) => ICU4XDecomposed { - first: s, - second: '\0', + _ => ICU4XDecomposed { + first: c, + second: '\0' as DiplomatChar, }, - Decomposed::Expansion(first, second) => ICU4XDecomposed { first, second }, } } } diff --git a/ffi/capi/src/properties_maps.rs b/ffi/capi/src/properties_maps.rs index 3d5cd6dfce7..c31a8edd27d 100644 --- a/ffi/capi/src/properties_maps.rs +++ b/ffi/capi/src/properties_maps.rs @@ -39,8 +39,8 @@ pub mod ffi { impl ICU4XCodePointMapData8 { /// Gets the value for a code point. #[diplomat::rust_link(icu::properties::maps::CodePointMapDataBorrowed::get, FnInStruct)] - pub fn get(&self, cp: char) -> u8 { - self.0.as_borrowed().get(cp) + pub fn get(&self, cp: DiplomatChar) -> u8 { + self.0.as_borrowed().get32(cp) } /// Gets the value for a code point (specified as a 32 bit integer, in UTF-32) @@ -49,8 +49,9 @@ pub mod ffi { FnInStruct, hidden )] + #[diplomat::attr(dart, disable)] pub fn get32(&self, cp: u32) -> u8 { - self.0.as_borrowed().get32(cp) + self.get(cp) } /// Converts a general category to its corresponding mask value @@ -239,8 +240,8 @@ pub mod ffi { impl ICU4XCodePointMapData16 { /// Gets the value for a code point. #[diplomat::rust_link(icu::properties::maps::CodePointMapDataBorrowed::get, FnInStruct)] - pub fn get(&self, cp: char) -> u16 { - self.0.as_borrowed().get(cp) + pub fn get(&self, cp: DiplomatChar) -> u16 { + self.0.as_borrowed().get32(cp) } /// Gets the value for a code point (specified as a 32 bit integer, in UTF-32) @@ -249,8 +250,9 @@ pub mod ffi { FnInStruct, hidden )] + #[diplomat::attr(dart, disable)] pub fn get32(&self, cp: u32) -> u16 { - self.0.as_borrowed().get32(cp) + self.get(cp) } /// Produces an iterator over ranges of code points that map to `value` diff --git a/ffi/capi/src/properties_sets.rs b/ffi/capi/src/properties_sets.rs index af14b9cbc87..f8e996060ce 100644 --- a/ffi/capi/src/properties_sets.rs +++ b/ffi/capi/src/properties_sets.rs @@ -26,8 +26,8 @@ pub mod ffi { icu::properties::sets::CodePointSetDataBorrowed::contains, FnInStruct )] - pub fn contains(&self, cp: char) -> bool { - self.0.as_borrowed().contains(cp) + pub fn contains(&self, cp: DiplomatChar) -> bool { + self.0.as_borrowed().contains32(cp) } /// Checks whether the code point (specified as a 32 bit integer, in UTF-32) is in the set. #[diplomat::rust_link( @@ -37,7 +37,7 @@ pub mod ffi { )] #[diplomat::attr(dart, disable)] pub fn contains32(&self, cp: u32) -> bool { - self.0.as_borrowed().contains32(cp) + self.contains(cp) } /// Produces an iterator over ranges of code points contained in this set diff --git a/ffi/capi/src/properties_unisets.rs b/ffi/capi/src/properties_unisets.rs index 7d2cf8cccc0..dcb41521fa3 100644 --- a/ffi/capi/src/properties_unisets.rs +++ b/ffi/capi/src/properties_unisets.rs @@ -37,8 +37,8 @@ pub mod ffi { icu::properties::sets::UnicodeSetDataBorrowed::contains_char, FnInStruct )] - pub fn contains_char(&self, cp: char) -> bool { - self.0.as_borrowed().contains_char(cp) + pub fn contains_char(&self, cp: DiplomatChar) -> bool { + self.0.as_borrowed().contains32(cp) } /// Checks whether the code point (specified as a 32 bit integer, in UTF-32) is in the set. #[diplomat::rust_link( @@ -48,7 +48,7 @@ pub mod ffi { )] #[diplomat::attr(dart, disable)] pub fn contains32(&self, cp: u32) -> bool { - self.0.as_borrowed().contains32(cp) + self.contains_char(cp) } #[diplomat::rust_link(icu::properties::sets::basic_emoji, Fn)] diff --git a/ffi/gn/.cargo/config b/ffi/gn/.cargo/config index 2b4dfa27fd0..8095c61799c 100644 --- a/ffi/gn/.cargo/config +++ b/ffi/gn/.cargo/config @@ -6,9 +6,9 @@ [source.crates-io] replace-with = "vendored-sources" -[source."git+https://github.com/rust-diplomat/diplomat.git?rev=7e0482c03ad2406e49bcc77795622c632d4cfed6"] +[source."git+https://github.com/rust-diplomat/diplomat.git?rev=f545acf50629b6f2135adca374507b717a821cd8"] git = "https://github.com/rust-diplomat/diplomat.git" -rev = "7e0482c03ad2406e49bcc77795622c632d4cfed6" +rev = "f545acf50629b6f2135adca374507b717a821cd8" replace-with = "vendored-sources" [source.vendored-sources] diff --git a/ffi/gn/Cargo.lock b/ffi/gn/Cargo.lock index 753db1ef307..172995b92d6 100644 --- a/ffi/gn/Cargo.lock +++ b/ffi/gn/Cargo.lock @@ -120,7 +120,7 @@ checksum = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198" [[package]] name = "diplomat" version = "0.7.0" -source = "git+https://github.com/rust-diplomat/diplomat.git?rev=7e0482c03ad2406e49bcc77795622c632d4cfed6#7e0482c03ad2406e49bcc77795622c632d4cfed6" +source = "git+https://github.com/rust-diplomat/diplomat.git?rev=f545acf50629b6f2135adca374507b717a821cd8#f545acf50629b6f2135adca374507b717a821cd8" dependencies = [ "diplomat_core", "proc-macro2", @@ -131,12 +131,12 @@ dependencies = [ [[package]] name = "diplomat-runtime" version = "0.7.0" -source = "git+https://github.com/rust-diplomat/diplomat.git?rev=7e0482c03ad2406e49bcc77795622c632d4cfed6#7e0482c03ad2406e49bcc77795622c632d4cfed6" +source = "git+https://github.com/rust-diplomat/diplomat.git?rev=f545acf50629b6f2135adca374507b717a821cd8#f545acf50629b6f2135adca374507b717a821cd8" [[package]] name = "diplomat_core" version = "0.7.0" -source = "git+https://github.com/rust-diplomat/diplomat.git?rev=7e0482c03ad2406e49bcc77795622c632d4cfed6#7e0482c03ad2406e49bcc77795622c632d4cfed6" +source = "git+https://github.com/rust-diplomat/diplomat.git?rev=f545acf50629b6f2135adca374507b717a821cd8#f545acf50629b6f2135adca374507b717a821cd8" dependencies = [ "lazy_static", "proc-macro2",