Debian Codegraph @

intl/icu_capi/bindings/cpp/ICU4XLineSegmenter.hpp

raw
1 #ifndef ICU4XLineSegmenter_HPP
2 #define ICU4XLineSegmenter_HPP
3 #include <stdint.h>
4 #include <stddef.h>
5 #include <stdbool.h>
6 #include <algorithm>
7 #include <memory>
8 #include <variant>
9 #include <optional>
10 #include "diplomat_runtime.hpp"
11
12 #include "ICU4XLineSegmenter.h"
13
14 class ICU4XDataProvider;
15 class ICU4XLineSegmenter;
16 #include "ICU4XError.hpp"
17 struct ICU4XLineBreakOptionsV1;
18 class ICU4XLineBreakIteratorUtf8;
19 class ICU4XLineBreakIteratorUtf16;
20 class ICU4XLineBreakIteratorLatin1;
21
22 /**
23 * A destruction policy for using ICU4XLineSegmenter with std::unique_ptr.
24 */
25 struct ICU4XLineSegmenterDeleter {
26 void operator()(capi::ICU4XLineSegmenter* l) const noexcept {
27 capi::ICU4XLineSegmenter_destroy(l);
28 }
29 };
30
31 /**
32 * An ICU4X line-break segmenter, capable of finding breakpoints in strings.
33 *
34 * See the [Rust documentation for `LineSegmenter`](https://docs.rs/icu/latest/icu/segmenter/struct.LineSegmenter.html) for more information.
35 */
36 class ICU4XLineSegmenter {
37 public:
38
39 /**
40 * Construct a [`ICU4XLineSegmenter`] with default options. It automatically loads the best
41 * available payload data for Burmese, Khmer, Lao, and Thai.
42 *
43 * See the [Rust documentation for `new_auto`](https://docs.rs/icu/latest/icu/segmenter/struct.LineSegmenter.html#method.new_auto) for more information.
44 */
45 static diplomat::result<ICU4XLineSegmenter, ICU4XError> create_auto(const ICU4XDataProvider& provider);
46
47 /**
48 * Construct a [`ICU4XLineSegmenter`] with default options and LSTM payload data for
49 * Burmese, Khmer, Lao, and Thai.
50 *
51 * See the [Rust documentation for `new_lstm`](https://docs.rs/icu/latest/icu/segmenter/struct.LineSegmenter.html#method.new_lstm) for more information.
52 */
53 static diplomat::result<ICU4XLineSegmenter, ICU4XError> create_lstm(const ICU4XDataProvider& provider);
54
55 /**
56 * Construct a [`ICU4XLineSegmenter`] with default options and dictionary payload data for
57 * Burmese, Khmer, Lao, and Thai..
58 *
59 * See the [Rust documentation for `new_dictionary`](https://docs.rs/icu/latest/icu/segmenter/struct.LineSegmenter.html#method.new_dictionary) for more information.
60 */
61 static diplomat::result<ICU4XLineSegmenter, ICU4XError> create_dictionary(const ICU4XDataProvider& provider);
62
63 /**
64 * Construct a [`ICU4XLineSegmenter`] with custom options. It automatically loads the best
65 * available payload data for Burmese, Khmer, Lao, and Thai.
66 *
67 * See the [Rust documentation for `new_auto_with_options`](https://docs.rs/icu/latest/icu/segmenter/struct.LineSegmenter.html#method.new_auto_with_options) for more information.
68 */
69 static diplomat::result<ICU4XLineSegmenter, ICU4XError> create_auto_with_options_v1(const ICU4XDataProvider& provider, ICU4XLineBreakOptionsV1 options);
70
71 /**
72 * Construct a [`ICU4XLineSegmenter`] with custom options and LSTM payload data for
73 * Burmese, Khmer, Lao, and Thai.
74 *
75 * See the [Rust documentation for `new_lstm_with_options`](https://docs.rs/icu/latest/icu/segmenter/struct.LineSegmenter.html#method.new_lstm_with_options) for more information.
76 */
77 static diplomat::result<ICU4XLineSegmenter, ICU4XError> create_lstm_with_options_v1(const ICU4XDataProvider& provider, ICU4XLineBreakOptionsV1 options);
78
79 /**
80 * Construct a [`ICU4XLineSegmenter`] with custom options and dictionary payload data for
81 * Burmese, Khmer, Lao, and Thai.
82 *
83 * See the [Rust documentation for `new_dictionary_with_options`](https://docs.rs/icu/latest/icu/segmenter/struct.LineSegmenter.html#method.new_dictionary_with_options) for more information.
84 */
85 static diplomat::result<ICU4XLineSegmenter, ICU4XError> create_dictionary_with_options_v1(const ICU4XDataProvider& provider, ICU4XLineBreakOptionsV1 options);
86
87 /**
88 * Segments a string.
89 *
90 * Ill-formed input is treated as if errors had been replaced with REPLACEMENT CHARACTERs according
91 * to the WHATWG Encoding Standard.
92 *
93 * See the [Rust documentation for `segment_utf8`](https://docs.rs/icu/latest/icu/segmenter/struct.LineSegmenter.html#method.segment_utf8) for more information.
94 *
95 * Lifetimes: `this`, `input` must live at least as long as the output.
96 */
97 ICU4XLineBreakIteratorUtf8 segment_utf8(const std::string_view input) const;
98
99 /**
100 * Segments a string.
101 *
102 * Ill-formed input is treated as if errors had been replaced with REPLACEMENT CHARACTERs according
103 * to the WHATWG Encoding Standard.
104 *
105 * See the [Rust documentation for `segment_utf16`](https://docs.rs/icu/latest/icu/segmenter/struct.LineSegmenter.html#method.segment_utf16) for more information.
106 *
107 * Lifetimes: `this`, `input` must live at least as long as the output.
108 */
109 ICU4XLineBreakIteratorUtf16 segment_utf16(const std::u16string_view input) const;
110
111 /**
112 * Segments a Latin-1 string.
113 *
114 * See the [Rust documentation for `segment_latin1`](https://docs.rs/icu/latest/icu/segmenter/struct.LineSegmenter.html#method.segment_latin1) for more information.
115 *
116 * Lifetimes: `this`, `input` must live at least as long as the output.
117 */
118 ICU4XLineBreakIteratorLatin1 segment_latin1(const diplomat::span<const uint8_t> input) const;
119 inline const capi::ICU4XLineSegmenter* AsFFI() const { return this->inner.get(); }
120 inline capi::ICU4XLineSegmenter* AsFFIMut() { return this->inner.get(); }
121 inline explicit ICU4XLineSegmenter(capi::ICU4XLineSegmenter* i) : inner(i) {}
122 ICU4XLineSegmenter() = default;
123 ICU4XLineSegmenter(ICU4XLineSegmenter&&) noexcept = default;
124 ICU4XLineSegmenter& operator=(ICU4XLineSegmenter&& other) noexcept = default;
125 private:
126 std::unique_ptr<capi::ICU4XLineSegmenter, ICU4XLineSegmenterDeleter> inner;
127 };
128
129 #include "ICU4XDataProvider.hpp"
130 #include "ICU4XLineBreakOptionsV1.hpp"
131 #include "ICU4XLineBreakIteratorUtf8.hpp"
132 #include "ICU4XLineBreakIteratorUtf16.hpp"
133 #include "ICU4XLineBreakIteratorLatin1.hpp"
134
135 inline diplomat::result<ICU4XLineSegmenter, ICU4XError> ICU4XLineSegmenter::create_auto(const ICU4XDataProvider& provider) {
136 auto diplomat_result_raw_out_value = capi::ICU4XLineSegmenter_create_auto(provider.AsFFI());
137 diplomat::result<ICU4XLineSegmenter, ICU4XError> diplomat_result_out_value;
138 if (diplomat_result_raw_out_value.is_ok) {
139 diplomat_result_out_value = diplomat::Ok<ICU4XLineSegmenter>(ICU4XLineSegmenter(diplomat_result_raw_out_value.ok));
140 } else {
141 diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err));
142 }
143 return diplomat_result_out_value;
144 }
145 inline diplomat::result<ICU4XLineSegmenter, ICU4XError> ICU4XLineSegmenter::create_lstm(const ICU4XDataProvider& provider) {
146 auto diplomat_result_raw_out_value = capi::ICU4XLineSegmenter_create_lstm(provider.AsFFI());
147 diplomat::result<ICU4XLineSegmenter, ICU4XError> diplomat_result_out_value;
148 if (diplomat_result_raw_out_value.is_ok) {
149 diplomat_result_out_value = diplomat::Ok<ICU4XLineSegmenter>(ICU4XLineSegmenter(diplomat_result_raw_out_value.ok));
150 } else {
151 diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err));
152 }
153 return diplomat_result_out_value;
154 }
155 inline diplomat::result<ICU4XLineSegmenter, ICU4XError> ICU4XLineSegmenter::create_dictionary(const ICU4XDataProvider& provider) {
156 auto diplomat_result_raw_out_value = capi::ICU4XLineSegmenter_create_dictionary(provider.AsFFI());
157 diplomat::result<ICU4XLineSegmenter, ICU4XError> diplomat_result_out_value;
158 if (diplomat_result_raw_out_value.is_ok) {
159 diplomat_result_out_value = diplomat::Ok<ICU4XLineSegmenter>(ICU4XLineSegmenter(diplomat_result_raw_out_value.ok));
160 } else {
161 diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err));
162 }
163 return diplomat_result_out_value;
164 }
165 inline diplomat::result<ICU4XLineSegmenter, ICU4XError> ICU4XLineSegmenter::create_auto_with_options_v1(const ICU4XDataProvider& provider, ICU4XLineBreakOptionsV1 options) {
166 ICU4XLineBreakOptionsV1 diplomat_wrapped_struct_options = options;
167 auto diplomat_result_raw_out_value = capi::ICU4XLineSegmenter_create_auto_with_options_v1(provider.AsFFI(), capi::ICU4XLineBreakOptionsV1{ .strictness = static_cast<capi::ICU4XLineBreakStrictness>(diplomat_wrapped_struct_options.strictness), .word_option = static_cast<capi::ICU4XLineBreakWordOption>(diplomat_wrapped_struct_options.word_option), .ja_zh = diplomat_wrapped_struct_options.ja_zh });
168 diplomat::result<ICU4XLineSegmenter, ICU4XError> diplomat_result_out_value;
169 if (diplomat_result_raw_out_value.is_ok) {
170 diplomat_result_out_value = diplomat::Ok<ICU4XLineSegmenter>(ICU4XLineSegmenter(diplomat_result_raw_out_value.ok));
171 } else {
172 diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err));
173 }
174 return diplomat_result_out_value;
175 }
176 inline diplomat::result<ICU4XLineSegmenter, ICU4XError> ICU4XLineSegmenter::create_lstm_with_options_v1(const ICU4XDataProvider& provider, ICU4XLineBreakOptionsV1 options) {
177 ICU4XLineBreakOptionsV1 diplomat_wrapped_struct_options = options;
178 auto diplomat_result_raw_out_value = capi::ICU4XLineSegmenter_create_lstm_with_options_v1(provider.AsFFI(), capi::ICU4XLineBreakOptionsV1{ .strictness = static_cast<capi::ICU4XLineBreakStrictness>(diplomat_wrapped_struct_options.strictness), .word_option = static_cast<capi::ICU4XLineBreakWordOption>(diplomat_wrapped_struct_options.word_option), .ja_zh = diplomat_wrapped_struct_options.ja_zh });
179 diplomat::result<ICU4XLineSegmenter, ICU4XError> diplomat_result_out_value;
180 if (diplomat_result_raw_out_value.is_ok) {
181 diplomat_result_out_value = diplomat::Ok<ICU4XLineSegmenter>(ICU4XLineSegmenter(diplomat_result_raw_out_value.ok));
182 } else {
183 diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err));
184 }
185 return diplomat_result_out_value;
186 }
187 inline diplomat::result<ICU4XLineSegmenter, ICU4XError> ICU4XLineSegmenter::create_dictionary_with_options_v1(const ICU4XDataProvider& provider, ICU4XLineBreakOptionsV1 options) {
188 ICU4XLineBreakOptionsV1 diplomat_wrapped_struct_options = options;
189 auto diplomat_result_raw_out_value = capi::ICU4XLineSegmenter_create_dictionary_with_options_v1(provider.AsFFI(), capi::ICU4XLineBreakOptionsV1{ .strictness = static_cast<capi::ICU4XLineBreakStrictness>(diplomat_wrapped_struct_options.strictness), .word_option = static_cast<capi::ICU4XLineBreakWordOption>(diplomat_wrapped_struct_options.word_option), .ja_zh = diplomat_wrapped_struct_options.ja_zh });
190 diplomat::result<ICU4XLineSegmenter, ICU4XError> diplomat_result_out_value;
191 if (diplomat_result_raw_out_value.is_ok) {
192 diplomat_result_out_value = diplomat::Ok<ICU4XLineSegmenter>(ICU4XLineSegmenter(diplomat_result_raw_out_value.ok));
193 } else {
194 diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err));
195 }
196 return diplomat_result_out_value;
197 }
198 inline ICU4XLineBreakIteratorUtf8 ICU4XLineSegmenter::segment_utf8(const std::string_view input) const {
199 return ICU4XLineBreakIteratorUtf8(capi::ICU4XLineSegmenter_segment_utf8(this->inner.get(), input.data(), input.size()));
200 }
201 inline ICU4XLineBreakIteratorUtf16 ICU4XLineSegmenter::segment_utf16(const std::u16string_view input) const {
202 return ICU4XLineBreakIteratorUtf16(capi::ICU4XLineSegmenter_segment_utf16(this->inner.get(), input.data(), input.size()));
203 }
204 inline ICU4XLineBreakIteratorLatin1 ICU4XLineSegmenter::segment_latin1(const diplomat::span<const uint8_t> input) const {
205 return ICU4XLineBreakIteratorLatin1(capi::ICU4XLineSegmenter_segment_latin1(this->inner.get(), input.data(), input.size()));
206 }
207 #endif