| 1 |
#ifndef ICU4XDataStruct_HPP |
| 2 |
#define ICU4XDataStruct_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 "ICU4XDataStruct.h" |
| 13 |
|
| 14 |
class ICU4XDataStruct; |
| 15 |
#include "ICU4XError.hpp" |
| 16 |
|
| 17 |
/** |
| 18 |
* A destruction policy for using ICU4XDataStruct with std::unique_ptr. |
| 19 |
*/ |
| 20 |
struct ICU4XDataStructDeleter { |
| 21 |
void operator()(capi::ICU4XDataStruct* l) const noexcept { |
| 22 |
capi::ICU4XDataStruct_destroy(l); |
| 23 |
} |
| 24 |
}; |
| 25 |
|
| 26 |
/** |
| 27 |
* A generic data struct to be used by ICU4X |
| 28 |
* |
| 29 |
* This can be used to construct a StructDataProvider. |
| 30 |
*/ |
| 31 |
class ICU4XDataStruct { |
| 32 |
public: |
| 33 |
|
| 34 |
/** |
| 35 |
* Construct a new DecimalSymbolsV1 data struct. |
| 36 |
* |
| 37 |
* Ill-formed input is treated as if errors had been replaced with REPLACEMENT CHARACTERs according |
| 38 |
* to the WHATWG Encoding Standard. |
| 39 |
* |
| 40 |
* See the [Rust documentation for `DecimalSymbolsV1`](https://docs.rs/icu/latest/icu/decimal/provider/struct.DecimalSymbolsV1.html) for more information. |
| 41 |
*/ |
| 42 |
static diplomat::result<ICU4XDataStruct, ICU4XError> create_decimal_symbols_v1(const std::string_view plus_sign_prefix, const std::string_view plus_sign_suffix, const std::string_view minus_sign_prefix, const std::string_view minus_sign_suffix, const std::string_view decimal_separator, const std::string_view grouping_separator, uint8_t primary_group_size, uint8_t secondary_group_size, uint8_t min_group_size, const diplomat::span<const char32_t> digits); |
| 43 |
inline const capi::ICU4XDataStruct* AsFFI() const { return this->inner.get(); } |
| 44 |
inline capi::ICU4XDataStruct* AsFFIMut() { return this->inner.get(); } |
| 45 |
inline explicit ICU4XDataStruct(capi::ICU4XDataStruct* i) : inner(i) {} |
| 46 |
ICU4XDataStruct() = default; |
| 47 |
ICU4XDataStruct(ICU4XDataStruct&&) noexcept = default; |
| 48 |
ICU4XDataStruct& operator=(ICU4XDataStruct&& other) noexcept = default; |
| 49 |
private: |
| 50 |
std::unique_ptr<capi::ICU4XDataStruct, ICU4XDataStructDeleter> inner; |
| 51 |
}; |
| 52 |
|
| 53 |
|
| 54 |
inline diplomat::result<ICU4XDataStruct, ICU4XError> ICU4XDataStruct::create_decimal_symbols_v1(const std::string_view plus_sign_prefix, const std::string_view plus_sign_suffix, const std::string_view minus_sign_prefix, const std::string_view minus_sign_suffix, const std::string_view decimal_separator, const std::string_view grouping_separator, uint8_t primary_group_size, uint8_t secondary_group_size, uint8_t min_group_size, const diplomat::span<const char32_t> digits) { |
| 55 |
auto diplomat_result_raw_out_value = capi::ICU4XDataStruct_create_decimal_symbols_v1(plus_sign_prefix.data(), plus_sign_prefix.size(), plus_sign_suffix.data(), plus_sign_suffix.size(), minus_sign_prefix.data(), minus_sign_prefix.size(), minus_sign_suffix.data(), minus_sign_suffix.size(), decimal_separator.data(), decimal_separator.size(), grouping_separator.data(), grouping_separator.size(), primary_group_size, secondary_group_size, min_group_size, digits.data(), digits.size()); |
| 56 |
diplomat::result<ICU4XDataStruct, ICU4XError> diplomat_result_out_value; |
| 57 |
if (diplomat_result_raw_out_value.is_ok) { |
| 58 |
diplomat_result_out_value = diplomat::Ok<ICU4XDataStruct>(ICU4XDataStruct(diplomat_result_raw_out_value.ok)); |
| 59 |
} else { |
| 60 |
diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); |
| 61 |
} |
| 62 |
return diplomat_result_out_value; |
| 63 |
} |
| 64 |
#endif |