| 1 |
#ifndef ICU4XLocale_HPP |
| 2 |
#define ICU4XLocale_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 "ICU4XLocale.h" |
| 13 |
|
| 14 |
class ICU4XLocale; |
| 15 |
#include "ICU4XError.hpp" |
| 16 |
#include "ICU4XOrdering.hpp" |
| 17 |
|
| 18 |
/** |
| 19 |
* A destruction policy for using ICU4XLocale with std::unique_ptr. |
| 20 |
*/ |
| 21 |
struct ICU4XLocaleDeleter { |
| 22 |
void operator()(capi::ICU4XLocale* l) const noexcept { |
| 23 |
capi::ICU4XLocale_destroy(l); |
| 24 |
} |
| 25 |
}; |
| 26 |
|
| 27 |
/** |
| 28 |
* An ICU4X Locale, capable of representing strings like `"en-US"`. |
| 29 |
* |
| 30 |
* See the [Rust documentation for `Locale`](https://docs.rs/icu/latest/icu/locid/struct.Locale.html) for more information. |
| 31 |
*/ |
| 32 |
class ICU4XLocale { |
| 33 |
public: |
| 34 |
|
| 35 |
/** |
| 36 |
* Construct an [`ICU4XLocale`] from an locale identifier. |
| 37 |
* |
| 38 |
* This will run the complete locale parsing algorithm. If code size and |
| 39 |
* performance are critical and the locale is of a known shape (such as |
| 40 |
* `aa-BB`) use `create_und`, `set_language`, `set_script`, and `set_region`. |
| 41 |
* |
| 42 |
* See the [Rust documentation for `try_from_bytes`](https://docs.rs/icu/latest/icu/locid/struct.Locale.html#method.try_from_bytes) for more information. |
| 43 |
*/ |
| 44 |
static diplomat::result<ICU4XLocale, ICU4XError> create_from_string(const std::string_view name); |
| 45 |
|
| 46 |
/** |
| 47 |
* Construct a default undefined [`ICU4XLocale`] "und". |
| 48 |
* |
| 49 |
* See the [Rust documentation for `UND`](https://docs.rs/icu/latest/icu/locid/struct.Locale.html#associatedconstant.UND) for more information. |
| 50 |
*/ |
| 51 |
static ICU4XLocale create_und(); |
| 52 |
|
| 53 |
/** |
| 54 |
* Clones the [`ICU4XLocale`]. |
| 55 |
* |
| 56 |
* See the [Rust documentation for `Locale`](https://docs.rs/icu/latest/icu/locid/struct.Locale.html) for more information. |
| 57 |
*/ |
| 58 |
ICU4XLocale clone() const; |
| 59 |
|
| 60 |
/** |
| 61 |
* Write a string representation of the `LanguageIdentifier` part of |
| 62 |
* [`ICU4XLocale`] to `write`. |
| 63 |
* |
| 64 |
* See the [Rust documentation for `id`](https://docs.rs/icu/latest/icu/locid/struct.Locale.html#structfield.id) for more information. |
| 65 |
*/ |
| 66 |
template<typename W> diplomat::result<std::monostate, ICU4XError> basename_to_writeable(W& write) const; |
| 67 |
|
| 68 |
/** |
| 69 |
* Write a string representation of the `LanguageIdentifier` part of |
| 70 |
* [`ICU4XLocale`] to `write`. |
| 71 |
* |
| 72 |
* See the [Rust documentation for `id`](https://docs.rs/icu/latest/icu/locid/struct.Locale.html#structfield.id) for more information. |
| 73 |
*/ |
| 74 |
diplomat::result<std::string, ICU4XError> basename() const; |
| 75 |
|
| 76 |
/** |
| 77 |
* Write a string representation of the unicode extension to `write` |
| 78 |
* |
| 79 |
* See the [Rust documentation for `extensions`](https://docs.rs/icu/latest/icu/locid/struct.Locale.html#structfield.extensions) for more information. |
| 80 |
*/ |
| 81 |
template<typename W> diplomat::result<std::monostate, ICU4XError> get_unicode_extension_to_writeable(const std::string_view bytes, W& write) const; |
| 82 |
|
| 83 |
/** |
| 84 |
* Write a string representation of the unicode extension to `write` |
| 85 |
* |
| 86 |
* See the [Rust documentation for `extensions`](https://docs.rs/icu/latest/icu/locid/struct.Locale.html#structfield.extensions) for more information. |
| 87 |
*/ |
| 88 |
diplomat::result<std::string, ICU4XError> get_unicode_extension(const std::string_view bytes) const; |
| 89 |
|
| 90 |
/** |
| 91 |
* Write a string representation of [`ICU4XLocale`] language to `write` |
| 92 |
* |
| 93 |
* See the [Rust documentation for `id`](https://docs.rs/icu/latest/icu/locid/struct.Locale.html#structfield.id) for more information. |
| 94 |
*/ |
| 95 |
template<typename W> diplomat::result<std::monostate, ICU4XError> language_to_writeable(W& write) const; |
| 96 |
|
| 97 |
/** |
| 98 |
* Write a string representation of [`ICU4XLocale`] language to `write` |
| 99 |
* |
| 100 |
* See the [Rust documentation for `id`](https://docs.rs/icu/latest/icu/locid/struct.Locale.html#structfield.id) for more information. |
| 101 |
*/ |
| 102 |
diplomat::result<std::string, ICU4XError> language() const; |
| 103 |
|
| 104 |
/** |
| 105 |
* Set the language part of the [`ICU4XLocale`]. |
| 106 |
* |
| 107 |
* See the [Rust documentation for `try_from_bytes`](https://docs.rs/icu/latest/icu/locid/struct.Locale.html#method.try_from_bytes) for more information. |
| 108 |
*/ |
| 109 |
diplomat::result<std::monostate, ICU4XError> set_language(const std::string_view bytes); |
| 110 |
|
| 111 |
/** |
| 112 |
* Write a string representation of [`ICU4XLocale`] region to `write` |
| 113 |
* |
| 114 |
* See the [Rust documentation for `id`](https://docs.rs/icu/latest/icu/locid/struct.Locale.html#structfield.id) for more information. |
| 115 |
*/ |
| 116 |
template<typename W> diplomat::result<std::monostate, ICU4XError> region_to_writeable(W& write) const; |
| 117 |
|
| 118 |
/** |
| 119 |
* Write a string representation of [`ICU4XLocale`] region to `write` |
| 120 |
* |
| 121 |
* See the [Rust documentation for `id`](https://docs.rs/icu/latest/icu/locid/struct.Locale.html#structfield.id) for more information. |
| 122 |
*/ |
| 123 |
diplomat::result<std::string, ICU4XError> region() const; |
| 124 |
|
| 125 |
/** |
| 126 |
* Set the region part of the [`ICU4XLocale`]. |
| 127 |
* |
| 128 |
* See the [Rust documentation for `try_from_bytes`](https://docs.rs/icu/latest/icu/locid/struct.Locale.html#method.try_from_bytes) for more information. |
| 129 |
*/ |
| 130 |
diplomat::result<std::monostate, ICU4XError> set_region(const std::string_view bytes); |
| 131 |
|
| 132 |
/** |
| 133 |
* Write a string representation of [`ICU4XLocale`] script to `write` |
| 134 |
* |
| 135 |
* See the [Rust documentation for `id`](https://docs.rs/icu/latest/icu/locid/struct.Locale.html#structfield.id) for more information. |
| 136 |
*/ |
| 137 |
template<typename W> diplomat::result<std::monostate, ICU4XError> script_to_writeable(W& write) const; |
| 138 |
|
| 139 |
/** |
| 140 |
* Write a string representation of [`ICU4XLocale`] script to `write` |
| 141 |
* |
| 142 |
* See the [Rust documentation for `id`](https://docs.rs/icu/latest/icu/locid/struct.Locale.html#structfield.id) for more information. |
| 143 |
*/ |
| 144 |
diplomat::result<std::string, ICU4XError> script() const; |
| 145 |
|
| 146 |
/** |
| 147 |
* Set the script part of the [`ICU4XLocale`]. Pass an empty string to remove the script. |
| 148 |
* |
| 149 |
* See the [Rust documentation for `try_from_bytes`](https://docs.rs/icu/latest/icu/locid/struct.Locale.html#method.try_from_bytes) for more information. |
| 150 |
*/ |
| 151 |
diplomat::result<std::monostate, ICU4XError> set_script(const std::string_view bytes); |
| 152 |
|
| 153 |
/** |
| 154 |
* Best effort locale canonicalizer that doesn't need any data |
| 155 |
* |
| 156 |
* Use ICU4XLocaleCanonicalizer for better control and functionality |
| 157 |
* |
| 158 |
* See the [Rust documentation for `canonicalize`](https://docs.rs/icu/latest/icu/locid/struct.Locale.html#method.canonicalize) for more information. |
| 159 |
*/ |
| 160 |
template<typename W> static diplomat::result<std::monostate, ICU4XError> canonicalize_to_writeable(const std::string_view bytes, W& write); |
| 161 |
|
| 162 |
/** |
| 163 |
* Best effort locale canonicalizer that doesn't need any data |
| 164 |
* |
| 165 |
* Use ICU4XLocaleCanonicalizer for better control and functionality |
| 166 |
* |
| 167 |
* See the [Rust documentation for `canonicalize`](https://docs.rs/icu/latest/icu/locid/struct.Locale.html#method.canonicalize) for more information. |
| 168 |
*/ |
| 169 |
static diplomat::result<std::string, ICU4XError> canonicalize(const std::string_view bytes); |
| 170 |
|
| 171 |
/** |
| 172 |
* Write a string representation of [`ICU4XLocale`] to `write` |
| 173 |
* |
| 174 |
* See the [Rust documentation for `write_to`](https://docs.rs/icu/latest/icu/locid/struct.Locale.html#method.write_to) for more information. |
| 175 |
*/ |
| 176 |
template<typename W> diplomat::result<std::monostate, ICU4XError> to_string_to_writeable(W& write) const; |
| 177 |
|
| 178 |
/** |
| 179 |
* Write a string representation of [`ICU4XLocale`] to `write` |
| 180 |
* |
| 181 |
* See the [Rust documentation for `write_to`](https://docs.rs/icu/latest/icu/locid/struct.Locale.html#method.write_to) for more information. |
| 182 |
*/ |
| 183 |
diplomat::result<std::string, ICU4XError> to_string() const; |
| 184 |
|
| 185 |
/** |
| 186 |
* See the [Rust documentation for `normalizing_eq`](https://docs.rs/icu/latest/icu/locid/struct.Locale.html#method.normalizing_eq) for more information. |
| 187 |
*/ |
| 188 |
bool normalizing_eq(const std::string_view other) const; |
| 189 |
|
| 190 |
/** |
| 191 |
* See the [Rust documentation for `strict_cmp`](https://docs.rs/icu/latest/icu/locid/struct.Locale.html#method.strict_cmp) for more information. |
| 192 |
*/ |
| 193 |
ICU4XOrdering strict_cmp(const std::string_view other) const; |
| 194 |
|
| 195 |
/** |
| 196 |
* See the [Rust documentation for `total_cmp`](https://docs.rs/icu/latest/icu/locid/struct.Locale.html#method.total_cmp) for more information. |
| 197 |
*/ |
| 198 |
ICU4XOrdering total_cmp(const ICU4XLocale& other) const; |
| 199 |
|
| 200 |
/** |
| 201 |
* Deprecated |
| 202 |
* |
| 203 |
* Use `create_from_string("en"). |
| 204 |
*/ |
| 205 |
static ICU4XLocale create_en(); |
| 206 |
|
| 207 |
/** |
| 208 |
* Deprecated |
| 209 |
* |
| 210 |
* Use `create_from_string("bn"). |
| 211 |
*/ |
| 212 |
static ICU4XLocale create_bn(); |
| 213 |
inline const capi::ICU4XLocale* AsFFI() const { return this->inner.get(); } |
| 214 |
inline capi::ICU4XLocale* AsFFIMut() { return this->inner.get(); } |
| 215 |
inline explicit ICU4XLocale(capi::ICU4XLocale* i) : inner(i) {} |
| 216 |
ICU4XLocale() = default; |
| 217 |
ICU4XLocale(ICU4XLocale&&) noexcept = default; |
| 218 |
ICU4XLocale& operator=(ICU4XLocale&& other) noexcept = default; |
| 219 |
private: |
| 220 |
std::unique_ptr<capi::ICU4XLocale, ICU4XLocaleDeleter> inner; |
| 221 |
}; |
| 222 |
|
| 223 |
|
| 224 |
inline diplomat::result<ICU4XLocale, ICU4XError> ICU4XLocale::create_from_string(const std::string_view name) { |
| 225 |
auto diplomat_result_raw_out_value = capi::ICU4XLocale_create_from_string(name.data(), name.size()); |
| 226 |
diplomat::result<ICU4XLocale, ICU4XError> diplomat_result_out_value; |
| 227 |
if (diplomat_result_raw_out_value.is_ok) { |
| 228 |
diplomat_result_out_value = diplomat::Ok<ICU4XLocale>(ICU4XLocale(diplomat_result_raw_out_value.ok)); |
| 229 |
} else { |
| 230 |
diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); |
| 231 |
} |
| 232 |
return diplomat_result_out_value; |
| 233 |
} |
| 234 |
inline ICU4XLocale ICU4XLocale::create_und() { |
| 235 |
return ICU4XLocale(capi::ICU4XLocale_create_und()); |
| 236 |
} |
| 237 |
inline ICU4XLocale ICU4XLocale::clone() const { |
| 238 |
return ICU4XLocale(capi::ICU4XLocale_clone(this->inner.get())); |
| 239 |
} |
| 240 |
template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XLocale::basename_to_writeable(W& write) const { |
| 241 |
capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write); |
| 242 |
auto diplomat_result_raw_out_value = capi::ICU4XLocale_basename(this->inner.get(), &write_writer); |
| 243 |
diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; |
| 244 |
if (diplomat_result_raw_out_value.is_ok) { |
| 245 |
diplomat_result_out_value = diplomat::Ok<std::monostate>(std::monostate()); |
| 246 |
} else { |
| 247 |
diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); |
| 248 |
} |
| 249 |
return diplomat_result_out_value; |
| 250 |
} |
| 251 |
inline diplomat::result<std::string, ICU4XError> ICU4XLocale::basename() const { |
| 252 |
std::string diplomat_writeable_string; |
| 253 |
capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); |
| 254 |
auto diplomat_result_raw_out_value = capi::ICU4XLocale_basename(this->inner.get(), &diplomat_writeable_out); |
| 255 |
diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; |
| 256 |
if (diplomat_result_raw_out_value.is_ok) { |
| 257 |
diplomat_result_out_value = diplomat::Ok<std::monostate>(std::monostate()); |
| 258 |
} else { |
| 259 |
diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); |
| 260 |
} |
| 261 |
return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string)); |
| 262 |
} |
| 263 |
template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XLocale::get_unicode_extension_to_writeable(const std::string_view bytes, W& write) const { |
| 264 |
capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write); |
| 265 |
auto diplomat_result_raw_out_value = capi::ICU4XLocale_get_unicode_extension(this->inner.get(), bytes.data(), bytes.size(), &write_writer); |
| 266 |
diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; |
| 267 |
if (diplomat_result_raw_out_value.is_ok) { |
| 268 |
diplomat_result_out_value = diplomat::Ok<std::monostate>(std::monostate()); |
| 269 |
} else { |
| 270 |
diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); |
| 271 |
} |
| 272 |
return diplomat_result_out_value; |
| 273 |
} |
| 274 |
inline diplomat::result<std::string, ICU4XError> ICU4XLocale::get_unicode_extension(const std::string_view bytes) const { |
| 275 |
std::string diplomat_writeable_string; |
| 276 |
capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); |
| 277 |
auto diplomat_result_raw_out_value = capi::ICU4XLocale_get_unicode_extension(this->inner.get(), bytes.data(), bytes.size(), &diplomat_writeable_out); |
| 278 |
diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; |
| 279 |
if (diplomat_result_raw_out_value.is_ok) { |
| 280 |
diplomat_result_out_value = diplomat::Ok<std::monostate>(std::monostate()); |
| 281 |
} else { |
| 282 |
diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); |
| 283 |
} |
| 284 |
return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string)); |
| 285 |
} |
| 286 |
template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XLocale::language_to_writeable(W& write) const { |
| 287 |
capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write); |
| 288 |
auto diplomat_result_raw_out_value = capi::ICU4XLocale_language(this->inner.get(), &write_writer); |
| 289 |
diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; |
| 290 |
if (diplomat_result_raw_out_value.is_ok) { |
| 291 |
diplomat_result_out_value = diplomat::Ok<std::monostate>(std::monostate()); |
| 292 |
} else { |
| 293 |
diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); |
| 294 |
} |
| 295 |
return diplomat_result_out_value; |
| 296 |
} |
| 297 |
inline diplomat::result<std::string, ICU4XError> ICU4XLocale::language() const { |
| 298 |
std::string diplomat_writeable_string; |
| 299 |
capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); |
| 300 |
auto diplomat_result_raw_out_value = capi::ICU4XLocale_language(this->inner.get(), &diplomat_writeable_out); |
| 301 |
diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; |
| 302 |
if (diplomat_result_raw_out_value.is_ok) { |
| 303 |
diplomat_result_out_value = diplomat::Ok<std::monostate>(std::monostate()); |
| 304 |
} else { |
| 305 |
diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); |
| 306 |
} |
| 307 |
return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string)); |
| 308 |
} |
| 309 |
inline diplomat::result<std::monostate, ICU4XError> ICU4XLocale::set_language(const std::string_view bytes) { |
| 310 |
auto diplomat_result_raw_out_value = capi::ICU4XLocale_set_language(this->inner.get(), bytes.data(), bytes.size()); |
| 311 |
diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; |
| 312 |
if (diplomat_result_raw_out_value.is_ok) { |
| 313 |
diplomat_result_out_value = diplomat::Ok<std::monostate>(std::monostate()); |
| 314 |
} else { |
| 315 |
diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); |
| 316 |
} |
| 317 |
return diplomat_result_out_value; |
| 318 |
} |
| 319 |
template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XLocale::region_to_writeable(W& write) const { |
| 320 |
capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write); |
| 321 |
auto diplomat_result_raw_out_value = capi::ICU4XLocale_region(this->inner.get(), &write_writer); |
| 322 |
diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; |
| 323 |
if (diplomat_result_raw_out_value.is_ok) { |
| 324 |
diplomat_result_out_value = diplomat::Ok<std::monostate>(std::monostate()); |
| 325 |
} else { |
| 326 |
diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); |
| 327 |
} |
| 328 |
return diplomat_result_out_value; |
| 329 |
} |
| 330 |
inline diplomat::result<std::string, ICU4XError> ICU4XLocale::region() const { |
| 331 |
std::string diplomat_writeable_string; |
| 332 |
capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); |
| 333 |
auto diplomat_result_raw_out_value = capi::ICU4XLocale_region(this->inner.get(), &diplomat_writeable_out); |
| 334 |
diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; |
| 335 |
if (diplomat_result_raw_out_value.is_ok) { |
| 336 |
diplomat_result_out_value = diplomat::Ok<std::monostate>(std::monostate()); |
| 337 |
} else { |
| 338 |
diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); |
| 339 |
} |
| 340 |
return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string)); |
| 341 |
} |
| 342 |
inline diplomat::result<std::monostate, ICU4XError> ICU4XLocale::set_region(const std::string_view bytes) { |
| 343 |
auto diplomat_result_raw_out_value = capi::ICU4XLocale_set_region(this->inner.get(), bytes.data(), bytes.size()); |
| 344 |
diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; |
| 345 |
if (diplomat_result_raw_out_value.is_ok) { |
| 346 |
diplomat_result_out_value = diplomat::Ok<std::monostate>(std::monostate()); |
| 347 |
} else { |
| 348 |
diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); |
| 349 |
} |
| 350 |
return diplomat_result_out_value; |
| 351 |
} |
| 352 |
template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XLocale::script_to_writeable(W& write) const { |
| 353 |
capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write); |
| 354 |
auto diplomat_result_raw_out_value = capi::ICU4XLocale_script(this->inner.get(), &write_writer); |
| 355 |
diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; |
| 356 |
if (diplomat_result_raw_out_value.is_ok) { |
| 357 |
diplomat_result_out_value = diplomat::Ok<std::monostate>(std::monostate()); |
| 358 |
} else { |
| 359 |
diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); |
| 360 |
} |
| 361 |
return diplomat_result_out_value; |
| 362 |
} |
| 363 |
inline diplomat::result<std::string, ICU4XError> ICU4XLocale::script() const { |
| 364 |
std::string diplomat_writeable_string; |
| 365 |
capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); |
| 366 |
auto diplomat_result_raw_out_value = capi::ICU4XLocale_script(this->inner.get(), &diplomat_writeable_out); |
| 367 |
diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; |
| 368 |
if (diplomat_result_raw_out_value.is_ok) { |
| 369 |
diplomat_result_out_value = diplomat::Ok<std::monostate>(std::monostate()); |
| 370 |
} else { |
| 371 |
diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); |
| 372 |
} |
| 373 |
return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string)); |
| 374 |
} |
| 375 |
inline diplomat::result<std::monostate, ICU4XError> ICU4XLocale::set_script(const std::string_view bytes) { |
| 376 |
auto diplomat_result_raw_out_value = capi::ICU4XLocale_set_script(this->inner.get(), bytes.data(), bytes.size()); |
| 377 |
diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; |
| 378 |
if (diplomat_result_raw_out_value.is_ok) { |
| 379 |
diplomat_result_out_value = diplomat::Ok<std::monostate>(std::monostate()); |
| 380 |
} else { |
| 381 |
diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); |
| 382 |
} |
| 383 |
return diplomat_result_out_value; |
| 384 |
} |
| 385 |
template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XLocale::canonicalize_to_writeable(const std::string_view bytes, W& write) { |
| 386 |
capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write); |
| 387 |
auto diplomat_result_raw_out_value = capi::ICU4XLocale_canonicalize(bytes.data(), bytes.size(), &write_writer); |
| 388 |
diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; |
| 389 |
if (diplomat_result_raw_out_value.is_ok) { |
| 390 |
diplomat_result_out_value = diplomat::Ok<std::monostate>(std::monostate()); |
| 391 |
} else { |
| 392 |
diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); |
| 393 |
} |
| 394 |
return diplomat_result_out_value; |
| 395 |
} |
| 396 |
inline diplomat::result<std::string, ICU4XError> ICU4XLocale::canonicalize(const std::string_view bytes) { |
| 397 |
std::string diplomat_writeable_string; |
| 398 |
capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); |
| 399 |
auto diplomat_result_raw_out_value = capi::ICU4XLocale_canonicalize(bytes.data(), bytes.size(), &diplomat_writeable_out); |
| 400 |
diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; |
| 401 |
if (diplomat_result_raw_out_value.is_ok) { |
| 402 |
diplomat_result_out_value = diplomat::Ok<std::monostate>(std::monostate()); |
| 403 |
} else { |
| 404 |
diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); |
| 405 |
} |
| 406 |
return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string)); |
| 407 |
} |
| 408 |
template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XLocale::to_string_to_writeable(W& write) const { |
| 409 |
capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write); |
| 410 |
auto diplomat_result_raw_out_value = capi::ICU4XLocale_to_string(this->inner.get(), &write_writer); |
| 411 |
diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; |
| 412 |
if (diplomat_result_raw_out_value.is_ok) { |
| 413 |
diplomat_result_out_value = diplomat::Ok<std::monostate>(std::monostate()); |
| 414 |
} else { |
| 415 |
diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); |
| 416 |
} |
| 417 |
return diplomat_result_out_value; |
| 418 |
} |
| 419 |
inline diplomat::result<std::string, ICU4XError> ICU4XLocale::to_string() const { |
| 420 |
std::string diplomat_writeable_string; |
| 421 |
capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); |
| 422 |
auto diplomat_result_raw_out_value = capi::ICU4XLocale_to_string(this->inner.get(), &diplomat_writeable_out); |
| 423 |
diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; |
| 424 |
if (diplomat_result_raw_out_value.is_ok) { |
| 425 |
diplomat_result_out_value = diplomat::Ok<std::monostate>(std::monostate()); |
| 426 |
} else { |
| 427 |
diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); |
| 428 |
} |
| 429 |
return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string)); |
| 430 |
} |
| 431 |
inline bool ICU4XLocale::normalizing_eq(const std::string_view other) const { |
| 432 |
return capi::ICU4XLocale_normalizing_eq(this->inner.get(), other.data(), other.size()); |
| 433 |
} |
| 434 |
inline ICU4XOrdering ICU4XLocale::strict_cmp(const std::string_view other) const { |
| 435 |
return static_cast<ICU4XOrdering>(capi::ICU4XLocale_strict_cmp(this->inner.get(), other.data(), other.size())); |
| 436 |
} |
| 437 |
inline ICU4XOrdering ICU4XLocale::total_cmp(const ICU4XLocale& other) const { |
| 438 |
return static_cast<ICU4XOrdering>(capi::ICU4XLocale_total_cmp(this->inner.get(), other.AsFFI())); |
| 439 |
} |
| 440 |
inline ICU4XLocale ICU4XLocale::create_en() { |
| 441 |
return ICU4XLocale(capi::ICU4XLocale_create_en()); |
| 442 |
} |
| 443 |
inline ICU4XLocale ICU4XLocale::create_bn() { |
| 444 |
return ICU4XLocale(capi::ICU4XLocale_create_bn()); |
| 445 |
} |
| 446 |
#endif |