Debian Codegraph @

intl/icu_capi/bindings/cpp/ICU4XLocaleExpander.hpp

raw
1 #ifndef ICU4XLocaleExpander_HPP
2 #define ICU4XLocaleExpander_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 "ICU4XLocaleExpander.h"
13
14 class ICU4XDataProvider;
15 class ICU4XLocaleExpander;
16 #include "ICU4XError.hpp"
17 class ICU4XLocale;
18 #include "ICU4XTransformResult.hpp"
19
20 /**
21 * A destruction policy for using ICU4XLocaleExpander with std::unique_ptr.
22 */
23 struct ICU4XLocaleExpanderDeleter {
24 void operator()(capi::ICU4XLocaleExpander* l) const noexcept {
25 capi::ICU4XLocaleExpander_destroy(l);
26 }
27 };
28
29 /**
30 * A locale expander.
31 *
32 * See the [Rust documentation for `LocaleExpander`](https://docs.rs/icu/latest/icu/locid_transform/struct.LocaleExpander.html) for more information.
33 */
34 class ICU4XLocaleExpander {
35 public:
36
37 /**
38 * Create a new [`ICU4XLocaleExpander`].
39 *
40 * See the [Rust documentation for `new`](https://docs.rs/icu/latest/icu/locid_transform/struct.LocaleExpander.html#method.new) for more information.
41 */
42 static diplomat::result<ICU4XLocaleExpander, ICU4XError> create(const ICU4XDataProvider& provider);
43
44 /**
45 * Create a new [`ICU4XLocaleExpander`] with extended data.
46 *
47 * See the [Rust documentation for `new_extended`](https://docs.rs/icu/latest/icu/locid_transform/struct.LocaleExpander.html#method.new_extended) for more information.
48 */
49 static diplomat::result<ICU4XLocaleExpander, ICU4XError> create_extended(const ICU4XDataProvider& provider);
50
51 /**
52 * See the [Rust documentation for `maximize`](https://docs.rs/icu/latest/icu/locid_transform/struct.LocaleExpander.html#method.maximize) for more information.
53 */
54 ICU4XTransformResult maximize(ICU4XLocale& locale) const;
55
56 /**
57 * See the [Rust documentation for `minimize`](https://docs.rs/icu/latest/icu/locid_transform/struct.LocaleExpander.html#method.minimize) for more information.
58 */
59 ICU4XTransformResult minimize(ICU4XLocale& locale) const;
60
61 /**
62 * See the [Rust documentation for `minimize_favor_script`](https://docs.rs/icu/latest/icu/locid_transform/struct.LocaleExpander.html#method.minimize_favor_script) for more information.
63 */
64 ICU4XTransformResult minimize_favor_script(ICU4XLocale& locale) const;
65 inline const capi::ICU4XLocaleExpander* AsFFI() const { return this->inner.get(); }
66 inline capi::ICU4XLocaleExpander* AsFFIMut() { return this->inner.get(); }
67 inline explicit ICU4XLocaleExpander(capi::ICU4XLocaleExpander* i) : inner(i) {}
68 ICU4XLocaleExpander() = default;
69 ICU4XLocaleExpander(ICU4XLocaleExpander&&) noexcept = default;
70 ICU4XLocaleExpander& operator=(ICU4XLocaleExpander&& other) noexcept = default;
71 private:
72 std::unique_ptr<capi::ICU4XLocaleExpander, ICU4XLocaleExpanderDeleter> inner;
73 };
74
75 #include "ICU4XDataProvider.hpp"
76 #include "ICU4XLocale.hpp"
77
78 inline diplomat::result<ICU4XLocaleExpander, ICU4XError> ICU4XLocaleExpander::create(const ICU4XDataProvider& provider) {
79 auto diplomat_result_raw_out_value = capi::ICU4XLocaleExpander_create(provider.AsFFI());
80 diplomat::result<ICU4XLocaleExpander, ICU4XError> diplomat_result_out_value;
81 if (diplomat_result_raw_out_value.is_ok) {
82 diplomat_result_out_value = diplomat::Ok<ICU4XLocaleExpander>(ICU4XLocaleExpander(diplomat_result_raw_out_value.ok));
83 } else {
84 diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err));
85 }
86 return diplomat_result_out_value;
87 }
88 inline diplomat::result<ICU4XLocaleExpander, ICU4XError> ICU4XLocaleExpander::create_extended(const ICU4XDataProvider& provider) {
89 auto diplomat_result_raw_out_value = capi::ICU4XLocaleExpander_create_extended(provider.AsFFI());
90 diplomat::result<ICU4XLocaleExpander, ICU4XError> diplomat_result_out_value;
91 if (diplomat_result_raw_out_value.is_ok) {
92 diplomat_result_out_value = diplomat::Ok<ICU4XLocaleExpander>(ICU4XLocaleExpander(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 ICU4XTransformResult ICU4XLocaleExpander::maximize(ICU4XLocale& locale) const {
99 return static_cast<ICU4XTransformResult>(capi::ICU4XLocaleExpander_maximize(this->inner.get(), locale.AsFFIMut()));
100 }
101 inline ICU4XTransformResult ICU4XLocaleExpander::minimize(ICU4XLocale& locale) const {
102 return static_cast<ICU4XTransformResult>(capi::ICU4XLocaleExpander_minimize(this->inner.get(), locale.AsFFIMut()));
103 }
104 inline ICU4XTransformResult ICU4XLocaleExpander::minimize_favor_script(ICU4XLocale& locale) const {
105 return static_cast<ICU4XTransformResult>(capi::ICU4XLocaleExpander_minimize_favor_script(this->inner.get(), locale.AsFFIMut()));
106 }
107 #endif