// generated by diplomat-tool
// dart format off

part of 'lib.g.dart';

/// An ICU4X word-break segmenter, capable of finding word breakpoints in strings.
///
/// See the [Rust documentation for `WordSegmenter`](https://docs.rs/icu/2.2.0/icu/segmenter/struct.WordSegmenter.html) for more information.
final class WordSegmenter 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.
  WordSegmenter._fromFfi(this._ffi, this._selfEdge) {
    if (_selfEdge.isEmpty) {
      _icu4x_WordSegmenter_destroy_mv1(this, _ffi.cast());
    }
  }

  // ignore: experimental_member_use
  @meta.RecordUse()
  // ignore: non_constant_identifier_names
  static void _icu4x_WordSegmenter_destroy_mv1(WordSegmenter cl, ffi.Pointer<ffi.Void> pointer) => _finalizer.attach(cl, pointer);

  static final _finalizer = ffi.NativeFinalizer(ffi.Native.addressOf(_internal_icu4x_WordSegmenter_destroy_mv1));

  /// Construct a [WordSegmenter] with automatically selecting the best available LSTM
  /// or dictionary payload data, using compiled data. This does not assume any content locale.
  ///
  /// Note: currently, it uses dictionary for Chinese and Japanese, and LSTM for Burmese,
  /// Khmer, Lao, and Thai.
  ///
  /// See the [Rust documentation for `new_auto`](https://docs.rs/icu/2.2.0/icu/segmenter/struct.WordSegmenter.html#method.new_auto) for more information.
  factory WordSegmenter.auto() {
    final result = _icu4x_WordSegmenter_create_auto_mv1();
    return WordSegmenter._fromFfi(result, []);
  }

  /// Construct a [WordSegmenter] with automatically selecting the best available LSTM
  /// or dictionary payload data, using compiled data.
  ///
  /// Note: currently, it uses dictionary for Chinese and Japanese, and LSTM for Burmese,
  /// Khmer, Lao, and Thai.
  ///
  /// See the [Rust documentation for `try_new_auto`](https://docs.rs/icu/2.2.0/icu/segmenter/struct.WordSegmenter.html#method.try_new_auto) for more information.
  ///
  /// Throws [DataError] on failure.
  factory WordSegmenter.autoWithContentLocale(Locale locale) {
    final result = _icu4x_WordSegmenter_create_auto_with_content_locale_mv1(locale._ffi);
    if (!result.isOk) {
      throw DataError.values[result.union.err];
    }
    return WordSegmenter._fromFfi(result.union.ok, []);
  }

  /// Construct a [WordSegmenter] with automatically selecting the best available LSTM
  /// or dictionary payload data, using a particular data source.
  ///
  /// Note: currently, it uses dictionary for Chinese and Japanese, and LSTM for Burmese,
  /// Khmer, Lao, and Thai.
  ///
  /// See the [Rust documentation for `try_new_auto`](https://docs.rs/icu/2.2.0/icu/segmenter/struct.WordSegmenter.html#method.try_new_auto) for more information.
  ///
  /// Throws [DataError] on failure.
  factory WordSegmenter.autoWithContentLocaleAndProvider(DataProvider provider, Locale locale) {
    final result = _icu4x_WordSegmenter_create_auto_with_content_locale_and_provider_mv1(provider._ffi, locale._ffi);
    if (!result.isOk) {
      throw DataError.values[result.union.err];
    }
    return WordSegmenter._fromFfi(result.union.ok, []);
  }

  /// Construct a [WordSegmenter] with LSTM payload data for Burmese, Khmer, Lao, and
  /// Thai, using compiled data. This does not assume any content locale.
  ///
  /// Note: currently, it uses dictionary for Chinese and Japanese, and LSTM for Burmese,
  /// Khmer, Lao, and Thai.
  ///
  /// See the [Rust documentation for `new_lstm`](https://docs.rs/icu/2.2.0/icu/segmenter/struct.WordSegmenter.html#method.new_lstm) for more information.
  factory WordSegmenter.lstm() {
    final result = _icu4x_WordSegmenter_create_lstm_mv1();
    return WordSegmenter._fromFfi(result, []);
  }

  /// Construct a [WordSegmenter] with LSTM payload data for Burmese, Khmer, Lao, and
  /// Thai, using compiled data.
  ///
  /// Note: currently, it uses dictionary for Chinese and Japanese, and LSTM for Burmese,
  /// Khmer, Lao, and Thai.
  ///
  /// See the [Rust documentation for `try_new_lstm`](https://docs.rs/icu/2.2.0/icu/segmenter/struct.WordSegmenter.html#method.try_new_lstm) for more information.
  ///
  /// Throws [DataError] on failure.
  factory WordSegmenter.lstmWithContentLocale(Locale locale) {
    final result = _icu4x_WordSegmenter_create_lstm_with_content_locale_mv1(locale._ffi);
    if (!result.isOk) {
      throw DataError.values[result.union.err];
    }
    return WordSegmenter._fromFfi(result.union.ok, []);
  }

  /// Construct a [WordSegmenter] with LSTM payload data for Burmese, Khmer, Lao, and
  /// Thai, using a particular data source.
  ///
  /// Note: currently, it uses dictionary for Chinese and Japanese, and LSTM for Burmese,
  /// Khmer, Lao, and Thai.
  ///
  /// See the [Rust documentation for `try_new_lstm`](https://docs.rs/icu/2.2.0/icu/segmenter/struct.WordSegmenter.html#method.try_new_lstm) for more information.
  ///
  /// Throws [DataError] on failure.
  factory WordSegmenter.lstmWithContentLocaleAndProvider(DataProvider provider, Locale locale) {
    final result = _icu4x_WordSegmenter_create_lstm_with_content_locale_and_provider_mv1(provider._ffi, locale._ffi);
    if (!result.isOk) {
      throw DataError.values[result.union.err];
    }
    return WordSegmenter._fromFfi(result.union.ok, []);
  }

  /// Construct a [WordSegmenter] with dictionary payload data for Chinese, Japanese,
  /// Burmese, Khmer, Lao, and Thai, using compiled data. This does not assume any content locale.
  ///
  /// Note: currently, it uses dictionary for Chinese and Japanese, and dictionary for Burmese,
  /// Khmer, Lao, and Thai.
  ///
  /// See the [Rust documentation for `new_dictionary`](https://docs.rs/icu/2.2.0/icu/segmenter/struct.WordSegmenter.html#method.new_dictionary) for more information.
  factory WordSegmenter.dictionary() {
    final result = _icu4x_WordSegmenter_create_dictionary_mv1();
    return WordSegmenter._fromFfi(result, []);
  }

  /// Construct a [WordSegmenter] with dictionary payload data for Chinese, Japanese,
  /// Burmese, Khmer, Lao, and Thai, using compiled data.
  ///
  /// Note: currently, it uses dictionary for Chinese and Japanese, and dictionary for Burmese,
  /// Khmer, Lao, and Thai.
  ///
  /// See the [Rust documentation for `try_new_dictionary`](https://docs.rs/icu/2.2.0/icu/segmenter/struct.WordSegmenter.html#method.try_new_dictionary) for more information.
  ///
  /// Throws [DataError] on failure.
  factory WordSegmenter.dictionaryWithContentLocale(Locale locale) {
    final result = _icu4x_WordSegmenter_create_dictionary_with_content_locale_mv1(locale._ffi);
    if (!result.isOk) {
      throw DataError.values[result.union.err];
    }
    return WordSegmenter._fromFfi(result.union.ok, []);
  }

  /// Construct a [WordSegmenter] with dictionary payload data for Chinese, Japanese,
  /// Burmese, Khmer, Lao, and Thai, using a particular data source.
  ///
  /// Note: currently, it uses dictionary for Chinese and Japanese, and dictionary for Burmese,
  /// Khmer, Lao, and Thai.
  ///
  /// See the [Rust documentation for `try_new_dictionary`](https://docs.rs/icu/2.2.0/icu/segmenter/struct.WordSegmenter.html#method.try_new_dictionary) for more information.
  ///
  /// Throws [DataError] on failure.
  factory WordSegmenter.dictionaryWithContentLocaleAndProvider(DataProvider provider, Locale locale) {
    final result = _icu4x_WordSegmenter_create_dictionary_with_content_locale_and_provider_mv1(provider._ffi, locale._ffi);
    if (!result.isOk) {
      throw DataError.values[result.union.err];
    }
    return WordSegmenter._fromFfi(result.union.ok, []);
  }

  /// Construct a [WordSegmenter] with no support for scripts requiring complex context dependent word breaks (Chinese, Japanese,
  /// Burmese, Khmer, Lao, and Thai), using compiled data. This does not assume any content locale.
  ///
  /// See the [Rust documentation for `new_for_non_complex_scripts`](https://docs.rs/icu/2.2.0/icu/segmenter/struct.WordSegmenter.html#method.new_for_non_complex_scripts) for more information.
  factory WordSegmenter.forNonComplexScripts() {
    final result = _icu4x_WordSegmenter_create_for_non_complex_scripts_mv1();
    return WordSegmenter._fromFfi(result, []);
  }

  /// Construct a [WordSegmenter] with no support for scripts requiring complex context dependent word breaks (Chinese, Japanese,
  /// Burmese, Khmer, Lao, and Thai), using compiled data.
  ///
  /// See the [Rust documentation for `try_new_for_non_complex_scripts`](https://docs.rs/icu/2.2.0/icu/segmenter/struct.WordSegmenter.html#method.try_new_for_non_complex_scripts) for more information.
  ///
  /// Throws [DataError] on failure.
  factory WordSegmenter.forNonComplexScriptsWithContentLocale(Locale locale) {
    final result = _icu4x_WordSegmenter_create_for_non_complex_scripts_with_content_locale_mv1(locale._ffi);
    if (!result.isOk) {
      throw DataError.values[result.union.err];
    }
    return WordSegmenter._fromFfi(result.union.ok, []);
  }

  /// Construct a [WordSegmenter] with no support for scripts requiring complex context dependent word breaks (Chinese, Japanese,
  /// Burmese, Khmer, Lao, and Thai), using a particular data source.
  ///
  /// See the [Rust documentation for `try_new_for_non_complex_scripts`](https://docs.rs/icu/2.2.0/icu/segmenter/struct.WordSegmenter.html#method.try_new_for_non_complex_scripts) for more information.
  ///
  /// Throws [DataError] on failure.
  factory WordSegmenter.forNonComplexScriptsWithContentLocaleAndProvider(DataProvider provider, Locale locale) {
    final result = _icu4x_WordSegmenter_create_for_non_complex_scripts_with_content_locale_and_provider_mv1(provider._ffi, locale._ffi);
    if (!result.isOk) {
      throw DataError.values[result.union.err];
    }
    return WordSegmenter._fromFfi(result.union.ok, []);
  }

  /// Segments 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 `segment_utf16`](https://docs.rs/icu/2.2.0/icu/segmenter/struct.WordSegmenterBorrowed.html#method.segment_utf16) for more information.
  WordBreakIteratorUtf16 segment(String input) {
    final inputArena = _FinalizedArena();
    // This lifetime edge depends on lifetimes: 'a
    final aEdges = [this, inputArena];
    final result = _icu4x_WordSegmenter_segment_utf16_mv1(_ffi, input._utf16AllocIn(inputArena.arena));
    return WordBreakIteratorUtf16._fromFfi(result, [], aEdges);
  }

}

