Debian Codegraph @

intl/icu_capi/bindings/cpp/ICU4XComposingNormalizer.hpp

raw
1 #ifndef ICU4XComposingNormalizer_HPP
2 #define ICU4XComposingNormalizer_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 "ICU4XComposingNormalizer.h"
13
14 class ICU4XDataProvider;
15 class ICU4XComposingNormalizer;
16 #include "ICU4XError.hpp"
17
18 /**
19 * A destruction policy for using ICU4XComposingNormalizer with std::unique_ptr.
20 */
21 struct ICU4XComposingNormalizerDeleter {
22 void operator()(capi::ICU4XComposingNormalizer* l) const noexcept {
23 capi::ICU4XComposingNormalizer_destroy(l);
24 }
25 };
26
27 /**
28 * See the [Rust documentation for `ComposingNormalizer`](https://docs.rs/icu/latest/icu/normalizer/struct.ComposingNormalizer.html) for more information.
29 */
30 class ICU4XComposingNormalizer {
31 public:
32
33 /**
34 * Construct a new ICU4XComposingNormalizer instance for NFC
35 *
36 * See the [Rust documentation for `new_nfc`](https://docs.rs/icu/latest/icu/normalizer/struct.ComposingNormalizer.html#method.new_nfc) for more information.
37 */
38 static diplomat::result<ICU4XComposingNormalizer, ICU4XError> create_nfc(const ICU4XDataProvider& provider);
39
40 /**
41 * Construct a new ICU4XComposingNormalizer instance for NFKC
42 *
43 * See the [Rust documentation for `new_nfkc`](https://docs.rs/icu/latest/icu/normalizer/struct.ComposingNormalizer.html#method.new_nfkc) for more information.
44 */
45 static diplomat::result<ICU4XComposingNormalizer, ICU4XError> create_nfkc(const ICU4XDataProvider& provider);
46
47 /**
48 * Normalize a string
49 *
50 * Ill-formed input is treated as if errors had been replaced with REPLACEMENT CHARACTERs according
51 * to the WHATWG Encoding Standard.
52 *
53 * See the [Rust documentation for `normalize_utf8`](https://docs.rs/icu/latest/icu/normalizer/struct.ComposingNormalizer.html#method.normalize_utf8) for more information.
54 */
55 template<typename W> diplomat::result<std::monostate, ICU4XError> normalize_to_writeable(const std::string_view s, W& write) const;
56
57 /**
58 * Normalize a string
59 *
60 * Ill-formed input is treated as if errors had been replaced with REPLACEMENT CHARACTERs according
61 * to the WHATWG Encoding Standard.
62 *
63 * See the [Rust documentation for `normalize_utf8`](https://docs.rs/icu/latest/icu/normalizer/struct.ComposingNormalizer.html#method.normalize_utf8) for more information.
64 */
65 diplomat::result<std::string, ICU4XError> normalize(const std::string_view s) const;
66
67 /**
68 * Check if a string is normalized
69 *
70 * Ill-formed input is treated as if errors had been replaced with REPLACEMENT CHARACTERs according
71 * to the WHATWG Encoding Standard.
72 *
73 * 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.
74 */
75 bool is_normalized(const std::string_view s) const;
76 inline const capi::ICU4XComposingNormalizer* AsFFI() const { return this->inner.get(); }
77 inline capi::ICU4XComposingNormalizer* AsFFIMut() { return this->inner.get(); }
78 inline explicit ICU4XComposingNormalizer(capi::ICU4XComposingNormalizer* i) : inner(i) {}
79 ICU4XComposingNormalizer() = default;
80 ICU4XComposingNormalizer(ICU4XComposingNormalizer&&) noexcept = default;
81 ICU4XComposingNormalizer& operator=(ICU4XComposingNormalizer&& other) noexcept = default;
82 private:
83 std::unique_ptr<capi::ICU4XComposingNormalizer, ICU4XComposingNormalizerDeleter> inner;
84 };
85
86 #include "ICU4XDataProvider.hpp"
87
88 inline diplomat::result<ICU4XComposingNormalizer, ICU4XError> ICU4XComposingNormalizer::create_nfc(const ICU4XDataProvider& provider) {
89 auto diplomat_result_raw_out_value = capi::ICU4XComposingNormalizer_create_nfc(provider.AsFFI());
90 diplomat::result<ICU4XComposingNormalizer, ICU4XError> diplomat_result_out_value;
91 if (diplomat_result_raw_out_value.is_ok) {
92 diplomat_result_out_value = diplomat::Ok<ICU4XComposingNormalizer>(ICU4XComposingNormalizer(diplomat_result_raw_out_value.ok));
93 } else {
94 diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err));
95 }
96 return diplomat_result_out_value;
97 }
98 inline diplomat::result<ICU4XComposingNormalizer, ICU4XError> ICU4XComposingNormalizer::create_nfkc(const ICU4XDataProvider& provider) {
99 auto diplomat_result_raw_out_value = capi::ICU4XComposingNormalizer_create_nfkc(provider.AsFFI());
100 diplomat::result<ICU4XComposingNormalizer, ICU4XError> diplomat_result_out_value;
101 if (diplomat_result_raw_out_value.is_ok) {
102 diplomat_result_out_value = diplomat::Ok<ICU4XComposingNormalizer>(ICU4XComposingNormalizer(diplomat_result_raw_out_value.ok));
103 } else {
104 diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err));
105 }
106 return diplomat_result_out_value;
107 }
108 template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XComposingNormalizer::normalize_to_writeable(const std::string_view s, W& write) const {
109 capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write);
110 auto diplomat_result_raw_out_value = capi::ICU4XComposingNormalizer_normalize(this->inner.get(), s.data(), s.size(), &write_writer);
111 diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value;
112 if (diplomat_result_raw_out_value.is_ok) {
113 diplomat_result_out_value = diplomat::Ok<std::monostate>(std::monostate());
114 } else {
115 diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err));
116 }
117 return diplomat_result_out_value;
118 }
119 inline diplomat::result<std::string, ICU4XError> ICU4XComposingNormalizer::normalize(const std::string_view s) const {
120 std::string diplomat_writeable_string;
121 capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string);
122 auto diplomat_result_raw_out_value = capi::ICU4XComposingNormalizer_normalize(this->inner.get(), s.data(), s.size(), &diplomat_writeable_out);
123 diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value;
124 if (diplomat_result_raw_out_value.is_ok) {
125 diplomat_result_out_value = diplomat::Ok<std::monostate>(std::monostate());
126 } else {
127 diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err));
128 }
129 return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string));
130 }
131 inline bool ICU4XComposingNormalizer::is_normalized(const std::string_view s) const {
132 return capi::ICU4XComposingNormalizer_is_normalized(this->inner.get(), s.data(), s.size());
133 }
134 #endif