diff --git a/Cargo.lock b/Cargo.lock index cb9da02ae3d..7cae65a2569 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=f545acf50629b6f2135adca374507b717a821cd8#f545acf50629b6f2135adca374507b717a821cd8" +source = "git+https://github.com/rust-diplomat/diplomat.git?rev=04efb3cb53f853fd6fd560eb248940c59472f425#04efb3cb53f853fd6fd560eb248940c59472f425" 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=f545acf50629b6f2135adca374507b717a821cd8#f545acf50629b6f2135adca374507b717a821cd8" +source = "git+https://github.com/rust-diplomat/diplomat.git?rev=04efb3cb53f853fd6fd560eb248940c59472f425#04efb3cb53f853fd6fd560eb248940c59472f425" 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=f545acf50629b6f2135adca374507b717a821cd8#f545acf50629b6f2135adca374507b717a821cd8" +source = "git+https://github.com/rust-diplomat/diplomat.git?rev=04efb3cb53f853fd6fd560eb248940c59472f425#04efb3cb53f853fd6fd560eb248940c59472f425" 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=f545acf50629b6f2135adca374507b717a821cd8#f545acf50629b6f2135adca374507b717a821cd8" +source = "git+https://github.com/rust-diplomat/diplomat.git?rev=04efb3cb53f853fd6fd560eb248940c59472f425#04efb3cb53f853fd6fd560eb248940c59472f425" dependencies = [ "displaydoc", "lazy_static", diff --git a/Cargo.toml b/Cargo.toml index b435836f986..92a78fb2a4e 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 = "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" } +diplomat = { git = "https://github.com/rust-diplomat/diplomat.git", rev = "04efb3cb53f853fd6fd560eb248940c59472f425" } +diplomat-runtime = { git = "https://github.com/rust-diplomat/diplomat.git", rev = "04efb3cb53f853fd6fd560eb248940c59472f425" } +diplomat_core = { git = "https://github.com/rust-diplomat/diplomat.git", rev = "04efb3cb53f853fd6fd560eb248940c59472f425" } +diplomat-tool = { git = "https://github.com/rust-diplomat/diplomat.git", rev = "04efb3cb53f853fd6fd560eb248940c59472f425" } # Size optimized builds [profile.release-opt-size] diff --git a/components/timezone/src/iana_ids.rs b/components/timezone/src/iana_ids.rs index b53ceca2663..616e486b9dc 100644 --- a/components/timezone/src/iana_ids.rs +++ b/components/timezone/src/iana_ids.rs @@ -105,10 +105,15 @@ impl<'a> IanaToBcp47MapperBorrowed<'a> { /// /// [ECMAScript Temporal]: https://tc39.es/proposal-temporal/#sec-isavailabletimezonename pub fn get(&self, iana_id: &str) -> Option { + self.get_bytes(iana_id.as_bytes()) + } + + #[doc(hidden)] + pub fn get_bytes(&self, iana_id: &[u8]) -> Option { // The longest IANA name in CLDR appears to be "America/Argentina/ComodRivadavia" // which is 32 characters long, so 48 should be plenty. Add a debug assertion // just in case. - let name_for_lookup = match tinystr::TinyAsciiStr::<48>::from_str(iana_id) { + let name_for_lookup = match tinystr::TinyAsciiStr::<48>::from_bytes(iana_id) { Ok(tinystr) => tinystr.to_ascii_lowercase(), Err(tinystr::TinyStrError::TooLarge { .. }) => { debug_assert!(false, "IANA string too long for lookup"); diff --git a/ffi/capi/dart/package/lib/src/AnyCalendarKind.g.dart b/ffi/capi/dart/package/lib/src/AnyCalendarKind.g.dart index 6473b08e4a7..3380c698417 100644 --- a/ffi/capi/dart/package/lib/src/AnyCalendarKind.g.dart +++ b/ffi/capi/dart/package/lib/src/AnyCalendarKind.g.dart @@ -92,10 +92,10 @@ enum AnyCalendarKind { /// /// Throws [VoidError] on failure. factory AnyCalendarKind.forBcp47(String s) { - final alloc = ffi2.Arena(); - final sSlice = _SliceFfi2Utf8._fromDart(s, alloc); - final result = _ICU4XAnyCalendarKind_get_for_bcp47(sSlice._bytes, sSlice._length); - alloc.releaseAll(); + final temp = ffi2.Arena(); + final sLength = s.utf8Length; + final result = _ICU4XAnyCalendarKind_get_for_bcp47(Utf8Encoder().allocConvert(temp, s, length: sLength), sLength); + temp.releaseAll(); if (!result.isOk) { throw VoidError(); } @@ -104,8 +104,8 @@ enum AnyCalendarKind { // ignore: non_constant_identifier_names static final _ICU4XAnyCalendarKind_get_for_bcp47 = - _capi, ffi.Size)>>('ICU4XAnyCalendarKind_get_for_bcp47') - .asFunction<_ResultInt32Void Function(ffi.Pointer, int)>(isLeaf: true); + _capi, ffi.Size)>>('ICU4XAnyCalendarKind_get_for_bcp47') + .asFunction<_ResultInt32Void Function(ffi.Pointer, int)>(isLeaf: true); /// Obtain the string suitable for use in the -u-ca- extension in a BCP47 locale. /// diff --git a/ffi/capi/dart/package/lib/src/Bcp47ToIanaMapper.g.dart b/ffi/capi/dart/package/lib/src/Bcp47ToIanaMapper.g.dart index 7067cb49e2a..887eaad1bd0 100644 --- a/ffi/capi/dart/package/lib/src/Bcp47ToIanaMapper.g.dart +++ b/ffi/capi/dart/package/lib/src/Bcp47ToIanaMapper.g.dart @@ -39,11 +39,11 @@ final class Bcp47ToIanaMapper implements ffi.Finalizable { /// /// Throws [Error] on failure. String operator [](String value) { - final alloc = ffi2.Arena(); - final valueSlice = _SliceFfi2Utf8._fromDart(value, alloc); + final temp = ffi2.Arena(); + final valueLength = value.utf8Length; final writeable = _Writeable(); - final result = _ICU4XBcp47ToIanaMapper_get(_underlying, valueSlice._bytes, valueSlice._length, writeable._underlying); - alloc.releaseAll(); + final result = _ICU4XBcp47ToIanaMapper_get(_underlying, Utf8Encoder().allocConvert(temp, value, length: valueLength), valueLength, writeable._underlying); + temp.releaseAll(); if (!result.isOk) { throw Error.values.firstWhere((v) => v._underlying == result.union.err); } @@ -52,6 +52,6 @@ final class Bcp47ToIanaMapper implements ffi.Finalizable { // ignore: non_constant_identifier_names static final _ICU4XBcp47ToIanaMapper_get = - _capi, ffi.Pointer, ffi.Size, ffi.Pointer)>>('ICU4XBcp47ToIanaMapper_get') - .asFunction<_ResultVoidInt32 Function(ffi.Pointer, ffi.Pointer, int, ffi.Pointer)>(isLeaf: true); + _capi, ffi.Pointer, ffi.Size, ffi.Pointer)>>('ICU4XBcp47ToIanaMapper_get') + .asFunction<_ResultVoidInt32 Function(ffi.Pointer, ffi.Pointer, int, ffi.Pointer)>(isLeaf: true); } diff --git a/ffi/capi/dart/package/lib/src/Bidi.g.dart b/ffi/capi/dart/package/lib/src/Bidi.g.dart index aa94ebe0d06..1d87c7ad772 100644 --- a/ffi/capi/dart/package/lib/src/Bidi.g.dart +++ b/ffi/capi/dart/package/lib/src/Bidi.g.dart @@ -41,17 +41,17 @@ final class Bidi implements ffi.Finalizable { /// /// See the [Rust documentation for `new_with_data_source`](https://docs.rs/unicode_bidi/latest/unicode_bidi/struct.BidiInfo.html#method.new_with_data_source) for more information. BidiInfo forText(String text, int defaultLevel) { - final alloc = ffi2.Arena(); - final textSlice = _SliceFfi2Utf8._fromDart(text, alloc); - final result = _ICU4XBidi_for_text(_underlying, textSlice._bytes, textSlice._length, defaultLevel); - alloc.releaseAll(); + final temp = ffi2.Arena(); + final textLength = text.utf8Length; + final result = _ICU4XBidi_for_text(_underlying, Utf8Encoder().allocConvert(temp, text, length: textLength), textLength, defaultLevel); + temp.releaseAll(); return BidiInfo._(result); } // ignore: non_constant_identifier_names static final _ICU4XBidi_for_text = - _capi Function(ffi.Pointer, ffi.Pointer, ffi.Size, ffi.Uint8)>>('ICU4XBidi_for_text') - .asFunction Function(ffi.Pointer, ffi.Pointer, int, int)>(isLeaf: true); + _capi Function(ffi.Pointer, ffi.Pointer, ffi.Size, ffi.Uint8)>>('ICU4XBidi_for_text') + .asFunction Function(ffi.Pointer, ffi.Pointer, int, int)>(isLeaf: true); /// Utility function for producing reorderings given a list of levels /// @@ -64,10 +64,9 @@ final class Bidi implements ffi.Finalizable { /// /// See the [Rust documentation for `reorder_visual`](https://docs.rs/unicode_bidi/latest/unicode_bidi/struct.BidiInfo.html#method.reorder_visual) for more information. ReorderedIndexMap reorderVisual(Uint8List levels) { - final alloc = ffi2.Arena(); - final levelsSlice = _SliceFfiUint8._fromDart(levels, alloc); - final result = _ICU4XBidi_reorder_visual(_underlying, levelsSlice._bytes, levelsSlice._length); - alloc.releaseAll(); + final temp = ffi2.Arena(); + final result = _ICU4XBidi_reorder_visual(_underlying, levels.copy(temp), levels.length); + temp.releaseAll(); return ReorderedIndexMap._(result); } @@ -109,10 +108,26 @@ final class Bidi implements ffi.Finalizable { /// Get a basic RTL Level value /// /// See the [Rust documentation for `rtl`](https://docs.rs/unicode_bidi/latest/unicode_bidi/struct.Level.html#method.rtl) for more information. - static final int levelRtl = _capi>('ICU4XBidi_level_rtl').asFunction(isLeaf: true)(); + static final int levelRtl = () { + final result = _ICU4XBidi_level_rtl(); + return result; + }(); + + // ignore: non_constant_identifier_names + static final _ICU4XBidi_level_rtl = + _capi>('ICU4XBidi_level_rtl') + .asFunction(isLeaf: true); /// Get a simple LTR Level value /// /// See the [Rust documentation for `ltr`](https://docs.rs/unicode_bidi/latest/unicode_bidi/struct.Level.html#method.ltr) for more information. - static final int levelLtr = _capi>('ICU4XBidi_level_ltr').asFunction(isLeaf: true)(); + static final int levelLtr = () { + final result = _ICU4XBidi_level_ltr(); + return result; + }(); + + // ignore: non_constant_identifier_names + static final _ICU4XBidi_level_ltr = + _capi>('ICU4XBidi_level_ltr') + .asFunction(isLeaf: true); } diff --git a/ffi/capi/dart/package/lib/src/CaseMapCloser.g.dart b/ffi/capi/dart/package/lib/src/CaseMapCloser.g.dart index 63680be5c72..47fe7e7c3a5 100644 --- a/ffi/capi/dart/package/lib/src/CaseMapCloser.g.dart +++ b/ffi/capi/dart/package/lib/src/CaseMapCloser.g.dart @@ -53,15 +53,15 @@ final class CaseMapCloser implements ffi.Finalizable { /// /// See the [Rust documentation for `add_string_case_closure_to`](https://docs.rs/icu/latest/icu/casemap/struct.CaseMapCloser.html#method.add_string_case_closure_to) for more information. bool addStringCaseClosureTo(String s, CodePointSetBuilder builder) { - final alloc = ffi2.Arena(); - final sSlice = _SliceFfi2Utf8._fromDart(s, alloc); - final result = _ICU4XCaseMapCloser_add_string_case_closure_to(_underlying, sSlice._bytes, sSlice._length, builder._underlying); - alloc.releaseAll(); + final temp = ffi2.Arena(); + final sLength = s.utf8Length; + final result = _ICU4XCaseMapCloser_add_string_case_closure_to(_underlying, Utf8Encoder().allocConvert(temp, s, length: sLength), sLength, builder._underlying); + temp.releaseAll(); return result; } // ignore: non_constant_identifier_names static final _ICU4XCaseMapCloser_add_string_case_closure_to = - _capi, ffi.Pointer, ffi.Size, ffi.Pointer)>>('ICU4XCaseMapCloser_add_string_case_closure_to') - .asFunction, ffi.Pointer, int, ffi.Pointer)>(isLeaf: true); + _capi, ffi.Pointer, ffi.Size, ffi.Pointer)>>('ICU4XCaseMapCloser_add_string_case_closure_to') + .asFunction, ffi.Pointer, int, ffi.Pointer)>(isLeaf: true); } diff --git a/ffi/capi/dart/package/lib/src/CaseMapper.g.dart b/ffi/capi/dart/package/lib/src/CaseMapper.g.dart index aa86d9e4e9e..c18e4f8bcc3 100644 --- a/ffi/capi/dart/package/lib/src/CaseMapper.g.dart +++ b/ffi/capi/dart/package/lib/src/CaseMapper.g.dart @@ -39,11 +39,11 @@ final class CaseMapper implements ffi.Finalizable { /// /// Throws [Error] on failure. String lowercase(String s, Locale locale) { - final alloc = ffi2.Arena(); - final sSlice = _SliceFfi2Utf8._fromDart(s, alloc); + final temp = ffi2.Arena(); + final sLength = s.utf8Length; final writeable = _Writeable(); - final result = _ICU4XCaseMapper_lowercase(_underlying, sSlice._bytes, sSlice._length, locale._underlying, writeable._underlying); - alloc.releaseAll(); + final result = _ICU4XCaseMapper_lowercase(_underlying, Utf8Encoder().allocConvert(temp, s, length: sLength), sLength, locale._underlying, writeable._underlying); + temp.releaseAll(); if (!result.isOk) { throw Error.values.firstWhere((v) => v._underlying == result.union.err); } @@ -52,8 +52,8 @@ final class CaseMapper implements ffi.Finalizable { // ignore: non_constant_identifier_names static final _ICU4XCaseMapper_lowercase = - _capi, ffi.Pointer, ffi.Size, ffi.Pointer, ffi.Pointer)>>('ICU4XCaseMapper_lowercase') - .asFunction<_ResultVoidInt32 Function(ffi.Pointer, ffi.Pointer, int, ffi.Pointer, ffi.Pointer)>(isLeaf: true); + _capi, ffi.Pointer, ffi.Size, ffi.Pointer, ffi.Pointer)>>('ICU4XCaseMapper_lowercase') + .asFunction<_ResultVoidInt32 Function(ffi.Pointer, ffi.Pointer, int, ffi.Pointer, ffi.Pointer)>(isLeaf: true); /// Returns the full uppercase mapping of the given string /// @@ -61,11 +61,11 @@ final class CaseMapper implements ffi.Finalizable { /// /// Throws [Error] on failure. String uppercase(String s, Locale locale) { - final alloc = ffi2.Arena(); - final sSlice = _SliceFfi2Utf8._fromDart(s, alloc); + final temp = ffi2.Arena(); + final sLength = s.utf8Length; final writeable = _Writeable(); - final result = _ICU4XCaseMapper_uppercase(_underlying, sSlice._bytes, sSlice._length, locale._underlying, writeable._underlying); - alloc.releaseAll(); + final result = _ICU4XCaseMapper_uppercase(_underlying, Utf8Encoder().allocConvert(temp, s, length: sLength), sLength, locale._underlying, writeable._underlying); + temp.releaseAll(); if (!result.isOk) { throw Error.values.firstWhere((v) => v._underlying == result.union.err); } @@ -74,8 +74,8 @@ final class CaseMapper implements ffi.Finalizable { // ignore: non_constant_identifier_names static final _ICU4XCaseMapper_uppercase = - _capi, ffi.Pointer, ffi.Size, ffi.Pointer, ffi.Pointer)>>('ICU4XCaseMapper_uppercase') - .asFunction<_ResultVoidInt32 Function(ffi.Pointer, ffi.Pointer, int, ffi.Pointer, ffi.Pointer)>(isLeaf: true); + _capi, ffi.Pointer, ffi.Size, ffi.Pointer, ffi.Pointer)>>('ICU4XCaseMapper_uppercase') + .asFunction<_ResultVoidInt32 Function(ffi.Pointer, ffi.Pointer, int, ffi.Pointer, ffi.Pointer)>(isLeaf: true); /// Returns the full titlecase mapping of the given string, performing head adjustment without /// loading additional data. @@ -87,11 +87,11 @@ final class CaseMapper implements ffi.Finalizable { /// /// Throws [Error] on failure. String titlecaseSegmentWithOnlyCaseDataV1(String s, Locale locale, TitlecaseOptionsV1 options) { - final alloc = ffi2.Arena(); - final sSlice = _SliceFfi2Utf8._fromDart(s, alloc); + final temp = ffi2.Arena(); + final sLength = s.utf8Length; final writeable = _Writeable(); - final result = _ICU4XCaseMapper_titlecase_segment_with_only_case_data_v1(_underlying, sSlice._bytes, sSlice._length, locale._underlying, options._underlying, writeable._underlying); - alloc.releaseAll(); + final result = _ICU4XCaseMapper_titlecase_segment_with_only_case_data_v1(_underlying, Utf8Encoder().allocConvert(temp, s, length: sLength), sLength, locale._underlying, options._underlying, writeable._underlying); + temp.releaseAll(); if (!result.isOk) { throw Error.values.firstWhere((v) => v._underlying == result.union.err); } @@ -100,8 +100,8 @@ final class CaseMapper implements ffi.Finalizable { // ignore: non_constant_identifier_names static final _ICU4XCaseMapper_titlecase_segment_with_only_case_data_v1 = - _capi, ffi.Pointer, ffi.Size, ffi.Pointer, _TitlecaseOptionsV1Ffi, ffi.Pointer)>>('ICU4XCaseMapper_titlecase_segment_with_only_case_data_v1') - .asFunction<_ResultVoidInt32 Function(ffi.Pointer, ffi.Pointer, int, ffi.Pointer, _TitlecaseOptionsV1Ffi, ffi.Pointer)>(isLeaf: true); + _capi, ffi.Pointer, ffi.Size, ffi.Pointer, _TitlecaseOptionsV1Ffi, ffi.Pointer)>>('ICU4XCaseMapper_titlecase_segment_with_only_case_data_v1') + .asFunction<_ResultVoidInt32 Function(ffi.Pointer, ffi.Pointer, int, ffi.Pointer, _TitlecaseOptionsV1Ffi, ffi.Pointer)>(isLeaf: true); /// Case-folds the characters in the given string /// @@ -109,11 +109,11 @@ final class CaseMapper implements ffi.Finalizable { /// /// Throws [Error] on failure. String fold(String s) { - final alloc = ffi2.Arena(); - final sSlice = _SliceFfi2Utf8._fromDart(s, alloc); + final temp = ffi2.Arena(); + final sLength = s.utf8Length; final writeable = _Writeable(); - final result = _ICU4XCaseMapper_fold(_underlying, sSlice._bytes, sSlice._length, writeable._underlying); - alloc.releaseAll(); + final result = _ICU4XCaseMapper_fold(_underlying, Utf8Encoder().allocConvert(temp, s, length: sLength), sLength, writeable._underlying); + temp.releaseAll(); if (!result.isOk) { throw Error.values.firstWhere((v) => v._underlying == result.union.err); } @@ -122,8 +122,8 @@ final class CaseMapper implements ffi.Finalizable { // ignore: non_constant_identifier_names static final _ICU4XCaseMapper_fold = - _capi, ffi.Pointer, ffi.Size, ffi.Pointer)>>('ICU4XCaseMapper_fold') - .asFunction<_ResultVoidInt32 Function(ffi.Pointer, ffi.Pointer, int, ffi.Pointer)>(isLeaf: true); + _capi, ffi.Pointer, ffi.Size, ffi.Pointer)>>('ICU4XCaseMapper_fold') + .asFunction<_ResultVoidInt32 Function(ffi.Pointer, ffi.Pointer, int, ffi.Pointer)>(isLeaf: true); /// Case-folds the characters in the given string /// using Turkic (T) mappings for dotted/dotless I. @@ -132,11 +132,11 @@ final class CaseMapper implements ffi.Finalizable { /// /// Throws [Error] on failure. String foldTurkic(String s) { - final alloc = ffi2.Arena(); - final sSlice = _SliceFfi2Utf8._fromDart(s, alloc); + final temp = ffi2.Arena(); + final sLength = s.utf8Length; final writeable = _Writeable(); - final result = _ICU4XCaseMapper_fold_turkic(_underlying, sSlice._bytes, sSlice._length, writeable._underlying); - alloc.releaseAll(); + final result = _ICU4XCaseMapper_fold_turkic(_underlying, Utf8Encoder().allocConvert(temp, s, length: sLength), sLength, writeable._underlying); + temp.releaseAll(); if (!result.isOk) { throw Error.values.firstWhere((v) => v._underlying == result.union.err); } @@ -145,8 +145,8 @@ final class CaseMapper implements ffi.Finalizable { // ignore: non_constant_identifier_names static final _ICU4XCaseMapper_fold_turkic = - _capi, ffi.Pointer, ffi.Size, ffi.Pointer)>>('ICU4XCaseMapper_fold_turkic') - .asFunction<_ResultVoidInt32 Function(ffi.Pointer, ffi.Pointer, int, ffi.Pointer)>(isLeaf: true); + _capi, ffi.Pointer, ffi.Size, ffi.Pointer)>>('ICU4XCaseMapper_fold_turkic') + .asFunction<_ResultVoidInt32 Function(ffi.Pointer, ffi.Pointer, int, ffi.Pointer)>(isLeaf: true); /// Adds all simple case mappings and the full case folding for `c` to `builder`. /// Also adds special case closure mappings. diff --git a/ffi/capi/dart/package/lib/src/CodePointRangeIteratorResult.g.dart b/ffi/capi/dart/package/lib/src/CodePointRangeIteratorResult.g.dart index 34dd91c4dc0..a2dc5111777 100644 --- a/ffi/capi/dart/package/lib/src/CodePointRangeIteratorResult.g.dart +++ b/ffi/capi/dart/package/lib/src/CodePointRangeIteratorResult.g.dart @@ -24,7 +24,6 @@ final class _CodePointRangeIteratorResultFfi extends ffi.Struct { final class CodePointRangeIteratorResult { final _CodePointRangeIteratorResultFfi _underlying; - // ignore: unused_element CodePointRangeIteratorResult._(this._underlying); factory CodePointRangeIteratorResult() { diff --git a/ffi/capi/dart/package/lib/src/CodePointSetData.g.dart b/ffi/capi/dart/package/lib/src/CodePointSetData.g.dart index 215667f087a..906b3352c9a 100644 --- a/ffi/capi/dart/package/lib/src/CodePointSetData.g.dart +++ b/ffi/capi/dart/package/lib/src/CodePointSetData.g.dart @@ -1130,10 +1130,10 @@ final class CodePointSetData implements ffi.Finalizable { /// /// Throws [Error] on failure. factory CodePointSetData.loadForEcma262(DataProvider provider, String propertyName) { - final alloc = ffi2.Arena(); - final propertyNameSlice = _SliceFfi2Utf8._fromDart(propertyName, alloc); - final result = _ICU4XCodePointSetData_load_for_ecma262(provider._underlying, propertyNameSlice._bytes, propertyNameSlice._length); - alloc.releaseAll(); + final temp = ffi2.Arena(); + final propertyNameLength = propertyName.utf8Length; + final result = _ICU4XCodePointSetData_load_for_ecma262(provider._underlying, Utf8Encoder().allocConvert(temp, propertyName, length: propertyNameLength), propertyNameLength); + temp.releaseAll(); if (!result.isOk) { throw Error.values.firstWhere((v) => v._underlying == result.union.err); } @@ -1142,6 +1142,6 @@ final class CodePointSetData implements ffi.Finalizable { // ignore: non_constant_identifier_names static final _ICU4XCodePointSetData_load_for_ecma262 = - _capi, ffi.Pointer, ffi.Size)>>('ICU4XCodePointSetData_load_for_ecma262') - .asFunction<_ResultOpaqueInt32 Function(ffi.Pointer, ffi.Pointer, int)>(isLeaf: true); + _capi, ffi.Pointer, ffi.Size)>>('ICU4XCodePointSetData_load_for_ecma262') + .asFunction<_ResultOpaqueInt32 Function(ffi.Pointer, ffi.Pointer, int)>(isLeaf: true); } diff --git a/ffi/capi/dart/package/lib/src/Collator.g.dart b/ffi/capi/dart/package/lib/src/Collator.g.dart index bcabc73dda1..935780e383f 100644 --- a/ffi/capi/dart/package/lib/src/Collator.g.dart +++ b/ffi/capi/dart/package/lib/src/Collator.g.dart @@ -33,36 +33,14 @@ final class Collator implements ffi.Finalizable { _capi, ffi.Pointer, _CollatorOptionsV1Ffi)>>('ICU4XCollator_create_v1') .asFunction<_ResultOpaqueInt32 Function(ffi.Pointer, ffi.Pointer, _CollatorOptionsV1Ffi)>(isLeaf: true); - /// Compare guaranteed well-formed UTF-8 strings. - /// - /// Note: In C++, passing ill-formed UTF-8 strings is undefined behavior - /// (and may be memory-unsafe to do so, too). - /// - /// See the [Rust documentation for `compare`](https://docs.rs/icu/latest/icu/collator/struct.Collator.html#method.compare) for more information. - Ordering compare(String left, String right) { - final alloc = ffi2.Arena(); - final leftSlice = _SliceFfi2Utf8._fromDart(left, alloc); - final rightSlice = _SliceFfi2Utf8._fromDart(right, alloc); - final result = _ICU4XCollator_compare_valid_utf8(_underlying, leftSlice._bytes, leftSlice._length, rightSlice._bytes, rightSlice._length); - alloc.releaseAll(); - return Ordering.values.firstWhere((v) => v._underlying == result); - } - - // ignore: non_constant_identifier_names - static final _ICU4XCollator_compare_valid_utf8 = - _capi, ffi.Pointer, ffi.Size, ffi.Pointer, ffi.Size)>>('ICU4XCollator_compare_valid_utf8') - .asFunction, ffi.Pointer, int, ffi.Pointer, int)>(isLeaf: true); - /// Compare potentially ill-formed UTF-16 strings, with unpaired surrogates /// compared as REPLACEMENT CHARACTER. /// /// See the [Rust documentation for `compare_utf16`](https://docs.rs/icu/latest/icu/collator/struct.Collator.html#method.compare_utf16) for more information. - Ordering compareUtf16(Uint16List left, Uint16List right) { - final alloc = ffi2.Arena(); - final leftSlice = _SliceFfiUint16._fromDart(left, alloc); - final rightSlice = _SliceFfiUint16._fromDart(right, alloc); - final result = _ICU4XCollator_compare_utf16(_underlying, leftSlice._bytes, leftSlice._length, rightSlice._bytes, rightSlice._length); - alloc.releaseAll(); + Ordering compare(String left, String right) { + final temp = ffi2.Arena(); + final result = _ICU4XCollator_compare_utf16(_underlying, left.copy(temp), left.length, right.copy(temp), right.length); + temp.releaseAll(); return Ordering.values.firstWhere((v) => v._underlying == result); } diff --git a/ffi/capi/dart/package/lib/src/CollatorOptionsV1.g.dart b/ffi/capi/dart/package/lib/src/CollatorOptionsV1.g.dart index 590bbb224bd..62a53eb29b4 100644 --- a/ffi/capi/dart/package/lib/src/CollatorOptionsV1.g.dart +++ b/ffi/capi/dart/package/lib/src/CollatorOptionsV1.g.dart @@ -26,7 +26,6 @@ final class _CollatorOptionsV1Ffi extends ffi.Struct { final class CollatorOptionsV1 { final _CollatorOptionsV1Ffi _underlying; - // ignore: unused_element CollatorOptionsV1._(this._underlying); factory CollatorOptionsV1() { diff --git a/ffi/capi/dart/package/lib/src/ComposingNormalizer.g.dart b/ffi/capi/dart/package/lib/src/ComposingNormalizer.g.dart index 41aa9a6205b..9deca273561 100644 --- a/ffi/capi/dart/package/lib/src/ComposingNormalizer.g.dart +++ b/ffi/capi/dart/package/lib/src/ComposingNormalizer.g.dart @@ -59,11 +59,11 @@ final class ComposingNormalizer implements ffi.Finalizable { /// /// Throws [Error] on failure. String normalize(String s) { - final alloc = ffi2.Arena(); - final sSlice = _SliceFfi2Utf8._fromDart(s, alloc); + final temp = ffi2.Arena(); + final sLength = s.utf8Length; final writeable = _Writeable(); - final result = _ICU4XComposingNormalizer_normalize(_underlying, sSlice._bytes, sSlice._length, writeable._underlying); - alloc.releaseAll(); + final result = _ICU4XComposingNormalizer_normalize(_underlying, Utf8Encoder().allocConvert(temp, s, length: sLength), sLength, writeable._underlying); + temp.releaseAll(); if (!result.isOk) { throw Error.values.firstWhere((v) => v._underlying == result.union.err); } @@ -72,8 +72,8 @@ final class ComposingNormalizer implements ffi.Finalizable { // ignore: non_constant_identifier_names static final _ICU4XComposingNormalizer_normalize = - _capi, ffi.Pointer, ffi.Size, ffi.Pointer)>>('ICU4XComposingNormalizer_normalize') - .asFunction<_ResultVoidInt32 Function(ffi.Pointer, ffi.Pointer, int, ffi.Pointer)>(isLeaf: true); + _capi, ffi.Pointer, ffi.Size, ffi.Pointer)>>('ICU4XComposingNormalizer_normalize') + .asFunction<_ResultVoidInt32 Function(ffi.Pointer, ffi.Pointer, int, ffi.Pointer)>(isLeaf: true); /// Check if a (potentially ill-formed) UTF8 string is normalized /// @@ -81,15 +81,15 @@ final class ComposingNormalizer implements ffi.Finalizable { /// /// See the [Rust documentation for `is_normalized_utf8`](https://docs.rs/icu/latest/icu/normalizer/struct.ComposingNormalizer.html#method.is_normalized_utf8) for more information. bool isNormalized(String s) { - final alloc = ffi2.Arena(); - final sSlice = _SliceFfi2Utf8._fromDart(s, alloc); - final result = _ICU4XComposingNormalizer_is_normalized(_underlying, sSlice._bytes, sSlice._length); - alloc.releaseAll(); + final temp = ffi2.Arena(); + final sLength = s.utf8Length; + final result = _ICU4XComposingNormalizer_is_normalized(_underlying, Utf8Encoder().allocConvert(temp, s, length: sLength), sLength); + temp.releaseAll(); return result; } // ignore: non_constant_identifier_names static final _ICU4XComposingNormalizer_is_normalized = - _capi, ffi.Pointer, ffi.Size)>>('ICU4XComposingNormalizer_is_normalized') - .asFunction, ffi.Pointer, int)>(isLeaf: true); + _capi, ffi.Pointer, ffi.Size)>>('ICU4XComposingNormalizer_is_normalized') + .asFunction, ffi.Pointer, int)>(isLeaf: true); } diff --git a/ffi/capi/dart/package/lib/src/CustomTimeZone.g.dart b/ffi/capi/dart/package/lib/src/CustomTimeZone.g.dart index 328d8389d83..d3f596e8918 100644 --- a/ffi/capi/dart/package/lib/src/CustomTimeZone.g.dart +++ b/ffi/capi/dart/package/lib/src/CustomTimeZone.g.dart @@ -21,10 +21,10 @@ final class CustomTimeZone implements ffi.Finalizable { /// /// Throws [Error] on failure. factory CustomTimeZone.fromString(String s) { - final alloc = ffi2.Arena(); - final sSlice = _SliceFfi2Utf8._fromDart(s, alloc); - final result = _ICU4XCustomTimeZone_create_from_string(sSlice._bytes, sSlice._length); - alloc.releaseAll(); + final temp = ffi2.Arena(); + final sLength = s.utf8Length; + final result = _ICU4XCustomTimeZone_create_from_string(Utf8Encoder().allocConvert(temp, s, length: sLength), sLength); + temp.releaseAll(); if (!result.isOk) { throw Error.values.firstWhere((v) => v._underlying == result.union.err); } @@ -33,8 +33,8 @@ final class CustomTimeZone implements ffi.Finalizable { // ignore: non_constant_identifier_names static final _ICU4XCustomTimeZone_create_from_string = - _capi, ffi.Size)>>('ICU4XCustomTimeZone_create_from_string') - .asFunction<_ResultOpaqueInt32 Function(ffi.Pointer, int)>(isLeaf: true); + _capi, ffi.Size)>>('ICU4XCustomTimeZone_create_from_string') + .asFunction<_ResultOpaqueInt32 Function(ffi.Pointer, int)>(isLeaf: true); /// Creates a time zone with no information. /// @@ -209,10 +209,10 @@ final class CustomTimeZone implements ffi.Finalizable { /// /// Throws [Error] on failure. void trySetTimeZoneId(String id) { - final alloc = ffi2.Arena(); - final idSlice = _SliceFfi2Utf8._fromDart(id, alloc); - final result = _ICU4XCustomTimeZone_try_set_time_zone_id(_underlying, idSlice._bytes, idSlice._length); - alloc.releaseAll(); + final temp = ffi2.Arena(); + final idLength = id.utf8Length; + final result = _ICU4XCustomTimeZone_try_set_time_zone_id(_underlying, Utf8Encoder().allocConvert(temp, id, length: idLength), idLength); + temp.releaseAll(); if (!result.isOk) { throw Error.values.firstWhere((v) => v._underlying == result.union.err); } @@ -220,8 +220,8 @@ final class CustomTimeZone implements ffi.Finalizable { // ignore: non_constant_identifier_names static final _ICU4XCustomTimeZone_try_set_time_zone_id = - _capi, ffi.Pointer, ffi.Size)>>('ICU4XCustomTimeZone_try_set_time_zone_id') - .asFunction<_ResultVoidInt32 Function(ffi.Pointer, ffi.Pointer, int)>(isLeaf: true); + _capi, ffi.Pointer, ffi.Size)>>('ICU4XCustomTimeZone_try_set_time_zone_id') + .asFunction<_ResultVoidInt32 Function(ffi.Pointer, ffi.Pointer, int)>(isLeaf: true); /// Sets the `time_zone_id` field from an IANA string by looking up /// the corresponding BCP-47 string. @@ -232,10 +232,10 @@ final class CustomTimeZone implements ffi.Finalizable { /// /// Throws [Error] on failure. void trySetIanaTimeZoneId(IanaToBcp47Mapper mapper, String id) { - final alloc = ffi2.Arena(); - final idSlice = _SliceFfi2Utf8._fromDart(id, alloc); - final result = _ICU4XCustomTimeZone_try_set_iana_time_zone_id(_underlying, mapper._underlying, idSlice._bytes, idSlice._length); - alloc.releaseAll(); + final temp = ffi2.Arena(); + final idLength = id.utf8Length; + final result = _ICU4XCustomTimeZone_try_set_iana_time_zone_id(_underlying, mapper._underlying, Utf8Encoder().allocConvert(temp, id, length: idLength), idLength); + temp.releaseAll(); if (!result.isOk) { throw Error.values.firstWhere((v) => v._underlying == result.union.err); } @@ -243,8 +243,8 @@ final class CustomTimeZone implements ffi.Finalizable { // ignore: non_constant_identifier_names static final _ICU4XCustomTimeZone_try_set_iana_time_zone_id = - _capi, ffi.Pointer, ffi.Pointer, ffi.Size)>>('ICU4XCustomTimeZone_try_set_iana_time_zone_id') - .asFunction<_ResultVoidInt32 Function(ffi.Pointer, ffi.Pointer, ffi.Pointer, int)>(isLeaf: true); + _capi, ffi.Pointer, ffi.Pointer, ffi.Size)>>('ICU4XCustomTimeZone_try_set_iana_time_zone_id') + .asFunction<_ResultVoidInt32 Function(ffi.Pointer, ffi.Pointer, ffi.Pointer, int)>(isLeaf: true); /// Clears the `time_zone_id` field. /// @@ -293,10 +293,10 @@ final class CustomTimeZone implements ffi.Finalizable { /// /// Throws [Error] on failure. void trySetMetazoneId(String id) { - final alloc = ffi2.Arena(); - final idSlice = _SliceFfi2Utf8._fromDart(id, alloc); - final result = _ICU4XCustomTimeZone_try_set_metazone_id(_underlying, idSlice._bytes, idSlice._length); - alloc.releaseAll(); + final temp = ffi2.Arena(); + final idLength = id.utf8Length; + final result = _ICU4XCustomTimeZone_try_set_metazone_id(_underlying, Utf8Encoder().allocConvert(temp, id, length: idLength), idLength); + temp.releaseAll(); if (!result.isOk) { throw Error.values.firstWhere((v) => v._underlying == result.union.err); } @@ -304,8 +304,8 @@ final class CustomTimeZone implements ffi.Finalizable { // ignore: non_constant_identifier_names static final _ICU4XCustomTimeZone_try_set_metazone_id = - _capi, ffi.Pointer, ffi.Size)>>('ICU4XCustomTimeZone_try_set_metazone_id') - .asFunction<_ResultVoidInt32 Function(ffi.Pointer, ffi.Pointer, int)>(isLeaf: true); + _capi, ffi.Pointer, ffi.Size)>>('ICU4XCustomTimeZone_try_set_metazone_id') + .asFunction<_ResultVoidInt32 Function(ffi.Pointer, ffi.Pointer, int)>(isLeaf: true); /// Clears the `metazone_id` field. /// @@ -354,10 +354,10 @@ final class CustomTimeZone implements ffi.Finalizable { /// /// Throws [Error] on failure. void trySetZoneVariant(String id) { - final alloc = ffi2.Arena(); - final idSlice = _SliceFfi2Utf8._fromDart(id, alloc); - final result = _ICU4XCustomTimeZone_try_set_zone_variant(_underlying, idSlice._bytes, idSlice._length); - alloc.releaseAll(); + final temp = ffi2.Arena(); + final idLength = id.utf8Length; + final result = _ICU4XCustomTimeZone_try_set_zone_variant(_underlying, Utf8Encoder().allocConvert(temp, id, length: idLength), idLength); + temp.releaseAll(); if (!result.isOk) { throw Error.values.firstWhere((v) => v._underlying == result.union.err); } @@ -365,8 +365,8 @@ final class CustomTimeZone implements ffi.Finalizable { // ignore: non_constant_identifier_names static final _ICU4XCustomTimeZone_try_set_zone_variant = - _capi, ffi.Pointer, ffi.Size)>>('ICU4XCustomTimeZone_try_set_zone_variant') - .asFunction<_ResultVoidInt32 Function(ffi.Pointer, ffi.Pointer, int)>(isLeaf: true); + _capi, ffi.Pointer, ffi.Size)>>('ICU4XCustomTimeZone_try_set_zone_variant') + .asFunction<_ResultVoidInt32 Function(ffi.Pointer, ffi.Pointer, int)>(isLeaf: true); /// Clears the `zone_variant` field. /// diff --git a/ffi/capi/dart/package/lib/src/DataProvider.g.dart b/ffi/capi/dart/package/lib/src/DataProvider.g.dart index 7fcc736fd5f..74069cd88f4 100644 --- a/ffi/capi/dart/package/lib/src/DataProvider.g.dart +++ b/ffi/capi/dart/package/lib/src/DataProvider.g.dart @@ -39,10 +39,9 @@ final class DataProvider implements ffi.Finalizable { /// /// Throws [Error] on failure. factory DataProvider.fromByteSlice(Uint8List blob) { - final alloc = ffi2.Arena(); - final blobSlice = _SliceFfiUint8._fromDart(blob, alloc); - final result = _ICU4XDataProvider_create_from_byte_slice(blobSlice._bytes, blobSlice._length); - alloc.releaseAll(); + final temp = ffi2.Arena(); + final result = _ICU4XDataProvider_create_from_byte_slice(blob.copy(temp), blob.length); + temp.releaseAll(); if (!result.isOk) { throw Error.values.firstWhere((v) => v._underlying == result.union.err); } diff --git a/ffi/capi/dart/package/lib/src/Date.g.dart b/ffi/capi/dart/package/lib/src/Date.g.dart index ff52c7763c0..07c33304f3e 100644 --- a/ffi/capi/dart/package/lib/src/Date.g.dart +++ b/ffi/capi/dart/package/lib/src/Date.g.dart @@ -42,11 +42,11 @@ final class Date implements ffi.Finalizable { /// /// Throws [Error] on failure. factory Date.fromCodesInCalendar(String eraCode, int year, String monthCode, int day, Calendar calendar) { - final alloc = ffi2.Arena(); - final eraCodeSlice = _SliceFfi2Utf8._fromDart(eraCode, alloc); - final monthCodeSlice = _SliceFfi2Utf8._fromDart(monthCode, alloc); - final result = _ICU4XDate_create_from_codes_in_calendar(eraCodeSlice._bytes, eraCodeSlice._length, year, monthCodeSlice._bytes, monthCodeSlice._length, day, calendar._underlying); - alloc.releaseAll(); + final temp = ffi2.Arena(); + final eraCodeLength = eraCode.utf8Length; + final monthCodeLength = monthCode.utf8Length; + final result = _ICU4XDate_create_from_codes_in_calendar(Utf8Encoder().allocConvert(temp, eraCode, length: eraCodeLength), eraCodeLength, year, Utf8Encoder().allocConvert(temp, monthCode, length: monthCodeLength), monthCodeLength, day, calendar._underlying); + temp.releaseAll(); if (!result.isOk) { throw Error.values.firstWhere((v) => v._underlying == result.union.err); } @@ -55,8 +55,8 @@ final class Date implements ffi.Finalizable { // ignore: non_constant_identifier_names static final _ICU4XDate_create_from_codes_in_calendar = - _capi, ffi.Size, ffi.Int32, ffi.Pointer, ffi.Size, ffi.Uint8, ffi.Pointer)>>('ICU4XDate_create_from_codes_in_calendar') - .asFunction<_ResultOpaqueInt32 Function(ffi.Pointer, int, int, ffi.Pointer, int, int, ffi.Pointer)>(isLeaf: true); + _capi, ffi.Size, ffi.Int32, ffi.Pointer, ffi.Size, ffi.Uint8, ffi.Pointer)>>('ICU4XDate_create_from_codes_in_calendar') + .asFunction<_ResultOpaqueInt32 Function(ffi.Pointer, int, int, ffi.Pointer, int, int, ffi.Pointer)>(isLeaf: true); /// Convert this date to one in a different calendar /// diff --git a/ffi/capi/dart/package/lib/src/DateTime.g.dart b/ffi/capi/dart/package/lib/src/DateTime.g.dart index bd87b2a78bc..3f395bcc7dd 100644 --- a/ffi/capi/dart/package/lib/src/DateTime.g.dart +++ b/ffi/capi/dart/package/lib/src/DateTime.g.dart @@ -42,11 +42,11 @@ final class DateTime implements ffi.Finalizable { /// /// Throws [Error] on failure. factory DateTime.fromCodesInCalendar(String eraCode, int year, String monthCode, int day, int hour, int minute, int second, int nanosecond, Calendar calendar) { - final alloc = ffi2.Arena(); - final eraCodeSlice = _SliceFfi2Utf8._fromDart(eraCode, alloc); - final monthCodeSlice = _SliceFfi2Utf8._fromDart(monthCode, alloc); - final result = _ICU4XDateTime_create_from_codes_in_calendar(eraCodeSlice._bytes, eraCodeSlice._length, year, monthCodeSlice._bytes, monthCodeSlice._length, day, hour, minute, second, nanosecond, calendar._underlying); - alloc.releaseAll(); + final temp = ffi2.Arena(); + final eraCodeLength = eraCode.utf8Length; + final monthCodeLength = monthCode.utf8Length; + final result = _ICU4XDateTime_create_from_codes_in_calendar(Utf8Encoder().allocConvert(temp, eraCode, length: eraCodeLength), eraCodeLength, year, Utf8Encoder().allocConvert(temp, monthCode, length: monthCodeLength), monthCodeLength, day, hour, minute, second, nanosecond, calendar._underlying); + temp.releaseAll(); if (!result.isOk) { throw Error.values.firstWhere((v) => v._underlying == result.union.err); } @@ -55,8 +55,8 @@ final class DateTime implements ffi.Finalizable { // ignore: non_constant_identifier_names static final _ICU4XDateTime_create_from_codes_in_calendar = - _capi, ffi.Size, ffi.Int32, ffi.Pointer, ffi.Size, ffi.Uint8, ffi.Uint8, ffi.Uint8, ffi.Uint8, ffi.Uint32, ffi.Pointer)>>('ICU4XDateTime_create_from_codes_in_calendar') - .asFunction<_ResultOpaqueInt32 Function(ffi.Pointer, int, int, ffi.Pointer, int, int, int, int, int, int, ffi.Pointer)>(isLeaf: true); + _capi, ffi.Size, ffi.Int32, ffi.Pointer, ffi.Size, ffi.Uint8, ffi.Uint8, ffi.Uint8, ffi.Uint8, ffi.Uint32, ffi.Pointer)>>('ICU4XDateTime_create_from_codes_in_calendar') + .asFunction<_ResultOpaqueInt32 Function(ffi.Pointer, int, int, ffi.Pointer, int, int, int, int, int, int, ffi.Pointer)>(isLeaf: true); /// Creates a new [`DateTime`] from an [`Date`] and [`Time`] object /// diff --git a/ffi/capi/dart/package/lib/src/Decomposed.g.dart b/ffi/capi/dart/package/lib/src/Decomposed.g.dart index 4469b276e25..906ab7ba024 100644 --- a/ffi/capi/dart/package/lib/src/Decomposed.g.dart +++ b/ffi/capi/dart/package/lib/src/Decomposed.g.dart @@ -20,7 +20,6 @@ final class _DecomposedFfi extends ffi.Struct { final class Decomposed { final _DecomposedFfi _underlying; - // ignore: unused_element Decomposed._(this._underlying); factory Decomposed() { diff --git a/ffi/capi/dart/package/lib/src/DecomposingNormalizer.g.dart b/ffi/capi/dart/package/lib/src/DecomposingNormalizer.g.dart index 7c118658812..1912f6ebff7 100644 --- a/ffi/capi/dart/package/lib/src/DecomposingNormalizer.g.dart +++ b/ffi/capi/dart/package/lib/src/DecomposingNormalizer.g.dart @@ -59,11 +59,11 @@ final class DecomposingNormalizer implements ffi.Finalizable { /// /// Throws [Error] on failure. String normalize(String s) { - final alloc = ffi2.Arena(); - final sSlice = _SliceFfi2Utf8._fromDart(s, alloc); + final temp = ffi2.Arena(); + final sLength = s.utf8Length; final writeable = _Writeable(); - final result = _ICU4XDecomposingNormalizer_normalize(_underlying, sSlice._bytes, sSlice._length, writeable._underlying); - alloc.releaseAll(); + final result = _ICU4XDecomposingNormalizer_normalize(_underlying, Utf8Encoder().allocConvert(temp, s, length: sLength), sLength, writeable._underlying); + temp.releaseAll(); if (!result.isOk) { throw Error.values.firstWhere((v) => v._underlying == result.union.err); } @@ -72,8 +72,8 @@ final class DecomposingNormalizer implements ffi.Finalizable { // ignore: non_constant_identifier_names static final _ICU4XDecomposingNormalizer_normalize = - _capi, ffi.Pointer, ffi.Size, ffi.Pointer)>>('ICU4XDecomposingNormalizer_normalize') - .asFunction<_ResultVoidInt32 Function(ffi.Pointer, ffi.Pointer, int, ffi.Pointer)>(isLeaf: true); + _capi, ffi.Pointer, ffi.Size, ffi.Pointer)>>('ICU4XDecomposingNormalizer_normalize') + .asFunction<_ResultVoidInt32 Function(ffi.Pointer, ffi.Pointer, int, ffi.Pointer)>(isLeaf: true); /// Check if a (potentially ill-formed) UTF8 string is normalized /// @@ -81,15 +81,15 @@ final class DecomposingNormalizer implements ffi.Finalizable { /// /// See the [Rust documentation for `is_normalized_utf8`](https://docs.rs/icu/latest/icu/normalizer/struct.DecomposingNormalizer.html#method.is_normalized_utf8) for more information. bool isNormalized(String s) { - final alloc = ffi2.Arena(); - final sSlice = _SliceFfi2Utf8._fromDart(s, alloc); - final result = _ICU4XDecomposingNormalizer_is_normalized(_underlying, sSlice._bytes, sSlice._length); - alloc.releaseAll(); + final temp = ffi2.Arena(); + final sLength = s.utf8Length; + final result = _ICU4XDecomposingNormalizer_is_normalized(_underlying, Utf8Encoder().allocConvert(temp, s, length: sLength), sLength); + temp.releaseAll(); return result; } // ignore: non_constant_identifier_names static final _ICU4XDecomposingNormalizer_is_normalized = - _capi, ffi.Pointer, ffi.Size)>>('ICU4XDecomposingNormalizer_is_normalized') - .asFunction, ffi.Pointer, int)>(isLeaf: true); + _capi, ffi.Pointer, ffi.Size)>>('ICU4XDecomposingNormalizer_is_normalized') + .asFunction, ffi.Pointer, int)>(isLeaf: true); } diff --git a/ffi/capi/dart/package/lib/src/DisplayNamesOptionsV1.g.dart b/ffi/capi/dart/package/lib/src/DisplayNamesOptionsV1.g.dart index 2d649dc6118..f9ae98fdb11 100644 --- a/ffi/capi/dart/package/lib/src/DisplayNamesOptionsV1.g.dart +++ b/ffi/capi/dart/package/lib/src/DisplayNamesOptionsV1.g.dart @@ -18,7 +18,6 @@ final class _DisplayNamesOptionsV1Ffi extends ffi.Struct { final class DisplayNamesOptionsV1 { final _DisplayNamesOptionsV1Ffi _underlying; - // ignore: unused_element DisplayNamesOptionsV1._(this._underlying); factory DisplayNamesOptionsV1() { diff --git a/ffi/capi/dart/package/lib/src/FixedDecimal.g.dart b/ffi/capi/dart/package/lib/src/FixedDecimal.g.dart index 7e62e9f450f..dae247acb13 100644 --- a/ffi/capi/dart/package/lib/src/FixedDecimal.g.dart +++ b/ffi/capi/dart/package/lib/src/FixedDecimal.g.dart @@ -95,10 +95,10 @@ final class FixedDecimal implements ffi.Finalizable { /// /// Throws [Error] on failure. factory FixedDecimal.fromString(String v) { - final alloc = ffi2.Arena(); - final vSlice = _SliceFfi2Utf8._fromDart(v, alloc); - final result = _ICU4XFixedDecimal_create_from_string(vSlice._bytes, vSlice._length); - alloc.releaseAll(); + final temp = ffi2.Arena(); + final vLength = v.utf8Length; + final result = _ICU4XFixedDecimal_create_from_string(Utf8Encoder().allocConvert(temp, v, length: vLength), vLength); + temp.releaseAll(); if (!result.isOk) { throw Error.values.firstWhere((v) => v._underlying == result.union.err); } @@ -107,8 +107,8 @@ final class FixedDecimal implements ffi.Finalizable { // ignore: non_constant_identifier_names static final _ICU4XFixedDecimal_create_from_string = - _capi, ffi.Size)>>('ICU4XFixedDecimal_create_from_string') - .asFunction<_ResultOpaqueInt32 Function(ffi.Pointer, int)>(isLeaf: true); + _capi, ffi.Size)>>('ICU4XFixedDecimal_create_from_string') + .asFunction<_ResultOpaqueInt32 Function(ffi.Pointer, int)>(isLeaf: true); /// See the [Rust documentation for `digit_at`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.digit_at) for more information. int digitAt(int magnitude) { diff --git a/ffi/capi/dart/package/lib/src/GeneralCategoryNameToMaskMapper.g.dart b/ffi/capi/dart/package/lib/src/GeneralCategoryNameToMaskMapper.g.dart index e59be600c5b..ae5dd1165ce 100644 --- a/ffi/capi/dart/package/lib/src/GeneralCategoryNameToMaskMapper.g.dart +++ b/ffi/capi/dart/package/lib/src/GeneralCategoryNameToMaskMapper.g.dart @@ -23,33 +23,33 @@ final class GeneralCategoryNameToMaskMapper implements ffi.Finalizable { /// /// Returns 0 if the name is unknown for this property int getStrict(String name) { - final alloc = ffi2.Arena(); - final nameSlice = _SliceFfi2Utf8._fromDart(name, alloc); - final result = _ICU4XGeneralCategoryNameToMaskMapper_get_strict(_underlying, nameSlice._bytes, nameSlice._length); - alloc.releaseAll(); + final temp = ffi2.Arena(); + final nameLength = name.utf8Length; + final result = _ICU4XGeneralCategoryNameToMaskMapper_get_strict(_underlying, Utf8Encoder().allocConvert(temp, name, length: nameLength), nameLength); + temp.releaseAll(); return result; } // ignore: non_constant_identifier_names static final _ICU4XGeneralCategoryNameToMaskMapper_get_strict = - _capi, ffi.Pointer, ffi.Size)>>('ICU4XGeneralCategoryNameToMaskMapper_get_strict') - .asFunction, ffi.Pointer, int)>(isLeaf: true); + _capi, ffi.Pointer, ffi.Size)>>('ICU4XGeneralCategoryNameToMaskMapper_get_strict') + .asFunction, ffi.Pointer, int)>(isLeaf: true); /// Get the mask value matching the given name, using loose matching /// /// Returns 0 if the name is unknown for this property int getLoose(String name) { - final alloc = ffi2.Arena(); - final nameSlice = _SliceFfi2Utf8._fromDart(name, alloc); - final result = _ICU4XGeneralCategoryNameToMaskMapper_get_loose(_underlying, nameSlice._bytes, nameSlice._length); - alloc.releaseAll(); + final temp = ffi2.Arena(); + final nameLength = name.utf8Length; + final result = _ICU4XGeneralCategoryNameToMaskMapper_get_loose(_underlying, Utf8Encoder().allocConvert(temp, name, length: nameLength), nameLength); + temp.releaseAll(); return result; } // ignore: non_constant_identifier_names static final _ICU4XGeneralCategoryNameToMaskMapper_get_loose = - _capi, ffi.Pointer, ffi.Size)>>('ICU4XGeneralCategoryNameToMaskMapper_get_loose') - .asFunction, ffi.Pointer, int)>(isLeaf: true); + _capi, ffi.Pointer, ffi.Size)>>('ICU4XGeneralCategoryNameToMaskMapper_get_loose') + .asFunction, ffi.Pointer, int)>(isLeaf: true); /// See the [Rust documentation for `get_name_to_enum_mapper`](https://docs.rs/icu/latest/icu/properties/struct.GeneralCategoryGroup.html#method.get_name_to_enum_mapper) for more information. /// diff --git a/ffi/capi/dart/package/lib/src/GraphemeClusterSegmenter.g.dart b/ffi/capi/dart/package/lib/src/GraphemeClusterSegmenter.g.dart index aa258302364..b59fd6e8b29 100644 --- a/ffi/capi/dart/package/lib/src/GraphemeClusterSegmenter.g.dart +++ b/ffi/capi/dart/package/lib/src/GraphemeClusterSegmenter.g.dart @@ -36,30 +36,13 @@ final class GraphemeClusterSegmenter implements ffi.Finalizable { _capi)>>('ICU4XGraphemeClusterSegmenter_create') .asFunction<_ResultOpaqueInt32 Function(ffi.Pointer)>(isLeaf: true); - /// Segments a (potentially ill-formed) UTF-8 string. - /// - /// See the [Rust documentation for `segment_utf8`](https://docs.rs/icu/latest/icu/segmenter/struct.GraphemeClusterSegmenter.html#method.segment_utf8) for more information. - GraphemeClusterBreakIteratorUtf8 segmentUtf8(String input) { - final alloc = ffi2.Arena(); - final inputSlice = _SliceFfi2Utf8._fromDart(input, alloc); - final result = _ICU4XGraphemeClusterSegmenter_segment_utf8(_underlying, inputSlice._bytes, inputSlice._length); - alloc.releaseAll(); - return GraphemeClusterBreakIteratorUtf8._(result); - } - - // ignore: non_constant_identifier_names - static final _ICU4XGraphemeClusterSegmenter_segment_utf8 = - _capi Function(ffi.Pointer, ffi.Pointer, ffi.Size)>>('ICU4XGraphemeClusterSegmenter_segment_utf8') - .asFunction Function(ffi.Pointer, ffi.Pointer, int)>(isLeaf: true); - /// Segments a UTF-16 string. /// /// See the [Rust documentation for `segment_utf16`](https://docs.rs/icu/latest/icu/segmenter/struct.GraphemeClusterSegmenter.html#method.segment_utf16) for more information. - GraphemeClusterBreakIteratorUtf16 segmentUtf16(Uint16List input) { - final alloc = ffi2.Arena(); - final inputSlice = _SliceFfiUint16._fromDart(input, alloc); - final result = _ICU4XGraphemeClusterSegmenter_segment_utf16(_underlying, inputSlice._bytes, inputSlice._length); - alloc.releaseAll(); + GraphemeClusterBreakIteratorUtf16 segment(String input) { + final temp = ffi2.Arena(); + final result = _ICU4XGraphemeClusterSegmenter_segment_utf16(_underlying, input.copy(temp), input.length); + temp.releaseAll(); return GraphemeClusterBreakIteratorUtf16._(result); } @@ -67,20 +50,4 @@ final class GraphemeClusterSegmenter implements ffi.Finalizable { static final _ICU4XGraphemeClusterSegmenter_segment_utf16 = _capi Function(ffi.Pointer, ffi.Pointer, ffi.Size)>>('ICU4XGraphemeClusterSegmenter_segment_utf16') .asFunction Function(ffi.Pointer, ffi.Pointer, int)>(isLeaf: true); - - /// Segments a Latin-1 string. - /// - /// See the [Rust documentation for `segment_latin1`](https://docs.rs/icu/latest/icu/segmenter/struct.GraphemeClusterSegmenter.html#method.segment_latin1) for more information. - GraphemeClusterBreakIteratorLatin1 segmentLatin1(Uint8List input) { - final alloc = ffi2.Arena(); - final inputSlice = _SliceFfiUint8._fromDart(input, alloc); - final result = _ICU4XGraphemeClusterSegmenter_segment_latin1(_underlying, inputSlice._bytes, inputSlice._length); - alloc.releaseAll(); - return GraphemeClusterBreakIteratorLatin1._(result); - } - - // ignore: non_constant_identifier_names - static final _ICU4XGraphemeClusterSegmenter_segment_latin1 = - _capi Function(ffi.Pointer, ffi.Pointer, ffi.Size)>>('ICU4XGraphemeClusterSegmenter_segment_latin1') - .asFunction Function(ffi.Pointer, ffi.Pointer, int)>(isLeaf: true); } diff --git a/ffi/capi/dart/package/lib/src/IsoTimeZoneOptions.g.dart b/ffi/capi/dart/package/lib/src/IsoTimeZoneOptions.g.dart index f3bb47e3f71..70af318a7d5 100644 --- a/ffi/capi/dart/package/lib/src/IsoTimeZoneOptions.g.dart +++ b/ffi/capi/dart/package/lib/src/IsoTimeZoneOptions.g.dart @@ -17,7 +17,6 @@ final class _IsoTimeZoneOptionsFfi extends ffi.Struct { final class IsoTimeZoneOptions { final _IsoTimeZoneOptionsFfi _underlying; - // ignore: unused_element IsoTimeZoneOptions._(this._underlying); factory IsoTimeZoneOptions() { diff --git a/ffi/capi/dart/package/lib/src/LineBreakOptionsV1.g.dart b/ffi/capi/dart/package/lib/src/LineBreakOptionsV1.g.dart index 35ad1ec5eb5..84541ea87ff 100644 --- a/ffi/capi/dart/package/lib/src/LineBreakOptionsV1.g.dart +++ b/ffi/capi/dart/package/lib/src/LineBreakOptionsV1.g.dart @@ -18,7 +18,6 @@ final class _LineBreakOptionsV1Ffi extends ffi.Struct { final class LineBreakOptionsV1 { final _LineBreakOptionsV1Ffi _underlying; - // ignore: unused_element LineBreakOptionsV1._(this._underlying); factory LineBreakOptionsV1() { diff --git a/ffi/capi/dart/package/lib/src/LineSegmenter.g.dart b/ffi/capi/dart/package/lib/src/LineSegmenter.g.dart index effd4983f56..f2621af23c5 100644 --- a/ffi/capi/dart/package/lib/src/LineSegmenter.g.dart +++ b/ffi/capi/dart/package/lib/src/LineSegmenter.g.dart @@ -131,30 +131,13 @@ final class LineSegmenter implements ffi.Finalizable { _capi, _LineBreakOptionsV1Ffi)>>('ICU4XLineSegmenter_create_dictionary_with_options_v1') .asFunction<_ResultOpaqueInt32 Function(ffi.Pointer, _LineBreakOptionsV1Ffi)>(isLeaf: true); - /// Segments a (potentially ill-formed) UTF-8 string. - /// - /// See the [Rust documentation for `segment_utf8`](https://docs.rs/icu/latest/icu/segmenter/struct.LineSegmenter.html#method.segment_utf8) for more information. - LineBreakIteratorUtf8 segmentUtf8(String input) { - final alloc = ffi2.Arena(); - final inputSlice = _SliceFfi2Utf8._fromDart(input, alloc); - final result = _ICU4XLineSegmenter_segment_utf8(_underlying, inputSlice._bytes, inputSlice._length); - alloc.releaseAll(); - return LineBreakIteratorUtf8._(result); - } - - // ignore: non_constant_identifier_names - static final _ICU4XLineSegmenter_segment_utf8 = - _capi Function(ffi.Pointer, ffi.Pointer, ffi.Size)>>('ICU4XLineSegmenter_segment_utf8') - .asFunction Function(ffi.Pointer, ffi.Pointer, int)>(isLeaf: true); - /// Segments a UTF-16 string. /// /// See the [Rust documentation for `segment_utf16`](https://docs.rs/icu/latest/icu/segmenter/struct.LineSegmenter.html#method.segment_utf16) for more information. - LineBreakIteratorUtf16 segmentUtf16(Uint16List input) { - final alloc = ffi2.Arena(); - final inputSlice = _SliceFfiUint16._fromDart(input, alloc); - final result = _ICU4XLineSegmenter_segment_utf16(_underlying, inputSlice._bytes, inputSlice._length); - alloc.releaseAll(); + LineBreakIteratorUtf16 segment(String input) { + final temp = ffi2.Arena(); + final result = _ICU4XLineSegmenter_segment_utf16(_underlying, input.copy(temp), input.length); + temp.releaseAll(); return LineBreakIteratorUtf16._(result); } @@ -162,20 +145,4 @@ final class LineSegmenter implements ffi.Finalizable { static final _ICU4XLineSegmenter_segment_utf16 = _capi Function(ffi.Pointer, ffi.Pointer, ffi.Size)>>('ICU4XLineSegmenter_segment_utf16') .asFunction Function(ffi.Pointer, ffi.Pointer, int)>(isLeaf: true); - - /// Segments a Latin-1 string. - /// - /// See the [Rust documentation for `segment_latin1`](https://docs.rs/icu/latest/icu/segmenter/struct.LineSegmenter.html#method.segment_latin1) for more information. - LineBreakIteratorLatin1 segmentLatin1(Uint8List input) { - final alloc = ffi2.Arena(); - final inputSlice = _SliceFfiUint8._fromDart(input, alloc); - final result = _ICU4XLineSegmenter_segment_latin1(_underlying, inputSlice._bytes, inputSlice._length); - alloc.releaseAll(); - return LineBreakIteratorLatin1._(result); - } - - // ignore: non_constant_identifier_names - static final _ICU4XLineSegmenter_segment_latin1 = - _capi Function(ffi.Pointer, ffi.Pointer, ffi.Size)>>('ICU4XLineSegmenter_segment_latin1') - .asFunction Function(ffi.Pointer, ffi.Pointer, int)>(isLeaf: true); } diff --git a/ffi/capi/dart/package/lib/src/List.g.dart b/ffi/capi/dart/package/lib/src/List.g.dart index ff6b146d005..4712b205af6 100644 --- a/ffi/capi/dart/package/lib/src/List.g.dart +++ b/ffi/capi/dart/package/lib/src/List.g.dart @@ -43,16 +43,16 @@ final class List implements ffi.Finalizable { /// For C++ users, potentially invalid UTF8 will be handled via /// REPLACEMENT CHARACTERs void push(String val) { - final alloc = ffi2.Arena(); - final valSlice = _SliceFfi2Utf8._fromDart(val, alloc); - _ICU4XList_push(_underlying, valSlice._bytes, valSlice._length); - alloc.releaseAll(); + final temp = ffi2.Arena(); + final valLength = val.utf8Length; + _ICU4XList_push(_underlying, Utf8Encoder().allocConvert(temp, val, length: valLength), valLength); + temp.releaseAll(); } // ignore: non_constant_identifier_names static final _ICU4XList_push = - _capi, ffi.Pointer, ffi.Size)>>('ICU4XList_push') - .asFunction, ffi.Pointer, int)>(isLeaf: true); + _capi, ffi.Pointer, ffi.Size)>>('ICU4XList_push') + .asFunction, ffi.Pointer, int)>(isLeaf: true); /// The number of elements in this list int get length { diff --git a/ffi/capi/dart/package/lib/src/Locale.g.dart b/ffi/capi/dart/package/lib/src/Locale.g.dart index bd3f096e496..6bb24d0fa85 100644 --- a/ffi/capi/dart/package/lib/src/Locale.g.dart +++ b/ffi/capi/dart/package/lib/src/Locale.g.dart @@ -27,10 +27,10 @@ final class Locale implements ffi.Finalizable { /// /// Throws [Error] on failure. factory Locale.fromString(String name) { - final alloc = ffi2.Arena(); - final nameSlice = _SliceFfi2Utf8._fromDart(name, alloc); - final result = _ICU4XLocale_create_from_string(nameSlice._bytes, nameSlice._length); - alloc.releaseAll(); + final temp = ffi2.Arena(); + final nameLength = name.utf8Length; + final result = _ICU4XLocale_create_from_string(Utf8Encoder().allocConvert(temp, name, length: nameLength), nameLength); + temp.releaseAll(); if (!result.isOk) { throw Error.values.firstWhere((v) => v._underlying == result.union.err); } @@ -39,8 +39,8 @@ final class Locale implements ffi.Finalizable { // ignore: non_constant_identifier_names static final _ICU4XLocale_create_from_string = - _capi, ffi.Size)>>('ICU4XLocale_create_from_string') - .asFunction<_ResultOpaqueInt32 Function(ffi.Pointer, int)>(isLeaf: true); + _capi, ffi.Size)>>('ICU4XLocale_create_from_string') + .asFunction<_ResultOpaqueInt32 Function(ffi.Pointer, int)>(isLeaf: true); /// Construct a default undefined [`Locale`] "und". /// @@ -94,11 +94,11 @@ final class Locale implements ffi.Finalizable { /// /// Throws [Error] on failure. String getUnicodeExtension(String bytes) { - final alloc = ffi2.Arena(); - final bytesSlice = _SliceFfi2Utf8._fromDart(bytes, alloc); + final temp = ffi2.Arena(); + final bytesLength = bytes.utf8Length; final writeable = _Writeable(); - final result = _ICU4XLocale_get_unicode_extension(_underlying, bytesSlice._bytes, bytesSlice._length, writeable._underlying); - alloc.releaseAll(); + final result = _ICU4XLocale_get_unicode_extension(_underlying, Utf8Encoder().allocConvert(temp, bytes, length: bytesLength), bytesLength, writeable._underlying); + temp.releaseAll(); if (!result.isOk) { throw Error.values.firstWhere((v) => v._underlying == result.union.err); } @@ -107,8 +107,8 @@ final class Locale implements ffi.Finalizable { // ignore: non_constant_identifier_names static final _ICU4XLocale_get_unicode_extension = - _capi, ffi.Pointer, ffi.Size, ffi.Pointer)>>('ICU4XLocale_get_unicode_extension') - .asFunction<_ResultVoidInt32 Function(ffi.Pointer, ffi.Pointer, int, ffi.Pointer)>(isLeaf: true); + _capi, ffi.Pointer, ffi.Size, ffi.Pointer)>>('ICU4XLocale_get_unicode_extension') + .asFunction<_ResultVoidInt32 Function(ffi.Pointer, ffi.Pointer, int, ffi.Pointer)>(isLeaf: true); /// Write a string representation of [`Locale`] language to `write` /// @@ -135,10 +135,10 @@ final class Locale implements ffi.Finalizable { /// /// Throws [Error] on failure. set language(String bytes) { - final alloc = ffi2.Arena(); - final bytesSlice = _SliceFfi2Utf8._fromDart(bytes, alloc); - final result = _ICU4XLocale_set_language(_underlying, bytesSlice._bytes, bytesSlice._length); - alloc.releaseAll(); + final temp = ffi2.Arena(); + final bytesLength = bytes.utf8Length; + final result = _ICU4XLocale_set_language(_underlying, Utf8Encoder().allocConvert(temp, bytes, length: bytesLength), bytesLength); + temp.releaseAll(); if (!result.isOk) { throw Error.values.firstWhere((v) => v._underlying == result.union.err); } @@ -146,8 +146,8 @@ final class Locale implements ffi.Finalizable { // ignore: non_constant_identifier_names static final _ICU4XLocale_set_language = - _capi, ffi.Pointer, ffi.Size)>>('ICU4XLocale_set_language') - .asFunction<_ResultVoidInt32 Function(ffi.Pointer, ffi.Pointer, int)>(isLeaf: true); + _capi, ffi.Pointer, ffi.Size)>>('ICU4XLocale_set_language') + .asFunction<_ResultVoidInt32 Function(ffi.Pointer, ffi.Pointer, int)>(isLeaf: true); /// Write a string representation of [`Locale`] region to `write` /// @@ -174,10 +174,10 @@ final class Locale implements ffi.Finalizable { /// /// Throws [Error] on failure. set region(String bytes) { - final alloc = ffi2.Arena(); - final bytesSlice = _SliceFfi2Utf8._fromDart(bytes, alloc); - final result = _ICU4XLocale_set_region(_underlying, bytesSlice._bytes, bytesSlice._length); - alloc.releaseAll(); + final temp = ffi2.Arena(); + final bytesLength = bytes.utf8Length; + final result = _ICU4XLocale_set_region(_underlying, Utf8Encoder().allocConvert(temp, bytes, length: bytesLength), bytesLength); + temp.releaseAll(); if (!result.isOk) { throw Error.values.firstWhere((v) => v._underlying == result.union.err); } @@ -185,8 +185,8 @@ final class Locale implements ffi.Finalizable { // ignore: non_constant_identifier_names static final _ICU4XLocale_set_region = - _capi, ffi.Pointer, ffi.Size)>>('ICU4XLocale_set_region') - .asFunction<_ResultVoidInt32 Function(ffi.Pointer, ffi.Pointer, int)>(isLeaf: true); + _capi, ffi.Pointer, ffi.Size)>>('ICU4XLocale_set_region') + .asFunction<_ResultVoidInt32 Function(ffi.Pointer, ffi.Pointer, int)>(isLeaf: true); /// Write a string representation of [`Locale`] script to `write` /// @@ -213,10 +213,10 @@ final class Locale implements ffi.Finalizable { /// /// Throws [Error] on failure. set script(String bytes) { - final alloc = ffi2.Arena(); - final bytesSlice = _SliceFfi2Utf8._fromDart(bytes, alloc); - final result = _ICU4XLocale_set_script(_underlying, bytesSlice._bytes, bytesSlice._length); - alloc.releaseAll(); + final temp = ffi2.Arena(); + final bytesLength = bytes.utf8Length; + final result = _ICU4XLocale_set_script(_underlying, Utf8Encoder().allocConvert(temp, bytes, length: bytesLength), bytesLength); + temp.releaseAll(); if (!result.isOk) { throw Error.values.firstWhere((v) => v._underlying == result.union.err); } @@ -224,8 +224,8 @@ final class Locale implements ffi.Finalizable { // ignore: non_constant_identifier_names static final _ICU4XLocale_set_script = - _capi, ffi.Pointer, ffi.Size)>>('ICU4XLocale_set_script') - .asFunction<_ResultVoidInt32 Function(ffi.Pointer, ffi.Pointer, int)>(isLeaf: true); + _capi, ffi.Pointer, ffi.Size)>>('ICU4XLocale_set_script') + .asFunction<_ResultVoidInt32 Function(ffi.Pointer, ffi.Pointer, int)>(isLeaf: true); /// Best effort locale canonicalizer that doesn't need any data /// @@ -235,11 +235,11 @@ final class Locale implements ffi.Finalizable { /// /// Throws [Error] on failure. static String canonicalize(String bytes) { - final alloc = ffi2.Arena(); - final bytesSlice = _SliceFfi2Utf8._fromDart(bytes, alloc); + final temp = ffi2.Arena(); + final bytesLength = bytes.utf8Length; final writeable = _Writeable(); - final result = _ICU4XLocale_canonicalize(bytesSlice._bytes, bytesSlice._length, writeable._underlying); - alloc.releaseAll(); + final result = _ICU4XLocale_canonicalize(Utf8Encoder().allocConvert(temp, bytes, length: bytesLength), bytesLength, writeable._underlying); + temp.releaseAll(); if (!result.isOk) { throw Error.values.firstWhere((v) => v._underlying == result.union.err); } @@ -248,8 +248,8 @@ final class Locale implements ffi.Finalizable { // ignore: non_constant_identifier_names static final _ICU4XLocale_canonicalize = - _capi, ffi.Size, ffi.Pointer)>>('ICU4XLocale_canonicalize') - .asFunction<_ResultVoidInt32 Function(ffi.Pointer, int, ffi.Pointer)>(isLeaf: true); + _capi, ffi.Size, ffi.Pointer)>>('ICU4XLocale_canonicalize') + .asFunction<_ResultVoidInt32 Function(ffi.Pointer, int, ffi.Pointer)>(isLeaf: true); /// Write a string representation of [`Locale`] to `write` /// @@ -273,29 +273,29 @@ final class Locale implements ffi.Finalizable { /// See the [Rust documentation for `normalizing_eq`](https://docs.rs/icu/latest/icu/locid/struct.Locale.html#method.normalizing_eq) for more information. bool normalizingEq(String other) { - final alloc = ffi2.Arena(); - final otherSlice = _SliceFfi2Utf8._fromDart(other, alloc); - final result = _ICU4XLocale_normalizing_eq(_underlying, otherSlice._bytes, otherSlice._length); - alloc.releaseAll(); + final temp = ffi2.Arena(); + final otherLength = other.utf8Length; + final result = _ICU4XLocale_normalizing_eq(_underlying, Utf8Encoder().allocConvert(temp, other, length: otherLength), otherLength); + temp.releaseAll(); return result; } // ignore: non_constant_identifier_names static final _ICU4XLocale_normalizing_eq = - _capi, ffi.Pointer, ffi.Size)>>('ICU4XLocale_normalizing_eq') - .asFunction, ffi.Pointer, int)>(isLeaf: true); + _capi, ffi.Pointer, ffi.Size)>>('ICU4XLocale_normalizing_eq') + .asFunction, ffi.Pointer, int)>(isLeaf: true); /// See the [Rust documentation for `strict_cmp`](https://docs.rs/icu/latest/icu/locid/struct.Locale.html#method.strict_cmp) for more information. Ordering strictCmp(String other) { - final alloc = ffi2.Arena(); - final otherSlice = _SliceFfi2Utf8._fromDart(other, alloc); - final result = _ICU4XLocale_strict_cmp(_underlying, otherSlice._bytes, otherSlice._length); - alloc.releaseAll(); + final temp = ffi2.Arena(); + final otherLength = other.utf8Length; + final result = _ICU4XLocale_strict_cmp(_underlying, Utf8Encoder().allocConvert(temp, other, length: otherLength), otherLength); + temp.releaseAll(); return Ordering.values.firstWhere((v) => v._underlying == result); } // ignore: non_constant_identifier_names static final _ICU4XLocale_strict_cmp = - _capi, ffi.Pointer, ffi.Size)>>('ICU4XLocale_strict_cmp') - .asFunction, ffi.Pointer, int)>(isLeaf: true); + _capi, ffi.Pointer, ffi.Size)>>('ICU4XLocale_strict_cmp') + .asFunction, ffi.Pointer, int)>(isLeaf: true); } diff --git a/ffi/capi/dart/package/lib/src/LocaleFallbackConfig.g.dart b/ffi/capi/dart/package/lib/src/LocaleFallbackConfig.g.dart index 9af1500c61e..6cabfa656bd 100644 --- a/ffi/capi/dart/package/lib/src/LocaleFallbackConfig.g.dart +++ b/ffi/capi/dart/package/lib/src/LocaleFallbackConfig.g.dart @@ -11,7 +11,7 @@ part of 'lib.g.dart'; final class _LocaleFallbackConfigFfi extends ffi.Struct { @ffi.Int32() external int priority; - external _SliceFfi2Utf8 extensionKey; + external _SliceUtf8 extensionKey; @ffi.Int32() external int fallbackSupplement; } @@ -19,7 +19,6 @@ final class _LocaleFallbackConfigFfi extends ffi.Struct { final class LocaleFallbackConfig { final _LocaleFallbackConfigFfi _underlying; - // ignore: unused_element LocaleFallbackConfig._(this._underlying); factory LocaleFallbackConfig() { @@ -34,12 +33,11 @@ final class LocaleFallbackConfig { _underlying.priority = priority.index; } - String get extensionKey => _underlying.extensionKey._asDart; + String get extensionKey => Utf8Decoder().convert(_underlying.extensionKey._pointer.asTypedList(_underlying.extensionKey._length)); set extensionKey(String extensionKey) { - final alloc = ffi2.calloc; - alloc.free(_underlying.extensionKey._bytes); - final extensionKeySlice = _SliceFfi2Utf8._fromDart(extensionKey, alloc); - _underlying.extensionKey = extensionKeySlice; + ffi2.calloc.free(_underlying.extensionKey._pointer); + _underlying.extensionKey._length = extensionKey.utf8Length; + _underlying.extensionKey._pointer = Utf8Encoder().allocConvert(ffi2.calloc, extensionKey, length: _underlying.extensionKey._length); } LocaleFallbackSupplement get fallbackSupplement => LocaleFallbackSupplement.values[_underlying.fallbackSupplement]; diff --git a/ffi/capi/dart/package/lib/src/PluralCategories.g.dart b/ffi/capi/dart/package/lib/src/PluralCategories.g.dart index c9e1f1799f8..de86ade4a1b 100644 --- a/ffi/capi/dart/package/lib/src/PluralCategories.g.dart +++ b/ffi/capi/dart/package/lib/src/PluralCategories.g.dart @@ -24,7 +24,6 @@ final class _PluralCategoriesFfi extends ffi.Struct { final class PluralCategories { final _PluralCategoriesFfi _underlying; - // ignore: unused_element PluralCategories._(this._underlying); factory PluralCategories() { diff --git a/ffi/capi/dart/package/lib/src/PluralCategory.g.dart b/ffi/capi/dart/package/lib/src/PluralCategory.g.dart index 8c78801d9bf..7fb9ed6025b 100644 --- a/ffi/capi/dart/package/lib/src/PluralCategory.g.dart +++ b/ffi/capi/dart/package/lib/src/PluralCategory.g.dart @@ -30,10 +30,10 @@ enum PluralCategory { /// /// Throws [VoidError] on failure. factory PluralCategory.forCldrString(String s) { - final alloc = ffi2.Arena(); - final sSlice = _SliceFfi2Utf8._fromDart(s, alloc); - final result = _ICU4XPluralCategory_get_for_cldr_string(sSlice._bytes, sSlice._length); - alloc.releaseAll(); + final temp = ffi2.Arena(); + final sLength = s.utf8Length; + final result = _ICU4XPluralCategory_get_for_cldr_string(Utf8Encoder().allocConvert(temp, s, length: sLength), sLength); + temp.releaseAll(); if (!result.isOk) { throw VoidError(); } @@ -42,6 +42,6 @@ enum PluralCategory { // ignore: non_constant_identifier_names static final _ICU4XPluralCategory_get_for_cldr_string = - _capi, ffi.Size)>>('ICU4XPluralCategory_get_for_cldr_string') - .asFunction<_ResultInt32Void Function(ffi.Pointer, int)>(isLeaf: true); + _capi, ffi.Size)>>('ICU4XPluralCategory_get_for_cldr_string') + .asFunction<_ResultInt32Void Function(ffi.Pointer, int)>(isLeaf: true); } diff --git a/ffi/capi/dart/package/lib/src/PluralOperands.g.dart b/ffi/capi/dart/package/lib/src/PluralOperands.g.dart index 4dea22c9f12..6898425910a 100644 --- a/ffi/capi/dart/package/lib/src/PluralOperands.g.dart +++ b/ffi/capi/dart/package/lib/src/PluralOperands.g.dart @@ -23,10 +23,10 @@ final class PluralOperands implements ffi.Finalizable { /// /// Throws [Error] on failure. factory PluralOperands.fromString(String s) { - final alloc = ffi2.Arena(); - final sSlice = _SliceFfi2Utf8._fromDart(s, alloc); - final result = _ICU4XPluralOperands_create_from_string(sSlice._bytes, sSlice._length); - alloc.releaseAll(); + final temp = ffi2.Arena(); + final sLength = s.utf8Length; + final result = _ICU4XPluralOperands_create_from_string(Utf8Encoder().allocConvert(temp, s, length: sLength), sLength); + temp.releaseAll(); if (!result.isOk) { throw Error.values.firstWhere((v) => v._underlying == result.union.err); } @@ -35,6 +35,6 @@ final class PluralOperands implements ffi.Finalizable { // ignore: non_constant_identifier_names static final _ICU4XPluralOperands_create_from_string = - _capi, ffi.Size)>>('ICU4XPluralOperands_create_from_string') - .asFunction<_ResultOpaqueInt32 Function(ffi.Pointer, int)>(isLeaf: true); + _capi, ffi.Size)>>('ICU4XPluralOperands_create_from_string') + .asFunction<_ResultOpaqueInt32 Function(ffi.Pointer, int)>(isLeaf: true); } diff --git a/ffi/capi/dart/package/lib/src/PropertyValueNameToEnumMapper.g.dart b/ffi/capi/dart/package/lib/src/PropertyValueNameToEnumMapper.g.dart index cb03f5096ad..ad0b21ac07e 100644 --- a/ffi/capi/dart/package/lib/src/PropertyValueNameToEnumMapper.g.dart +++ b/ffi/capi/dart/package/lib/src/PropertyValueNameToEnumMapper.g.dart @@ -25,17 +25,17 @@ final class PropertyValueNameToEnumMapper implements ffi.Finalizable { /// /// See the [Rust documentation for `get_strict`](https://docs.rs/icu/latest/icu/properties/names/struct.PropertyValueNameToEnumMapperBorrowed.html#method.get_strict) for more information. int getStrict(String name) { - final alloc = ffi2.Arena(); - final nameSlice = _SliceFfi2Utf8._fromDart(name, alloc); - final result = _ICU4XPropertyValueNameToEnumMapper_get_strict(_underlying, nameSlice._bytes, nameSlice._length); - alloc.releaseAll(); + final temp = ffi2.Arena(); + final nameLength = name.utf8Length; + final result = _ICU4XPropertyValueNameToEnumMapper_get_strict(_underlying, Utf8Encoder().allocConvert(temp, name, length: nameLength), nameLength); + temp.releaseAll(); return result; } // ignore: non_constant_identifier_names static final _ICU4XPropertyValueNameToEnumMapper_get_strict = - _capi, ffi.Pointer, ffi.Size)>>('ICU4XPropertyValueNameToEnumMapper_get_strict') - .asFunction, ffi.Pointer, int)>(isLeaf: true); + _capi, ffi.Pointer, ffi.Size)>>('ICU4XPropertyValueNameToEnumMapper_get_strict') + .asFunction, ffi.Pointer, int)>(isLeaf: true); /// Get the property value matching the given name, using loose matching /// @@ -43,17 +43,17 @@ final class PropertyValueNameToEnumMapper implements ffi.Finalizable { /// /// See the [Rust documentation for `get_loose`](https://docs.rs/icu/latest/icu/properties/names/struct.PropertyValueNameToEnumMapperBorrowed.html#method.get_loose) for more information. int getLoose(String name) { - final alloc = ffi2.Arena(); - final nameSlice = _SliceFfi2Utf8._fromDart(name, alloc); - final result = _ICU4XPropertyValueNameToEnumMapper_get_loose(_underlying, nameSlice._bytes, nameSlice._length); - alloc.releaseAll(); + final temp = ffi2.Arena(); + final nameLength = name.utf8Length; + final result = _ICU4XPropertyValueNameToEnumMapper_get_loose(_underlying, Utf8Encoder().allocConvert(temp, name, length: nameLength), nameLength); + temp.releaseAll(); return result; } // ignore: non_constant_identifier_names static final _ICU4XPropertyValueNameToEnumMapper_get_loose = - _capi, ffi.Pointer, ffi.Size)>>('ICU4XPropertyValueNameToEnumMapper_get_loose') - .asFunction, ffi.Pointer, int)>(isLeaf: true); + _capi, ffi.Pointer, ffi.Size)>>('ICU4XPropertyValueNameToEnumMapper_get_loose') + .asFunction, ffi.Pointer, int)>(isLeaf: true); /// See the [Rust documentation for `get_name_to_enum_mapper`](https://docs.rs/icu/latest/icu/properties/struct.GeneralCategory.html#method.get_name_to_enum_mapper) for more information. /// diff --git a/ffi/capi/dart/package/lib/src/RegionDisplayNames.g.dart b/ffi/capi/dart/package/lib/src/RegionDisplayNames.g.dart index 60f6712523c..35e14f966e6 100644 --- a/ffi/capi/dart/package/lib/src/RegionDisplayNames.g.dart +++ b/ffi/capi/dart/package/lib/src/RegionDisplayNames.g.dart @@ -41,11 +41,11 @@ final class RegionDisplayNames implements ffi.Finalizable { /// /// Throws [Error] on failure. String of(String region) { - final alloc = ffi2.Arena(); - final regionSlice = _SliceFfi2Utf8._fromDart(region, alloc); + final temp = ffi2.Arena(); + final regionLength = region.utf8Length; final writeable = _Writeable(); - final result = _ICU4XRegionDisplayNames_of(_underlying, regionSlice._bytes, regionSlice._length, writeable._underlying); - alloc.releaseAll(); + final result = _ICU4XRegionDisplayNames_of(_underlying, Utf8Encoder().allocConvert(temp, region, length: regionLength), regionLength, writeable._underlying); + temp.releaseAll(); if (!result.isOk) { throw Error.values.firstWhere((v) => v._underlying == result.union.err); } @@ -54,6 +54,6 @@ final class RegionDisplayNames implements ffi.Finalizable { // ignore: non_constant_identifier_names static final _ICU4XRegionDisplayNames_of = - _capi, ffi.Pointer, ffi.Size, ffi.Pointer)>>('ICU4XRegionDisplayNames_of') - .asFunction<_ResultVoidInt32 Function(ffi.Pointer, ffi.Pointer, int, ffi.Pointer)>(isLeaf: true); + _capi, ffi.Pointer, ffi.Size, ffi.Pointer)>>('ICU4XRegionDisplayNames_of') + .asFunction<_ResultVoidInt32 Function(ffi.Pointer, ffi.Pointer, int, ffi.Pointer)>(isLeaf: true); } diff --git a/ffi/capi/dart/package/lib/src/ReorderedIndexMap.g.dart b/ffi/capi/dart/package/lib/src/ReorderedIndexMap.g.dart index 553be028a16..d74d7cc25cd 100644 --- a/ffi/capi/dart/package/lib/src/ReorderedIndexMap.g.dart +++ b/ffi/capi/dart/package/lib/src/ReorderedIndexMap.g.dart @@ -20,15 +20,15 @@ final class ReorderedIndexMap implements ffi.Finalizable { static final _finalizer = ffi.NativeFinalizer(_capi('ICU4XReorderedIndexMap_destroy')); /// Get this as a slice/array of indices - SizeList get asSlice { + core.List get asSlice { final result = _ICU4XReorderedIndexMap_as_slice(_underlying); - return result._asDart; + return core.Iterable.generate(result._length).map((i) => result._pointer[i]).toList(growable: false); } // ignore: non_constant_identifier_names static final _ICU4XReorderedIndexMap_as_slice = - _capi)>>('ICU4XReorderedIndexMap_as_slice') - .asFunction)>(isLeaf: true); + _capi)>>('ICU4XReorderedIndexMap_as_slice') + .asFunction<_SliceSize Function(ffi.Pointer)>(isLeaf: true); /// The length of this map int get length { diff --git a/ffi/capi/dart/package/lib/src/SentenceSegmenter.g.dart b/ffi/capi/dart/package/lib/src/SentenceSegmenter.g.dart index d656dbdd2bf..e992f498b93 100644 --- a/ffi/capi/dart/package/lib/src/SentenceSegmenter.g.dart +++ b/ffi/capi/dart/package/lib/src/SentenceSegmenter.g.dart @@ -35,30 +35,13 @@ final class SentenceSegmenter implements ffi.Finalizable { _capi)>>('ICU4XSentenceSegmenter_create') .asFunction<_ResultOpaqueInt32 Function(ffi.Pointer)>(isLeaf: true); - /// Segments a (potentially ill-formed) UTF-8 string. - /// - /// See the [Rust documentation for `segment_utf8`](https://docs.rs/icu/latest/icu/segmenter/struct.SentenceSegmenter.html#method.segment_utf8) for more information. - SentenceBreakIteratorUtf8 segmentUtf8(String input) { - final alloc = ffi2.Arena(); - final inputSlice = _SliceFfi2Utf8._fromDart(input, alloc); - final result = _ICU4XSentenceSegmenter_segment_utf8(_underlying, inputSlice._bytes, inputSlice._length); - alloc.releaseAll(); - return SentenceBreakIteratorUtf8._(result); - } - - // ignore: non_constant_identifier_names - static final _ICU4XSentenceSegmenter_segment_utf8 = - _capi Function(ffi.Pointer, ffi.Pointer, ffi.Size)>>('ICU4XSentenceSegmenter_segment_utf8') - .asFunction Function(ffi.Pointer, ffi.Pointer, int)>(isLeaf: true); - /// Segments a UTF-16 string. /// /// See the [Rust documentation for `segment_utf16`](https://docs.rs/icu/latest/icu/segmenter/struct.SentenceSegmenter.html#method.segment_utf16) for more information. - SentenceBreakIteratorUtf16 segmentUtf16(Uint16List input) { - final alloc = ffi2.Arena(); - final inputSlice = _SliceFfiUint16._fromDart(input, alloc); - final result = _ICU4XSentenceSegmenter_segment_utf16(_underlying, inputSlice._bytes, inputSlice._length); - alloc.releaseAll(); + SentenceBreakIteratorUtf16 segment(String input) { + final temp = ffi2.Arena(); + final result = _ICU4XSentenceSegmenter_segment_utf16(_underlying, input.copy(temp), input.length); + temp.releaseAll(); return SentenceBreakIteratorUtf16._(result); } @@ -66,20 +49,4 @@ final class SentenceSegmenter implements ffi.Finalizable { static final _ICU4XSentenceSegmenter_segment_utf16 = _capi Function(ffi.Pointer, ffi.Pointer, ffi.Size)>>('ICU4XSentenceSegmenter_segment_utf16') .asFunction Function(ffi.Pointer, ffi.Pointer, int)>(isLeaf: true); - - /// Segments a Latin-1 string. - /// - /// See the [Rust documentation for `segment_latin1`](https://docs.rs/icu/latest/icu/segmenter/struct.SentenceSegmenter.html#method.segment_latin1) for more information. - SentenceBreakIteratorLatin1 segmentLatin1(Uint8List input) { - final alloc = ffi2.Arena(); - final inputSlice = _SliceFfiUint8._fromDart(input, alloc); - final result = _ICU4XSentenceSegmenter_segment_latin1(_underlying, inputSlice._bytes, inputSlice._length); - alloc.releaseAll(); - return SentenceBreakIteratorLatin1._(result); - } - - // ignore: non_constant_identifier_names - static final _ICU4XSentenceSegmenter_segment_latin1 = - _capi Function(ffi.Pointer, ffi.Pointer, ffi.Size)>>('ICU4XSentenceSegmenter_segment_latin1') - .asFunction Function(ffi.Pointer, ffi.Pointer, int)>(isLeaf: true); } diff --git a/ffi/capi/dart/package/lib/src/TitlecaseMapper.g.dart b/ffi/capi/dart/package/lib/src/TitlecaseMapper.g.dart index a25cafe889f..7a21d419e3e 100644 --- a/ffi/capi/dart/package/lib/src/TitlecaseMapper.g.dart +++ b/ffi/capi/dart/package/lib/src/TitlecaseMapper.g.dart @@ -41,11 +41,11 @@ final class TitlecaseMapper implements ffi.Finalizable { /// /// Throws [Error] on failure. String titlecaseSegmentV1(String s, Locale locale, TitlecaseOptionsV1 options) { - final alloc = ffi2.Arena(); - final sSlice = _SliceFfi2Utf8._fromDart(s, alloc); + final temp = ffi2.Arena(); + final sLength = s.utf8Length; final writeable = _Writeable(); - final result = _ICU4XTitlecaseMapper_titlecase_segment_v1(_underlying, sSlice._bytes, sSlice._length, locale._underlying, options._underlying, writeable._underlying); - alloc.releaseAll(); + final result = _ICU4XTitlecaseMapper_titlecase_segment_v1(_underlying, Utf8Encoder().allocConvert(temp, s, length: sLength), sLength, locale._underlying, options._underlying, writeable._underlying); + temp.releaseAll(); if (!result.isOk) { throw Error.values.firstWhere((v) => v._underlying == result.union.err); } @@ -54,6 +54,6 @@ final class TitlecaseMapper implements ffi.Finalizable { // ignore: non_constant_identifier_names static final _ICU4XTitlecaseMapper_titlecase_segment_v1 = - _capi, ffi.Pointer, ffi.Size, ffi.Pointer, _TitlecaseOptionsV1Ffi, ffi.Pointer)>>('ICU4XTitlecaseMapper_titlecase_segment_v1') - .asFunction<_ResultVoidInt32 Function(ffi.Pointer, ffi.Pointer, int, ffi.Pointer, _TitlecaseOptionsV1Ffi, ffi.Pointer)>(isLeaf: true); + _capi, ffi.Pointer, ffi.Size, ffi.Pointer, _TitlecaseOptionsV1Ffi, ffi.Pointer)>>('ICU4XTitlecaseMapper_titlecase_segment_v1') + .asFunction<_ResultVoidInt32 Function(ffi.Pointer, ffi.Pointer, int, ffi.Pointer, _TitlecaseOptionsV1Ffi, ffi.Pointer)>(isLeaf: true); } diff --git a/ffi/capi/dart/package/lib/src/TitlecaseOptionsV1.g.dart b/ffi/capi/dart/package/lib/src/TitlecaseOptionsV1.g.dart index b95c86cec8d..f44e87c2b51 100644 --- a/ffi/capi/dart/package/lib/src/TitlecaseOptionsV1.g.dart +++ b/ffi/capi/dart/package/lib/src/TitlecaseOptionsV1.g.dart @@ -16,7 +16,6 @@ final class _TitlecaseOptionsV1Ffi extends ffi.Struct { final class TitlecaseOptionsV1 { final _TitlecaseOptionsV1Ffi _underlying; - // ignore: unused_element TitlecaseOptionsV1._(this._underlying); factory TitlecaseOptionsV1() { diff --git a/ffi/capi/dart/package/lib/src/UnicodeSetData.g.dart b/ffi/capi/dart/package/lib/src/UnicodeSetData.g.dart index e7ec6820f4c..336eaba4591 100644 --- a/ffi/capi/dart/package/lib/src/UnicodeSetData.g.dart +++ b/ffi/capi/dart/package/lib/src/UnicodeSetData.g.dart @@ -25,17 +25,17 @@ final class UnicodeSetData implements ffi.Finalizable { /// /// See the [Rust documentation for `contains`](https://docs.rs/icu/latest/icu/properties/sets/struct.UnicodeSetDataBorrowed.html#method.contains) for more information. bool contains(String s) { - final alloc = ffi2.Arena(); - final sSlice = _SliceFfi2Utf8._fromDart(s, alloc); - final result = _ICU4XUnicodeSetData_contains(_underlying, sSlice._bytes, sSlice._length); - alloc.releaseAll(); + final temp = ffi2.Arena(); + final sLength = s.utf8Length; + final result = _ICU4XUnicodeSetData_contains(_underlying, Utf8Encoder().allocConvert(temp, s, length: sLength), sLength); + temp.releaseAll(); return result; } // ignore: non_constant_identifier_names static final _ICU4XUnicodeSetData_contains = - _capi, ffi.Pointer, ffi.Size)>>('ICU4XUnicodeSetData_contains') - .asFunction, ffi.Pointer, int)>(isLeaf: true); + _capi, ffi.Pointer, ffi.Size)>>('ICU4XUnicodeSetData_contains') + .asFunction, ffi.Pointer, int)>(isLeaf: true); /// Checks whether the code point is in the set. /// diff --git a/ffi/capi/dart/package/lib/src/WeekOf.g.dart b/ffi/capi/dart/package/lib/src/WeekOf.g.dart index cb607e225ce..433235826e1 100644 --- a/ffi/capi/dart/package/lib/src/WeekOf.g.dart +++ b/ffi/capi/dart/package/lib/src/WeekOf.g.dart @@ -16,7 +16,6 @@ final class _WeekOfFfi extends ffi.Struct { final class WeekOf { final _WeekOfFfi _underlying; - // ignore: unused_element WeekOf._(this._underlying); factory WeekOf() { diff --git a/ffi/capi/dart/package/lib/src/WordSegmenter.g.dart b/ffi/capi/dart/package/lib/src/WordSegmenter.g.dart index 834833b8951..077bf8b1f65 100644 --- a/ffi/capi/dart/package/lib/src/WordSegmenter.g.dart +++ b/ffi/capi/dart/package/lib/src/WordSegmenter.g.dart @@ -80,30 +80,13 @@ final class WordSegmenter implements ffi.Finalizable { _capi)>>('ICU4XWordSegmenter_create_dictionary') .asFunction<_ResultOpaqueInt32 Function(ffi.Pointer)>(isLeaf: true); - /// Segments a (potentially ill-formed) UTF-8 string. - /// - /// See the [Rust documentation for `segment_utf8`](https://docs.rs/icu/latest/icu/segmenter/struct.WordSegmenter.html#method.segment_utf8) for more information. - WordBreakIteratorUtf8 segmentUtf8(String input) { - final alloc = ffi2.Arena(); - final inputSlice = _SliceFfi2Utf8._fromDart(input, alloc); - final result = _ICU4XWordSegmenter_segment_utf8(_underlying, inputSlice._bytes, inputSlice._length); - alloc.releaseAll(); - return WordBreakIteratorUtf8._(result); - } - - // ignore: non_constant_identifier_names - static final _ICU4XWordSegmenter_segment_utf8 = - _capi Function(ffi.Pointer, ffi.Pointer, ffi.Size)>>('ICU4XWordSegmenter_segment_utf8') - .asFunction Function(ffi.Pointer, ffi.Pointer, int)>(isLeaf: true); - /// Segments a UTF-16 string. /// /// See the [Rust documentation for `segment_utf16`](https://docs.rs/icu/latest/icu/segmenter/struct.WordSegmenter.html#method.segment_utf16) for more information. - WordBreakIteratorUtf16 segmentUtf16(Uint16List input) { - final alloc = ffi2.Arena(); - final inputSlice = _SliceFfiUint16._fromDart(input, alloc); - final result = _ICU4XWordSegmenter_segment_utf16(_underlying, inputSlice._bytes, inputSlice._length); - alloc.releaseAll(); + WordBreakIteratorUtf16 segment(String input) { + final temp = ffi2.Arena(); + final result = _ICU4XWordSegmenter_segment_utf16(_underlying, input.copy(temp), input.length); + temp.releaseAll(); return WordBreakIteratorUtf16._(result); } @@ -111,20 +94,4 @@ final class WordSegmenter implements ffi.Finalizable { static final _ICU4XWordSegmenter_segment_utf16 = _capi Function(ffi.Pointer, ffi.Pointer, ffi.Size)>>('ICU4XWordSegmenter_segment_utf16') .asFunction Function(ffi.Pointer, ffi.Pointer, int)>(isLeaf: true); - - /// Segments a Latin-1 string. - /// - /// See the [Rust documentation for `segment_latin1`](https://docs.rs/icu/latest/icu/segmenter/struct.WordSegmenter.html#method.segment_latin1) for more information. - WordBreakIteratorLatin1 segmentLatin1(Uint8List input) { - final alloc = ffi2.Arena(); - final inputSlice = _SliceFfiUint8._fromDart(input, alloc); - final result = _ICU4XWordSegmenter_segment_latin1(_underlying, inputSlice._bytes, inputSlice._length); - alloc.releaseAll(); - return WordBreakIteratorLatin1._(result); - } - - // ignore: non_constant_identifier_names - static final _ICU4XWordSegmenter_segment_latin1 = - _capi Function(ffi.Pointer, ffi.Pointer, ffi.Size)>>('ICU4XWordSegmenter_segment_latin1') - .asFunction Function(ffi.Pointer, ffi.Pointer, int)>(isLeaf: true); } diff --git a/ffi/capi/dart/package/lib/src/lib.g.dart b/ffi/capi/dart/package/lib/src/lib.g.dart index 2e28d9b5f4a..6c6aba69ff8 100644 --- a/ffi/capi/dart/package/lib/src/lib.g.dart +++ b/ffi/capi/dart/package/lib/src/lib.g.dart @@ -3,10 +3,12 @@ // https://github.com/dart-lang/sdk/issues/53946 // ignore_for_file: non_native_function_type_argument_to_pointer -import 'dart:convert'; -import 'dart:ffi' as ffi; -import 'dart:typed_data'; -import 'package:ffi/ffi.dart' as ffi2; +import 'dart:convert' ; +import 'dart:core'as core; +import 'dart:core'show int, double, bool, String, Object, override; +import 'dart:ffi'as ffi; +import 'dart:typed_data' ; +import 'package:ffi/ffi.dart'as ffi2 show Arena, calloc; part 'AnyCalendarKind.g.dart'; part 'Bcp47ToIanaMapper.g.dart'; part 'Bidi.g.dart'; @@ -149,37 +151,100 @@ typedef RuneList = Uint32List; late final ffi.Pointer Function(String) _capi; void init(String path) => _capi = ffi.DynamicLibrary.open(path).lookup; -final _callocFree = Finalizer(ffi2.calloc.free); +final _callocFree = core.Finalizer(ffi2.calloc.free); -final class SizeList extends ffi.Struct { - external ffi.Pointer _bytes; +extension _AllocConvert on Utf8Encoder { + ffi.Pointer allocConvert(ffi.Allocator alloc, String string, {int? length}) { + final l = length ?? string.utf8Length; + return alloc(l)..asTypedList(l).setAll(0, convert(string)); + } +} - @ffi.Size() - external int _length; +extension _Utf8Length on String { + int get utf8Length { + var length = 0; + for (var rune in runes) { + if (rune < 0x80) { + length += 1; + } else if (rune < 0x800) { + length += 2; + } else if (rune < 0x10000) { + length += 3; + } else { + length += 4; + } + } + return length; + } +} - // ignore: unused_element - SizeList get _asDart => this; +extension _CopyString on String { + ffi.Pointer copy(ffi.Allocator alloc) { + return alloc(length)..asTypedList(length).setAll(0, codeUnits); + } +} - // This is expensive - @override - bool operator ==(Object other) { - if (other is! SizeList || other._length != _length) { - return false; - } +extension _CopyInt8List on Int8List { + ffi.Pointer copy(ffi.Allocator alloc) { + return alloc(length)..asTypedList(length).setAll(0, this); + } +} - for (var i = 0; i < _length; i++) { - if (other._bytes[i] != _bytes[i]) { - return false; - } - } - return true; +extension _CopyInt16List on Int16List { + ffi.Pointer copy(ffi.Allocator alloc) { + return alloc(length)..asTypedList(length).setAll(0, this); } +} - // This is cheap - @override - int get hashCode => _length.hashCode; +extension _CopyInt32List on Int32List { + ffi.Pointer copy(ffi.Allocator alloc) { + return alloc(length)..asTypedList(length).setAll(0, this); + } +} + +extension _CopyInt64List on Int64List { + ffi.Pointer copy(ffi.Allocator alloc) { + return alloc(length)..asTypedList(length).setAll(0, this); + } +} + +extension _CopyUint8List on Uint8List { + ffi.Pointer copy(ffi.Allocator alloc) { + return alloc(length)..asTypedList(length).setAll(0, this); + } +} + +extension _CopyUint16List on Uint16List { + ffi.Pointer copy(ffi.Allocator alloc) { + return alloc(length)..asTypedList(length).setAll(0, this); + } } +extension _CopyUint32List on Uint32List { + ffi.Pointer copy(ffi.Allocator alloc) { + return alloc(length)..asTypedList(length).setAll(0, this); + } +} + +extension _CopyUint64List on Uint64List { + ffi.Pointer copy(ffi.Allocator alloc) { + return alloc(length)..asTypedList(length).setAll(0, this); + } +} + +extension _CopyFloat32List on Float32List { + ffi.Pointer copy(ffi.Allocator alloc) { + return alloc(length)..asTypedList(length).setAll(0, this); + } +} + +extension _CopyFloat64List on Float64List { + ffi.Pointer copy(ffi.Allocator alloc) { + return alloc(length)..asTypedList(length).setAll(0, this); + } +} + + final class _ResultBoolInt32Union extends ffi.Union { @ffi.Bool() external bool ok; @@ -281,37 +346,21 @@ final class _ResultWeekOfFfiInt32 extends ffi.Struct { external bool isOk; } -final class _SliceFfi2Utf8 extends ffi.Struct { - external ffi.Pointer _bytes; +final class _SliceSize extends ffi.Struct { + external ffi.Pointer _pointer; @ffi.Size() external int _length; - /// Produces a slice from a Dart object. The Dart object's data is copied into the given allocator - /// as it cannot be borrowed directly, and gets freed with the slice object. - // ignore: unused_element - static _SliceFfi2Utf8 _fromDart(String value, ffi.Allocator allocator) { - final pointer = allocator<_SliceFfi2Utf8>(); - final slice = pointer.ref; - final units = Utf8Encoder().convert(value); - slice._length = units.length; - slice._bytes = allocator(slice._length).cast(); - slice._bytes.cast().asTypedList(slice._length).setAll(0, units); - return slice; - } - - // ignore: unused_element - String get _asDart => Utf8Decoder().convert(_bytes.cast().asTypedList(_length)); - // This is expensive @override bool operator ==(Object other) { - if (other is! _SliceFfi2Utf8 || other._length != _length) { + if (other is! _SliceSize || other._length != _length) { return false; } for (var i = 0; i < _length; i++) { - if (other._bytes.cast()[i] != _bytes.cast()[i]) { + if (other._pointer[i] != _pointer[i]) { return false; } } @@ -323,77 +372,21 @@ final class _SliceFfi2Utf8 extends ffi.Struct { int get hashCode => _length.hashCode; } -final class _SliceFfiUint16 extends ffi.Struct { - external ffi.Pointer _bytes; +final class _SliceUtf8 extends ffi.Struct { + external ffi.Pointer _pointer; @ffi.Size() external int _length; - /// Produces a slice from a Dart object. The Dart object's data is copied into the given allocator - /// as it cannot be borrowed directly, and gets freed with the slice object. - // ignore: unused_element - static _SliceFfiUint16 _fromDart(Uint16List value, ffi.Allocator allocator) { - final pointer = allocator<_SliceFfiUint16>(); - final slice = pointer.ref; - slice._length = value.length; - slice._bytes = allocator(slice._length); - slice._bytes.asTypedList(slice._length).setAll(0, value); - return slice; - } - - // ignore: unused_element - Uint16List get _asDart => _bytes.asTypedList(_length); - - // This is expensive - @override - bool operator ==(Object other) { - if (other is! _SliceFfiUint16 || other._length != _length) { - return false; - } - - for (var i = 0; i < _length; i++) { - if (other._bytes[i] != _bytes[i]) { - return false; - } - } - return true; - } - - // This is cheap - @override - int get hashCode => _length.hashCode; -} - -final class _SliceFfiUint8 extends ffi.Struct { - external ffi.Pointer _bytes; - - @ffi.Size() - external int _length; - - /// Produces a slice from a Dart object. The Dart object's data is copied into the given allocator - /// as it cannot be borrowed directly, and gets freed with the slice object. - // ignore: unused_element - static _SliceFfiUint8 _fromDart(Uint8List value, ffi.Allocator allocator) { - final pointer = allocator<_SliceFfiUint8>(); - final slice = pointer.ref; - slice._length = value.length; - slice._bytes = allocator(slice._length); - slice._bytes.asTypedList(slice._length).setAll(0, value); - return slice; - } - - // ignore: unused_element - Uint8List get _asDart => _bytes.asTypedList(_length); - // This is expensive @override bool operator ==(Object other) { - if (other is! _SliceFfiUint8 || other._length != _length) { + if (other is! _SliceUtf8 || other._length != _length) { return false; } for (var i = 0; i < _length; i++) { - if (other._bytes[i] != _bytes[i]) { + if (other._pointer[i] != _pointer[i]) { return false; } } @@ -417,7 +410,7 @@ final class _Writeable { .asFunction Function(int)>(); String finalize() { - final string = _getBytes(_underlying).toDartString(length: _len(_underlying)); + final string = Utf8Decoder().convert(_getBytes(_underlying).asTypedList(_len(_underlying))); _destroy(_underlying); return string; } @@ -426,8 +419,8 @@ final class _Writeable { .asFunction)>(isLeaf: true); static final _getBytes = - _capi Function(ffi.Pointer)>>('diplomat_buffer_writeable_get_bytes') - .asFunction Function(ffi.Pointer)>(isLeaf: true); + _capi Function(ffi.Pointer)>>('diplomat_buffer_writeable_get_bytes') + .asFunction Function(ffi.Pointer)>(isLeaf: true); static final _destroy = _capi)>>('diplomat_buffer_writeable_destroy') .asFunction)>(isLeaf: true); diff --git a/ffi/capi/js/package/docs/source/collator_ffi.rst b/ffi/capi/js/package/docs/source/collator_ffi.rst index 2127d2713d6..a9e71c34f83 100644 --- a/ffi/capi/js/package/docs/source/collator_ffi.rst +++ b/ffi/capi/js/package/docs/source/collator_ffi.rst @@ -37,10 +37,6 @@ See the `Rust documentation for compare_utf16 `__ for more information. - - Note: ``left`` should be an ArrayBuffer or TypedArray corresponding to the slice type expected by Rust. - - - Note: ``right`` should be an ArrayBuffer or TypedArray corresponding to the slice type expected by Rust. - .. js:class:: ICU4XCollatorAlternateHandling diff --git a/ffi/capi/js/package/docs/source/segmenter_grapheme_ffi.rst b/ffi/capi/js/package/docs/source/segmenter_grapheme_ffi.rst index be0fd9192ef..501b1f32b9a 100644 --- a/ffi/capi/js/package/docs/source/segmenter_grapheme_ffi.rst +++ b/ffi/capi/js/package/docs/source/segmenter_grapheme_ffi.rst @@ -64,8 +64,6 @@ See the `Rust documentation for segment_utf16 `__ for more information. - - Note: ``input`` should be an ArrayBuffer or TypedArray corresponding to the slice type expected by Rust. - .. js:method:: segment_latin1(input) diff --git a/ffi/capi/js/package/docs/source/segmenter_line_ffi.rst b/ffi/capi/js/package/docs/source/segmenter_line_ffi.rst index 9a991deb83e..bb50acd8bc9 100644 --- a/ffi/capi/js/package/docs/source/segmenter_line_ffi.rst +++ b/ffi/capi/js/package/docs/source/segmenter_line_ffi.rst @@ -126,8 +126,6 @@ See the `Rust documentation for segment_utf16 `__ for more information. - - Note: ``input`` should be an ArrayBuffer or TypedArray corresponding to the slice type expected by Rust. - .. js:method:: segment_latin1(input) diff --git a/ffi/capi/js/package/docs/source/segmenter_sentence_ffi.rst b/ffi/capi/js/package/docs/source/segmenter_sentence_ffi.rst index b1f15a28683..b6668fc1a3c 100644 --- a/ffi/capi/js/package/docs/source/segmenter_sentence_ffi.rst +++ b/ffi/capi/js/package/docs/source/segmenter_sentence_ffi.rst @@ -64,8 +64,6 @@ See the `Rust documentation for segment_utf16 `__ for more information. - - Note: ``input`` should be an ArrayBuffer or TypedArray corresponding to the slice type expected by Rust. - .. js:method:: segment_latin1(input) diff --git a/ffi/capi/js/package/docs/source/segmenter_word_ffi.rst b/ffi/capi/js/package/docs/source/segmenter_word_ffi.rst index 913ef3479e1..e628df662a5 100644 --- a/ffi/capi/js/package/docs/source/segmenter_word_ffi.rst +++ b/ffi/capi/js/package/docs/source/segmenter_word_ffi.rst @@ -129,8 +129,6 @@ See the `Rust documentation for segment_utf16 `__ for more information. - - Note: ``input`` should be an ArrayBuffer or TypedArray corresponding to the slice type expected by Rust. - .. js:method:: segment_latin1(input) diff --git a/ffi/capi/js/package/lib/ICU4XBcp47ToIanaMapper.js b/ffi/capi/js/package/lib/ICU4XBcp47ToIanaMapper.js index bca64227b96..0be7e790f50 100644 --- a/ffi/capi/js/package/lib/ICU4XBcp47ToIanaMapper.js +++ b/ffi/capi/js/package/lib/ICU4XBcp47ToIanaMapper.js @@ -34,7 +34,7 @@ export class ICU4XBcp47ToIanaMapper { } get(arg_value) { - const buf_arg_value = diplomatRuntime.DiplomatBuf.str(wasm, arg_value); + const buf_arg_value = diplomatRuntime.DiplomatBuf.str8(wasm, arg_value); const diplomat_out = diplomatRuntime.withWriteable(wasm, (writeable) => { return (() => { const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); diff --git a/ffi/capi/js/package/lib/ICU4XBidi.js b/ffi/capi/js/package/lib/ICU4XBidi.js index 18676b88740..2e82d33925f 100644 --- a/ffi/capi/js/package/lib/ICU4XBidi.js +++ b/ffi/capi/js/package/lib/ICU4XBidi.js @@ -36,7 +36,7 @@ export class ICU4XBidi { } for_text(arg_text, arg_default_level) { - const buf_arg_text = diplomatRuntime.DiplomatBuf.str(wasm, arg_text); + const buf_arg_text = diplomatRuntime.DiplomatBuf.str8(wasm, arg_text); return new ICU4XBidiInfo(wasm.ICU4XBidi_for_text(this.underlying, buf_arg_text.ptr, buf_arg_text.size, arg_default_level), true, [buf_arg_text]); } diff --git a/ffi/capi/js/package/lib/ICU4XCaseMapCloser.js b/ffi/capi/js/package/lib/ICU4XCaseMapCloser.js index 1d908278be0..74b2660139f 100644 --- a/ffi/capi/js/package/lib/ICU4XCaseMapCloser.js +++ b/ffi/capi/js/package/lib/ICU4XCaseMapCloser.js @@ -38,7 +38,7 @@ export class ICU4XCaseMapCloser { } add_string_case_closure_to(arg_s, arg_builder) { - const buf_arg_s = diplomatRuntime.DiplomatBuf.str(wasm, arg_s); + const buf_arg_s = diplomatRuntime.DiplomatBuf.str8(wasm, arg_s); const diplomat_out = wasm.ICU4XCaseMapCloser_add_string_case_closure_to(this.underlying, buf_arg_s.ptr, buf_arg_s.size, arg_builder.underlying); buf_arg_s.free(); return diplomat_out; diff --git a/ffi/capi/js/package/lib/ICU4XCaseMapper.js b/ffi/capi/js/package/lib/ICU4XCaseMapper.js index b6bf60bdda9..65cac00fcc7 100644 --- a/ffi/capi/js/package/lib/ICU4XCaseMapper.js +++ b/ffi/capi/js/package/lib/ICU4XCaseMapper.js @@ -36,7 +36,7 @@ export class ICU4XCaseMapper { } lowercase(arg_s, arg_locale) { - const buf_arg_s = diplomatRuntime.DiplomatBuf.str(wasm, arg_s); + const buf_arg_s = diplomatRuntime.DiplomatBuf.str8(wasm, arg_s); const diplomat_out = diplomatRuntime.withWriteable(wasm, (writeable) => { return (() => { const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); @@ -58,7 +58,7 @@ export class ICU4XCaseMapper { } uppercase(arg_s, arg_locale) { - const buf_arg_s = diplomatRuntime.DiplomatBuf.str(wasm, arg_s); + const buf_arg_s = diplomatRuntime.DiplomatBuf.str8(wasm, arg_s); const diplomat_out = diplomatRuntime.withWriteable(wasm, (writeable) => { return (() => { const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); @@ -80,7 +80,7 @@ export class ICU4XCaseMapper { } titlecase_segment_with_only_case_data_v1(arg_s, arg_locale, arg_options) { - const buf_arg_s = diplomatRuntime.DiplomatBuf.str(wasm, arg_s); + const buf_arg_s = diplomatRuntime.DiplomatBuf.str8(wasm, arg_s); 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) => { @@ -104,7 +104,7 @@ export class ICU4XCaseMapper { } fold(arg_s) { - const buf_arg_s = diplomatRuntime.DiplomatBuf.str(wasm, arg_s); + const buf_arg_s = diplomatRuntime.DiplomatBuf.str8(wasm, arg_s); const diplomat_out = diplomatRuntime.withWriteable(wasm, (writeable) => { return (() => { const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); @@ -126,7 +126,7 @@ export class ICU4XCaseMapper { } fold_turkic(arg_s) { - const buf_arg_s = diplomatRuntime.DiplomatBuf.str(wasm, arg_s); + const buf_arg_s = diplomatRuntime.DiplomatBuf.str8(wasm, arg_s); const diplomat_out = diplomatRuntime.withWriteable(wasm, (writeable) => { return (() => { const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); diff --git a/ffi/capi/js/package/lib/ICU4XCodePointSetData.js b/ffi/capi/js/package/lib/ICU4XCodePointSetData.js index 55a1605d4e6..bcf6757302f 100644 --- a/ffi/capi/js/package/lib/ICU4XCodePointSetData.js +++ b/ffi/capi/js/package/lib/ICU4XCodePointSetData.js @@ -1156,7 +1156,7 @@ export class ICU4XCodePointSetData { } static load_for_ecma262(arg_provider, arg_property_name) { - const buf_arg_property_name = diplomatRuntime.DiplomatBuf.str(wasm, arg_property_name); + const buf_arg_property_name = diplomatRuntime.DiplomatBuf.str8(wasm, arg_property_name); const diplomat_out = (() => { const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); wasm.ICU4XCodePointSetData_load_for_ecma262(diplomat_receive_buffer, arg_provider.underlying, buf_arg_property_name.ptr, buf_arg_property_name.size); diff --git a/ffi/capi/js/package/lib/ICU4XCollator.d.ts b/ffi/capi/js/package/lib/ICU4XCollator.d.ts index 92e572493c8..b75dc36aa56 100644 --- a/ffi/capi/js/package/lib/ICU4XCollator.d.ts +++ b/ffi/capi/js/package/lib/ICU4XCollator.d.ts @@ -46,5 +46,5 @@ export class ICU4XCollator { * See the {@link https://docs.rs/icu/latest/icu/collator/struct.Collator.html#method.compare_utf16 Rust documentation for `compare_utf16`} for more information. */ - compare_utf16(left: Uint16Array, right: Uint16Array): ICU4XOrdering; + compare_utf16(left: string, right: string): ICU4XOrdering; } diff --git a/ffi/capi/js/package/lib/ICU4XCollator.js b/ffi/capi/js/package/lib/ICU4XCollator.js index 5fc796cbd24..9f2dacc8558 100644 --- a/ffi/capi/js/package/lib/ICU4XCollator.js +++ b/ffi/capi/js/package/lib/ICU4XCollator.js @@ -49,8 +49,8 @@ export class ICU4XCollator { } compare(arg_left, arg_right) { - const buf_arg_left = diplomatRuntime.DiplomatBuf.str(wasm, arg_left); - const buf_arg_right = diplomatRuntime.DiplomatBuf.str(wasm, arg_right); + const buf_arg_left = diplomatRuntime.DiplomatBuf.str8(wasm, arg_left); + const buf_arg_right = diplomatRuntime.DiplomatBuf.str8(wasm, arg_right); const diplomat_out = ICU4XOrdering_rust_to_js[wasm.ICU4XCollator_compare(this.underlying, buf_arg_left.ptr, buf_arg_left.size, buf_arg_right.ptr, buf_arg_right.size)]; buf_arg_left.free(); buf_arg_right.free(); @@ -58,8 +58,8 @@ export class ICU4XCollator { } compare_valid_utf8(arg_left, arg_right) { - const buf_arg_left = diplomatRuntime.DiplomatBuf.str(wasm, arg_left); - const buf_arg_right = diplomatRuntime.DiplomatBuf.str(wasm, arg_right); + const buf_arg_left = diplomatRuntime.DiplomatBuf.str8(wasm, arg_left); + const buf_arg_right = diplomatRuntime.DiplomatBuf.str8(wasm, arg_right); const diplomat_out = ICU4XOrdering_rust_to_js[wasm.ICU4XCollator_compare_valid_utf8(this.underlying, buf_arg_left.ptr, buf_arg_left.size, buf_arg_right.ptr, buf_arg_right.size)]; buf_arg_left.free(); buf_arg_right.free(); @@ -67,8 +67,8 @@ export class ICU4XCollator { } compare_utf16(arg_left, arg_right) { - const buf_arg_left = diplomatRuntime.DiplomatBuf.slice(wasm, arg_left, 2); - const buf_arg_right = diplomatRuntime.DiplomatBuf.slice(wasm, arg_right, 2); + const buf_arg_left = diplomatRuntime.DiplomatBuf.str16(wasm, arg_left, 2); + const buf_arg_right = diplomatRuntime.DiplomatBuf.str16(wasm, arg_right, 2); const diplomat_out = ICU4XOrdering_rust_to_js[wasm.ICU4XCollator_compare_utf16(this.underlying, buf_arg_left.ptr, buf_arg_left.size, buf_arg_right.ptr, buf_arg_right.size)]; buf_arg_left.free(); buf_arg_right.free(); diff --git a/ffi/capi/js/package/lib/ICU4XComposingNormalizer.js b/ffi/capi/js/package/lib/ICU4XComposingNormalizer.js index 8793316b7ac..68982d84f07 100644 --- a/ffi/capi/js/package/lib/ICU4XComposingNormalizer.js +++ b/ffi/capi/js/package/lib/ICU4XComposingNormalizer.js @@ -51,7 +51,7 @@ export class ICU4XComposingNormalizer { } normalize(arg_s) { - const buf_arg_s = diplomatRuntime.DiplomatBuf.str(wasm, arg_s); + const buf_arg_s = diplomatRuntime.DiplomatBuf.str8(wasm, arg_s); const diplomat_out = diplomatRuntime.withWriteable(wasm, (writeable) => { return (() => { const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); @@ -73,7 +73,7 @@ export class ICU4XComposingNormalizer { } is_normalized(arg_s) { - const buf_arg_s = diplomatRuntime.DiplomatBuf.str(wasm, arg_s); + const buf_arg_s = diplomatRuntime.DiplomatBuf.str8(wasm, arg_s); const diplomat_out = wasm.ICU4XComposingNormalizer_is_normalized(this.underlying, buf_arg_s.ptr, buf_arg_s.size); buf_arg_s.free(); return diplomat_out; diff --git a/ffi/capi/js/package/lib/ICU4XCustomTimeZone.js b/ffi/capi/js/package/lib/ICU4XCustomTimeZone.js index 615f0b2ea8f..d18c51e31b0 100644 --- a/ffi/capi/js/package/lib/ICU4XCustomTimeZone.js +++ b/ffi/capi/js/package/lib/ICU4XCustomTimeZone.js @@ -17,7 +17,7 @@ export class ICU4XCustomTimeZone { } static create_from_string(arg_s) { - const buf_arg_s = diplomatRuntime.DiplomatBuf.str(wasm, arg_s); + const buf_arg_s = diplomatRuntime.DiplomatBuf.str8(wasm, arg_s); const diplomat_out = (() => { const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); wasm.ICU4XCustomTimeZone_create_from_string(diplomat_receive_buffer, buf_arg_s.ptr, buf_arg_s.size); @@ -151,7 +151,7 @@ export class ICU4XCustomTimeZone { } try_set_time_zone_id(arg_id) { - const buf_arg_id = diplomatRuntime.DiplomatBuf.str(wasm, arg_id); + const buf_arg_id = diplomatRuntime.DiplomatBuf.str8(wasm, arg_id); const diplomat_out = (() => { const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); wasm.ICU4XCustomTimeZone_try_set_time_zone_id(diplomat_receive_buffer, this.underlying, buf_arg_id.ptr, buf_arg_id.size); @@ -171,7 +171,7 @@ export class ICU4XCustomTimeZone { } try_set_iana_time_zone_id(arg_mapper, arg_id) { - const buf_arg_id = diplomatRuntime.DiplomatBuf.str(wasm, arg_id); + const buf_arg_id = diplomatRuntime.DiplomatBuf.str8(wasm, arg_id); const diplomat_out = (() => { const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); wasm.ICU4XCustomTimeZone_try_set_iana_time_zone_id(diplomat_receive_buffer, this.underlying, arg_mapper.underlying, buf_arg_id.ptr, buf_arg_id.size); @@ -214,7 +214,7 @@ export class ICU4XCustomTimeZone { } try_set_metazone_id(arg_id) { - const buf_arg_id = diplomatRuntime.DiplomatBuf.str(wasm, arg_id); + const buf_arg_id = diplomatRuntime.DiplomatBuf.str8(wasm, arg_id); const diplomat_out = (() => { const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); wasm.ICU4XCustomTimeZone_try_set_metazone_id(diplomat_receive_buffer, this.underlying, buf_arg_id.ptr, buf_arg_id.size); @@ -257,7 +257,7 @@ export class ICU4XCustomTimeZone { } try_set_zone_variant(arg_id) { - const buf_arg_id = diplomatRuntime.DiplomatBuf.str(wasm, arg_id); + const buf_arg_id = diplomatRuntime.DiplomatBuf.str8(wasm, arg_id); const diplomat_out = (() => { const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); wasm.ICU4XCustomTimeZone_try_set_zone_variant(diplomat_receive_buffer, this.underlying, buf_arg_id.ptr, buf_arg_id.size); diff --git a/ffi/capi/js/package/lib/ICU4XDataProvider.js b/ffi/capi/js/package/lib/ICU4XDataProvider.js index 93341c6d6f2..980a1f7a99d 100644 --- a/ffi/capi/js/package/lib/ICU4XDataProvider.js +++ b/ffi/capi/js/package/lib/ICU4XDataProvider.js @@ -21,7 +21,7 @@ export class ICU4XDataProvider { } static create_fs(arg_path) { - const buf_arg_path = diplomatRuntime.DiplomatBuf.str(wasm, arg_path); + const buf_arg_path = diplomatRuntime.DiplomatBuf.str8(wasm, arg_path); const diplomat_out = (() => { const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); wasm.ICU4XDataProvider_create_fs(diplomat_receive_buffer, buf_arg_path.ptr, buf_arg_path.size); diff --git a/ffi/capi/js/package/lib/ICU4XDataStruct.js b/ffi/capi/js/package/lib/ICU4XDataStruct.js index 22bc10d69b2..c4010b32c39 100644 --- a/ffi/capi/js/package/lib/ICU4XDataStruct.js +++ b/ffi/capi/js/package/lib/ICU4XDataStruct.js @@ -17,12 +17,12 @@ export class ICU4XDataStruct { } static create_decimal_symbols_v1(arg_plus_sign_prefix, arg_plus_sign_suffix, arg_minus_sign_prefix, arg_minus_sign_suffix, arg_decimal_separator, arg_grouping_separator, arg_primary_group_size, arg_secondary_group_size, arg_min_group_size, arg_digits) { - const buf_arg_plus_sign_prefix = diplomatRuntime.DiplomatBuf.str(wasm, arg_plus_sign_prefix); - const buf_arg_plus_sign_suffix = diplomatRuntime.DiplomatBuf.str(wasm, arg_plus_sign_suffix); - const buf_arg_minus_sign_prefix = diplomatRuntime.DiplomatBuf.str(wasm, arg_minus_sign_prefix); - const buf_arg_minus_sign_suffix = diplomatRuntime.DiplomatBuf.str(wasm, arg_minus_sign_suffix); - const buf_arg_decimal_separator = diplomatRuntime.DiplomatBuf.str(wasm, arg_decimal_separator); - const buf_arg_grouping_separator = diplomatRuntime.DiplomatBuf.str(wasm, arg_grouping_separator); + const buf_arg_plus_sign_prefix = diplomatRuntime.DiplomatBuf.str8(wasm, arg_plus_sign_prefix); + const buf_arg_plus_sign_suffix = diplomatRuntime.DiplomatBuf.str8(wasm, arg_plus_sign_suffix); + const buf_arg_minus_sign_prefix = diplomatRuntime.DiplomatBuf.str8(wasm, arg_minus_sign_prefix); + const buf_arg_minus_sign_suffix = diplomatRuntime.DiplomatBuf.str8(wasm, arg_minus_sign_suffix); + const buf_arg_decimal_separator = diplomatRuntime.DiplomatBuf.str8(wasm, arg_decimal_separator); + const buf_arg_grouping_separator = diplomatRuntime.DiplomatBuf.str8(wasm, arg_grouping_separator); const buf_arg_digits = diplomatRuntime.DiplomatBuf.slice(wasm, arg_digits, 4); const diplomat_out = (() => { const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); diff --git a/ffi/capi/js/package/lib/ICU4XDate.js b/ffi/capi/js/package/lib/ICU4XDate.js index de7b646eb06..6bdcc706a4d 100644 --- a/ffi/capi/js/package/lib/ICU4XDate.js +++ b/ffi/capi/js/package/lib/ICU4XDate.js @@ -39,8 +39,8 @@ export class ICU4XDate { } static create_from_codes_in_calendar(arg_era_code, arg_year, arg_month_code, arg_day, arg_calendar) { - const buf_arg_era_code = diplomatRuntime.DiplomatBuf.str(wasm, arg_era_code); - const buf_arg_month_code = diplomatRuntime.DiplomatBuf.str(wasm, arg_month_code); + const buf_arg_era_code = diplomatRuntime.DiplomatBuf.str8(wasm, arg_era_code); + const buf_arg_month_code = diplomatRuntime.DiplomatBuf.str8(wasm, arg_month_code); const diplomat_out = (() => { const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); wasm.ICU4XDate_create_from_codes_in_calendar(diplomat_receive_buffer, buf_arg_era_code.ptr, buf_arg_era_code.size, arg_year, buf_arg_month_code.ptr, buf_arg_month_code.size, arg_day, arg_calendar.underlying); diff --git a/ffi/capi/js/package/lib/ICU4XDateTime.js b/ffi/capi/js/package/lib/ICU4XDateTime.js index 3d0d3d910fd..1ebff727cc7 100644 --- a/ffi/capi/js/package/lib/ICU4XDateTime.js +++ b/ffi/capi/js/package/lib/ICU4XDateTime.js @@ -41,8 +41,8 @@ export class ICU4XDateTime { } static create_from_codes_in_calendar(arg_era_code, arg_year, arg_month_code, arg_day, arg_hour, arg_minute, arg_second, arg_nanosecond, arg_calendar) { - const buf_arg_era_code = diplomatRuntime.DiplomatBuf.str(wasm, arg_era_code); - const buf_arg_month_code = diplomatRuntime.DiplomatBuf.str(wasm, arg_month_code); + const buf_arg_era_code = diplomatRuntime.DiplomatBuf.str8(wasm, arg_era_code); + const buf_arg_month_code = diplomatRuntime.DiplomatBuf.str8(wasm, arg_month_code); const diplomat_out = (() => { const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); wasm.ICU4XDateTime_create_from_codes_in_calendar(diplomat_receive_buffer, buf_arg_era_code.ptr, buf_arg_era_code.size, arg_year, buf_arg_month_code.ptr, buf_arg_month_code.size, arg_day, arg_hour, arg_minute, arg_second, arg_nanosecond, arg_calendar.underlying); diff --git a/ffi/capi/js/package/lib/ICU4XDecomposingNormalizer.js b/ffi/capi/js/package/lib/ICU4XDecomposingNormalizer.js index e1357dbb2a3..e2470199605 100644 --- a/ffi/capi/js/package/lib/ICU4XDecomposingNormalizer.js +++ b/ffi/capi/js/package/lib/ICU4XDecomposingNormalizer.js @@ -51,7 +51,7 @@ export class ICU4XDecomposingNormalizer { } normalize(arg_s) { - const buf_arg_s = diplomatRuntime.DiplomatBuf.str(wasm, arg_s); + const buf_arg_s = diplomatRuntime.DiplomatBuf.str8(wasm, arg_s); const diplomat_out = diplomatRuntime.withWriteable(wasm, (writeable) => { return (() => { const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); @@ -73,7 +73,7 @@ export class ICU4XDecomposingNormalizer { } is_normalized(arg_s) { - const buf_arg_s = diplomatRuntime.DiplomatBuf.str(wasm, arg_s); + const buf_arg_s = diplomatRuntime.DiplomatBuf.str8(wasm, arg_s); const diplomat_out = wasm.ICU4XDecomposingNormalizer_is_normalized(this.underlying, buf_arg_s.ptr, buf_arg_s.size); buf_arg_s.free(); return diplomat_out; diff --git a/ffi/capi/js/package/lib/ICU4XFixedDecimal.js b/ffi/capi/js/package/lib/ICU4XFixedDecimal.js index e517bc9f48c..0dbe410fba5 100644 --- a/ffi/capi/js/package/lib/ICU4XFixedDecimal.js +++ b/ffi/capi/js/package/lib/ICU4XFixedDecimal.js @@ -103,7 +103,7 @@ export class ICU4XFixedDecimal { } static create_from_string(arg_v) { - const buf_arg_v = diplomatRuntime.DiplomatBuf.str(wasm, arg_v); + const buf_arg_v = diplomatRuntime.DiplomatBuf.str8(wasm, arg_v); const diplomat_out = (() => { const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); wasm.ICU4XFixedDecimal_create_from_string(diplomat_receive_buffer, buf_arg_v.ptr, buf_arg_v.size); diff --git a/ffi/capi/js/package/lib/ICU4XGeneralCategoryNameToMaskMapper.js b/ffi/capi/js/package/lib/ICU4XGeneralCategoryNameToMaskMapper.js index 4f3319123a9..2b283ec515d 100644 --- a/ffi/capi/js/package/lib/ICU4XGeneralCategoryNameToMaskMapper.js +++ b/ffi/capi/js/package/lib/ICU4XGeneralCategoryNameToMaskMapper.js @@ -17,14 +17,14 @@ export class ICU4XGeneralCategoryNameToMaskMapper { } get_strict(arg_name) { - const buf_arg_name = diplomatRuntime.DiplomatBuf.str(wasm, arg_name); + const buf_arg_name = diplomatRuntime.DiplomatBuf.str8(wasm, arg_name); const diplomat_out = wasm.ICU4XGeneralCategoryNameToMaskMapper_get_strict(this.underlying, buf_arg_name.ptr, buf_arg_name.size); buf_arg_name.free(); return diplomat_out; } get_loose(arg_name) { - const buf_arg_name = diplomatRuntime.DiplomatBuf.str(wasm, arg_name); + const buf_arg_name = diplomatRuntime.DiplomatBuf.str8(wasm, arg_name); const diplomat_out = wasm.ICU4XGeneralCategoryNameToMaskMapper_get_loose(this.underlying, buf_arg_name.ptr, buf_arg_name.size); buf_arg_name.free(); return diplomat_out; diff --git a/ffi/capi/js/package/lib/ICU4XGraphemeClusterSegmenter.d.ts b/ffi/capi/js/package/lib/ICU4XGraphemeClusterSegmenter.d.ts index 860b6206c9d..0a15f2f516a 100644 --- a/ffi/capi/js/package/lib/ICU4XGraphemeClusterSegmenter.d.ts +++ b/ffi/capi/js/package/lib/ICU4XGraphemeClusterSegmenter.d.ts @@ -36,7 +36,7 @@ export class ICU4XGraphemeClusterSegmenter { * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.GraphemeClusterSegmenter.html#method.segment_utf16 Rust documentation for `segment_utf16`} for more information. */ - segment_utf16(input: Uint16Array): ICU4XGraphemeClusterBreakIteratorUtf16; + segment_utf16(input: string): ICU4XGraphemeClusterBreakIteratorUtf16; /** diff --git a/ffi/capi/js/package/lib/ICU4XGraphemeClusterSegmenter.js b/ffi/capi/js/package/lib/ICU4XGraphemeClusterSegmenter.js index 91dfea1ba51..8fa2b2f6069 100644 --- a/ffi/capi/js/package/lib/ICU4XGraphemeClusterSegmenter.js +++ b/ffi/capi/js/package/lib/ICU4XGraphemeClusterSegmenter.js @@ -37,12 +37,12 @@ export class ICU4XGraphemeClusterSegmenter { } segment_utf8(arg_input) { - const buf_arg_input = diplomatRuntime.DiplomatBuf.str(wasm, arg_input); + const buf_arg_input = diplomatRuntime.DiplomatBuf.str8(wasm, arg_input); return new ICU4XGraphemeClusterBreakIteratorUtf8(wasm.ICU4XGraphemeClusterSegmenter_segment_utf8(this.underlying, buf_arg_input.ptr, buf_arg_input.size), true, [this, buf_arg_input]); } segment_utf16(arg_input) { - const buf_arg_input = diplomatRuntime.DiplomatBuf.slice(wasm, arg_input, 2); + const buf_arg_input = diplomatRuntime.DiplomatBuf.str16(wasm, arg_input, 2); return new ICU4XGraphemeClusterBreakIteratorUtf16(wasm.ICU4XGraphemeClusterSegmenter_segment_utf16(this.underlying, buf_arg_input.ptr, buf_arg_input.size), true, [this, buf_arg_input]); } diff --git a/ffi/capi/js/package/lib/ICU4XLineSegmenter.d.ts b/ffi/capi/js/package/lib/ICU4XLineSegmenter.d.ts index 47ae8b18911..4cf2e124fc9 100644 --- a/ffi/capi/js/package/lib/ICU4XLineSegmenter.d.ts +++ b/ffi/capi/js/package/lib/ICU4XLineSegmenter.d.ts @@ -82,7 +82,7 @@ export class ICU4XLineSegmenter { * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.LineSegmenter.html#method.segment_utf16 Rust documentation for `segment_utf16`} for more information. */ - segment_utf16(input: Uint16Array): ICU4XLineBreakIteratorUtf16; + segment_utf16(input: string): ICU4XLineBreakIteratorUtf16; /** diff --git a/ffi/capi/js/package/lib/ICU4XLineSegmenter.js b/ffi/capi/js/package/lib/ICU4XLineSegmenter.js index eabb317515c..f941ec51105 100644 --- a/ffi/capi/js/package/lib/ICU4XLineSegmenter.js +++ b/ffi/capi/js/package/lib/ICU4XLineSegmenter.js @@ -133,12 +133,12 @@ export class ICU4XLineSegmenter { } segment_utf8(arg_input) { - const buf_arg_input = diplomatRuntime.DiplomatBuf.str(wasm, arg_input); + const buf_arg_input = diplomatRuntime.DiplomatBuf.str8(wasm, arg_input); return new ICU4XLineBreakIteratorUtf8(wasm.ICU4XLineSegmenter_segment_utf8(this.underlying, buf_arg_input.ptr, buf_arg_input.size), true, [this, buf_arg_input]); } segment_utf16(arg_input) { - const buf_arg_input = diplomatRuntime.DiplomatBuf.slice(wasm, arg_input, 2); + const buf_arg_input = diplomatRuntime.DiplomatBuf.str16(wasm, arg_input, 2); return new ICU4XLineBreakIteratorUtf16(wasm.ICU4XLineSegmenter_segment_utf16(this.underlying, buf_arg_input.ptr, buf_arg_input.size), true, [this, buf_arg_input]); } diff --git a/ffi/capi/js/package/lib/ICU4XList.js b/ffi/capi/js/package/lib/ICU4XList.js index 7ee9fc0c532..56c94a4d295 100644 --- a/ffi/capi/js/package/lib/ICU4XList.js +++ b/ffi/capi/js/package/lib/ICU4XList.js @@ -24,7 +24,7 @@ export class ICU4XList { } push(arg_val) { - const buf_arg_val = diplomatRuntime.DiplomatBuf.str(wasm, arg_val); + const buf_arg_val = diplomatRuntime.DiplomatBuf.str8(wasm, arg_val); wasm.ICU4XList_push(this.underlying, buf_arg_val.ptr, buf_arg_val.size); buf_arg_val.free(); } diff --git a/ffi/capi/js/package/lib/ICU4XLocale.js b/ffi/capi/js/package/lib/ICU4XLocale.js index b3cb1398424..500d1aa124d 100644 --- a/ffi/capi/js/package/lib/ICU4XLocale.js +++ b/ffi/capi/js/package/lib/ICU4XLocale.js @@ -18,7 +18,7 @@ export class ICU4XLocale { } static create_from_string(arg_name) { - const buf_arg_name = diplomatRuntime.DiplomatBuf.str(wasm, arg_name); + const buf_arg_name = diplomatRuntime.DiplomatBuf.str8(wasm, arg_name); const diplomat_out = (() => { const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); wasm.ICU4XLocale_create_from_string(diplomat_receive_buffer, buf_arg_name.ptr, buf_arg_name.size); @@ -65,7 +65,7 @@ export class ICU4XLocale { } get_unicode_extension(arg_bytes) { - const buf_arg_bytes = diplomatRuntime.DiplomatBuf.str(wasm, arg_bytes); + const buf_arg_bytes = diplomatRuntime.DiplomatBuf.str8(wasm, arg_bytes); const diplomat_out = diplomatRuntime.withWriteable(wasm, (writeable) => { return (() => { const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); @@ -106,7 +106,7 @@ export class ICU4XLocale { } set_language(arg_bytes) { - const buf_arg_bytes = diplomatRuntime.DiplomatBuf.str(wasm, arg_bytes); + const buf_arg_bytes = diplomatRuntime.DiplomatBuf.str8(wasm, arg_bytes); const diplomat_out = (() => { const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); wasm.ICU4XLocale_set_language(diplomat_receive_buffer, this.underlying, buf_arg_bytes.ptr, buf_arg_bytes.size); @@ -145,7 +145,7 @@ export class ICU4XLocale { } set_region(arg_bytes) { - const buf_arg_bytes = diplomatRuntime.DiplomatBuf.str(wasm, arg_bytes); + const buf_arg_bytes = diplomatRuntime.DiplomatBuf.str8(wasm, arg_bytes); const diplomat_out = (() => { const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); wasm.ICU4XLocale_set_region(diplomat_receive_buffer, this.underlying, buf_arg_bytes.ptr, buf_arg_bytes.size); @@ -184,7 +184,7 @@ export class ICU4XLocale { } set_script(arg_bytes) { - const buf_arg_bytes = diplomatRuntime.DiplomatBuf.str(wasm, arg_bytes); + const buf_arg_bytes = diplomatRuntime.DiplomatBuf.str8(wasm, arg_bytes); const diplomat_out = (() => { const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); wasm.ICU4XLocale_set_script(diplomat_receive_buffer, this.underlying, buf_arg_bytes.ptr, buf_arg_bytes.size); @@ -204,7 +204,7 @@ export class ICU4XLocale { } static canonicalize(arg_bytes) { - const buf_arg_bytes = diplomatRuntime.DiplomatBuf.str(wasm, arg_bytes); + const buf_arg_bytes = diplomatRuntime.DiplomatBuf.str8(wasm, arg_bytes); const diplomat_out = diplomatRuntime.withWriteable(wasm, (writeable) => { return (() => { const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); @@ -245,14 +245,14 @@ export class ICU4XLocale { } normalizing_eq(arg_other) { - const buf_arg_other = diplomatRuntime.DiplomatBuf.str(wasm, arg_other); + const buf_arg_other = diplomatRuntime.DiplomatBuf.str8(wasm, arg_other); const diplomat_out = wasm.ICU4XLocale_normalizing_eq(this.underlying, buf_arg_other.ptr, buf_arg_other.size); buf_arg_other.free(); return diplomat_out; } strict_cmp(arg_other) { - const buf_arg_other = diplomatRuntime.DiplomatBuf.str(wasm, arg_other); + const buf_arg_other = diplomatRuntime.DiplomatBuf.str8(wasm, arg_other); const diplomat_out = ICU4XOrdering_rust_to_js[wasm.ICU4XLocale_strict_cmp(this.underlying, buf_arg_other.ptr, buf_arg_other.size)]; buf_arg_other.free(); return diplomat_out; diff --git a/ffi/capi/js/package/lib/ICU4XLocaleFallbackConfig.js b/ffi/capi/js/package/lib/ICU4XLocaleFallbackConfig.js index f327a084bee..1f9314b3d08 100644 --- a/ffi/capi/js/package/lib/ICU4XLocaleFallbackConfig.js +++ b/ffi/capi/js/package/lib/ICU4XLocaleFallbackConfig.js @@ -8,7 +8,7 @@ export class ICU4XLocaleFallbackConfig { this.priority = ICU4XLocaleFallbackPriority_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, underlying)]; this.extension_key = (() => { const [ptr, size] = new Uint32Array(wasm.memory.buffer, underlying + 4, 2); - return diplomatRuntime.readString(wasm, ptr, size); + return diplomatRuntime.readString8(wasm, ptr, size); })(); this.fallback_supplement = ICU4XLocaleFallbackSupplement_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, underlying + 12)]; } diff --git a/ffi/capi/js/package/lib/ICU4XLocaleFallbacker.js b/ffi/capi/js/package/lib/ICU4XLocaleFallbacker.js index 8163c11bac5..4b6c43c06c3 100644 --- a/ffi/capi/js/package/lib/ICU4XLocaleFallbacker.js +++ b/ffi/capi/js/package/lib/ICU4XLocaleFallbacker.js @@ -43,7 +43,7 @@ export class ICU4XLocaleFallbacker { for_config(arg_config) { const field_priority_arg_config = arg_config["priority"]; const field_extension_key_arg_config = arg_config["extension_key"]; - const buf_field_extension_key_arg_config = diplomatRuntime.DiplomatBuf.str(wasm, field_extension_key_arg_config); + const buf_field_extension_key_arg_config = diplomatRuntime.DiplomatBuf.str8(wasm, field_extension_key_arg_config); const field_fallback_supplement_arg_config = arg_config["fallback_supplement"]; const diplomat_out = (() => { const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); diff --git a/ffi/capi/js/package/lib/ICU4XPluralOperands.js b/ffi/capi/js/package/lib/ICU4XPluralOperands.js index 6fdffaef2ad..e9a699be1fc 100644 --- a/ffi/capi/js/package/lib/ICU4XPluralOperands.js +++ b/ffi/capi/js/package/lib/ICU4XPluralOperands.js @@ -17,7 +17,7 @@ export class ICU4XPluralOperands { } static create_from_string(arg_s) { - const buf_arg_s = diplomatRuntime.DiplomatBuf.str(wasm, arg_s); + const buf_arg_s = diplomatRuntime.DiplomatBuf.str8(wasm, arg_s); const diplomat_out = (() => { const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); wasm.ICU4XPluralOperands_create_from_string(diplomat_receive_buffer, buf_arg_s.ptr, buf_arg_s.size); diff --git a/ffi/capi/js/package/lib/ICU4XPropertyValueNameToEnumMapper.js b/ffi/capi/js/package/lib/ICU4XPropertyValueNameToEnumMapper.js index ef0ddf1f377..1012971bc09 100644 --- a/ffi/capi/js/package/lib/ICU4XPropertyValueNameToEnumMapper.js +++ b/ffi/capi/js/package/lib/ICU4XPropertyValueNameToEnumMapper.js @@ -17,14 +17,14 @@ export class ICU4XPropertyValueNameToEnumMapper { } get_strict(arg_name) { - const buf_arg_name = diplomatRuntime.DiplomatBuf.str(wasm, arg_name); + const buf_arg_name = diplomatRuntime.DiplomatBuf.str8(wasm, arg_name); const diplomat_out = wasm.ICU4XPropertyValueNameToEnumMapper_get_strict(this.underlying, buf_arg_name.ptr, buf_arg_name.size); buf_arg_name.free(); return diplomat_out; } get_loose(arg_name) { - const buf_arg_name = diplomatRuntime.DiplomatBuf.str(wasm, arg_name); + const buf_arg_name = diplomatRuntime.DiplomatBuf.str8(wasm, arg_name); const diplomat_out = wasm.ICU4XPropertyValueNameToEnumMapper_get_loose(this.underlying, buf_arg_name.ptr, buf_arg_name.size); buf_arg_name.free(); return diplomat_out; diff --git a/ffi/capi/js/package/lib/ICU4XRegionDisplayNames.js b/ffi/capi/js/package/lib/ICU4XRegionDisplayNames.js index afaf0a9d4dc..e49a12617ae 100644 --- a/ffi/capi/js/package/lib/ICU4XRegionDisplayNames.js +++ b/ffi/capi/js/package/lib/ICU4XRegionDisplayNames.js @@ -34,7 +34,7 @@ export class ICU4XRegionDisplayNames { } of(arg_region) { - const buf_arg_region = diplomatRuntime.DiplomatBuf.str(wasm, arg_region); + const buf_arg_region = diplomatRuntime.DiplomatBuf.str8(wasm, arg_region); const diplomat_out = diplomatRuntime.withWriteable(wasm, (writeable) => { return (() => { const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); diff --git a/ffi/capi/js/package/lib/ICU4XSentenceSegmenter.d.ts b/ffi/capi/js/package/lib/ICU4XSentenceSegmenter.d.ts index acda263fad6..cd603a22fa0 100644 --- a/ffi/capi/js/package/lib/ICU4XSentenceSegmenter.d.ts +++ b/ffi/capi/js/package/lib/ICU4XSentenceSegmenter.d.ts @@ -36,7 +36,7 @@ export class ICU4XSentenceSegmenter { * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.SentenceSegmenter.html#method.segment_utf16 Rust documentation for `segment_utf16`} for more information. */ - segment_utf16(input: Uint16Array): ICU4XSentenceBreakIteratorUtf16; + segment_utf16(input: string): ICU4XSentenceBreakIteratorUtf16; /** diff --git a/ffi/capi/js/package/lib/ICU4XSentenceSegmenter.js b/ffi/capi/js/package/lib/ICU4XSentenceSegmenter.js index de617070a29..66a775066ad 100644 --- a/ffi/capi/js/package/lib/ICU4XSentenceSegmenter.js +++ b/ffi/capi/js/package/lib/ICU4XSentenceSegmenter.js @@ -37,12 +37,12 @@ export class ICU4XSentenceSegmenter { } segment_utf8(arg_input) { - const buf_arg_input = diplomatRuntime.DiplomatBuf.str(wasm, arg_input); + const buf_arg_input = diplomatRuntime.DiplomatBuf.str8(wasm, arg_input); return new ICU4XSentenceBreakIteratorUtf8(wasm.ICU4XSentenceSegmenter_segment_utf8(this.underlying, buf_arg_input.ptr, buf_arg_input.size), true, [this, buf_arg_input]); } segment_utf16(arg_input) { - const buf_arg_input = diplomatRuntime.DiplomatBuf.slice(wasm, arg_input, 2); + const buf_arg_input = diplomatRuntime.DiplomatBuf.str16(wasm, arg_input, 2); return new ICU4XSentenceBreakIteratorUtf16(wasm.ICU4XSentenceSegmenter_segment_utf16(this.underlying, buf_arg_input.ptr, buf_arg_input.size), true, [this, buf_arg_input]); } diff --git a/ffi/capi/js/package/lib/ICU4XTitlecaseMapper.js b/ffi/capi/js/package/lib/ICU4XTitlecaseMapper.js index c25bf087022..a4f5342587e 100644 --- a/ffi/capi/js/package/lib/ICU4XTitlecaseMapper.js +++ b/ffi/capi/js/package/lib/ICU4XTitlecaseMapper.js @@ -36,7 +36,7 @@ export class ICU4XTitlecaseMapper { } titlecase_segment_v1(arg_s, arg_locale, arg_options) { - const buf_arg_s = diplomatRuntime.DiplomatBuf.str(wasm, arg_s); + const buf_arg_s = diplomatRuntime.DiplomatBuf.str8(wasm, arg_s); 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) => { diff --git a/ffi/capi/js/package/lib/ICU4XUnicodeSetData.js b/ffi/capi/js/package/lib/ICU4XUnicodeSetData.js index b345a101237..8976275a962 100644 --- a/ffi/capi/js/package/lib/ICU4XUnicodeSetData.js +++ b/ffi/capi/js/package/lib/ICU4XUnicodeSetData.js @@ -17,7 +17,7 @@ export class ICU4XUnicodeSetData { } contains(arg_s) { - const buf_arg_s = diplomatRuntime.DiplomatBuf.str(wasm, arg_s); + const buf_arg_s = diplomatRuntime.DiplomatBuf.str8(wasm, arg_s); const diplomat_out = wasm.ICU4XUnicodeSetData_contains(this.underlying, buf_arg_s.ptr, buf_arg_s.size); buf_arg_s.free(); return diplomat_out; diff --git a/ffi/capi/js/package/lib/ICU4XWordSegmenter.d.ts b/ffi/capi/js/package/lib/ICU4XWordSegmenter.d.ts index 3c553428fd4..c3102a417a2 100644 --- a/ffi/capi/js/package/lib/ICU4XWordSegmenter.d.ts +++ b/ffi/capi/js/package/lib/ICU4XWordSegmenter.d.ts @@ -58,7 +58,7 @@ export class ICU4XWordSegmenter { * See the {@link https://docs.rs/icu/latest/icu/segmenter/struct.WordSegmenter.html#method.segment_utf16 Rust documentation for `segment_utf16`} for more information. */ - segment_utf16(input: Uint16Array): ICU4XWordBreakIteratorUtf16; + segment_utf16(input: string): ICU4XWordBreakIteratorUtf16; /** diff --git a/ffi/capi/js/package/lib/ICU4XWordSegmenter.js b/ffi/capi/js/package/lib/ICU4XWordSegmenter.js index f1a1b263ee3..1665c40c9a4 100644 --- a/ffi/capi/js/package/lib/ICU4XWordSegmenter.js +++ b/ffi/capi/js/package/lib/ICU4XWordSegmenter.js @@ -71,12 +71,12 @@ export class ICU4XWordSegmenter { } segment_utf8(arg_input) { - const buf_arg_input = diplomatRuntime.DiplomatBuf.str(wasm, arg_input); + const buf_arg_input = diplomatRuntime.DiplomatBuf.str8(wasm, arg_input); return new ICU4XWordBreakIteratorUtf8(wasm.ICU4XWordSegmenter_segment_utf8(this.underlying, buf_arg_input.ptr, buf_arg_input.size), true, [this, buf_arg_input]); } segment_utf16(arg_input) { - const buf_arg_input = diplomatRuntime.DiplomatBuf.slice(wasm, arg_input, 2); + const buf_arg_input = diplomatRuntime.DiplomatBuf.str16(wasm, arg_input, 2); return new ICU4XWordBreakIteratorUtf16(wasm.ICU4XWordSegmenter_segment_utf16(this.underlying, buf_arg_input.ptr, buf_arg_input.size), true, [this, buf_arg_input]); } diff --git a/ffi/capi/js/package/lib/diplomat-runtime.js b/ffi/capi/js/package/lib/diplomat-runtime.js index 75317d4a746..afb69ef0ae2 100644 --- a/ffi/capi/js/package/lib/diplomat-runtime.js +++ b/ffi/capi/js/package/lib/diplomat-runtime.js @@ -1,15 +1,20 @@ -export function readString(wasm, ptr, len) { +export function readString8(wasm, ptr, len) { const buf = new Uint8Array(wasm.memory.buffer, ptr, len); return (new TextDecoder("utf-8")).decode(buf) } +export function readString16(wasm, ptr, len) { + const buf = new Uint16Array(wasm.memory.buffer, ptr, len); + return String.fromCharCode.apply(null, buf) +} + export function withWriteable(wasm, callback) { const writeable = wasm.diplomat_buffer_writeable_create(0); try { callback(writeable); const outStringPtr = wasm.diplomat_buffer_writeable_get_bytes(writeable); const outStringLen = wasm.diplomat_buffer_writeable_len(writeable); - return readString(wasm, outStringPtr, outStringLen); + return readString8(wasm, outStringPtr, outStringLen); } finally { wasm.diplomat_buffer_writeable_destroy(writeable); } @@ -61,7 +66,7 @@ export function enumDiscriminant(wasm, ptr) { // they can create an edge to this object if they borrow from the str/slice, // or we can manually free the WASM memory if they don't. export class DiplomatBuf { - static str = (wasm, string) => { + static str8 = (wasm, string) => { var utf8_len = 0; for (const codepoint_string of string) { let codepoint = codepoint_string.codePointAt(0); @@ -78,8 +83,16 @@ export class DiplomatBuf { return new DiplomatBuf(wasm, utf8_len, 1, buf => { const result = (new TextEncoder()).encodeInto(string, buf); console.assert(string.length == result.read && utf8_len == result.written, "UTF-8 write error"); - }) -} + }) + } + + static str16 = (wasm, string) => { + return new DiplomatBuf(wasm, string.length, 2, buf => { + for (var i; i < string.length; i++) { + buf[i] = string.charCodeAt(i); + } + }) + } static slice = (wasm, slice, align) => { // If the slice is not a Uint8Array, we have to convert to one, as that's the only diff --git a/ffi/capi/js/package/lib/diplomat-wasm.mjs b/ffi/capi/js/package/lib/diplomat-wasm.mjs index 2dd3293ba02..70ad1454603 100644 --- a/ffi/capi/js/package/lib/diplomat-wasm.mjs +++ b/ffi/capi/js/package/lib/diplomat-wasm.mjs @@ -1,27 +1,27 @@ import cfg from '../diplomat.config.js'; -import {readString} from './diplomat-runtime.js' +import {readString8} from './diplomat-runtime.js' let wasm; const imports = { env: { diplomat_console_debug_js(ptr, len) { - console.debug(readString(wasm, ptr, len)); + console.debug(readString8(wasm, ptr, len)); }, diplomat_console_error_js(ptr, len) { - console.error(readString(wasm, ptr, len)); + console.error(readString8(wasm, ptr, len)); }, diplomat_console_info_js(ptr, len) { - console.info(readString(wasm, ptr, len)); + console.info(readString8(wasm, ptr, len)); }, diplomat_console_log_js(ptr, len) { - console.log(readString(wasm, ptr, len)); + console.log(readString8(wasm, ptr, len)); }, diplomat_console_warn_js(ptr, len) { - console.warn(readString(wasm, ptr, len)); + console.warn(readString8(wasm, ptr, len)); }, diplomat_throw_error_js(ptr, len) { - throw new Error(readString(wasm, ptr, len)); + throw new Error(readString8(wasm, ptr, len)); } } } diff --git a/ffi/capi/src/bidi.rs b/ffi/capi/src/bidi.rs index 7cd4a1e1846..a4b1ff6db6d 100644 --- a/ffi/capi/src/bidi.rs +++ b/ffi/capi/src/bidi.rs @@ -52,9 +52,11 @@ pub mod ffi { )] pub fn for_text<'text>( &self, - text: &'text str, + text: &'text DiplomatStr, default_level: u8, ) -> Box> { + #[allow(clippy::unwrap_used)] // #2520 + let text = core::str::from_utf8(text).unwrap(); let data = self.0.as_borrowed(); let adapter = BidiClassAdapter::new(data); diff --git a/ffi/capi/src/calendar.rs b/ffi/capi/src/calendar.rs index dd4b2dcbaaa..28d226f744f 100644 --- a/ffi/capi/src/calendar.rs +++ b/ffi/capi/src/calendar.rs @@ -82,8 +82,7 @@ pub mod ffi { FnInEnum, hidden )] - pub fn get_for_bcp47(s: &str) -> Result { - let s = s.as_bytes(); // #2520 + pub fn get_for_bcp47(s: &DiplomatStr) -> Result { AnyCalendarKind::get_for_bcp47_bytes(s) .map(Into::into) .ok_or(()) diff --git a/ffi/capi/src/casemap.rs b/ffi/capi/src/casemap.rs index aa073a670d2..312c7f75b1e 100644 --- a/ffi/capi/src/casemap.rs +++ b/ffi/capi/src/casemap.rs @@ -67,14 +67,12 @@ pub mod ffi { #[diplomat::rust_link(icu::casemap::CaseMapper::lowercase_to_string, FnInStruct, hidden)] pub fn lowercase( &self, - s: &str, + s: &DiplomatStr, locale: &ICU4XLocale, write: &mut DiplomatWriteable, ) -> Result<(), ICU4XError> { - // #2520 - // In the future we should be able to make assumptions based on backend - core::str::from_utf8(s.as_bytes()) - .map_err(|e| ICU4XError::DataIoError.log_original(&e))?; + let s = + core::str::from_utf8(s).map_err(|e| ICU4XError::DataIoError.log_original(&e))?; self.0.lowercase(s, &locale.0.id).write_to(write)?; Ok(()) @@ -85,14 +83,12 @@ pub mod ffi { #[diplomat::rust_link(icu::casemap::CaseMapper::uppercase_to_string, FnInStruct, hidden)] pub fn uppercase( &self, - s: &str, + s: &DiplomatStr, locale: &ICU4XLocale, write: &mut DiplomatWriteable, ) -> Result<(), ICU4XError> { - // #2520 - // In the future we should be able to make assumptions based on backend - core::str::from_utf8(s.as_bytes()) - .map_err(|e| ICU4XError::DataIoError.log_original(&e))?; + let s = + core::str::from_utf8(s).map_err(|e| ICU4XError::DataIoError.log_original(&e))?; self.0.uppercase(s, &locale.0.id).write_to(write)?; Ok(()) @@ -114,15 +110,13 @@ pub mod ffi { )] pub fn titlecase_segment_with_only_case_data_v1( &self, - s: &str, + s: &DiplomatStr, locale: &ICU4XLocale, options: ICU4XTitlecaseOptionsV1, write: &mut DiplomatWriteable, ) -> Result<(), ICU4XError> { - // #2520 - // In the future we should be able to make assumptions based on backend - core::str::from_utf8(s.as_bytes()) - .map_err(|e| ICU4XError::DataIoError.log_original(&e))?; + let s = + core::str::from_utf8(s).map_err(|e| ICU4XError::DataIoError.log_original(&e))?; self.0 .titlecase_segment_with_only_case_data(s, &locale.0.id, options.into()) .write_to(write)?; @@ -133,11 +127,13 @@ pub mod ffi { /// Case-folds the characters in the given string #[diplomat::rust_link(icu::casemap::CaseMapper::fold, FnInStruct)] #[diplomat::rust_link(icu::casemap::CaseMapper::fold_string, FnInStruct, hidden)] - pub fn fold(&self, s: &str, write: &mut DiplomatWriteable) -> Result<(), ICU4XError> { - // #2520 - // In the future we should be able to make assumptions based on backend - core::str::from_utf8(s.as_bytes()) - .map_err(|e| ICU4XError::DataIoError.log_original(&e))?; + pub fn fold( + &self, + s: &DiplomatStr, + write: &mut DiplomatWriteable, + ) -> Result<(), ICU4XError> { + let s = + core::str::from_utf8(s).map_err(|e| ICU4XError::DataIoError.log_original(&e))?; self.0.fold(s).write_to(write)?; Ok(()) @@ -148,13 +144,11 @@ pub mod ffi { #[diplomat::rust_link(icu::casemap::CaseMapper::fold_turkic_string, FnInStruct, hidden)] pub fn fold_turkic( &self, - s: &str, + s: &DiplomatStr, write: &mut DiplomatWriteable, ) -> Result<(), ICU4XError> { - // #2520 - // In the future we should be able to make assumptions based on backend - core::str::from_utf8(s.as_bytes()) - .map_err(|e| ICU4XError::DataIoError.log_original(&e))?; + let s = + core::str::from_utf8(s).map_err(|e| ICU4XError::DataIoError.log_original(&e))?; self.0.fold_turkic(s).write_to(write)?; Ok(()) @@ -280,12 +274,10 @@ pub mod ffi { #[diplomat::rust_link(icu::casemap::CaseMapCloser::add_string_case_closure_to, FnInStruct)] pub fn add_string_case_closure_to( &self, - s: &str, + s: &DiplomatStr, builder: &mut crate::collections_sets::ffi::ICU4XCodePointSetBuilder, ) -> bool { - // #2520 - // In the future we should be able to make assumptions based on backend - let s = core::str::from_utf8(s.as_bytes()).unwrap_or(""); + let s = core::str::from_utf8(s).unwrap_or(""); self.0.add_string_case_closure_to(s, &mut builder.0) } } @@ -320,15 +312,13 @@ pub mod ffi { )] pub fn titlecase_segment_v1( &self, - s: &str, + s: &DiplomatStr, locale: &ICU4XLocale, options: ICU4XTitlecaseOptionsV1, write: &mut DiplomatWriteable, ) -> Result<(), ICU4XError> { - // #2520 - // In the future we should be able to make assumptions based on backend - core::str::from_utf8(s.as_bytes()) - .map_err(|e| ICU4XError::DataIoError.log_original(&e))?; + let s = + core::str::from_utf8(s).map_err(|e| ICU4XError::DataIoError.log_original(&e))?; self.0 .titlecase_segment(s, &locale.0.id, options.into()) .write_to(write)?; diff --git a/ffi/capi/src/collator.rs b/ffi/capi/src/collator.rs index bbf56786b70..9893e4b46cc 100644 --- a/ffi/capi/src/collator.rs +++ b/ffi/capi/src/collator.rs @@ -111,9 +111,7 @@ pub mod ffi { /// to the WHATWG Encoding Standard. #[diplomat::rust_link(icu::collator::Collator::compare_utf8, FnInStruct)] #[diplomat::attr(dart, disable)] - pub fn compare(&self, left: &str, right: &str) -> ICU4XOrdering { - let left = left.as_bytes(); // #2520 - let right = right.as_bytes(); // #2520 + pub fn compare(&self, left: &DiplomatStr, right: &DiplomatStr) -> ICU4XOrdering { self.0.compare_utf8(left, right).into() } @@ -122,15 +120,20 @@ pub mod ffi { /// Note: In C++, passing ill-formed UTF-8 strings is undefined behavior /// (and may be memory-unsafe to do so, too). #[diplomat::rust_link(icu::collator::Collator::compare, FnInStruct)] - #[diplomat::attr(dart, rename = "compare")] - pub fn compare_valid_utf8(&self, left: &str, right: &str) -> ICU4XOrdering { - self.0.compare(left, right).into() + #[diplomat::attr(dart, disable)] + pub fn compare_valid_utf8(&self, left: &DiplomatStr, right: &DiplomatStr) -> ICU4XOrdering { + self.0 + .compare(unsafe { core::str::from_utf8_unchecked(left) }, unsafe { + core::str::from_utf8_unchecked(right) + }) + .into() } /// Compare potentially ill-formed UTF-16 strings, with unpaired surrogates /// compared as REPLACEMENT CHARACTER. #[diplomat::rust_link(icu::collator::Collator::compare_utf16, FnInStruct)] - pub fn compare_utf16(&self, left: &[u16], right: &[u16]) -> ICU4XOrdering { + #[diplomat::attr(dart, rename = "compare")] + pub fn compare_utf16(&self, left: &DiplomatStr16, right: &DiplomatStr16) -> ICU4XOrdering { self.0.compare_utf16(left, right).into() } } diff --git a/ffi/capi/src/data_struct.rs b/ffi/capi/src/data_struct.rs index 15151089214..8ad69e26af7 100644 --- a/ffi/capi/src/data_struct.rs +++ b/ffi/capi/src/data_struct.rs @@ -3,7 +3,7 @@ // (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). #[cfg(feature = "icu_decimal")] -use alloc::borrow::{Cow, ToOwned}; +use alloc::borrow::Cow; #[diplomat::bridge] pub mod ffi { @@ -30,12 +30,12 @@ pub mod ffi { #[allow(clippy::too_many_arguments)] #[cfg(feature = "icu_decimal")] pub fn create_decimal_symbols_v1( - plus_sign_prefix: &str, - plus_sign_suffix: &str, - minus_sign_prefix: &str, - minus_sign_suffix: &str, - decimal_separator: &str, - grouping_separator: &str, + plus_sign_prefix: &DiplomatStr, + plus_sign_suffix: &DiplomatStr, + minus_sign_prefix: &DiplomatStr, + minus_sign_suffix: &DiplomatStr, + decimal_separator: &DiplomatStr, + grouping_separator: &DiplomatStr, primary_group_size: u8, secondary_group_size: u8, min_group_size: u8, @@ -83,10 +83,10 @@ pub mod ffi { } } #[cfg(feature = "icu_decimal")] -fn str_to_cow(s: &str) -> Cow<'static, str> { +fn str_to_cow(s: &diplomat_runtime::DiplomatStr) -> Cow<'static, str> { if s.is_empty() { Cow::default() } else { - Cow::from(s.to_owned()) + Cow::Owned(alloc::string::String::from_utf8_lossy(s).into_owned()) } } diff --git a/ffi/capi/src/date.rs b/ffi/capi/src/date.rs index 39fd03835c0..385c568d8f3 100644 --- a/ffi/capi/src/date.rs +++ b/ffi/capi/src/date.rs @@ -163,14 +163,12 @@ pub mod ffi { /// Creates a new [`ICU4XDate`] from the given codes, which are interpreted in the given calendar system #[diplomat::rust_link(icu::calendar::Date::try_new_from_codes, FnInStruct)] pub fn create_from_codes_in_calendar( - era_code: &str, + era_code: &DiplomatStr, year: i32, - month_code: &str, + month_code: &DiplomatStr, day: u8, calendar: &ICU4XCalendar, ) -> Result, ICU4XError> { - let era_code = era_code.as_bytes(); // #2520 - let month_code = month_code.as_bytes(); // #2520 let era = TinyAsciiStr::from_bytes(era_code)?.into(); let month = TinyAsciiStr::from_bytes(month_code)?.into(); let cal = calendar.0.clone(); diff --git a/ffi/capi/src/datetime.rs b/ffi/capi/src/datetime.rs index 627b9c16a3d..220309877ff 100644 --- a/ffi/capi/src/datetime.rs +++ b/ffi/capi/src/datetime.rs @@ -226,9 +226,9 @@ pub mod ffi { #[diplomat::rust_link(icu::calendar::DateTime::try_new_from_codes, FnInStruct)] #[allow(clippy::too_many_arguments)] pub fn create_from_codes_in_calendar( - era_code: &str, + era_code: &DiplomatStr, year: i32, - month_code: &str, + month_code: &DiplomatStr, day: u8, hour: u8, minute: u8, @@ -236,8 +236,6 @@ pub mod ffi { nanosecond: u32, calendar: &ICU4XCalendar, ) -> Result, ICU4XError> { - let era_code = era_code.as_bytes(); // #2520 - let month_code = month_code.as_bytes(); // #2520 let era = TinyAsciiStr::from_bytes(era_code)?.into(); let month = TinyAsciiStr::from_bytes(month_code)?.into(); let cal = calendar.0.clone(); diff --git a/ffi/capi/src/displaynames.rs b/ffi/capi/src/displaynames.rs index f0744e994a4..19a8efba29d 100644 --- a/ffi/capi/src/displaynames.rs +++ b/ffi/capi/src/displaynames.rs @@ -119,9 +119,13 @@ pub mod ffi { /// Note that the funtion returns an empty string in case the display name for a given /// region code is not found. #[diplomat::rust_link(icu::displaynames::RegionDisplayNames::of, FnInStruct)] - pub fn of(&self, region: &str, write: &mut DiplomatWriteable) -> Result<(), ICU4XError> { + pub fn of( + &self, + region: &DiplomatStr, + write: &mut DiplomatWriteable, + ) -> Result<(), ICU4XError> { self.0 - .of(region.parse::()?) + .of(Region::try_from_bytes(region)?) .unwrap_or("") .write_to(write)?; Ok(()) diff --git a/ffi/capi/src/fallbacker.rs b/ffi/capi/src/fallbacker.rs index b3f21b7530a..4b5f2961952 100644 --- a/ffi/capi/src/fallbacker.rs +++ b/ffi/capi/src/fallbacker.rs @@ -62,7 +62,7 @@ pub mod ffi { /// Choice of priority mode. pub priority: ICU4XLocaleFallbackPriority, /// An empty string is considered `None`. - pub extension_key: &'a str, + pub extension_key: &'a DiplomatStr, /// Fallback supplement data key to customize fallback rules. pub fallback_supplement: ICU4XLocaleFallbackSupplement, } @@ -181,8 +181,8 @@ impl TryFrom> let mut result = Self::default(); result.priority = other.priority.into(); result.extension_key = match other.extension_key { - "" => None, - s => Some(s.parse()?), + b"" => None, + s => Some(icu_locid::extensions::unicode::Key::try_from_bytes(s)?), }; result.fallback_supplement = match other.fallback_supplement { ffi::ICU4XLocaleFallbackSupplement::None => None, diff --git a/ffi/capi/src/fixed_decimal.rs b/ffi/capi/src/fixed_decimal.rs index 64396983236..6949e48df94 100644 --- a/ffi/capi/src/fixed_decimal.rs +++ b/ffi/capi/src/fixed_decimal.rs @@ -138,8 +138,7 @@ pub mod ffi { /// Construct an [`ICU4XFixedDecimal`] from a string. #[diplomat::rust_link(fixed_decimal::FixedDecimal::from_str, FnInStruct)] - pub fn create_from_string(v: &str) -> Result, ICU4XError> { - let v = v.as_bytes(); // #2520 + pub fn create_from_string(v: &DiplomatStr) -> Result, ICU4XError> { Ok(Box::new(ICU4XFixedDecimal(FixedDecimal::try_from(v)?))) } diff --git a/ffi/capi/src/iana_bcp47_mapper.rs b/ffi/capi/src/iana_bcp47_mapper.rs index c77730410dc..8f11afc3d80 100644 --- a/ffi/capi/src/iana_bcp47_mapper.rs +++ b/ffi/capi/src/iana_bcp47_mapper.rs @@ -65,14 +65,14 @@ pub mod ffi { )] pub fn get( &self, - value: &str, + value: &DiplomatStr, write: &mut diplomat_runtime::DiplomatWriteable, ) -> Result<(), ICU4XError> { - use core::str::FromStr; use writeable::Writeable; let handle = self.0.as_borrowed(); - TimeZoneBcp47Id::from_str(value) + tinystr::TinyAsciiStr::from_bytes(value) .ok() + .map(TimeZoneBcp47Id) .and_then(|bcp47_id| handle.bcp47_to_iana(bcp47_id)) .ok_or(ICU4XError::TimeZoneInvalidIdError)? .write_to(write)?; diff --git a/ffi/capi/src/list.rs b/ffi/capi/src/list.rs index fbe0bb1fd5f..2e45c780df5 100644 --- a/ffi/capi/src/list.rs +++ b/ffi/capi/src/list.rs @@ -33,8 +33,7 @@ pub mod ffi { /// /// For C++ users, potentially invalid UTF8 will be handled via /// REPLACEMENT CHARACTERs - pub fn push(&mut self, val: &str) { - let val = val.as_bytes(); // #2520 + pub fn push(&mut self, val: &DiplomatStr) { self.0.push(String::from_utf8_lossy(val).into_owned()); } diff --git a/ffi/capi/src/locale.rs b/ffi/capi/src/locale.rs index 2ecdcc96829..49659813ef8 100644 --- a/ffi/capi/src/locale.rs +++ b/ffi/capi/src/locale.rs @@ -27,8 +27,7 @@ pub mod ffi { /// `aa-BB`) use `create_und`, `set_language`, `set_script`, and `set_region`. #[diplomat::rust_link(icu::locid::Locale::try_from_bytes, FnInStruct)] #[diplomat::rust_link(icu::locid::Locale::from_str, FnInStruct, hidden)] - pub fn create_from_string(name: &str) -> Result, ICU4XError> { - let name = name.as_bytes(); // #2520 + pub fn create_from_string(name: &DiplomatStr) -> Result, ICU4XError> { Ok(Box::new(ICU4XLocale(Locale::try_from_bytes(name)?))) } @@ -59,10 +58,9 @@ pub mod ffi { #[diplomat::rust_link(icu::locid::Locale::extensions, StructField)] pub fn get_unicode_extension( &self, - bytes: &str, + bytes: &DiplomatStr, write: &mut diplomat_runtime::DiplomatWriteable, ) -> Result<(), ICU4XError> { - let bytes = bytes.as_bytes(); // #2520 self.0 .extensions .unicode @@ -85,8 +83,7 @@ pub mod ffi { /// Set the language part of the [`ICU4XLocale`]. #[diplomat::rust_link(icu::locid::Locale::try_from_bytes, FnInStruct)] - pub fn set_language(&mut self, bytes: &str) -> Result<(), ICU4XError> { - let bytes = bytes.as_bytes(); // #2520 + pub fn set_language(&mut self, bytes: &DiplomatStr) -> Result<(), ICU4XError> { self.0.id.language = if bytes.is_empty() { Language::UND } else { @@ -111,8 +108,7 @@ pub mod ffi { /// Set the region part of the [`ICU4XLocale`]. #[diplomat::rust_link(icu::locid::Locale::try_from_bytes, FnInStruct)] - pub fn set_region(&mut self, bytes: &str) -> Result<(), ICU4XError> { - let bytes = bytes.as_bytes(); // #2520 + pub fn set_region(&mut self, bytes: &DiplomatStr) -> Result<(), ICU4XError> { self.0.id.region = if bytes.is_empty() { None } else { @@ -137,8 +133,7 @@ pub mod ffi { /// Set the script part of the [`ICU4XLocale`]. Pass an empty string to remove the script. #[diplomat::rust_link(icu::locid::Locale::try_from_bytes, FnInStruct)] - pub fn set_script(&mut self, bytes: &str) -> Result<(), ICU4XError> { - let bytes = bytes.as_bytes(); // #2520 + pub fn set_script(&mut self, bytes: &DiplomatStr) -> Result<(), ICU4XError> { self.0.id.script = if bytes.is_empty() { None } else { @@ -151,8 +146,10 @@ pub mod ffi { /// /// Use ICU4XLocaleCanonicalizer for better control and functionality #[diplomat::rust_link(icu::locid::Locale::canonicalize, FnInStruct)] - pub fn canonicalize(bytes: &str, write: &mut DiplomatWriteable) -> Result<(), ICU4XError> { - let bytes = bytes.as_bytes(); // #2520 + pub fn canonicalize( + bytes: &DiplomatStr, + write: &mut DiplomatWriteable, + ) -> Result<(), ICU4XError> { Locale::canonicalize(bytes)?.write_to(write)?; Ok(()) } @@ -167,8 +164,7 @@ pub mod ffi { } #[diplomat::rust_link(icu::locid::Locale::normalizing_eq, FnInStruct)] - pub fn normalizing_eq(&self, other: &str) -> bool { - let other = other.as_bytes(); // #2520 + pub fn normalizing_eq(&self, other: &DiplomatStr) -> bool { if let Ok(other) = str::from_utf8(other) { self.0.normalizing_eq(other) } else { @@ -178,8 +174,7 @@ pub mod ffi { } #[diplomat::rust_link(icu::locid::Locale::strict_cmp, FnInStruct)] - pub fn strict_cmp(&self, other: &str) -> ICU4XOrdering { - let other = other.as_bytes(); // #2520 + pub fn strict_cmp(&self, other: &DiplomatStr) -> ICU4XOrdering { self.0.strict_cmp(other).into() } diff --git a/ffi/capi/src/normalizer.rs b/ffi/capi/src/normalizer.rs index 7b650e4a252..443e46f3883 100644 --- a/ffi/capi/src/normalizer.rs +++ b/ffi/capi/src/normalizer.rs @@ -54,8 +54,11 @@ pub mod ffi { FnInStruct, hidden )] - pub fn normalize(&self, s: &str, write: &mut DiplomatWriteable) -> Result<(), ICU4XError> { - let s = s.as_bytes(); // #2520 + pub fn normalize( + &self, + s: &DiplomatStr, + write: &mut DiplomatWriteable, + ) -> Result<(), ICU4XError> { self.0.normalize_utf8_to(s, write)?; Ok(()) } @@ -69,8 +72,7 @@ pub mod ffi { FnInStruct, hidden )] - pub fn is_normalized(&self, s: &str) -> bool { - let s = s.as_bytes(); // #2520 + pub fn is_normalized(&self, s: &DiplomatStr) -> bool { self.0.is_normalized_utf8(s) } } @@ -125,8 +127,11 @@ pub mod ffi { FnInStruct, hidden )] - pub fn normalize(&self, s: &str, write: &mut DiplomatWriteable) -> Result<(), ICU4XError> { - let s = s.as_bytes(); // #2520 + pub fn normalize( + &self, + s: &DiplomatStr, + write: &mut DiplomatWriteable, + ) -> Result<(), ICU4XError> { self.0.normalize_utf8_to(s, write)?; Ok(()) } @@ -143,8 +148,7 @@ pub mod ffi { FnInStruct, hidden )] - pub fn is_normalized(&self, s: &str) -> bool { - let s = s.as_bytes(); // #2520 + pub fn is_normalized(&self, s: &DiplomatStr) -> bool { self.0.is_normalized_utf8(s) } } diff --git a/ffi/capi/src/pluralrules.rs b/ffi/capi/src/pluralrules.rs index 78720f536e2..97c1d1e14d4 100644 --- a/ffi/capi/src/pluralrules.rs +++ b/ffi/capi/src/pluralrules.rs @@ -4,8 +4,6 @@ #[diplomat::bridge] pub mod ffi { - use core::str::{self}; - use alloc::boxed::Box; use fixed_decimal::FixedDecimal; @@ -32,8 +30,7 @@ pub mod ffi { /// [specified in TR35](https://unicode.org/reports/tr35/tr35-numbers.html#Language_Plural_Rules) #[diplomat::rust_link(icu::plurals::PluralCategory::get_for_cldr_string, FnInEnum)] #[diplomat::rust_link(icu::plurals::PluralCategory::get_for_cldr_bytes, FnInEnum)] - pub fn get_for_cldr_string(s: &str) -> Result { - let s = s.as_bytes(); // #2520 + pub fn get_for_cldr_string(s: &DiplomatStr) -> Result { PluralCategory::get_for_cldr_bytes(s) .ok_or(()) .map(Into::into) @@ -103,8 +100,7 @@ pub mod ffi { impl ICU4XPluralOperands { /// Construct for a given string representing a number #[diplomat::rust_link(icu::plurals::PluralOperands::from_str, FnInStruct)] - pub fn create_from_string(s: &str) -> Result, ICU4XError> { - let s = s.as_bytes(); // #2520 + pub fn create_from_string(s: &DiplomatStr) -> Result, ICU4XError> { Ok(Box::new(ICU4XPluralOperands(PluralOperands::from( // XXX should this have its own errors? &FixedDecimal::try_from(s).map_err(|_| ICU4XError::PluralsParserError)?, diff --git a/ffi/capi/src/properties_names.rs b/ffi/capi/src/properties_names.rs index a5ab0e143aa..44c8de1de68 100644 --- a/ffi/capi/src/properties_names.rs +++ b/ffi/capi/src/properties_names.rs @@ -38,12 +38,14 @@ pub mod ffi { FnInStruct, hidden )] - pub fn get_strict(&self, name: &str) -> i16 { - self.0 - .as_borrowed() - .get_strict(name) - .map(|x| x as i16) - .unwrap_or(-1) + pub fn get_strict(&self, name: &DiplomatStr) -> i16 { + if let Ok(name) = core::str::from_utf8(name) { + self.0.as_borrowed().get_strict(name) + } else { + None + } + .map(|u_16| u_16 as i16) + .unwrap_or(-1) } /// Get the property value matching the given name, using loose matching @@ -58,12 +60,14 @@ pub mod ffi { FnInStruct, hidden )] - pub fn get_loose(&self, name: &str) -> i16 { - self.0 - .as_borrowed() - .get_loose(name) - .map(|x| x as i16) - .unwrap_or(-1) + pub fn get_loose(&self, name: &DiplomatStr) -> i16 { + if let Ok(name) = core::str::from_utf8(name) { + self.0.as_borrowed().get_loose(name) + } else { + None + } + .map(|u_16| u_16 as i16) + .unwrap_or(-1) } #[diplomat::rust_link( @@ -219,12 +223,14 @@ pub mod ffi { /// Returns 0 if the name is unknown for this property // #[diplomat::rust_link(icu::properties::maps::PropertyValueNameToEnumMapperBorrowed::get_strict, FnInStruct)] // #[diplomat::rust_link(icu::properties::maps::PropertyValueNameToEnumMapperBorrowed::get_strict_u16, FnInStruct, hidden)] - pub fn get_strict(&self, name: &str) -> u32 { - self.0 - .as_borrowed() - .get_strict(name) - .map(Into::into) - .unwrap_or(0) + pub fn get_strict(&self, name: &DiplomatStr) -> u32 { + if let Ok(name) = core::str::from_utf8(name) { + self.0.as_borrowed().get_strict(name) + } else { + None + } + .map(Into::into) + .unwrap_or_default() } /// Get the mask value matching the given name, using loose matching @@ -232,12 +238,14 @@ pub mod ffi { /// Returns 0 if the name is unknown for this property // #[diplomat::rust_link(icu::properties::maps::PropertyValueNameToEnumMapperBorrowed::get_loose, FnInStruct)] // #[diplomat::rust_link(icu::properties::maps::PropertyValueNameToEnumMapperBorrowed::get_loose_u16, FnInStruct, hidden)] - pub fn get_loose(&self, name: &str) -> u32 { - self.0 - .as_borrowed() - .get_loose(name) - .map(Into::into) - .unwrap_or(0) + pub fn get_loose(&self, name: &DiplomatStr) -> u32 { + if let Ok(name) = core::str::from_utf8(name) { + self.0.as_borrowed().get_loose(name) + } else { + None + } + .map(Into::into) + .unwrap_or_default() } #[diplomat::rust_link( diff --git a/ffi/capi/src/properties_sets.rs b/ffi/capi/src/properties_sets.rs index f8e996060ce..4b2808e95f5 100644 --- a/ffi/capi/src/properties_sets.rs +++ b/ffi/capi/src/properties_sets.rs @@ -868,10 +868,9 @@ pub mod ffi { #[diplomat::rust_link(icu::properties::sets::load_for_ecma262, Fn, hidden)] pub fn load_for_ecma262( provider: &ICU4XDataProvider, - property_name: &str, + property_name: &DiplomatStr, ) -> Result, ICU4XError> { - let name = property_name.as_bytes(); // #2520 - let name = if let Ok(s) = str::from_utf8(name) { + let name = if let Ok(s) = str::from_utf8(property_name) { s } else { return Err(ICU4XError::TinyStrNonAsciiError); diff --git a/ffi/capi/src/properties_unisets.rs b/ffi/capi/src/properties_unisets.rs index dcb41521fa3..83417dbf962 100644 --- a/ffi/capi/src/properties_unisets.rs +++ b/ffi/capi/src/properties_unisets.rs @@ -23,8 +23,7 @@ pub mod ffi { impl ICU4XUnicodeSetData { /// Checks whether the string is in the set. #[diplomat::rust_link(icu::properties::sets::UnicodeSetDataBorrowed::contains, FnInStruct)] - pub fn contains(&self, s: &str) -> bool { - let s = s.as_bytes(); // #2520 + pub fn contains(&self, s: &DiplomatStr) -> bool { let s = if let Ok(s) = str::from_utf8(s) { s } else { diff --git a/ffi/capi/src/provider.rs b/ffi/capi/src/provider.rs index 18234f374c1..f9630d6c7a5 100644 --- a/ffi/capi/src/provider.rs +++ b/ffi/capi/src/provider.rs @@ -65,14 +65,13 @@ pub mod ffi { not(any(target_arch = "wasm32", target_os = "none")) ))] #[diplomat::attr(dart, disable)] - pub fn create_fs(path: &str) -> Result, ICU4XError> { - // #2520 - // In the future we can start using OsString APIs to support non-utf8 paths - core::str::from_utf8(path.as_bytes()) - .map_err(|e| ICU4XError::DataIoError.log_original(&e))?; - + pub fn create_fs(path: &DiplomatStr) -> Result, ICU4XError> { Ok(Box::new(convert_buffer_provider( - icu_provider_fs::FsDataProvider::try_new(path)?, + icu_provider_fs::FsDataProvider::try_new( + // In the future we can start using OsString APIs to support non-utf8 paths + core::str::from_utf8(path) + .map_err(|e| ICU4XError::DataIoError.log_original(&e))?, + )?, ))) } diff --git a/ffi/capi/src/segmenter_grapheme.rs b/ffi/capi/src/segmenter_grapheme.rs index 4f6794448df..19252f93901 100644 --- a/ffi/capi/src/segmenter_grapheme.rs +++ b/ffi/capi/src/segmenter_grapheme.rs @@ -65,11 +65,11 @@ pub mod ffi { hidden )] #[diplomat::rust_link(icu::segmenter::GraphemeClusterSegmenter::segment_utf8, FnInStruct)] + #[diplomat::attr(dart, disable)] pub fn segment_utf8<'a>( &'a self, - input: &'a str, + input: &'a DiplomatStr, ) -> Box> { - let input = input.as_bytes(); // #2520 Box::new(ICU4XGraphemeClusterBreakIteratorUtf8( self.0.segment_utf8(input), )) @@ -77,9 +77,10 @@ pub mod ffi { /// Segments a UTF-16 string. #[diplomat::rust_link(icu::segmenter::GraphemeClusterSegmenter::segment_utf16, FnInStruct)] + #[diplomat::attr(dart, rename = "segment")] pub fn segment_utf16<'a>( &'a self, - input: &'a [u16], + input: &'a DiplomatStr16, ) -> Box> { Box::new(ICU4XGraphemeClusterBreakIteratorUtf16( self.0.segment_utf16(input), @@ -88,6 +89,7 @@ pub mod ffi { /// Segments a Latin-1 string. #[diplomat::rust_link(icu::segmenter::GraphemeClusterSegmenter::segment_latin1, FnInStruct)] + #[diplomat::attr(dart, disable)] pub fn segment_latin1<'a>( &'a self, input: &'a [u8], diff --git a/ffi/capi/src/segmenter_line.rs b/ffi/capi/src/segmenter_line.rs index 4bfd085f4ce..625f2a89038 100644 --- a/ffi/capi/src/segmenter_line.rs +++ b/ffi/capi/src/segmenter_line.rs @@ -160,22 +160,27 @@ pub mod ffi { /// Segments a (potentially ill-formed) UTF-8 string. #[diplomat::rust_link(icu::segmenter::LineSegmenter::segment_utf8, FnInStruct)] #[diplomat::rust_link(icu::segmenter::LineSegmenter::segment_str, FnInStruct, hidden)] - pub fn segment_utf8<'a>(&'a self, input: &'a str) -> Box> { - let input = input.as_bytes(); // #2520 + #[diplomat::attr(dart, disable)] + pub fn segment_utf8<'a>( + &'a self, + input: &'a DiplomatStr, + ) -> Box> { Box::new(ICU4XLineBreakIteratorUtf8(self.0.segment_utf8(input))) } /// Segments a UTF-16 string. #[diplomat::rust_link(icu::segmenter::LineSegmenter::segment_utf16, FnInStruct)] + #[diplomat::attr(dart, rename = "segment")] pub fn segment_utf16<'a>( &'a self, - input: &'a [u16], + input: &'a DiplomatStr16, ) -> Box> { Box::new(ICU4XLineBreakIteratorUtf16(self.0.segment_utf16(input))) } /// Segments a Latin-1 string. #[diplomat::rust_link(icu::segmenter::LineSegmenter::segment_latin1, FnInStruct)] + #[diplomat::attr(dart, disable)] pub fn segment_latin1<'a>( &'a self, input: &'a [u8], diff --git a/ffi/capi/src/segmenter_sentence.rs b/ffi/capi/src/segmenter_sentence.rs index 0114d09b3dd..a06116f6ac4 100644 --- a/ffi/capi/src/segmenter_sentence.rs +++ b/ffi/capi/src/segmenter_sentence.rs @@ -56,25 +56,27 @@ pub mod ffi { /// Segments a (potentially ill-formed) UTF-8 string. #[diplomat::rust_link(icu::segmenter::SentenceSegmenter::segment_utf8, FnInStruct)] #[diplomat::rust_link(icu::segmenter::SentenceSegmenter::segment_str, FnInStruct, hidden)] + #[diplomat::attr(dart, disable)] pub fn segment_utf8<'a>( &'a self, - input: &'a str, + input: &'a DiplomatStr, ) -> Box> { - let input = input.as_bytes(); // #2520 Box::new(ICU4XSentenceBreakIteratorUtf8(self.0.segment_utf8(input))) } /// Segments a UTF-16 string. #[diplomat::rust_link(icu::segmenter::SentenceSegmenter::segment_utf16, FnInStruct)] + #[diplomat::attr(dart, rename = "segment")] pub fn segment_utf16<'a>( &'a self, - input: &'a [u16], + input: &'a DiplomatStr16, ) -> Box> { Box::new(ICU4XSentenceBreakIteratorUtf16(self.0.segment_utf16(input))) } /// Segments a Latin-1 string. #[diplomat::rust_link(icu::segmenter::SentenceSegmenter::segment_latin1, FnInStruct)] + #[diplomat::attr(dart, disable)] pub fn segment_latin1<'a>( &'a self, input: &'a [u8], diff --git a/ffi/capi/src/segmenter_word.rs b/ffi/capi/src/segmenter_word.rs index a7e9fed4b9d..8e3d1beedec 100644 --- a/ffi/capi/src/segmenter_word.rs +++ b/ffi/capi/src/segmenter_word.rs @@ -97,22 +97,27 @@ pub mod ffi { /// Segments a (potentially ill-formed) UTF-8 string. #[diplomat::rust_link(icu::segmenter::WordSegmenter::segment_utf8, FnInStruct)] #[diplomat::rust_link(icu::segmenter::WordSegmenter::segment_str, FnInStruct, hidden)] - pub fn segment_utf8<'a>(&'a self, input: &'a str) -> Box> { - let input = input.as_bytes(); // #2520 + #[diplomat::attr(dart, disable)] + pub fn segment_utf8<'a>( + &'a self, + input: &'a DiplomatStr, + ) -> Box> { Box::new(ICU4XWordBreakIteratorUtf8(self.0.segment_utf8(input))) } /// Segments a UTF-16 string. #[diplomat::rust_link(icu::segmenter::WordSegmenter::segment_utf16, FnInStruct)] + #[diplomat::attr(dart, rename = "segment")] pub fn segment_utf16<'a>( &'a self, - input: &'a [u16], + input: &'a DiplomatStr16, ) -> Box> { Box::new(ICU4XWordBreakIteratorUtf16(self.0.segment_utf16(input))) } /// Segments a Latin-1 string. #[diplomat::rust_link(icu::segmenter::WordSegmenter::segment_latin1, FnInStruct)] + #[diplomat::attr(dart, disable)] pub fn segment_latin1<'a>( &'a self, input: &'a [u8], diff --git a/ffi/capi/src/timezone.rs b/ffi/capi/src/timezone.rs index 4c8b2659b79..0757bb4d243 100644 --- a/ffi/capi/src/timezone.rs +++ b/ffi/capi/src/timezone.rs @@ -9,7 +9,6 @@ pub mod ffi { use crate::errors::ffi::ICU4XError; use alloc::boxed::Box; use core::fmt::Write; - use core::str::{self}; use icu_timezone::CustomTimeZone; use icu_timezone::GmtOffset; use icu_timezone::ZoneVariant; @@ -24,10 +23,9 @@ pub mod ffi { #[diplomat::rust_link(icu::timezone::CustomTimeZone::try_from_bytes, FnInStruct, hidden)] #[diplomat::rust_link(icu::timezone::GmtOffset::from_str, FnInStruct, hidden)] #[diplomat::rust_link(icu::timezone::GmtOffset::try_from_bytes, FnInStruct, hidden)] - pub fn create_from_string(s: &str) -> Result, ICU4XError> { - let bytes = s.as_bytes(); + pub fn create_from_string(s: &DiplomatStr) -> Result, ICU4XError> { Ok(Box::new(ICU4XCustomTimeZone::from( - CustomTimeZone::try_from_bytes(bytes)?, + CustomTimeZone::try_from_bytes(s)?, ))) } @@ -132,8 +130,10 @@ pub mod ffi { #[diplomat::rust_link(icu::timezone::CustomTimeZone::time_zone_id, StructField)] #[diplomat::rust_link(icu::timezone::TimeZoneBcp47Id, Struct, compact)] #[diplomat::rust_link(icu::timezone::TimeZoneBcp47Id::from_str, FnInStruct, hidden)] - pub fn try_set_time_zone_id(&mut self, id: &str) -> Result<(), ICU4XError> { - self.0.time_zone_id = Some(id.parse()?); + pub fn try_set_time_zone_id(&mut self, id: &DiplomatStr) -> Result<(), ICU4XError> { + self.0.time_zone_id = Some(icu_timezone::TimeZoneBcp47Id( + tinystr::TinyAsciiStr::from_bytes(id)?, + )); Ok(()) } @@ -145,9 +145,9 @@ pub mod ffi { pub fn try_set_iana_time_zone_id( &mut self, mapper: &crate::iana_bcp47_mapper::ffi::ICU4XIanaToBcp47Mapper, - id: &str, + id: &DiplomatStr, ) -> Result<(), ICU4XError> { - match mapper.0.as_borrowed().get(id) { + match mapper.0.as_borrowed().get_bytes(id) { Some(id) => { self.0.time_zone_id = Some(id); Ok(()) @@ -188,8 +188,10 @@ pub mod ffi { #[diplomat::rust_link(icu::timezone::CustomTimeZone::metazone_id, StructField)] #[diplomat::rust_link(icu::timezone::MetazoneId, Struct, compact)] #[diplomat::rust_link(icu::timezone::MetazoneId::from_str, FnInStruct, hidden)] - pub fn try_set_metazone_id(&mut self, id: &str) -> Result<(), ICU4XError> { - self.0.metazone_id = Some(id.parse()?); + pub fn try_set_metazone_id(&mut self, id: &DiplomatStr) -> Result<(), ICU4XError> { + self.0.metazone_id = Some(icu_timezone::MetazoneId(tinystr::TinyAsciiStr::from_bytes( + id, + )?)); Ok(()) } @@ -225,8 +227,10 @@ pub mod ffi { #[diplomat::rust_link(icu::timezone::CustomTimeZone::zone_variant, StructField)] #[diplomat::rust_link(icu::timezone::ZoneVariant, Struct, compact)] #[diplomat::rust_link(icu::timezone::ZoneVariant::from_str, FnInStruct, hidden)] - pub fn try_set_zone_variant(&mut self, id: &str) -> Result<(), ICU4XError> { - self.0.zone_variant = Some(id.parse()?); + pub fn try_set_zone_variant(&mut self, id: &DiplomatStr) -> Result<(), ICU4XError> { + self.0.zone_variant = Some(icu_timezone::ZoneVariant( + tinystr::TinyAsciiStr::from_bytes(id)?, + )); Ok(()) } diff --git a/ffi/gn/.cargo/config b/ffi/gn/.cargo/config index 8095c61799c..13221376df2 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=f545acf50629b6f2135adca374507b717a821cd8"] +[source."git+https://github.com/rust-diplomat/diplomat.git?rev=04efb3cb53f853fd6fd560eb248940c59472f425"] git = "https://github.com/rust-diplomat/diplomat.git" -rev = "f545acf50629b6f2135adca374507b717a821cd8" +rev = "04efb3cb53f853fd6fd560eb248940c59472f425" replace-with = "vendored-sources" [source.vendored-sources] diff --git a/ffi/gn/Cargo.lock b/ffi/gn/Cargo.lock index 172995b92d6..70a8f71daa4 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=f545acf50629b6f2135adca374507b717a821cd8#f545acf50629b6f2135adca374507b717a821cd8" +source = "git+https://github.com/rust-diplomat/diplomat.git?rev=04efb3cb53f853fd6fd560eb248940c59472f425#04efb3cb53f853fd6fd560eb248940c59472f425" 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=f545acf50629b6f2135adca374507b717a821cd8#f545acf50629b6f2135adca374507b717a821cd8" +source = "git+https://github.com/rust-diplomat/diplomat.git?rev=04efb3cb53f853fd6fd560eb248940c59472f425#04efb3cb53f853fd6fd560eb248940c59472f425" [[package]] name = "diplomat_core" version = "0.7.0" -source = "git+https://github.com/rust-diplomat/diplomat.git?rev=f545acf50629b6f2135adca374507b717a821cd8#f545acf50629b6f2135adca374507b717a821cd8" +source = "git+https://github.com/rust-diplomat/diplomat.git?rev=04efb3cb53f853fd6fd560eb248940c59472f425#04efb3cb53f853fd6fd560eb248940c59472f425" dependencies = [ "lazy_static", "proc-macro2",