CaseMapper.hpp (9433B)
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 <cstdlib> 14 #include "../diplomat_runtime.hpp" 15 #include "CodePointSetBuilder.hpp" 16 #include "DataError.hpp" 17 #include "DataProvider.hpp" 18 #include "Locale.hpp" 19 #include "TitlecaseOptionsV1.hpp" 20 21 22 namespace icu4x { 23 namespace capi { 24 extern "C" { 25 26 icu4x::capi::CaseMapper* icu4x_CaseMapper_create_mv1(void); 27 28 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; 29 icu4x_CaseMapper_create_with_provider_mv1_result icu4x_CaseMapper_create_with_provider_mv1(const icu4x::capi::DataProvider* provider); 30 31 void icu4x_CaseMapper_lowercase_mv1(const icu4x::capi::CaseMapper* self, diplomat::capi::DiplomatStringView s, const icu4x::capi::Locale* locale, diplomat::capi::DiplomatWrite* write); 32 33 void icu4x_CaseMapper_uppercase_mv1(const icu4x::capi::CaseMapper* self, diplomat::capi::DiplomatStringView s, const icu4x::capi::Locale* locale, diplomat::capi::DiplomatWrite* write); 34 35 void icu4x_CaseMapper_lowercase_with_compiled_data_mv1(diplomat::capi::DiplomatStringView s, const icu4x::capi::Locale* locale, diplomat::capi::DiplomatWrite* write); 36 37 void icu4x_CaseMapper_uppercase_with_compiled_data_mv1(diplomat::capi::DiplomatStringView s, const icu4x::capi::Locale* locale, diplomat::capi::DiplomatWrite* write); 38 39 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); 40 41 void icu4x_CaseMapper_fold_mv1(const icu4x::capi::CaseMapper* self, diplomat::capi::DiplomatStringView s, diplomat::capi::DiplomatWrite* write); 42 43 void icu4x_CaseMapper_fold_turkic_mv1(const icu4x::capi::CaseMapper* self, diplomat::capi::DiplomatStringView s, diplomat::capi::DiplomatWrite* write); 44 45 void icu4x_CaseMapper_add_case_closure_to_mv1(const icu4x::capi::CaseMapper* self, char32_t c, icu4x::capi::CodePointSetBuilder* builder); 46 47 char32_t icu4x_CaseMapper_simple_lowercase_mv1(const icu4x::capi::CaseMapper* self, char32_t ch); 48 49 char32_t icu4x_CaseMapper_simple_uppercase_mv1(const icu4x::capi::CaseMapper* self, char32_t ch); 50 51 char32_t icu4x_CaseMapper_simple_titlecase_mv1(const icu4x::capi::CaseMapper* self, char32_t ch); 52 53 char32_t icu4x_CaseMapper_simple_fold_mv1(const icu4x::capi::CaseMapper* self, char32_t ch); 54 55 char32_t icu4x_CaseMapper_simple_fold_turkic_mv1(const icu4x::capi::CaseMapper* self, char32_t ch); 56 57 void icu4x_CaseMapper_destroy_mv1(CaseMapper* self); 58 59 } // extern "C" 60 } // namespace capi 61 } // namespace 62 63 inline std::unique_ptr<icu4x::CaseMapper> icu4x::CaseMapper::create() { 64 auto result = icu4x::capi::icu4x_CaseMapper_create_mv1(); 65 return std::unique_ptr<icu4x::CaseMapper>(icu4x::CaseMapper::FromFFI(result)); 66 } 67 68 inline diplomat::result<std::unique_ptr<icu4x::CaseMapper>, icu4x::DataError> icu4x::CaseMapper::create_with_provider(const icu4x::DataProvider& provider) { 69 auto result = icu4x::capi::icu4x_CaseMapper_create_with_provider_mv1(provider.AsFFI()); 70 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))); 71 } 72 73 inline diplomat::result<std::string, diplomat::Utf8Error> icu4x::CaseMapper::lowercase(std::string_view s, const icu4x::Locale& locale) const { 74 if (!diplomat::capi::diplomat_is_str(s.data(), s.size())) { 75 return diplomat::Err<diplomat::Utf8Error>(); 76 } 77 std::string output; 78 diplomat::capi::DiplomatWrite write = diplomat::WriteFromString(output); 79 icu4x::capi::icu4x_CaseMapper_lowercase_mv1(this->AsFFI(), 80 {s.data(), s.size()}, 81 locale.AsFFI(), 82 &write); 83 return diplomat::Ok<std::string>(std::move(output)); 84 } 85 86 inline diplomat::result<std::string, diplomat::Utf8Error> icu4x::CaseMapper::uppercase(std::string_view s, const icu4x::Locale& locale) const { 87 if (!diplomat::capi::diplomat_is_str(s.data(), s.size())) { 88 return diplomat::Err<diplomat::Utf8Error>(); 89 } 90 std::string output; 91 diplomat::capi::DiplomatWrite write = diplomat::WriteFromString(output); 92 icu4x::capi::icu4x_CaseMapper_uppercase_mv1(this->AsFFI(), 93 {s.data(), s.size()}, 94 locale.AsFFI(), 95 &write); 96 return diplomat::Ok<std::string>(std::move(output)); 97 } 98 99 inline diplomat::result<std::string, diplomat::Utf8Error> icu4x::CaseMapper::lowercase_with_compiled_data(std::string_view s, const icu4x::Locale& locale) { 100 if (!diplomat::capi::diplomat_is_str(s.data(), s.size())) { 101 return diplomat::Err<diplomat::Utf8Error>(); 102 } 103 std::string output; 104 diplomat::capi::DiplomatWrite write = diplomat::WriteFromString(output); 105 icu4x::capi::icu4x_CaseMapper_lowercase_with_compiled_data_mv1({s.data(), s.size()}, 106 locale.AsFFI(), 107 &write); 108 return diplomat::Ok<std::string>(std::move(output)); 109 } 110 111 inline diplomat::result<std::string, diplomat::Utf8Error> icu4x::CaseMapper::uppercase_with_compiled_data(std::string_view s, const icu4x::Locale& locale) { 112 if (!diplomat::capi::diplomat_is_str(s.data(), s.size())) { 113 return diplomat::Err<diplomat::Utf8Error>(); 114 } 115 std::string output; 116 diplomat::capi::DiplomatWrite write = diplomat::WriteFromString(output); 117 icu4x::capi::icu4x_CaseMapper_uppercase_with_compiled_data_mv1({s.data(), s.size()}, 118 locale.AsFFI(), 119 &write); 120 return diplomat::Ok<std::string>(std::move(output)); 121 } 122 123 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 { 124 if (!diplomat::capi::diplomat_is_str(s.data(), s.size())) { 125 return diplomat::Err<diplomat::Utf8Error>(); 126 } 127 std::string output; 128 diplomat::capi::DiplomatWrite write = diplomat::WriteFromString(output); 129 icu4x::capi::icu4x_CaseMapper_titlecase_segment_with_only_case_data_v1_mv1(this->AsFFI(), 130 {s.data(), s.size()}, 131 locale.AsFFI(), 132 options.AsFFI(), 133 &write); 134 return diplomat::Ok<std::string>(std::move(output)); 135 } 136 137 inline diplomat::result<std::string, diplomat::Utf8Error> icu4x::CaseMapper::fold(std::string_view s) const { 138 if (!diplomat::capi::diplomat_is_str(s.data(), s.size())) { 139 return diplomat::Err<diplomat::Utf8Error>(); 140 } 141 std::string output; 142 diplomat::capi::DiplomatWrite write = diplomat::WriteFromString(output); 143 icu4x::capi::icu4x_CaseMapper_fold_mv1(this->AsFFI(), 144 {s.data(), s.size()}, 145 &write); 146 return diplomat::Ok<std::string>(std::move(output)); 147 } 148 149 inline diplomat::result<std::string, diplomat::Utf8Error> icu4x::CaseMapper::fold_turkic(std::string_view s) const { 150 if (!diplomat::capi::diplomat_is_str(s.data(), s.size())) { 151 return diplomat::Err<diplomat::Utf8Error>(); 152 } 153 std::string output; 154 diplomat::capi::DiplomatWrite write = diplomat::WriteFromString(output); 155 icu4x::capi::icu4x_CaseMapper_fold_turkic_mv1(this->AsFFI(), 156 {s.data(), s.size()}, 157 &write); 158 return diplomat::Ok<std::string>(std::move(output)); 159 } 160 161 inline void icu4x::CaseMapper::add_case_closure_to(char32_t c, icu4x::CodePointSetBuilder& builder) const { 162 icu4x::capi::icu4x_CaseMapper_add_case_closure_to_mv1(this->AsFFI(), 163 c, 164 builder.AsFFI()); 165 } 166 167 inline char32_t icu4x::CaseMapper::simple_lowercase(char32_t ch) const { 168 auto result = icu4x::capi::icu4x_CaseMapper_simple_lowercase_mv1(this->AsFFI(), 169 ch); 170 return result; 171 } 172 173 inline char32_t icu4x::CaseMapper::simple_uppercase(char32_t ch) const { 174 auto result = icu4x::capi::icu4x_CaseMapper_simple_uppercase_mv1(this->AsFFI(), 175 ch); 176 return result; 177 } 178 179 inline char32_t icu4x::CaseMapper::simple_titlecase(char32_t ch) const { 180 auto result = icu4x::capi::icu4x_CaseMapper_simple_titlecase_mv1(this->AsFFI(), 181 ch); 182 return result; 183 } 184 185 inline char32_t icu4x::CaseMapper::simple_fold(char32_t ch) const { 186 auto result = icu4x::capi::icu4x_CaseMapper_simple_fold_mv1(this->AsFFI(), 187 ch); 188 return result; 189 } 190 191 inline char32_t icu4x::CaseMapper::simple_fold_turkic(char32_t ch) const { 192 auto result = icu4x::capi::icu4x_CaseMapper_simple_fold_turkic_mv1(this->AsFFI(), 193 ch); 194 return result; 195 } 196 197 inline const icu4x::capi::CaseMapper* icu4x::CaseMapper::AsFFI() const { 198 return reinterpret_cast<const icu4x::capi::CaseMapper*>(this); 199 } 200 201 inline icu4x::capi::CaseMapper* icu4x::CaseMapper::AsFFI() { 202 return reinterpret_cast<icu4x::capi::CaseMapper*>(this); 203 } 204 205 inline const icu4x::CaseMapper* icu4x::CaseMapper::FromFFI(const icu4x::capi::CaseMapper* ptr) { 206 return reinterpret_cast<const icu4x::CaseMapper*>(ptr); 207 } 208 209 inline icu4x::CaseMapper* icu4x::CaseMapper::FromFFI(icu4x::capi::CaseMapper* ptr) { 210 return reinterpret_cast<icu4x::CaseMapper*>(ptr); 211 } 212 213 inline void icu4x::CaseMapper::operator delete(void* ptr) { 214 icu4x::capi::icu4x_CaseMapper_destroy_mv1(reinterpret_cast<icu4x::capi::CaseMapper*>(ptr)); 215 } 216 217 218 #endif // icu4x_CaseMapper_HPP