// ignore: experimental_member_use
@meta.RecordUse()
@ffi.Native<ffi.Void Function(ffi.Pointer<ffi.Void>)>(isLeaf: true, symbol: 'icu4x_WordSegmenter_destroy_mv1')
// ignore: non_constant_identifier_names
external void _internal_icu4x_WordSegmenter_destroy_mv1(ffi.Pointer<ffi.Void> self);

// ignore: experimental_member_use
@meta.RecordUse()
@ffi.Native<ffi.Pointer<ffi.Opaque> Function()>(isLeaf: true, symbol: 'icu4x_WordSegmenter_create_auto_mv1')
// ignore: non_constant_identifier_names
external ffi.Pointer<ffi.Opaque> _icu4x_WordSegmenter_create_auto_mv1();

// ignore: experimental_member_use
@meta.RecordUse()
@ffi.Native<_ResultOpaqueInt32 Function(ffi.Pointer<ffi.Opaque>)>(isLeaf: true, symbol: 'icu4x_WordSegmenter_create_auto_with_content_locale_mv1')
// ignore: non_constant_identifier_names
external _ResultOpaqueInt32 _icu4x_WordSegmenter_create_auto_with_content_locale_mv1(ffi.Pointer<ffi.Opaque> locale);

// ignore: experimental_member_use
@meta.RecordUse()
@ffi.Native<_ResultOpaqueInt32 Function(ffi.Pointer<ffi.Opaque>, ffi.Pointer<ffi.Opaque>)>(isLeaf: true, symbol: 'icu4x_WordSegmenter_create_auto_with_content_locale_and_provider_mv1')
// ignore: non_constant_identifier_names
external _ResultOpaqueInt32 _icu4x_WordSegmenter_create_auto_with_content_locale_and_provider_mv1(ffi.Pointer<ffi.Opaque> provider, ffi.Pointer<ffi.Opaque> locale);

