Debian Codegraph @

intl/icu_capi/bindings/cpp/ICU4XTimeZoneFormatter.hpp

raw
1 #ifndef ICU4XTimeZoneFormatter_HPP
2 #define ICU4XTimeZoneFormatter_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 "ICU4XTimeZoneFormatter.h"
13
14 class ICU4XDataProvider;
15 class ICU4XLocale;
16 class ICU4XTimeZoneFormatter;
17 #include "ICU4XError.hpp"
18 struct ICU4XIsoTimeZoneOptions;
19 class ICU4XCustomTimeZone;
20
21 /**
22 * A destruction policy for using ICU4XTimeZoneFormatter with std::unique_ptr.
23 */
24 struct ICU4XTimeZoneFormatterDeleter {
25 void operator()(capi::ICU4XTimeZoneFormatter* l) const noexcept {
26 capi::ICU4XTimeZoneFormatter_destroy(l);
27 }
28 };
29
30 /**
31 * An ICU4X TimeZoneFormatter object capable of formatting an [`ICU4XCustomTimeZone`] type (and others) as a string
32 *
33 * See the [Rust documentation for `TimeZoneFormatter`](https://docs.rs/icu/latest/icu/datetime/time_zone/struct.TimeZoneFormatter.html) for more information.
34 */
35 class ICU4XTimeZoneFormatter {
36 public:
37
38 /**
39 * Creates a new [`ICU4XTimeZoneFormatter`] from locale data.
40 *
41 * Uses localized GMT as the fallback format.
42 *
43 * See the [Rust documentation for `try_new`](https://docs.rs/icu/latest/icu/datetime/time_zone/struct.TimeZoneFormatter.html#method.try_new) for more information.
44 *
45 * Additional information: [1](https://docs.rs/icu/latest/icu/datetime/time_zone/enum.FallbackFormat.html)
46 */
47 static diplomat::result<ICU4XTimeZoneFormatter, ICU4XError> create_with_localized_gmt_fallback(const ICU4XDataProvider& provider, const ICU4XLocale& locale);
48
49 /**
50 * Creates a new [`ICU4XTimeZoneFormatter`] from locale data.
51 *
52 * Uses ISO-8601 as the fallback format.
53 *
54 * See the [Rust documentation for `try_new`](https://docs.rs/icu/latest/icu/datetime/time_zone/struct.TimeZoneFormatter.html#method.try_new) for more information.
55 *
56 * Additional information: [1](https://docs.rs/icu/latest/icu/datetime/time_zone/enum.FallbackFormat.html)
57 */
58 static diplomat::result<ICU4XTimeZoneFormatter, ICU4XError> create_with_iso_8601_fallback(const ICU4XDataProvider& provider, const ICU4XLocale& locale, ICU4XIsoTimeZoneOptions options);
59
60 /**
61 * Loads generic non-location long format. Example: "Pacific Time"
62 *
63 * See the [Rust documentation for `include_generic_non_location_long`](https://docs.rs/icu/latest/icu/datetime/time_zone/struct.TimeZoneFormatter.html#method.include_generic_non_location_long) for more information.
64 */
65 diplomat::result<std::monostate, ICU4XError> load_generic_non_location_long(const ICU4XDataProvider& provider);
66
67 /**
68 * Loads generic non-location short format. Example: "PT"
69 *
70 * See the [Rust documentation for `include_generic_non_location_short`](https://docs.rs/icu/latest/icu/datetime/time_zone/struct.TimeZoneFormatter.html#method.include_generic_non_location_short) for more information.
71 */
72 diplomat::result<std::monostate, ICU4XError> load_generic_non_location_short(const ICU4XDataProvider& provider);
73
74 /**
75 * Loads specific non-location long format. Example: "Pacific Standard Time"
76 *
77 * See the [Rust documentation for `include_specific_non_location_long`](https://docs.rs/icu/latest/icu/datetime/time_zone/struct.TimeZoneFormatter.html#method.include_specific_non_location_long) for more information.
78 */
79 diplomat::result<std::monostate, ICU4XError> load_specific_non_location_long(const ICU4XDataProvider& provider);
80
81 /**
82 * Loads specific non-location short format. Example: "PST"
83 *
84 * See the [Rust documentation for `include_specific_non_location_short`](https://docs.rs/icu/latest/icu/datetime/time_zone/struct.TimeZoneFormatter.html#method.include_specific_non_location_short) for more information.
85 */
86 diplomat::result<std::monostate, ICU4XError> load_specific_non_location_short(const ICU4XDataProvider& provider);
87
88 /**
89 * Loads generic location format. Example: "Los Angeles Time"
90 *
91 * See the [Rust documentation for `include_generic_location_format`](https://docs.rs/icu/latest/icu/datetime/time_zone/struct.TimeZoneFormatter.html#method.include_generic_location_format) for more information.
92 */
93 diplomat::result<std::monostate, ICU4XError> load_generic_location_format(const ICU4XDataProvider& provider);
94
95 /**
96 * Loads localized GMT format. Example: "GMT-07:00"
97 *
98 * See the [Rust documentation for `include_localized_gmt_format`](https://docs.rs/icu/latest/icu/datetime/time_zone/struct.TimeZoneFormatter.html#method.include_localized_gmt_format) for more information.
99 */
100 diplomat::result<std::monostate, ICU4XError> include_localized_gmt_format();
101
102 /**
103 * Loads ISO-8601 format. Example: "-07:00"
104 *
105 * See the [Rust documentation for `include_iso_8601_format`](https://docs.rs/icu/latest/icu/datetime/time_zone/struct.TimeZoneFormatter.html#method.include_iso_8601_format) for more information.
106 */
107 diplomat::result<std::monostate, ICU4XError> load_iso_8601_format(ICU4XIsoTimeZoneOptions options);
108
109 /**
110 * Formats a [`ICU4XCustomTimeZone`] to a string.
111 *
112 * See the [Rust documentation for `format`](https://docs.rs/icu/latest/icu/datetime/time_zone/struct.TimeZoneFormatter.html#method.format) for more information.
113 *
114 * See the [Rust documentation for `format_to_string`](https://docs.rs/icu/latest/icu/datetime/time_zone/struct.TimeZoneFormatter.html#method.format_to_string) for more information.
115 */
116 template<typename W> diplomat::result<std::monostate, ICU4XError> format_custom_time_zone_to_writeable(const ICU4XCustomTimeZone& value, W& write) const;
117
118 /**
119 * Formats a [`ICU4XCustomTimeZone`] to a string.
120 *
121 * See the [Rust documentation for `format`](https://docs.rs/icu/latest/icu/datetime/time_zone/struct.TimeZoneFormatter.html#method.format) for more information.
122 *
123 * See the [Rust documentation for `format_to_string`](https://docs.rs/icu/latest/icu/datetime/time_zone/struct.TimeZoneFormatter.html#method.format_to_string) for more information.
124 */
125 diplomat::result<std::string, ICU4XError> format_custom_time_zone(const ICU4XCustomTimeZone& value) const;
126
127 /**
128 * Formats a [`ICU4XCustomTimeZone`] to a string, performing no fallback
129 *
130 * See the [Rust documentation for `write_no_fallback`](https://docs.rs/icu/latest/icu/datetime/struct.FormattedTimeZone.html#method.write_no_fallback) for more information.
131 */
132 template<typename W> diplomat::result<std::monostate, ICU4XError> format_custom_time_zone_no_fallback_to_writeable(const ICU4XCustomTimeZone& value, W& write) const;
133
134 /**
135 * Formats a [`ICU4XCustomTimeZone`] to a string, performing no fallback
136 *
137 * See the [Rust documentation for `write_no_fallback`](https://docs.rs/icu/latest/icu/datetime/struct.FormattedTimeZone.html#method.write_no_fallback) for more information.
138 */
139 diplomat::result<std::string, ICU4XError> format_custom_time_zone_no_fallback(const ICU4XCustomTimeZone& value) const;
140 inline const capi::ICU4XTimeZoneFormatter* AsFFI() const { return this->inner.get(); }
141 inline capi::ICU4XTimeZoneFormatter* AsFFIMut() { return this->inner.get(); }
142 inline explicit ICU4XTimeZoneFormatter(capi::ICU4XTimeZoneFormatter* i) : inner(i) {}
143 ICU4XTimeZoneFormatter() = default;
144 ICU4XTimeZoneFormatter(ICU4XTimeZoneFormatter&&) noexcept = default;
145 ICU4XTimeZoneFormatter& operator=(ICU4XTimeZoneFormatter&& other) noexcept = default;
146 private:
147 std::unique_ptr<capi::ICU4XTimeZoneFormatter, ICU4XTimeZoneFormatterDeleter> inner;
148 };
149
150 #include "ICU4XDataProvider.hpp"
151 #include "ICU4XLocale.hpp"
152 #include "ICU4XIsoTimeZoneOptions.hpp"
153 #include "ICU4XCustomTimeZone.hpp"
154
155 inline diplomat::result<ICU4XTimeZoneFormatter, ICU4XError> ICU4XTimeZoneFormatter::create_with_localized_gmt_fallback(const ICU4XDataProvider& provider, const ICU4XLocale& locale) {
156 auto diplomat_result_raw_out_value = capi::ICU4XTimeZoneFormatter_create_with_localized_gmt_fallback(provider.AsFFI(), locale.AsFFI());
157 diplomat::result<ICU4XTimeZoneFormatter, ICU4XError> diplomat_result_out_value;
158 if (diplomat_result_raw_out_value.is_ok) {
159 diplomat_result_out_value = diplomat::Ok<ICU4XTimeZoneFormatter>(ICU4XTimeZoneFormatter(diplomat_result_raw_out_value.ok));
160 } else {
161 diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err));
162 }
163 return diplomat_result_out_value;
164 }
165 inline diplomat::result<ICU4XTimeZoneFormatter, ICU4XError> ICU4XTimeZoneFormatter::create_with_iso_8601_fallback(const ICU4XDataProvider& provider, const ICU4XLocale& locale, ICU4XIsoTimeZoneOptions options) {
166 ICU4XIsoTimeZoneOptions diplomat_wrapped_struct_options = options;
167 auto diplomat_result_raw_out_value = capi::ICU4XTimeZoneFormatter_create_with_iso_8601_fallback(provider.AsFFI(), locale.AsFFI(), capi::ICU4XIsoTimeZoneOptions{ .format = static_cast<capi::ICU4XIsoTimeZoneFormat>(diplomat_wrapped_struct_options.format), .minutes = static_cast<capi::ICU4XIsoTimeZoneMinuteDisplay>(diplomat_wrapped_struct_options.minutes), .seconds = static_cast<capi::ICU4XIsoTimeZoneSecondDisplay>(diplomat_wrapped_struct_options.seconds) });
168 diplomat::result<ICU4XTimeZoneFormatter, ICU4XError> diplomat_result_out_value;
169 if (diplomat_result_raw_out_value.is_ok) {
170 diplomat_result_out_value = diplomat::Ok<ICU4XTimeZoneFormatter>(ICU4XTimeZoneFormatter(diplomat_result_raw_out_value.ok));
171 } else {
172 diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err));
173 }
174 return diplomat_result_out_value;
175 }
176 inline diplomat::result<std::monostate, ICU4XError> ICU4XTimeZoneFormatter::load_generic_non_location_long(const ICU4XDataProvider& provider) {
177 auto diplomat_result_raw_out_value = capi::ICU4XTimeZoneFormatter_load_generic_non_location_long(this->inner.get(), provider.AsFFI());
178 diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value;
179 if (diplomat_result_raw_out_value.is_ok) {
180 diplomat_result_out_value = diplomat::Ok<std::monostate>(std::monostate());
181 } else {
182 diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err));
183 }
184 return diplomat_result_out_value;
185 }
186 inline diplomat::result<std::monostate, ICU4XError> ICU4XTimeZoneFormatter::load_generic_non_location_short(const ICU4XDataProvider& provider) {
187 auto diplomat_result_raw_out_value = capi::ICU4XTimeZoneFormatter_load_generic_non_location_short(this->inner.get(), provider.AsFFI());
188 diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value;
189 if (diplomat_result_raw_out_value.is_ok) {
190 diplomat_result_out_value = diplomat::Ok<std::monostate>(std::monostate());
191 } else {
192 diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err));
193 }
194 return diplomat_result_out_value;
195 }
196 inline diplomat::result<std::monostate, ICU4XError> ICU4XTimeZoneFormatter::load_specific_non_location_long(const ICU4XDataProvider& provider) {
197 auto diplomat_result_raw_out_value = capi::ICU4XTimeZoneFormatter_load_specific_non_location_long(this->inner.get(), provider.AsFFI());
198 diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value;
199 if (diplomat_result_raw_out_value.is_ok) {
200 diplomat_result_out_value = diplomat::Ok<std::monostate>(std::monostate());
201 } else {
202 diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err));
203 }
204 return diplomat_result_out_value;
205 }
206 inline diplomat::result<std::monostate, ICU4XError> ICU4XTimeZoneFormatter::load_specific_non_location_short(const ICU4XDataProvider& provider) {
207 auto diplomat_result_raw_out_value = capi::ICU4XTimeZoneFormatter_load_specific_non_location_short(this->inner.get(), provider.AsFFI());
208 diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value;
209 if (diplomat_result_raw_out_value.is_ok) {
210 diplomat_result_out_value = diplomat::Ok<std::monostate>(std::monostate());
211 } else {
212 diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err));
213 }
214 return diplomat_result_out_value;
215 }
216 inline diplomat::result<std::monostate, ICU4XError> ICU4XTimeZoneFormatter::load_generic_location_format(const ICU4XDataProvider& provider) {
217 auto diplomat_result_raw_out_value = capi::ICU4XTimeZoneFormatter_load_generic_location_format(this->inner.get(), provider.AsFFI());
218 diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value;
219 if (diplomat_result_raw_out_value.is_ok) {
220 diplomat_result_out_value = diplomat::Ok<std::monostate>(std::monostate());
221 } else {
222 diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err));
223 }
224 return diplomat_result_out_value;
225 }
226 inline diplomat::result<std::monostate, ICU4XError> ICU4XTimeZoneFormatter::include_localized_gmt_format() {
227 auto diplomat_result_raw_out_value = capi::ICU4XTimeZoneFormatter_include_localized_gmt_format(this->inner.get());
228 diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value;
229 if (diplomat_result_raw_out_value.is_ok) {
230 diplomat_result_out_value = diplomat::Ok<std::monostate>(std::monostate());
231 } else {
232 diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err));
233 }
234 return diplomat_result_out_value;
235 }
236 inline diplomat::result<std::monostate, ICU4XError> ICU4XTimeZoneFormatter::load_iso_8601_format(ICU4XIsoTimeZoneOptions options) {
237 ICU4XIsoTimeZoneOptions diplomat_wrapped_struct_options = options;
238 auto diplomat_result_raw_out_value = capi::ICU4XTimeZoneFormatter_load_iso_8601_format(this->inner.get(), capi::ICU4XIsoTimeZoneOptions{ .format = static_cast<capi::ICU4XIsoTimeZoneFormat>(diplomat_wrapped_struct_options.format), .minutes = static_cast<capi::ICU4XIsoTimeZoneMinuteDisplay>(diplomat_wrapped_struct_options.minutes), .seconds = static_cast<capi::ICU4XIsoTimeZoneSecondDisplay>(diplomat_wrapped_struct_options.seconds) });
239 diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value;
240 if (diplomat_result_raw_out_value.is_ok) {
241 diplomat_result_out_value = diplomat::Ok<std::monostate>(std::monostate());
242 } else {
243 diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err));
244 }
245 return diplomat_result_out_value;
246 }
247 template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XTimeZoneFormatter::format_custom_time_zone_to_writeable(const ICU4XCustomTimeZone& value, W& write) const {
248 capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write);
249 auto diplomat_result_raw_out_value = capi::ICU4XTimeZoneFormatter_format_custom_time_zone(this->inner.get(), value.AsFFI(), &write_writer);
250 diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value;
251 if (diplomat_result_raw_out_value.is_ok) {
252 diplomat_result_out_value = diplomat::Ok<std::monostate>(std::monostate());
253 } else {
254 diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err));
255 }
256 return diplomat_result_out_value;
257 }
258 inline diplomat::result<std::string, ICU4XError> ICU4XTimeZoneFormatter::format_custom_time_zone(const ICU4XCustomTimeZone& value) const {
259 std::string diplomat_writeable_string;
260 capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string);
261 auto diplomat_result_raw_out_value = capi::ICU4XTimeZoneFormatter_format_custom_time_zone(this->inner.get(), value.AsFFI(), &diplomat_writeable_out);
262 diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value;
263 if (diplomat_result_raw_out_value.is_ok) {
264 diplomat_result_out_value = diplomat::Ok<std::monostate>(std::monostate());
265 } else {
266 diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err));
267 }
268 return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string));
269 }
270 template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XTimeZoneFormatter::format_custom_time_zone_no_fallback_to_writeable(const ICU4XCustomTimeZone& value, W& write) const {
271 capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write);
272 auto diplomat_result_raw_out_value = capi::ICU4XTimeZoneFormatter_format_custom_time_zone_no_fallback(this->inner.get(), value.AsFFI(), &write_writer);
273 diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value;
274 if (diplomat_result_raw_out_value.is_ok) {
275 diplomat_result_out_value = diplomat::Ok<std::monostate>(std::monostate());
276 } else {
277 diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err));
278 }
279 return diplomat_result_out_value;
280 }
281 inline diplomat::result<std::string, ICU4XError> ICU4XTimeZoneFormatter::format_custom_time_zone_no_fallback(const ICU4XCustomTimeZone& value) const {
282 std::string diplomat_writeable_string;
283 capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string);
284 auto diplomat_result_raw_out_value = capi::ICU4XTimeZoneFormatter_format_custom_time_zone_no_fallback(this->inner.get(), value.AsFFI(), &diplomat_writeable_out);
285 diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value;
286 if (diplomat_result_raw_out_value.is_ok) {
287 diplomat_result_out_value = diplomat::Ok<std::monostate>(std::monostate());
288 } else {
289 diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err));
290 }
291 return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string));
292 }
293 #endif