| 1 |
#ifndef ICU4XLocaleFallbacker_HPP |
| 2 |
#define ICU4XLocaleFallbacker_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 "ICU4XLocaleFallbacker.h" |
| 13 |
|
| 14 |
class ICU4XDataProvider; |
| 15 |
class ICU4XLocaleFallbacker; |
| 16 |
#include "ICU4XError.hpp" |
| 17 |
struct ICU4XLocaleFallbackConfig; |
| 18 |
class ICU4XLocaleFallbackerWithConfig; |
| 19 |
|
| 20 |
/** |
| 21 |
* A destruction policy for using ICU4XLocaleFallbacker with std::unique_ptr. |
| 22 |
*/ |
| 23 |
struct ICU4XLocaleFallbackerDeleter { |
| 24 |
void operator()(capi::ICU4XLocaleFallbacker* l) const noexcept { |
| 25 |
capi::ICU4XLocaleFallbacker_destroy(l); |
| 26 |
} |
| 27 |
}; |
| 28 |
|
| 29 |
/** |
| 30 |
* An object that runs the ICU4X locale fallback algorithm. |
| 31 |
* |
| 32 |
* See the [Rust documentation for `LocaleFallbacker`](https://docs.rs/icu/latest/icu/locid_transform/fallback/struct.LocaleFallbacker.html) for more information. |
| 33 |
*/ |
| 34 |
class ICU4XLocaleFallbacker { |
| 35 |
public: |
| 36 |
|
| 37 |
/** |
| 38 |
* Creates a new `ICU4XLocaleFallbacker` from a data provider. |
| 39 |
* |
| 40 |
* See the [Rust documentation for `new`](https://docs.rs/icu/latest/icu/locid_transform/fallback/struct.LocaleFallbacker.html#method.new) for more information. |
| 41 |
*/ |
| 42 |
static diplomat::result<ICU4XLocaleFallbacker, ICU4XError> create(const ICU4XDataProvider& provider); |
| 43 |
|
| 44 |
/** |
| 45 |
* Creates a new `ICU4XLocaleFallbacker` without data for limited functionality. |
| 46 |
* |
| 47 |
* See the [Rust documentation for `new_without_data`](https://docs.rs/icu/latest/icu/locid_transform/fallback/struct.LocaleFallbacker.html#method.new_without_data) for more information. |
| 48 |
*/ |
| 49 |
static ICU4XLocaleFallbacker create_without_data(); |
| 50 |
|
| 51 |
/** |
| 52 |
* Associates this `ICU4XLocaleFallbacker` with configuration options. |
| 53 |
* |
| 54 |
* See the [Rust documentation for `for_config`](https://docs.rs/icu/latest/icu/locid_transform/fallback/struct.LocaleFallbacker.html#method.for_config) for more information. |
| 55 |
* |
| 56 |
* Lifetimes: `this` must live at least as long as the output. |
| 57 |
*/ |
| 58 |
diplomat::result<ICU4XLocaleFallbackerWithConfig, ICU4XError> for_config(ICU4XLocaleFallbackConfig config) const; |
| 59 |
inline const capi::ICU4XLocaleFallbacker* AsFFI() const { return this->inner.get(); } |
| 60 |
inline capi::ICU4XLocaleFallbacker* AsFFIMut() { return this->inner.get(); } |
| 61 |
inline explicit ICU4XLocaleFallbacker(capi::ICU4XLocaleFallbacker* i) : inner(i) {} |
| 62 |
ICU4XLocaleFallbacker() = default; |
| 63 |
ICU4XLocaleFallbacker(ICU4XLocaleFallbacker&&) noexcept = default; |
| 64 |
ICU4XLocaleFallbacker& operator=(ICU4XLocaleFallbacker&& other) noexcept = default; |
| 65 |
private: |
| 66 |
std::unique_ptr<capi::ICU4XLocaleFallbacker, ICU4XLocaleFallbackerDeleter> inner; |
| 67 |
}; |
| 68 |
|
| 69 |
#include "ICU4XDataProvider.hpp" |
| 70 |
#include "ICU4XLocaleFallbackConfig.hpp" |
| 71 |
#include "ICU4XLocaleFallbackerWithConfig.hpp" |
| 72 |
|
| 73 |
inline diplomat::result<ICU4XLocaleFallbacker, ICU4XError> ICU4XLocaleFallbacker::create(const ICU4XDataProvider& provider) { |
| 74 |
auto diplomat_result_raw_out_value = capi::ICU4XLocaleFallbacker_create(provider.AsFFI()); |
| 75 |
diplomat::result<ICU4XLocaleFallbacker, ICU4XError> diplomat_result_out_value; |
| 76 |
if (diplomat_result_raw_out_value.is_ok) { |
| 77 |
diplomat_result_out_value = diplomat::Ok<ICU4XLocaleFallbacker>(ICU4XLocaleFallbacker(diplomat_result_raw_out_value.ok)); |
| 78 |
} else { |
| 79 |
diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); |
| 80 |
} |
| 81 |
return diplomat_result_out_value; |
| 82 |
} |
| 83 |
inline ICU4XLocaleFallbacker ICU4XLocaleFallbacker::create_without_data() { |
| 84 |
return ICU4XLocaleFallbacker(capi::ICU4XLocaleFallbacker_create_without_data()); |
| 85 |
} |
| 86 |
inline diplomat::result<ICU4XLocaleFallbackerWithConfig, ICU4XError> ICU4XLocaleFallbacker::for_config(ICU4XLocaleFallbackConfig config) const { |
| 87 |
ICU4XLocaleFallbackConfig diplomat_wrapped_struct_config = config; |
| 88 |
auto diplomat_result_raw_out_value = capi::ICU4XLocaleFallbacker_for_config(this->inner.get(), capi::ICU4XLocaleFallbackConfig{ .priority = static_cast<capi::ICU4XLocaleFallbackPriority>(diplomat_wrapped_struct_config.priority), .extension_key = { diplomat_wrapped_struct_config.extension_key.data(), diplomat_wrapped_struct_config.extension_key.size() }, .fallback_supplement = static_cast<capi::ICU4XLocaleFallbackSupplement>(diplomat_wrapped_struct_config.fallback_supplement) }); |
| 89 |
diplomat::result<ICU4XLocaleFallbackerWithConfig, ICU4XError> diplomat_result_out_value; |
| 90 |
if (diplomat_result_raw_out_value.is_ok) { |
| 91 |
diplomat_result_out_value = diplomat::Ok<ICU4XLocaleFallbackerWithConfig>(ICU4XLocaleFallbackerWithConfig(diplomat_result_raw_out_value.ok)); |
| 92 |
} else { |
| 93 |
diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); |
| 94 |
} |
| 95 |
return diplomat_result_out_value; |
| 96 |
} |
| 97 |
#endif |