// ignore: experimental_member_use
@meta.RecordUse()
@ffi.Native<ffi.Pointer<ffi.Opaque> Function()>(isLeaf: true, symbol: 'icu4x_WordSegmenter_create_lstm_mv1')
// ignore: non_constant_identifier_names
external ffi.Pointer<ffi.Opaque> _icu4x_WordSegmenter_create_lstm_mv1();

// ignore: experimental_member_use
@meta.RecordUse()
@ffi.Native<_ResultOpaqueInt32 Function(ffi.Pointer<ffi.Opaque>)>(isLeaf: true, symbol: 'icu4x_WordSegmenter_create_lstm_with_content_locale_mv1')
// ignore: non_constant_identifier_names
external _ResultOpaqueInt32 _icu4x_WordSegmenter_create_lstm_with_content_locale_mv1(ffi.Pointer<ffi.Opaque> locale);

// ignore: experimental_member_use
@meta.RecordUse()
@ffi.Native<_ResultOpaqueInt32 Function(ffi.Pointer<ffi.Opaque>, ffi.Pointer<ffi.Opaque>)>(isLeaf: true, symbol: 'icu4x_WordSegmenter_create_lstm_with_content_locale_and_provider_mv1')
// ignore: non_constant_identifier_names
external _ResultOpaqueInt32 _icu4x_WordSegmenter_create_lstm_with_content_locale_and_provider_mv1(ffi.Pointer<ffi.Opaque> provider, ffi.Pointer<ffi.Opaque> locale);

