Debian Codegraph @

intl/icu_capi/bindings/cpp/ICU4XCollator.hpp

raw
1 #ifndef ICU4XCollator_HPP
2 #define ICU4XCollator_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 "ICU4XCollator.h"
13
14 class ICU4XDataProvider;
15 class ICU4XLocale;
16 struct ICU4XCollatorOptionsV1;
17 class ICU4XCollator;
18 #include "ICU4XError.hpp"
19 #include "ICU4XOrdering.hpp"
20 struct ICU4XCollatorResolvedOptionsV1;
21
22 /**
23 * A destruction policy for using ICU4XCollator with std::unique_ptr.
24 */
25 struct ICU4XCollatorDeleter {
26 void operator()(capi::ICU4XCollator* l) const noexcept {
27 capi::ICU4XCollator_destroy(l);
28 }
29 };
30
31 /**
32 * See the [Rust documentation for `Collator`](https://docs.rs/icu/latest/icu/collator/struct.Collator.html) for more information.
33 */
34 class ICU4XCollator {
35 public:
36
37 /**
38 * Construct a new Collator instance.
39 *
40 * See the [Rust documentation for `try_new`](https://docs.rs/icu/latest/icu/collator/struct.Collator.html#method.try_new) for more information.
41 */
42 static diplomat::result<ICU4XCollator, ICU4XError> create_v1(const ICU4XDataProvider& provider, const ICU4XLocale& locale, ICU4XCollatorOptionsV1 options);
43
44 /**
45 * Compare two strings.
46 *
47 * Ill-formed input is treated as if errors had been replaced with REPLACEMENT CHARACTERs according
48 * to the WHATWG Encoding Standard.
49 *
50 * See the [Rust documentation for `compare_utf8`](https://docs.rs/icu/latest/icu/collator/struct.Collator.html#method.compare_utf8) for more information.
51 */
52 ICU4XOrdering compare(const std::string_view left, const std::string_view right) const;
53
54 /**
55 * Compare two strings.
56 *
57 * See the [Rust documentation for `compare`](https://docs.rs/icu/latest/icu/collator/struct.Collator.html#method.compare) for more information.
58 *
59 * Warning: Passing ill-formed UTF-8 is undefined behavior (and may be memory-unsafe).
60 */
61 ICU4XOrdering compare_valid_utf8(const std::string_view left, const std::string_view right) const;
62
63 /**
64 * Compare two strings.
65 *
66 * Ill-formed input is treated as if errors had been replaced with REPLACEMENT CHARACTERs according
67 * to the WHATWG Encoding Standard.
68 *
69 * See the [Rust documentation for `compare_utf16`](https://docs.rs/icu/latest/icu/collator/struct.Collator.html#method.compare_utf16) for more information.
70 */
71 ICU4XOrdering compare_utf16(const std::u16string_view left, const std::u16string_view right) const;
72
73 /**
74 * The resolved options showing how the default options, the requested options,
75 * and the options from locale data were combined. None of the struct fields
76 * will have `Auto` as the value.
77 *
78 * See the [Rust documentation for `resolved_options`](https://docs.rs/icu/latest/icu/collator/struct.Collator.html#method.resolved_options) for more information.
79 */
80 ICU4XCollatorResolvedOptionsV1 resolved_options() const;
81 inline const capi::ICU4XCollator* AsFFI() const { return this->inner.get(); }
82 inline capi::ICU4XCollator* AsFFIMut() { return this->inner.get(); }
83 inline explicit ICU4XCollator(capi::ICU4XCollator* i) : inner(i) {}
84 ICU4XCollator() = default;
85 ICU4XCollator(ICU4XCollator&&) noexcept = default;
86 ICU4XCollator& operator=(ICU4XCollator&& other) noexcept = default;
87 private:
88 std::unique_ptr<capi::ICU4XCollator, ICU4XCollatorDeleter> inner;
89 };
90
91 #include "ICU4XDataProvider.hpp"
92 #include "ICU4XLocale.hpp"
93 #include "ICU4XCollatorOptionsV1.hpp"
94 #include "ICU4XCollatorResolvedOptionsV1.hpp"
95
96 inline diplomat::result<ICU4XCollator, ICU4XError> ICU4XCollator::create_v1(const ICU4XDataProvider& provider, const ICU4XLocale& locale, ICU4XCollatorOptionsV1 options) {
97 ICU4XCollatorOptionsV1 diplomat_wrapped_struct_options = options;
98 auto diplomat_result_raw_out_value = capi::ICU4XCollator_create_v1(provider.AsFFI(), locale.AsFFI(), capi::ICU4XCollatorOptionsV1{ .strength = static_cast<capi::ICU4XCollatorStrength>(diplomat_wrapped_struct_options.strength), .alternate_handling = static_cast<capi::ICU4XCollatorAlternateHandling>(diplomat_wrapped_struct_options.alternate_handling), .case_first = static_cast<capi::ICU4XCollatorCaseFirst>(diplomat_wrapped_struct_options.case_first), .max_variable = static_cast<capi::ICU4XCollatorMaxVariable>(diplomat_wrapped_struct_options.max_variable), .case_level = static_cast<capi::ICU4XCollatorCaseLevel>(diplomat_wrapped_struct_options.case_level), .numeric = static_cast<capi::ICU4XCollatorNumeric>(diplomat_wrapped_struct_options.numeric), .backward_second_level = static_cast<capi::ICU4XCollatorBackwardSecondLevel>(diplomat_wrapped_struct_options.backward_second_level) });
99 diplomat::result<ICU4XCollator, ICU4XError> diplomat_result_out_value;
100 if (diplomat_result_raw_out_value.is_ok) {
101 diplomat_result_out_value = diplomat::Ok<ICU4XCollator>(ICU4XCollator(diplomat_result_raw_out_value.ok));
102 } else {
103 diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err));
104 }
105 return diplomat_result_out_value;
106 }
107 inline ICU4XOrdering ICU4XCollator::compare(const std::string_view left, const std::string_view right) const {
108 return static_cast<ICU4XOrdering>(capi::ICU4XCollator_compare(this->inner.get(), left.data(), left.size(), right.data(), right.size()));
109 }
110 inline ICU4XOrdering ICU4XCollator::compare_valid_utf8(const std::string_view left, const std::string_view right) const {
111 return static_cast<ICU4XOrdering>(capi::ICU4XCollator_compare_valid_utf8(this->inner.get(), left.data(), left.size(), right.data(), right.size()));
112 }
113 inline ICU4XOrdering ICU4XCollator::compare_utf16(const std::u16string_view left, const std::u16string_view right) const {
114 return static_cast<ICU4XOrdering>(capi::ICU4XCollator_compare_utf16(this->inner.get(), left.data(), left.size(), right.data(), right.size()));
115 }
116 inline ICU4XCollatorResolvedOptionsV1 ICU4XCollator::resolved_options() const {
117 capi::ICU4XCollatorResolvedOptionsV1 diplomat_raw_struct_out_value = capi::ICU4XCollator_resolved_options(this->inner.get());
118 return ICU4XCollatorResolvedOptionsV1{ .strength = std::move(static_cast<ICU4XCollatorStrength>(diplomat_raw_struct_out_value.strength)), .alternate_handling = std::move(static_cast<ICU4XCollatorAlternateHandling>(diplomat_raw_struct_out_value.alternate_handling)), .case_first = std::move(static_cast<ICU4XCollatorCaseFirst>(diplomat_raw_struct_out_value.case_first)), .max_variable = std::move(static_cast<ICU4XCollatorMaxVariable>(diplomat_raw_struct_out_value.max_variable)), .case_level = std::move(static_cast<ICU4XCollatorCaseLevel>(diplomat_raw_struct_out_value.case_level)), .numeric = std::move(static_cast<ICU4XCollatorNumeric>(diplomat_raw_struct_out_value.numeric)), .backward_second_level = std::move(static_cast<ICU4XCollatorBackwardSecondLevel>(diplomat_raw_struct_out_value.backward_second_level)) };
119 }
120 #endif