| 1 |
#ifndef ICU4XTimeZoneIdMapper_HPP |
| 2 |
#define ICU4XTimeZoneIdMapper_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 "ICU4XTimeZoneIdMapper.h" |
| 13 |
|
| 14 |
class ICU4XDataProvider; |
| 15 |
class ICU4XTimeZoneIdMapper; |
| 16 |
#include "ICU4XError.hpp" |
| 17 |
|
| 18 |
/** |
| 19 |
* A destruction policy for using ICU4XTimeZoneIdMapper with std::unique_ptr. |
| 20 |
*/ |
| 21 |
struct ICU4XTimeZoneIdMapperDeleter { |
| 22 |
void operator()(capi::ICU4XTimeZoneIdMapper* l) const noexcept { |
| 23 |
capi::ICU4XTimeZoneIdMapper_destroy(l); |
| 24 |
} |
| 25 |
}; |
| 26 |
|
| 27 |
/** |
| 28 |
* A mapper between IANA time zone identifiers and BCP-47 time zone identifiers. |
| 29 |
* |
| 30 |
* This mapper supports two-way mapping, but it is optimized for the case of IANA to BCP-47. |
| 31 |
* It also supports normalizing and canonicalizing the IANA strings. |
| 32 |
* |
| 33 |
* See the [Rust documentation for `TimeZoneIdMapper`](https://docs.rs/icu/latest/icu/timezone/struct.TimeZoneIdMapper.html) for more information. |
| 34 |
*/ |
| 35 |
class ICU4XTimeZoneIdMapper { |
| 36 |
public: |
| 37 |
|
| 38 |
/** |
| 39 |
* See the [Rust documentation for `new`](https://docs.rs/icu/latest/icu/timezone/struct.TimeZoneIdMapper.html#method.new) for more information. |
| 40 |
*/ |
| 41 |
static diplomat::result<ICU4XTimeZoneIdMapper, ICU4XError> create(const ICU4XDataProvider& provider); |
| 42 |
|
| 43 |
/** |
| 44 |
* See the [Rust documentation for `iana_to_bcp47`](https://docs.rs/icu/latest/icu/timezone/struct.TimeZoneIdMapperBorrowed.html#method.iana_to_bcp47) for more information. |
| 45 |
*/ |
| 46 |
template<typename W> diplomat::result<std::monostate, ICU4XError> iana_to_bcp47_to_writeable(const std::string_view value, W& write) const; |
| 47 |
|
| 48 |
/** |
| 49 |
* See the [Rust documentation for `iana_to_bcp47`](https://docs.rs/icu/latest/icu/timezone/struct.TimeZoneIdMapperBorrowed.html#method.iana_to_bcp47) for more information. |
| 50 |
*/ |
| 51 |
diplomat::result<std::string, ICU4XError> iana_to_bcp47(const std::string_view value) const; |
| 52 |
|
| 53 |
/** |
| 54 |
* See the [Rust documentation for `normalize_iana`](https://docs.rs/icu/latest/icu/timezone/struct.TimeZoneIdMapperBorrowed.html#method.normalize_iana) for more information. |
| 55 |
*/ |
| 56 |
template<typename W> diplomat::result<std::monostate, ICU4XError> normalize_iana_to_writeable(const std::string_view value, W& write) const; |
| 57 |
|
| 58 |
/** |
| 59 |
* See the [Rust documentation for `normalize_iana`](https://docs.rs/icu/latest/icu/timezone/struct.TimeZoneIdMapperBorrowed.html#method.normalize_iana) for more information. |
| 60 |
*/ |
| 61 |
diplomat::result<std::string, ICU4XError> normalize_iana(const std::string_view value) const; |
| 62 |
|
| 63 |
/** |
| 64 |
* See the [Rust documentation for `canonicalize_iana`](https://docs.rs/icu/latest/icu/timezone/struct.TimeZoneIdMapperBorrowed.html#method.canonicalize_iana) for more information. |
| 65 |
*/ |
| 66 |
template<typename W> diplomat::result<std::monostate, ICU4XError> canonicalize_iana_to_writeable(const std::string_view value, W& write) const; |
| 67 |
|
| 68 |
/** |
| 69 |
* See the [Rust documentation for `canonicalize_iana`](https://docs.rs/icu/latest/icu/timezone/struct.TimeZoneIdMapperBorrowed.html#method.canonicalize_iana) for more information. |
| 70 |
*/ |
| 71 |
diplomat::result<std::string, ICU4XError> canonicalize_iana(const std::string_view value) const; |
| 72 |
|
| 73 |
/** |
| 74 |
* See the [Rust documentation for `find_canonical_iana_from_bcp47`](https://docs.rs/icu/latest/icu/timezone/struct.TimeZoneIdMapperBorrowed.html#method.find_canonical_iana_from_bcp47) for more information. |
| 75 |
*/ |
| 76 |
template<typename W> diplomat::result<std::monostate, ICU4XError> find_canonical_iana_from_bcp47_to_writeable(const std::string_view value, W& write) const; |
| 77 |
|
| 78 |
/** |
| 79 |
* See the [Rust documentation for `find_canonical_iana_from_bcp47`](https://docs.rs/icu/latest/icu/timezone/struct.TimeZoneIdMapperBorrowed.html#method.find_canonical_iana_from_bcp47) for more information. |
| 80 |
*/ |
| 81 |
diplomat::result<std::string, ICU4XError> find_canonical_iana_from_bcp47(const std::string_view value) const; |
| 82 |
inline const capi::ICU4XTimeZoneIdMapper* AsFFI() const { return this->inner.get(); } |
| 83 |
inline capi::ICU4XTimeZoneIdMapper* AsFFIMut() { return this->inner.get(); } |
| 84 |
inline explicit ICU4XTimeZoneIdMapper(capi::ICU4XTimeZoneIdMapper* i) : inner(i) {} |
| 85 |
ICU4XTimeZoneIdMapper() = default; |
| 86 |
ICU4XTimeZoneIdMapper(ICU4XTimeZoneIdMapper&&) noexcept = default; |
| 87 |
ICU4XTimeZoneIdMapper& operator=(ICU4XTimeZoneIdMapper&& other) noexcept = default; |
| 88 |
private: |
| 89 |
std::unique_ptr<capi::ICU4XTimeZoneIdMapper, ICU4XTimeZoneIdMapperDeleter> inner; |
| 90 |
}; |
| 91 |
|
| 92 |
#include "ICU4XDataProvider.hpp" |
| 93 |
|
| 94 |
inline diplomat::result<ICU4XTimeZoneIdMapper, ICU4XError> ICU4XTimeZoneIdMapper::create(const ICU4XDataProvider& provider) { |
| 95 |
auto diplomat_result_raw_out_value = capi::ICU4XTimeZoneIdMapper_create(provider.AsFFI()); |
| 96 |
diplomat::result<ICU4XTimeZoneIdMapper, ICU4XError> diplomat_result_out_value; |
| 97 |
if (diplomat_result_raw_out_value.is_ok) { |
| 98 |
diplomat_result_out_value = diplomat::Ok<ICU4XTimeZoneIdMapper>(ICU4XTimeZoneIdMapper(diplomat_result_raw_out_value.ok)); |
| 99 |
} else { |
| 100 |
diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); |
| 101 |
} |
| 102 |
return diplomat_result_out_value; |
| 103 |
} |
| 104 |
template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XTimeZoneIdMapper::iana_to_bcp47_to_writeable(const std::string_view value, W& write) const { |
| 105 |
capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write); |
| 106 |
auto diplomat_result_raw_out_value = capi::ICU4XTimeZoneIdMapper_iana_to_bcp47(this->inner.get(), value.data(), value.size(), &write_writer); |
| 107 |
diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; |
| 108 |
if (diplomat_result_raw_out_value.is_ok) { |
| 109 |
diplomat_result_out_value = diplomat::Ok<std::monostate>(std::monostate()); |
| 110 |
} else { |
| 111 |
diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); |
| 112 |
} |
| 113 |
return diplomat_result_out_value; |
| 114 |
} |
| 115 |
inline diplomat::result<std::string, ICU4XError> ICU4XTimeZoneIdMapper::iana_to_bcp47(const std::string_view value) const { |
| 116 |
std::string diplomat_writeable_string; |
| 117 |
capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); |
| 118 |
auto diplomat_result_raw_out_value = capi::ICU4XTimeZoneIdMapper_iana_to_bcp47(this->inner.get(), value.data(), value.size(), &diplomat_writeable_out); |
| 119 |
diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; |
| 120 |
if (diplomat_result_raw_out_value.is_ok) { |
| 121 |
diplomat_result_out_value = diplomat::Ok<std::monostate>(std::monostate()); |
| 122 |
} else { |
| 123 |
diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); |
| 124 |
} |
| 125 |
return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string)); |
| 126 |
} |
| 127 |
template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XTimeZoneIdMapper::normalize_iana_to_writeable(const std::string_view value, W& write) const { |
| 128 |
capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write); |
| 129 |
auto diplomat_result_raw_out_value = capi::ICU4XTimeZoneIdMapper_normalize_iana(this->inner.get(), value.data(), value.size(), &write_writer); |
| 130 |
diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; |
| 131 |
if (diplomat_result_raw_out_value.is_ok) { |
| 132 |
diplomat_result_out_value = diplomat::Ok<std::monostate>(std::monostate()); |
| 133 |
} else { |
| 134 |
diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); |
| 135 |
} |
| 136 |
return diplomat_result_out_value; |
| 137 |
} |
| 138 |
inline diplomat::result<std::string, ICU4XError> ICU4XTimeZoneIdMapper::normalize_iana(const std::string_view value) const { |
| 139 |
std::string diplomat_writeable_string; |
| 140 |
capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); |
| 141 |
auto diplomat_result_raw_out_value = capi::ICU4XTimeZoneIdMapper_normalize_iana(this->inner.get(), value.data(), value.size(), &diplomat_writeable_out); |
| 142 |
diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; |
| 143 |
if (diplomat_result_raw_out_value.is_ok) { |
| 144 |
diplomat_result_out_value = diplomat::Ok<std::monostate>(std::monostate()); |
| 145 |
} else { |
| 146 |
diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); |
| 147 |
} |
| 148 |
return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string)); |
| 149 |
} |
| 150 |
template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XTimeZoneIdMapper::canonicalize_iana_to_writeable(const std::string_view value, W& write) const { |
| 151 |
capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write); |
| 152 |
auto diplomat_result_raw_out_value = capi::ICU4XTimeZoneIdMapper_canonicalize_iana(this->inner.get(), value.data(), value.size(), &write_writer); |
| 153 |
diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; |
| 154 |
if (diplomat_result_raw_out_value.is_ok) { |
| 155 |
diplomat_result_out_value = diplomat::Ok<std::monostate>(std::monostate()); |
| 156 |
} else { |
| 157 |
diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); |
| 158 |
} |
| 159 |
return diplomat_result_out_value; |
| 160 |
} |
| 161 |
inline diplomat::result<std::string, ICU4XError> ICU4XTimeZoneIdMapper::canonicalize_iana(const std::string_view value) const { |
| 162 |
std::string diplomat_writeable_string; |
| 163 |
capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); |
| 164 |
auto diplomat_result_raw_out_value = capi::ICU4XTimeZoneIdMapper_canonicalize_iana(this->inner.get(), value.data(), value.size(), &diplomat_writeable_out); |
| 165 |
diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; |
| 166 |
if (diplomat_result_raw_out_value.is_ok) { |
| 167 |
diplomat_result_out_value = diplomat::Ok<std::monostate>(std::monostate()); |
| 168 |
} else { |
| 169 |
diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); |
| 170 |
} |
| 171 |
return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string)); |
| 172 |
} |
| 173 |
template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XTimeZoneIdMapper::find_canonical_iana_from_bcp47_to_writeable(const std::string_view value, W& write) const { |
| 174 |
capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write); |
| 175 |
auto diplomat_result_raw_out_value = capi::ICU4XTimeZoneIdMapper_find_canonical_iana_from_bcp47(this->inner.get(), value.data(), value.size(), &write_writer); |
| 176 |
diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; |
| 177 |
if (diplomat_result_raw_out_value.is_ok) { |
| 178 |
diplomat_result_out_value = diplomat::Ok<std::monostate>(std::monostate()); |
| 179 |
} else { |
| 180 |
diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); |
| 181 |
} |
| 182 |
return diplomat_result_out_value; |
| 183 |
} |
| 184 |
inline diplomat::result<std::string, ICU4XError> ICU4XTimeZoneIdMapper::find_canonical_iana_from_bcp47(const std::string_view value) const { |
| 185 |
std::string diplomat_writeable_string; |
| 186 |
capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); |
| 187 |
auto diplomat_result_raw_out_value = capi::ICU4XTimeZoneIdMapper_find_canonical_iana_from_bcp47(this->inner.get(), value.data(), value.size(), &diplomat_writeable_out); |
| 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.replace_ok(std::move(diplomat_writeable_string)); |
| 195 |
} |
| 196 |
#endif |