// ignore: experimental_member_use
@meta.RecordUse()
@ffi.Native<ffi.Pointer<ffi.Opaque> Function()>(isLeaf: true, symbol: 'icu4x_WordSegmenter_create_dictionary_mv1')
// ignore: non_constant_identifier_names
external ffi.Pointer<ffi.Opaque> _icu4x_WordSegmenter_create_dictionary_mv1();

// ignore: experimental_member_use
@meta.RecordUse()
@ffi.Native<_ResultOpaqueInt32 Function(ffi.Pointer<ffi.Opaque>)>(isLeaf: true, symbol: 'icu4x_WordSegmenter_create_dictionary_with_content_locale_mv1')
// ignore: non_constant_identifier_names
external _ResultOpaqueInt32 _icu4x_WordSegmenter_create_dictionary_with_content_locale_mv1(ffi.Pointer<ffi.Opaque> locale);

// ignore: experimental_member_use
@meta.RecordUse()
@ffi.Native<_ResultOpaqueInt32 Function(ffi.Pointer<ffi.Opaque>, ffi.Pointer<ffi.Opaque>)>(isLeaf: true, symbol: 'icu4x_WordSegmenter_create_dictionary_with_content_locale_and_provider_mv1')
// ignore: non_constant_identifier_names
external _ResultOpaqueInt32 _icu4x_WordSegmenter_create_dictionary_with_content_locale_and_provider_mv1(ffi.Pointer<ffi.Opaque> provider, ffi.Pointer<ffi.Opaque> locale);

// ignore: experimental_member_use
@meta.RecordUse()
@ffi.Native<ffi.Pointer<ffi.Opaque> Function()>(isLeaf: true, symbol: 'icu4x_WordSegmenter_create_for_non_complex_scripts_mv1')
// ignore: non_constant_identifier_names
external ffi.Pointer<ffi.Opaque> _icu4x_WordSegmenter_create_for_non_complex_scripts_mv1();

// ignore: experimental_member_use
@meta.RecordUse()
@ffi.Native<_ResultOpaqueInt32 Function(ffi.Pointer<ffi.Opaque>)>(isLeaf: true, symbol: 'icu4x_WordSegmenter_create_for_non_complex_scripts_with_content_locale_mv1')
// ignore: non_constant_identifier_names
external _ResultOpaqueInt32 _icu4x_WordSegmenter_create_for_non_complex_scripts_with_content_locale_mv1(ffi.Pointer<ffi.Opaque> locale);

// ignore: experimental_member_use
@meta.RecordUse()
@ffi.Native<_ResultOpaqueInt32 Function(ffi.Pointer<ffi.Opaque>, ffi.Pointer<ffi.Opaque>)>(isLeaf: true, symbol: 'icu4x_WordSegmenter_create_for_non_complex_scripts_with_content_locale_and_provider_mv1')
// ignore: non_constant_identifier_names
external _ResultOpaqueInt32 _icu4x_WordSegmenter_create_for_non_complex_scripts_with_content_locale_and_provider_mv1(ffi.Pointer<ffi.Opaque> provider, ffi.Pointer<ffi.Opaque> locale);

// ignore: experimental_member_use
@meta.RecordUse()
@ffi.Native<ffi.Pointer<ffi.Opaque> Function(ffi.Pointer<ffi.Opaque>, _SliceUtf16)>(isLeaf: true, symbol: 'icu4x_WordSegmenter_segment_utf16_mv1')
// ignore: non_constant_identifier_names
external ffi.Pointer<ffi.Opaque> _icu4x_WordSegmenter_segment_utf16_mv1(ffi.Pointer<ffi.Opaque> self, _SliceUtf16 input);

// dart format on
