| 1 |
#ifndef ICU4XTitlecaseMapper_HPP |
| 2 |
#define ICU4XTitlecaseMapper_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 "ICU4XTitlecaseMapper.h" |
| 13 |
|
| 14 |
class ICU4XDataProvider; |
| 15 |
class ICU4XTitlecaseMapper; |
| 16 |
#include "ICU4XError.hpp" |
| 17 |
class ICU4XLocale; |
| 18 |
struct ICU4XTitlecaseOptionsV1; |
| 19 |
|
| 20 |
/** |
| 21 |
* A destruction policy for using ICU4XTitlecaseMapper with std::unique_ptr. |
| 22 |
*/ |
| 23 |
struct ICU4XTitlecaseMapperDeleter { |
| 24 |
void operator()(capi::ICU4XTitlecaseMapper* l) const noexcept { |
| 25 |
capi::ICU4XTitlecaseMapper_destroy(l); |
| 26 |
} |
| 27 |
}; |
| 28 |
|
| 29 |
/** |
| 30 |
* See the [Rust documentation for `TitlecaseMapper`](https://docs.rs/icu/latest/icu/casemap/struct.TitlecaseMapper.html) for more information. |
| 31 |
*/ |
| 32 |
class ICU4XTitlecaseMapper { |
| 33 |
public: |
| 34 |
|
| 35 |
/** |
| 36 |
* Construct a new `ICU4XTitlecaseMapper` instance |
| 37 |
* |
| 38 |
* See the [Rust documentation for `new`](https://docs.rs/icu/latest/icu/casemap/struct.TitlecaseMapper.html#method.new) for more information. |
| 39 |
*/ |
| 40 |
static diplomat::result<ICU4XTitlecaseMapper, ICU4XError> create(const ICU4XDataProvider& provider); |
| 41 |
|
| 42 |
/** |
| 43 |
* Returns the full titlecase mapping of the given string |
| 44 |
* |
| 45 |
* The `v1` refers to the version of the options struct, which may change as we add more options |
| 46 |
* |
| 47 |
* See the [Rust documentation for `titlecase_segment`](https://docs.rs/icu/latest/icu/casemap/struct.TitlecaseMapper.html#method.titlecase_segment) for more information. |
| 48 |
*/ |
| 49 |
template<typename W> diplomat::result<std::monostate, ICU4XError> titlecase_segment_v1_to_writeable(const std::string_view s, const ICU4XLocale& locale, ICU4XTitlecaseOptionsV1 options, W& write) const; |
| 50 |
|
| 51 |
/** |
| 52 |
* Returns the full titlecase mapping of the given string |
| 53 |
* |
| 54 |
* The `v1` refers to the version of the options struct, which may change as we add more options |
| 55 |
* |
| 56 |
* See the [Rust documentation for `titlecase_segment`](https://docs.rs/icu/latest/icu/casemap/struct.TitlecaseMapper.html#method.titlecase_segment) for more information. |
| 57 |
*/ |
| 58 |
diplomat::result<std::string, ICU4XError> titlecase_segment_v1(const std::string_view s, const ICU4XLocale& locale, ICU4XTitlecaseOptionsV1 options) const; |
| 59 |
inline const capi::ICU4XTitlecaseMapper* AsFFI() const { return this->inner.get(); } |
| 60 |
inline capi::ICU4XTitlecaseMapper* AsFFIMut() { return this->inner.get(); } |
| 61 |
inline explicit ICU4XTitlecaseMapper(capi::ICU4XTitlecaseMapper* i) : inner(i) {} |
| 62 |
ICU4XTitlecaseMapper() = default; |
| 63 |
ICU4XTitlecaseMapper(ICU4XTitlecaseMapper&&) noexcept = default; |
| 64 |
ICU4XTitlecaseMapper& operator=(ICU4XTitlecaseMapper&& other) noexcept = default; |
| 65 |
private: |
| 66 |
std::unique_ptr<capi::ICU4XTitlecaseMapper, ICU4XTitlecaseMapperDeleter> inner; |
| 67 |
}; |
| 68 |
|
| 69 |
#include "ICU4XDataProvider.hpp" |
| 70 |
#include "ICU4XLocale.hpp" |
| 71 |
#include "ICU4XTitlecaseOptionsV1.hpp" |
| 72 |
|
| 73 |
inline diplomat::result<ICU4XTitlecaseMapper, ICU4XError> ICU4XTitlecaseMapper::create(const ICU4XDataProvider& provider) { |
| 74 |
auto diplomat_result_raw_out_value = capi::ICU4XTitlecaseMapper_create(provider.AsFFI()); |
| 75 |
diplomat::result<ICU4XTitlecaseMapper, ICU4XError> diplomat_result_out_value; |
| 76 |
if (diplomat_result_raw_out_value.is_ok) { |
| 77 |
diplomat_result_out_value = diplomat::Ok<ICU4XTitlecaseMapper>(ICU4XTitlecaseMapper(diplomat_result_raw_out_value.ok)); |
| 78 |
} else { |
| 79 |
diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); |
| 80 |
} |
| 81 |
return diplomat_result_out_value; |
| 82 |
} |
| 83 |
template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XTitlecaseMapper::titlecase_segment_v1_to_writeable(const std::string_view s, const ICU4XLocale& locale, ICU4XTitlecaseOptionsV1 options, W& write) const { |
| 84 |
ICU4XTitlecaseOptionsV1 diplomat_wrapped_struct_options = options; |
| 85 |
capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write); |
| 86 |
auto diplomat_result_raw_out_value = capi::ICU4XTitlecaseMapper_titlecase_segment_v1(this->inner.get(), s.data(), s.size(), locale.AsFFI(), capi::ICU4XTitlecaseOptionsV1{ .leading_adjustment = static_cast<capi::ICU4XLeadingAdjustment>(diplomat_wrapped_struct_options.leading_adjustment), .trailing_case = static_cast<capi::ICU4XTrailingCase>(diplomat_wrapped_struct_options.trailing_case) }, &write_writer); |
| 87 |
diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; |
| 88 |
if (diplomat_result_raw_out_value.is_ok) { |
| 89 |
diplomat_result_out_value = diplomat::Ok<std::monostate>(std::monostate()); |
| 90 |
} else { |
| 91 |
diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); |
| 92 |
} |
| 93 |
return diplomat_result_out_value; |
| 94 |
} |
| 95 |
inline diplomat::result<std::string, ICU4XError> ICU4XTitlecaseMapper::titlecase_segment_v1(const std::string_view s, const ICU4XLocale& locale, ICU4XTitlecaseOptionsV1 options) const { |
| 96 |
ICU4XTitlecaseOptionsV1 diplomat_wrapped_struct_options = options; |
| 97 |
std::string diplomat_writeable_string; |
| 98 |
capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); |
| 99 |
auto diplomat_result_raw_out_value = capi::ICU4XTitlecaseMapper_titlecase_segment_v1(this->inner.get(), s.data(), s.size(), locale.AsFFI(), capi::ICU4XTitlecaseOptionsV1{ .leading_adjustment = static_cast<capi::ICU4XLeadingAdjustment>(diplomat_wrapped_struct_options.leading_adjustment), .trailing_case = static_cast<capi::ICU4XTrailingCase>(diplomat_wrapped_struct_options.trailing_case) }, &diplomat_writeable_out); |
| 100 |
diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; |
| 101 |
if (diplomat_result_raw_out_value.is_ok) { |
| 102 |
diplomat_result_out_value = diplomat::Ok<std::monostate>(std::monostate()); |
| 103 |
} else { |
| 104 |
diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); |
| 105 |
} |
| 106 |
return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string)); |
| 107 |
} |
| 108 |
#endif |