ICU4X
International Components for Unicode
Loading...
Searching...
No Matches
ICU4XLineSegmenter.hpp
Go to the documentation of this file.
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
16#include "ICU4XError.hpp"
21
25struct ICU4XLineSegmenterDeleter {
26 void operator()(capi::ICU4XLineSegmenter* l) const noexcept {
27 capi::ICU4XLineSegmenter_destroy(l);
28 }
29};
30
37 public:
38
46
54
62
70
78
86
97 ICU4XLineBreakIteratorUtf8 segment_utf8(const std::string_view input) const;
98
109 ICU4XLineBreakIteratorUtf16 segment_utf16(const std::u16string_view input) const;
110
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) {}
124 ICU4XLineSegmenter& operator=(ICU4XLineSegmenter&& other) noexcept = default;
125 private:
126 std::unique_ptr<capi::ICU4XLineSegmenter, ICU4XLineSegmenterDeleter> inner;
127};
128
129#include "ICU4XDataProvider.hpp"
134
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}
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}
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}
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}
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}
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}
198inline 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}
201inline 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}
205 return ICU4XLineBreakIteratorLatin1(capi::ICU4XLineSegmenter_segment_latin1(this->inner.get(), input.data(), input.size()));
206}
207#endif
ICU4XError
Definition ICU4XError.hpp:23
Definition ICU4XDataProvider.hpp:32
Definition ICU4XLineBreakIteratorLatin1.hpp:29
Definition ICU4XLineBreakIteratorUtf16.hpp:29
Definition ICU4XLineBreakIteratorUtf8.hpp:29
Definition ICU4XLineSegmenter.hpp:36
static diplomat::result< ICU4XLineSegmenter, ICU4XError > create_auto_with_options_v1(const ICU4XDataProvider &provider, ICU4XLineBreakOptionsV1 options)
Definition ICU4XLineSegmenter.hpp:165
static diplomat::result< ICU4XLineSegmenter, ICU4XError > create_dictionary(const ICU4XDataProvider &provider)
Definition ICU4XLineSegmenter.hpp:155
ICU4XLineBreakIteratorLatin1 segment_latin1(const diplomat::span< const uint8_t > input) const
Definition ICU4XLineSegmenter.hpp:204
ICU4XLineSegmenter(capi::ICU4XLineSegmenter *i)
Definition ICU4XLineSegmenter.hpp:121
ICU4XLineBreakIteratorUtf16 segment_utf16(const std::u16string_view input) const
Definition ICU4XLineSegmenter.hpp:201
static diplomat::result< ICU4XLineSegmenter, ICU4XError > create_lstm(const ICU4XDataProvider &provider)
Definition ICU4XLineSegmenter.hpp:145
ICU4XLineBreakIteratorUtf8 segment_utf8(const std::string_view input) const
Definition ICU4XLineSegmenter.hpp:198
ICU4XLineSegmenter(ICU4XLineSegmenter &&) noexcept=default
static diplomat::result< ICU4XLineSegmenter, ICU4XError > create_auto(const ICU4XDataProvider &provider)
Definition ICU4XLineSegmenter.hpp:135
ICU4XLineSegmenter()=default
static diplomat::result< ICU4XLineSegmenter, ICU4XError > create_dictionary_with_options_v1(const ICU4XDataProvider &provider, ICU4XLineBreakOptionsV1 options)
Definition ICU4XLineSegmenter.hpp:187
static diplomat::result< ICU4XLineSegmenter, ICU4XError > create_lstm_with_options_v1(const ICU4XDataProvider &provider, ICU4XLineBreakOptionsV1 options)
Definition ICU4XLineSegmenter.hpp:176
Definition diplomat_runtime.hpp:84
Definition diplomat_runtime.hpp:144
constexpr T * data() const noexcept
Definition diplomat_runtime.hpp:152
constexpr size_t size() const noexcept
Definition diplomat_runtime.hpp:155
Definition ICU4XLineBreakOptionsV1.hpp:21
Definition diplomat_runtime.hpp:69
Definition diplomat_runtime.hpp:55