| 1 |
#ifndef ICU4XListFormatter_HPP |
| 2 |
#define ICU4XListFormatter_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 "ICU4XListFormatter.h" |
| 13 |
|
| 14 |
class ICU4XDataProvider; |
| 15 |
class ICU4XLocale; |
| 16 |
#include "ICU4XListLength.hpp" |
| 17 |
class ICU4XListFormatter; |
| 18 |
#include "ICU4XError.hpp" |
| 19 |
class ICU4XList; |
| 20 |
|
| 21 |
/** |
| 22 |
* A destruction policy for using ICU4XListFormatter with std::unique_ptr. |
| 23 |
*/ |
| 24 |
struct ICU4XListFormatterDeleter { |
| 25 |
void operator()(capi::ICU4XListFormatter* l) const noexcept { |
| 26 |
capi::ICU4XListFormatter_destroy(l); |
| 27 |
} |
| 28 |
}; |
| 29 |
|
| 30 |
/** |
| 31 |
* See the [Rust documentation for `ListFormatter`](https://docs.rs/icu/latest/icu/list/struct.ListFormatter.html) for more information. |
| 32 |
*/ |
| 33 |
class ICU4XListFormatter { |
| 34 |
public: |
| 35 |
|
| 36 |
/** |
| 37 |
* Construct a new ICU4XListFormatter instance for And patterns |
| 38 |
* |
| 39 |
* See the [Rust documentation for `try_new_and_with_length`](https://docs.rs/icu/latest/icu/list/struct.ListFormatter.html#method.try_new_and_with_length) for more information. |
| 40 |
*/ |
| 41 |
static diplomat::result<ICU4XListFormatter, ICU4XError> create_and_with_length(const ICU4XDataProvider& provider, const ICU4XLocale& locale, ICU4XListLength length); |
| 42 |
|
| 43 |
/** |
| 44 |
* Construct a new ICU4XListFormatter instance for And patterns |
| 45 |
* |
| 46 |
* See the [Rust documentation for `try_new_or_with_length`](https://docs.rs/icu/latest/icu/list/struct.ListFormatter.html#method.try_new_or_with_length) for more information. |
| 47 |
*/ |
| 48 |
static diplomat::result<ICU4XListFormatter, ICU4XError> create_or_with_length(const ICU4XDataProvider& provider, const ICU4XLocale& locale, ICU4XListLength length); |
| 49 |
|
| 50 |
/** |
| 51 |
* Construct a new ICU4XListFormatter instance for And patterns |
| 52 |
* |
| 53 |
* See the [Rust documentation for `try_new_unit_with_length`](https://docs.rs/icu/latest/icu/list/struct.ListFormatter.html#method.try_new_unit_with_length) for more information. |
| 54 |
*/ |
| 55 |
static diplomat::result<ICU4XListFormatter, ICU4XError> create_unit_with_length(const ICU4XDataProvider& provider, const ICU4XLocale& locale, ICU4XListLength length); |
| 56 |
|
| 57 |
/** |
| 58 |
* See the [Rust documentation for `format`](https://docs.rs/icu/latest/icu/list/struct.ListFormatter.html#method.format) for more information. |
| 59 |
*/ |
| 60 |
template<typename W> diplomat::result<std::monostate, ICU4XError> format_to_writeable(const ICU4XList& list, W& write) const; |
| 61 |
|
| 62 |
/** |
| 63 |
* See the [Rust documentation for `format`](https://docs.rs/icu/latest/icu/list/struct.ListFormatter.html#method.format) for more information. |
| 64 |
*/ |
| 65 |
diplomat::result<std::string, ICU4XError> format(const ICU4XList& list) const; |
| 66 |
inline const capi::ICU4XListFormatter* AsFFI() const { return this->inner.get(); } |
| 67 |
inline capi::ICU4XListFormatter* AsFFIMut() { return this->inner.get(); } |
| 68 |
inline explicit ICU4XListFormatter(capi::ICU4XListFormatter* i) : inner(i) {} |
| 69 |
ICU4XListFormatter() = default; |
| 70 |
ICU4XListFormatter(ICU4XListFormatter&&) noexcept = default; |
| 71 |
ICU4XListFormatter& operator=(ICU4XListFormatter&& other) noexcept = default; |
| 72 |
private: |
| 73 |
std::unique_ptr<capi::ICU4XListFormatter, ICU4XListFormatterDeleter> inner; |
| 74 |
}; |
| 75 |
|
| 76 |
#include "ICU4XDataProvider.hpp" |
| 77 |
#include "ICU4XLocale.hpp" |
| 78 |
#include "ICU4XList.hpp" |
| 79 |
|
| 80 |
inline diplomat::result<ICU4XListFormatter, ICU4XError> ICU4XListFormatter::create_and_with_length(const ICU4XDataProvider& provider, const ICU4XLocale& locale, ICU4XListLength length) { |
| 81 |
auto diplomat_result_raw_out_value = capi::ICU4XListFormatter_create_and_with_length(provider.AsFFI(), locale.AsFFI(), static_cast<capi::ICU4XListLength>(length)); |
| 82 |
diplomat::result<ICU4XListFormatter, ICU4XError> diplomat_result_out_value; |
| 83 |
if (diplomat_result_raw_out_value.is_ok) { |
| 84 |
diplomat_result_out_value = diplomat::Ok<ICU4XListFormatter>(ICU4XListFormatter(diplomat_result_raw_out_value.ok)); |
| 85 |
} else { |
| 86 |
diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); |
| 87 |
} |
| 88 |
return diplomat_result_out_value; |
| 89 |
} |
| 90 |
inline diplomat::result<ICU4XListFormatter, ICU4XError> ICU4XListFormatter::create_or_with_length(const ICU4XDataProvider& provider, const ICU4XLocale& locale, ICU4XListLength length) { |
| 91 |
auto diplomat_result_raw_out_value = capi::ICU4XListFormatter_create_or_with_length(provider.AsFFI(), locale.AsFFI(), static_cast<capi::ICU4XListLength>(length)); |
| 92 |
diplomat::result<ICU4XListFormatter, ICU4XError> diplomat_result_out_value; |
| 93 |
if (diplomat_result_raw_out_value.is_ok) { |
| 94 |
diplomat_result_out_value = diplomat::Ok<ICU4XListFormatter>(ICU4XListFormatter(diplomat_result_raw_out_value.ok)); |
| 95 |
} else { |
| 96 |
diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); |
| 97 |
} |
| 98 |
return diplomat_result_out_value; |
| 99 |
} |
| 100 |
inline diplomat::result<ICU4XListFormatter, ICU4XError> ICU4XListFormatter::create_unit_with_length(const ICU4XDataProvider& provider, const ICU4XLocale& locale, ICU4XListLength length) { |
| 101 |
auto diplomat_result_raw_out_value = capi::ICU4XListFormatter_create_unit_with_length(provider.AsFFI(), locale.AsFFI(), static_cast<capi::ICU4XListLength>(length)); |
| 102 |
diplomat::result<ICU4XListFormatter, ICU4XError> diplomat_result_out_value; |
| 103 |
if (diplomat_result_raw_out_value.is_ok) { |
| 104 |
diplomat_result_out_value = diplomat::Ok<ICU4XListFormatter>(ICU4XListFormatter(diplomat_result_raw_out_value.ok)); |
| 105 |
} else { |
| 106 |
diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); |
| 107 |
} |
| 108 |
return diplomat_result_out_value; |
| 109 |
} |
| 110 |
template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XListFormatter::format_to_writeable(const ICU4XList& list, W& write) const { |
| 111 |
capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write); |
| 112 |
auto diplomat_result_raw_out_value = capi::ICU4XListFormatter_format(this->inner.get(), list.AsFFI(), &write_writer); |
| 113 |
diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; |
| 114 |
if (diplomat_result_raw_out_value.is_ok) { |
| 115 |
diplomat_result_out_value = diplomat::Ok<std::monostate>(std::monostate()); |
| 116 |
} else { |
| 117 |
diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); |
| 118 |
} |
| 119 |
return diplomat_result_out_value; |
| 120 |
} |
| 121 |
inline diplomat::result<std::string, ICU4XError> ICU4XListFormatter::format(const ICU4XList& list) const { |
| 122 |
std::string diplomat_writeable_string; |
| 123 |
capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); |
| 124 |
auto diplomat_result_raw_out_value = capi::ICU4XListFormatter_format(this->inner.get(), list.AsFFI(), &diplomat_writeable_out); |
| 125 |
diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; |
| 126 |
if (diplomat_result_raw_out_value.is_ok) { |
| 127 |
diplomat_result_out_value = diplomat::Ok<std::monostate>(std::monostate()); |
| 128 |
} else { |
| 129 |
diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); |
| 130 |
} |
| 131 |
return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string)); |
| 132 |
} |
| 133 |
#endif |