blob: 648572e8db443821c0380c03401c594421feb076 [file] [edit]
// generated by diplomat-tool
part of 'lib.g.dart';
/// See the [Rust documentation for `ComposingNormalizer`](https://docs.rs/icu/latest/icu/normalizer/struct.ComposingNormalizer.html) for more information.
final class ComposingNormalizer 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.
ComposingNormalizer._fromFfi(this._ffi, this._selfEdge) {
if (_selfEdge.isEmpty) {
_finalizer.attach(this, _ffi.cast());
}
}
static final _finalizer = ffi.NativeFinalizer(
ffi.Native.addressOf(_ICU4XComposingNormalizer_destroy));
/// Construct a new ICU4XComposingNormalizer instance for NFC
///
/// See the [Rust documentation for `new_nfc`](https://docs.rs/icu/latest/icu/normalizer/struct.ComposingNormalizer.html#method.new_nfc) for more information.
///
/// Throws [Error] on failure.
factory ComposingNormalizer.nfc(DataProvider provider) {
final result = _ICU4XComposingNormalizer_create_nfc(provider._ffi);
if (!result.isOk) {
throw Error.values.firstWhere((v) => v._ffi == result.union.err);
}
return ComposingNormalizer._fromFfi(result.union.ok, []);
}
/// Construct a new ICU4XComposingNormalizer instance for NFKC
///
/// See the [Rust documentation for `new_nfkc`](https://docs.rs/icu/latest/icu/normalizer/struct.ComposingNormalizer.html#method.new_nfkc) for more information.
///
/// Throws [Error] on failure.
factory ComposingNormalizer.nfkc(DataProvider provider) {
final result = _ICU4XComposingNormalizer_create_nfkc(provider._ffi);
if (!result.isOk) {
throw Error.values.firstWhere((v) => v._ffi == result.union.err);
}
return ComposingNormalizer._fromFfi(result.union.ok, []);
}
/// Normalize a string
///
/// Ill-formed input is treated as if errors had been replaced with REPLACEMENT CHARACTERs according
/// to the WHATWG Encoding Standard.
///
/// See the [Rust documentation for `normalize_utf8`](https://docs.rs/icu/latest/icu/normalizer/struct.ComposingNormalizer.html#method.normalize_utf8) for more information.
///
/// Throws [Error] on failure.
String normalize(String s) {
final temp = ffi2.Arena();
final sView = s.utf8View;
final writeable = _Writeable();
final result = _ICU4XComposingNormalizer_normalize(
_ffi, sView.allocIn(temp), sView.length, writeable._ffi);
temp.releaseAll();
if (!result.isOk) {
throw Error.values.firstWhere((v) => v._ffi == result.union.err);
}
return writeable.finalize();
}
/// Check if a string is normalized
///
/// Ill-formed input is treated as if errors had been replaced with REPLACEMENT CHARACTERs according
/// to the WHATWG Encoding Standard.
///
/// 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 temp = ffi2.Arena();
final sView = s.utf8View;
final result = _ICU4XComposingNormalizer_is_normalized(
_ffi, sView.allocIn(temp), sView.length);
temp.releaseAll();
return result;
}
}
@meta.ResourceIdentifier('ICU4XComposingNormalizer_destroy')
@ffi.Native<ffi.Void Function(ffi.Pointer<ffi.Void>)>(
isLeaf: true, symbol: 'ICU4XComposingNormalizer_destroy')
// ignore: non_constant_identifier_names
external void _ICU4XComposingNormalizer_destroy(ffi.Pointer<ffi.Void> self);
@meta.ResourceIdentifier('ICU4XComposingNormalizer_create_nfc')
@ffi.Native<_ResultOpaqueInt32 Function(ffi.Pointer<ffi.Opaque>)>(
isLeaf: true, symbol: 'ICU4XComposingNormalizer_create_nfc')
// ignore: non_constant_identifier_names
external _ResultOpaqueInt32 _ICU4XComposingNormalizer_create_nfc(
ffi.Pointer<ffi.Opaque> provider);
@meta.ResourceIdentifier('ICU4XComposingNormalizer_create_nfkc')
@ffi.Native<_ResultOpaqueInt32 Function(ffi.Pointer<ffi.Opaque>)>(
isLeaf: true, symbol: 'ICU4XComposingNormalizer_create_nfkc')
// ignore: non_constant_identifier_names
external _ResultOpaqueInt32 _ICU4XComposingNormalizer_create_nfkc(
ffi.Pointer<ffi.Opaque> provider);
@meta.ResourceIdentifier('ICU4XComposingNormalizer_normalize')
@ffi.Native<
_ResultVoidInt32 Function(ffi.Pointer<ffi.Opaque>,
ffi.Pointer<ffi.Uint8>, ffi.Size, ffi.Pointer<ffi.Opaque>)>(
isLeaf: true, symbol: 'ICU4XComposingNormalizer_normalize')
// ignore: non_constant_identifier_names
external _ResultVoidInt32 _ICU4XComposingNormalizer_normalize(
ffi.Pointer<ffi.Opaque> self,
ffi.Pointer<ffi.Uint8> sData,
int sLength,
ffi.Pointer<ffi.Opaque> writeable);
@meta.ResourceIdentifier('ICU4XComposingNormalizer_is_normalized')
@ffi.Native<
ffi.Bool Function(
ffi.Pointer<ffi.Opaque>, ffi.Pointer<ffi.Uint8>, ffi.Size)>(
isLeaf: true, symbol: 'ICU4XComposingNormalizer_is_normalized')
// ignore: non_constant_identifier_names
external bool _ICU4XComposingNormalizer_is_normalized(
ffi.Pointer<ffi.Opaque> self, ffi.Pointer<ffi.Uint8> sData, int sLength);