| // generated by diplomat-tool |
| |
| part of 'lib.g.dart'; |
| |
| /// A mapper between IANA time zone identifiers and BCP-47 time zone identifiers. |
| /// |
| /// This mapper supports two-way mapping, but it is optimized for the case of IANA to BCP-47. |
| /// It also supports normalizing and canonicalizing the IANA strings. |
| /// |
| /// See the [Rust documentation for `TimeZoneIdMapper`](https://docs.rs/icu/latest/icu/timezone/struct.TimeZoneIdMapper.html) for more information. |
| final class TimeZoneIdMapper implements ffi.Finalizable { |
| final ffi.Pointer<ffi.Opaque> _ffi; |
| |
| // These are "used" in the sense that they keep dependencies alive |
| // ignore: unused_field |
| final core.List<Object> _selfEdge; |
| |
| // This takes in a list of lifetime edges (including for &self borrows) |
| // corresponding to data this may borrow from. These should be flat arrays containing |
| // references to objects, and this object will hold on to them to keep them alive and |
| // maintain borrow validity. |
| TimeZoneIdMapper._fromFfi(this._ffi, this._selfEdge) { |
| if (_selfEdge.isEmpty) { |
| _finalizer.attach(this, _ffi.cast()); |
| } |
| } |
| |
| static final _finalizer = |
| ffi.NativeFinalizer(ffi.Native.addressOf(_ICU4XTimeZoneIdMapper_destroy)); |
| |
| /// See the [Rust documentation for `new`](https://docs.rs/icu/latest/icu/timezone/struct.TimeZoneIdMapper.html#method.new) for more information. |
| /// |
| /// Throws [Error] on failure. |
| factory TimeZoneIdMapper(DataProvider provider) { |
| final result = _ICU4XTimeZoneIdMapper_create(provider._ffi); |
| if (!result.isOk) { |
| throw Error.values.firstWhere((v) => v._ffi == result.union.err); |
| } |
| return TimeZoneIdMapper._fromFfi(result.union.ok, []); |
| } |
| |
| /// See the [Rust documentation for `iana_to_bcp47`](https://docs.rs/icu/latest/icu/timezone/struct.TimeZoneIdMapperBorrowed.html#method.iana_to_bcp47) for more information. |
| /// |
| /// Throws [Error] on failure. |
| String ianaToBcp47(String value) { |
| final temp = ffi2.Arena(); |
| final valueView = value.utf8View; |
| final writeable = _Writeable(); |
| final result = _ICU4XTimeZoneIdMapper_iana_to_bcp47( |
| _ffi, valueView.allocIn(temp), valueView.length, writeable._ffi); |
| temp.releaseAll(); |
| if (!result.isOk) { |
| throw Error.values.firstWhere((v) => v._ffi == result.union.err); |
| } |
| return writeable.finalize(); |
| } |
| |
| /// See the [Rust documentation for `normalize_iana`](https://docs.rs/icu/latest/icu/timezone/struct.TimeZoneIdMapperBorrowed.html#method.normalize_iana) for more information. |
| /// |
| /// Throws [Error] on failure. |
| String normalizeIana(String value) { |
| final temp = ffi2.Arena(); |
| final valueView = value.utf8View; |
| final writeable = _Writeable(); |
| final result = _ICU4XTimeZoneIdMapper_normalize_iana( |
| _ffi, valueView.allocIn(temp), valueView.length, writeable._ffi); |
| temp.releaseAll(); |
| if (!result.isOk) { |
| throw Error.values.firstWhere((v) => v._ffi == result.union.err); |
| } |
| return writeable.finalize(); |
| } |
| |
| /// See the [Rust documentation for `canonicalize_iana`](https://docs.rs/icu/latest/icu/timezone/struct.TimeZoneIdMapperBorrowed.html#method.canonicalize_iana) for more information. |
| /// |
| /// Throws [Error] on failure. |
| String canonicalizeIana(String value) { |
| final temp = ffi2.Arena(); |
| final valueView = value.utf8View; |
| final writeable = _Writeable(); |
| final result = _ICU4XTimeZoneIdMapper_canonicalize_iana( |
| _ffi, valueView.allocIn(temp), valueView.length, writeable._ffi); |
| temp.releaseAll(); |
| if (!result.isOk) { |
| throw Error.values.firstWhere((v) => v._ffi == result.union.err); |
| } |
| return writeable.finalize(); |
| } |
| |
| /// See the [Rust documentation for `find_canonical_iana_from_bcp47`](https://docs.rs/icu/latest/icu/timezone/struct.TimeZoneIdMapperBorrowed.html#method.find_canonical_iana_from_bcp47) for more information. |
| /// |
| /// Throws [Error] on failure. |
| String findCanonicalIanaFromBcp47(String value) { |
| final temp = ffi2.Arena(); |
| final valueView = value.utf8View; |
| final writeable = _Writeable(); |
| final result = _ICU4XTimeZoneIdMapper_find_canonical_iana_from_bcp47( |
| _ffi, valueView.allocIn(temp), valueView.length, writeable._ffi); |
| temp.releaseAll(); |
| if (!result.isOk) { |
| throw Error.values.firstWhere((v) => v._ffi == result.union.err); |
| } |
| return writeable.finalize(); |
| } |
| } |
| |
| @meta.ResourceIdentifier('ICU4XTimeZoneIdMapper_destroy') |
| @ffi.Native<ffi.Void Function(ffi.Pointer<ffi.Void>)>( |
| isLeaf: true, symbol: 'ICU4XTimeZoneIdMapper_destroy') |
| // ignore: non_constant_identifier_names |
| external void _ICU4XTimeZoneIdMapper_destroy(ffi.Pointer<ffi.Void> self); |
| |
| @meta.ResourceIdentifier('ICU4XTimeZoneIdMapper_create') |
| @ffi.Native<_ResultOpaqueInt32 Function(ffi.Pointer<ffi.Opaque>)>( |
| isLeaf: true, symbol: 'ICU4XTimeZoneIdMapper_create') |
| // ignore: non_constant_identifier_names |
| external _ResultOpaqueInt32 _ICU4XTimeZoneIdMapper_create( |
| ffi.Pointer<ffi.Opaque> provider); |
| |
| @meta.ResourceIdentifier('ICU4XTimeZoneIdMapper_iana_to_bcp47') |
| @ffi.Native< |
| _ResultVoidInt32 Function(ffi.Pointer<ffi.Opaque>, |
| ffi.Pointer<ffi.Uint8>, ffi.Size, ffi.Pointer<ffi.Opaque>)>( |
| isLeaf: true, symbol: 'ICU4XTimeZoneIdMapper_iana_to_bcp47') |
| // ignore: non_constant_identifier_names |
| external _ResultVoidInt32 _ICU4XTimeZoneIdMapper_iana_to_bcp47( |
| ffi.Pointer<ffi.Opaque> self, |
| ffi.Pointer<ffi.Uint8> valueData, |
| int valueLength, |
| ffi.Pointer<ffi.Opaque> writeable); |
| |
| @meta.ResourceIdentifier('ICU4XTimeZoneIdMapper_normalize_iana') |
| @ffi.Native< |
| _ResultVoidInt32 Function(ffi.Pointer<ffi.Opaque>, |
| ffi.Pointer<ffi.Uint8>, ffi.Size, ffi.Pointer<ffi.Opaque>)>( |
| isLeaf: true, symbol: 'ICU4XTimeZoneIdMapper_normalize_iana') |
| // ignore: non_constant_identifier_names |
| external _ResultVoidInt32 _ICU4XTimeZoneIdMapper_normalize_iana( |
| ffi.Pointer<ffi.Opaque> self, |
| ffi.Pointer<ffi.Uint8> valueData, |
| int valueLength, |
| ffi.Pointer<ffi.Opaque> writeable); |
| |
| @meta.ResourceIdentifier('ICU4XTimeZoneIdMapper_canonicalize_iana') |
| @ffi.Native< |
| _ResultVoidInt32 Function(ffi.Pointer<ffi.Opaque>, |
| ffi.Pointer<ffi.Uint8>, ffi.Size, ffi.Pointer<ffi.Opaque>)>( |
| isLeaf: true, symbol: 'ICU4XTimeZoneIdMapper_canonicalize_iana') |
| // ignore: non_constant_identifier_names |
| external _ResultVoidInt32 _ICU4XTimeZoneIdMapper_canonicalize_iana( |
| ffi.Pointer<ffi.Opaque> self, |
| ffi.Pointer<ffi.Uint8> valueData, |
| int valueLength, |
| ffi.Pointer<ffi.Opaque> writeable); |
| |
| @meta.ResourceIdentifier('ICU4XTimeZoneIdMapper_find_canonical_iana_from_bcp47') |
| @ffi.Native< |
| _ResultVoidInt32 Function(ffi.Pointer<ffi.Opaque>, |
| ffi.Pointer<ffi.Uint8>, ffi.Size, ffi.Pointer<ffi.Opaque>)>( |
| isLeaf: true, |
| symbol: 'ICU4XTimeZoneIdMapper_find_canonical_iana_from_bcp47') |
| // ignore: non_constant_identifier_names |
| external _ResultVoidInt32 _ICU4XTimeZoneIdMapper_find_canonical_iana_from_bcp47( |
| ffi.Pointer<ffi.Opaque> self, |
| ffi.Pointer<ffi.Uint8> valueData, |
| int valueLength, |
| ffi.Pointer<ffi.Opaque> writeable); |