1 #ifndef icu4x_CaseMapper_HPP
2 #define icu4x_CaseMapper_HPP
3
4 #include "CaseMapper.d.hpp"
5
6 #include <stdio.h>
7 #include <stdint.h>
8 #include <stddef.h>
9 #include <stdbool.h>
10 #include <memory>
11 #include <functional>
12 #include <optional>
13 #include "../diplomat_runtime.hpp"
14 #include "CodePointSetBuilder.hpp"
15 #include "DataError.hpp"
16 #include "DataProvider.hpp"
17 #include "Locale.hpp"
18 #include "TitlecaseOptionsV1.hpp"
19
20
21 namespace icu4x {
22 namespace capi {
23 extern "C" {
24
25 icu4x::capi::CaseMapper* icu4x_CaseMapper_create_mv1(void);
26
27 typedef struct icu4x_CaseMapper_create_with_provider_mv1_result {union {icu4x::capi::CaseMapper* ok; icu4x::capi::DataError err;}; bool is_ok;} icu4x_CaseMapper_create_with_provider_mv1_result;
28 icu4x_CaseMapper_create_with_provider_mv1_result icu4x_CaseMapper_create_with_provider_mv1(const icu4x::capi::DataProvider* provider);
29
30 void icu4x_CaseMapper_lowercase_mv1(const icu4x::capi::CaseMapper* self, diplomat::capi::DiplomatStringView s, const icu4x::capi::Locale* locale, diplomat::capi::DiplomatWrite* write);
31
32 void icu4x_CaseMapper_uppercase_mv1(const icu4x::capi::CaseMapper* self, diplomat::capi::DiplomatStringView s, const icu4x::capi::Locale* locale, diplomat::capi::DiplomatWrite* write);
33
34 void icu4x_CaseMapper_titlecase_segment_with_only_case_data_v1_mv1(const icu4x::capi::CaseMapper* self, diplomat::capi::DiplomatStringView s, const icu4x::capi::Locale* locale, icu4x::capi::TitlecaseOptionsV1 options, diplomat::capi::DiplomatWrite* write);
35
36 void icu4x_CaseMapper_fold_mv1(const icu4x::capi::CaseMapper* self, diplomat::capi::DiplomatStringView s, diplomat::capi::DiplomatWrite* write);
37
38 void icu4x_CaseMapper_fold_turkic_mv1(const icu4x::capi::CaseMapper* self, diplomat::capi::DiplomatStringView s, diplomat::capi::DiplomatWrite* write);
39
40 void icu4x_CaseMapper_add_case_closure_to_mv1(const icu4x::capi::CaseMapper* self, char32_t c, icu4x::capi::CodePointSetBuilder* builder);
41
42 char32_t icu4x_CaseMapper_simple_lowercase_mv1(const icu4x::capi::CaseMapper* self, char32_t ch);
43
44 char32_t icu4x_CaseMapper_simple_uppercase_mv1(const icu4x::capi::CaseMapper* self, char32_t ch);
45
46 char32_t icu4x_CaseMapper_simple_titlecase_mv1(const icu4x::capi::CaseMapper* self, char32_t ch);
47
48 char32_t icu4x_CaseMapper_simple_fold_mv1(const icu4x::capi::CaseMapper* self, char32_t ch);
49
50 char32_t icu4x_CaseMapper_simple_fold_turkic_mv1(const icu4x::capi::CaseMapper* self, char32_t ch);
51
52
53 void icu4x_CaseMapper_destroy_mv1(CaseMapper* self);
54
55 } // extern "C"
56 } // namespace capi
57 } // namespace
58
create()59 inline std::unique_ptr<icu4x::CaseMapper> icu4x::CaseMapper::create() {
60 auto result = icu4x::capi::icu4x_CaseMapper_create_mv1();
61 return std::unique_ptr<icu4x::CaseMapper>(icu4x::CaseMapper::FromFFI(result));
62 }
63
create_with_provider(const icu4x::DataProvider & provider)64 inline diplomat::result<std::unique_ptr<icu4x::CaseMapper>, icu4x::DataError> icu4x::CaseMapper::create_with_provider(const icu4x::DataProvider& provider) {
65 auto result = icu4x::capi::icu4x_CaseMapper_create_with_provider_mv1(provider.AsFFI());
66 return result.is_ok ? diplomat::result<std::unique_ptr<icu4x::CaseMapper>, icu4x::DataError>(diplomat::Ok<std::unique_ptr<icu4x::CaseMapper>>(std::unique_ptr<icu4x::CaseMapper>(icu4x::CaseMapper::FromFFI(result.ok)))) : diplomat::result<std::unique_ptr<icu4x::CaseMapper>, icu4x::DataError>(diplomat::Err<icu4x::DataError>(icu4x::DataError::FromFFI(result.err)));
67 }
68
lowercase(std::string_view s,const icu4x::Locale & locale) const69 inline diplomat::result<std::string, diplomat::Utf8Error> icu4x::CaseMapper::lowercase(std::string_view s, const icu4x::Locale& locale) const {
70 if (!diplomat::capi::diplomat_is_str(s.data(), s.size())) {
71 return diplomat::Err<diplomat::Utf8Error>();
72 }
73 std::string output;
74 diplomat::capi::DiplomatWrite write = diplomat::WriteFromString(output);
75 icu4x::capi::icu4x_CaseMapper_lowercase_mv1(this->AsFFI(),
76 {s.data(), s.size()},
77 locale.AsFFI(),
78 &write);
79 return diplomat::Ok<std::string>(std::move(output));
80 }
81
uppercase(std::string_view s,const icu4x::Locale & locale) const82 inline diplomat::result<std::string, diplomat::Utf8Error> icu4x::CaseMapper::uppercase(std::string_view s, const icu4x::Locale& locale) const {
83 if (!diplomat::capi::diplomat_is_str(s.data(), s.size())) {
84 return diplomat::Err<diplomat::Utf8Error>();
85 }
86 std::string output;
87 diplomat::capi::DiplomatWrite write = diplomat::WriteFromString(output);
88 icu4x::capi::icu4x_CaseMapper_uppercase_mv1(this->AsFFI(),
89 {s.data(), s.size()},
90 locale.AsFFI(),
91 &write);
92 return diplomat::Ok<std::string>(std::move(output));
93 }
94
titlecase_segment_with_only_case_data_v1(std::string_view s,const icu4x::Locale & locale,icu4x::TitlecaseOptionsV1 options) const95 inline diplomat::result<std::string, diplomat::Utf8Error> icu4x::CaseMapper::titlecase_segment_with_only_case_data_v1(std::string_view s, const icu4x::Locale& locale, icu4x::TitlecaseOptionsV1 options) const {
96 if (!diplomat::capi::diplomat_is_str(s.data(), s.size())) {
97 return diplomat::Err<diplomat::Utf8Error>();
98 }
99 std::string output;
100 diplomat::capi::DiplomatWrite write = diplomat::WriteFromString(output);
101 icu4x::capi::icu4x_CaseMapper_titlecase_segment_with_only_case_data_v1_mv1(this->AsFFI(),
102 {s.data(), s.size()},
103 locale.AsFFI(),
104 options.AsFFI(),
105 &write);
106 return diplomat::Ok<std::string>(std::move(output));
107 }
108
fold(std::string_view s) const109 inline diplomat::result<std::string, diplomat::Utf8Error> icu4x::CaseMapper::fold(std::string_view s) const {
110 if (!diplomat::capi::diplomat_is_str(s.data(), s.size())) {
111 return diplomat::Err<diplomat::Utf8Error>();
112 }
113 std::string output;
114 diplomat::capi::DiplomatWrite write = diplomat::WriteFromString(output);
115 icu4x::capi::icu4x_CaseMapper_fold_mv1(this->AsFFI(),
116 {s.data(), s.size()},
117 &write);
118 return diplomat::Ok<std::string>(std::move(output));
119 }
120
fold_turkic(std::string_view s) const121 inline diplomat::result<std::string, diplomat::Utf8Error> icu4x::CaseMapper::fold_turkic(std::string_view s) const {
122 if (!diplomat::capi::diplomat_is_str(s.data(), s.size())) {
123 return diplomat::Err<diplomat::Utf8Error>();
124 }
125 std::string output;
126 diplomat::capi::DiplomatWrite write = diplomat::WriteFromString(output);
127 icu4x::capi::icu4x_CaseMapper_fold_turkic_mv1(this->AsFFI(),
128 {s.data(), s.size()},
129 &write);
130 return diplomat::Ok<std::string>(std::move(output));
131 }
132
add_case_closure_to(char32_t c,icu4x::CodePointSetBuilder & builder) const133 inline void icu4x::CaseMapper::add_case_closure_to(char32_t c, icu4x::CodePointSetBuilder& builder) const {
134 icu4x::capi::icu4x_CaseMapper_add_case_closure_to_mv1(this->AsFFI(),
135 c,
136 builder.AsFFI());
137 }
138
simple_lowercase(char32_t ch) const139 inline char32_t icu4x::CaseMapper::simple_lowercase(char32_t ch) const {
140 auto result = icu4x::capi::icu4x_CaseMapper_simple_lowercase_mv1(this->AsFFI(),
141 ch);
142 return result;
143 }
144
simple_uppercase(char32_t ch) const145 inline char32_t icu4x::CaseMapper::simple_uppercase(char32_t ch) const {
146 auto result = icu4x::capi::icu4x_CaseMapper_simple_uppercase_mv1(this->AsFFI(),
147 ch);
148 return result;
149 }
150
simple_titlecase(char32_t ch) const151 inline char32_t icu4x::CaseMapper::simple_titlecase(char32_t ch) const {
152 auto result = icu4x::capi::icu4x_CaseMapper_simple_titlecase_mv1(this->AsFFI(),
153 ch);
154 return result;
155 }
156
simple_fold(char32_t ch) const157 inline char32_t icu4x::CaseMapper::simple_fold(char32_t ch) const {
158 auto result = icu4x::capi::icu4x_CaseMapper_simple_fold_mv1(this->AsFFI(),
159 ch);
160 return result;
161 }
162
simple_fold_turkic(char32_t ch) const163 inline char32_t icu4x::CaseMapper::simple_fold_turkic(char32_t ch) const {
164 auto result = icu4x::capi::icu4x_CaseMapper_simple_fold_turkic_mv1(this->AsFFI(),
165 ch);
166 return result;
167 }
168
AsFFI() const169 inline const icu4x::capi::CaseMapper* icu4x::CaseMapper::AsFFI() const {
170 return reinterpret_cast<const icu4x::capi::CaseMapper*>(this);
171 }
172
AsFFI()173 inline icu4x::capi::CaseMapper* icu4x::CaseMapper::AsFFI() {
174 return reinterpret_cast<icu4x::capi::CaseMapper*>(this);
175 }
176
FromFFI(const icu4x::capi::CaseMapper * ptr)177 inline const icu4x::CaseMapper* icu4x::CaseMapper::FromFFI(const icu4x::capi::CaseMapper* ptr) {
178 return reinterpret_cast<const icu4x::CaseMapper*>(ptr);
179 }
180
FromFFI(icu4x::capi::CaseMapper * ptr)181 inline icu4x::CaseMapper* icu4x::CaseMapper::FromFFI(icu4x::capi::CaseMapper* ptr) {
182 return reinterpret_cast<icu4x::CaseMapper*>(ptr);
183 }
184
operator delete(void * ptr)185 inline void icu4x::CaseMapper::operator delete(void* ptr) {
186 icu4x::capi::icu4x_CaseMapper_destroy_mv1(reinterpret_cast<icu4x::capi::CaseMapper*>(ptr));
187 }
188
189
190 #endif // icu4x_CaseMapper_HPP
191