ICU4X
International Components for Unicode
Loading...
Searching...
No Matches
ICU4XWordSegmenter.hpp
Go to the documentation of this file.
1#ifndef ICU4XWordSegmenter_HPP
2#define ICU4XWordSegmenter_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 "ICU4XWordSegmenter.h"
13
16#include "ICU4XError.hpp"
20
24struct ICU4XWordSegmenterDeleter {
25 void operator()(capi::ICU4XWordSegmenter* l) const noexcept {
26 capi::ICU4XWordSegmenter_destroy(l);
27 }
28};
29
36 public:
37
48
59
67
78 ICU4XWordBreakIteratorUtf8 segment_utf8(const std::string_view input) const;
79
90 ICU4XWordBreakIteratorUtf16 segment_utf16(const std::u16string_view input) const;
91
100 inline const capi::ICU4XWordSegmenter* AsFFI() const { return this->inner.get(); }
101 inline capi::ICU4XWordSegmenter* AsFFIMut() { return this->inner.get(); }
102 inline explicit ICU4XWordSegmenter(capi::ICU4XWordSegmenter* i) : inner(i) {}
105 ICU4XWordSegmenter& operator=(ICU4XWordSegmenter&& other) noexcept = default;
106 private:
107 std::unique_ptr<capi::ICU4XWordSegmenter, ICU4XWordSegmenterDeleter> inner;
108};
109
110#include "ICU4XDataProvider.hpp"
114
116 auto diplomat_result_raw_out_value = capi::ICU4XWordSegmenter_create_auto(provider.AsFFI());
117 diplomat::result<ICU4XWordSegmenter, ICU4XError> diplomat_result_out_value;
118 if (diplomat_result_raw_out_value.is_ok) {
119 diplomat_result_out_value = diplomat::Ok<ICU4XWordSegmenter>(ICU4XWordSegmenter(diplomat_result_raw_out_value.ok));
120 } else {
121 diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err));
122 }
123 return diplomat_result_out_value;
124}
126 auto diplomat_result_raw_out_value = capi::ICU4XWordSegmenter_create_lstm(provider.AsFFI());
127 diplomat::result<ICU4XWordSegmenter, ICU4XError> diplomat_result_out_value;
128 if (diplomat_result_raw_out_value.is_ok) {
129 diplomat_result_out_value = diplomat::Ok<ICU4XWordSegmenter>(ICU4XWordSegmenter(diplomat_result_raw_out_value.ok));
130 } else {
131 diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err));
132 }
133 return diplomat_result_out_value;
134}
136 auto diplomat_result_raw_out_value = capi::ICU4XWordSegmenter_create_dictionary(provider.AsFFI());
137 diplomat::result<ICU4XWordSegmenter, ICU4XError> diplomat_result_out_value;
138 if (diplomat_result_raw_out_value.is_ok) {
139 diplomat_result_out_value = diplomat::Ok<ICU4XWordSegmenter>(ICU4XWordSegmenter(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}
145inline ICU4XWordBreakIteratorUtf8 ICU4XWordSegmenter::segment_utf8(const std::string_view input) const {
146 return ICU4XWordBreakIteratorUtf8(capi::ICU4XWordSegmenter_segment_utf8(this->inner.get(), input.data(), input.size()));
147}
148inline ICU4XWordBreakIteratorUtf16 ICU4XWordSegmenter::segment_utf16(const std::u16string_view input) const {
149 return ICU4XWordBreakIteratorUtf16(capi::ICU4XWordSegmenter_segment_utf16(this->inner.get(), input.data(), input.size()));
150}
152 return ICU4XWordBreakIteratorLatin1(capi::ICU4XWordSegmenter_segment_latin1(this->inner.get(), input.data(), input.size()));
153}
154#endif
ICU4XError
Definition ICU4XError.hpp:23
Definition ICU4XDataProvider.hpp:32
Definition ICU4XWordBreakIteratorLatin1.hpp:28
Definition ICU4XWordBreakIteratorUtf16.hpp:28
Definition ICU4XWordBreakIteratorUtf8.hpp:28
Definition ICU4XWordSegmenter.hpp:35
ICU4XWordSegmenter()=default
static diplomat::result< ICU4XWordSegmenter, ICU4XError > create_auto(const ICU4XDataProvider &provider)
Definition ICU4XWordSegmenter.hpp:115
ICU4XWordSegmenter(ICU4XWordSegmenter &&) noexcept=default
static diplomat::result< ICU4XWordSegmenter, ICU4XError > create_lstm(const ICU4XDataProvider &provider)
Definition ICU4XWordSegmenter.hpp:125
static diplomat::result< ICU4XWordSegmenter, ICU4XError > create_dictionary(const ICU4XDataProvider &provider)
Definition ICU4XWordSegmenter.hpp:135
ICU4XWordBreakIteratorUtf8 segment_utf8(const std::string_view input) const
Definition ICU4XWordSegmenter.hpp:145
ICU4XWordBreakIteratorLatin1 segment_latin1(const diplomat::span< const uint8_t > input) const
Definition ICU4XWordSegmenter.hpp:151
ICU4XWordSegmenter(capi::ICU4XWordSegmenter *i)
Definition ICU4XWordSegmenter.hpp:102
ICU4XWordBreakIteratorUtf16 segment_utf16(const std::u16string_view input) const
Definition ICU4XWordSegmenter.hpp:148
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 diplomat_runtime.hpp:69
Definition diplomat_runtime.hpp:55