| 1 |
#ifndef ICU4XScriptWithExtensions_HPP |
| 2 |
#define ICU4XScriptWithExtensions_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 "ICU4XScriptWithExtensions.h" |
| 13 |
|
| 14 |
class ICU4XDataProvider; |
| 15 |
class ICU4XScriptWithExtensions; |
| 16 |
#include "ICU4XError.hpp" |
| 17 |
class ICU4XScriptWithExtensionsBorrowed; |
| 18 |
class CodePointRangeIterator; |
| 19 |
|
| 20 |
/** |
| 21 |
* A destruction policy for using ICU4XScriptWithExtensions with std::unique_ptr. |
| 22 |
*/ |
| 23 |
struct ICU4XScriptWithExtensionsDeleter { |
| 24 |
void operator()(capi::ICU4XScriptWithExtensions* l) const noexcept { |
| 25 |
capi::ICU4XScriptWithExtensions_destroy(l); |
| 26 |
} |
| 27 |
}; |
| 28 |
|
| 29 |
/** |
| 30 |
* An ICU4X ScriptWithExtensions map object, capable of holding a map of codepoints to scriptextensions values |
| 31 |
* |
| 32 |
* See the [Rust documentation for `ScriptWithExtensions`](https://docs.rs/icu/latest/icu/properties/script/struct.ScriptWithExtensions.html) for more information. |
| 33 |
*/ |
| 34 |
class ICU4XScriptWithExtensions { |
| 35 |
public: |
| 36 |
|
| 37 |
/** |
| 38 |
* See the [Rust documentation for `script_with_extensions`](https://docs.rs/icu/latest/icu/properties/script/fn.script_with_extensions.html) for more information. |
| 39 |
*/ |
| 40 |
static diplomat::result<ICU4XScriptWithExtensions, ICU4XError> create(const ICU4XDataProvider& provider); |
| 41 |
|
| 42 |
/** |
| 43 |
* Get the Script property value for a code point |
| 44 |
* |
| 45 |
* See the [Rust documentation for `get_script_val`](https://docs.rs/icu/latest/icu/properties/script/struct.ScriptWithExtensionsBorrowed.html#method.get_script_val) for more information. |
| 46 |
*/ |
| 47 |
uint16_t get_script_val(uint32_t code_point) const; |
| 48 |
|
| 49 |
/** |
| 50 |
* Check if the Script_Extensions property of the given code point covers the given script |
| 51 |
* |
| 52 |
* See the [Rust documentation for `has_script`](https://docs.rs/icu/latest/icu/properties/script/struct.ScriptWithExtensionsBorrowed.html#method.has_script) for more information. |
| 53 |
*/ |
| 54 |
bool has_script(uint32_t code_point, uint16_t script) const; |
| 55 |
|
| 56 |
/** |
| 57 |
* Borrow this object for a slightly faster variant with more operations |
| 58 |
* |
| 59 |
* See the [Rust documentation for `as_borrowed`](https://docs.rs/icu/latest/icu/properties/script/struct.ScriptWithExtensions.html#method.as_borrowed) for more information. |
| 60 |
* |
| 61 |
* Lifetimes: `this` must live at least as long as the output. |
| 62 |
*/ |
| 63 |
ICU4XScriptWithExtensionsBorrowed as_borrowed() const; |
| 64 |
|
| 65 |
/** |
| 66 |
* Get a list of ranges of code points that contain this script in their Script_Extensions values |
| 67 |
* |
| 68 |
* See the [Rust documentation for `get_script_extensions_ranges`](https://docs.rs/icu/latest/icu/properties/script/struct.ScriptWithExtensionsBorrowed.html#method.get_script_extensions_ranges) for more information. |
| 69 |
* |
| 70 |
* Lifetimes: `this` must live at least as long as the output. |
| 71 |
*/ |
| 72 |
CodePointRangeIterator iter_ranges_for_script(uint16_t script) const; |
| 73 |
inline const capi::ICU4XScriptWithExtensions* AsFFI() const { return this->inner.get(); } |
| 74 |
inline capi::ICU4XScriptWithExtensions* AsFFIMut() { return this->inner.get(); } |
| 75 |
inline explicit ICU4XScriptWithExtensions(capi::ICU4XScriptWithExtensions* i) : inner(i) {} |
| 76 |
ICU4XScriptWithExtensions() = default; |
| 77 |
ICU4XScriptWithExtensions(ICU4XScriptWithExtensions&&) noexcept = default; |
| 78 |
ICU4XScriptWithExtensions& operator=(ICU4XScriptWithExtensions&& other) noexcept = default; |
| 79 |
private: |
| 80 |
std::unique_ptr<capi::ICU4XScriptWithExtensions, ICU4XScriptWithExtensionsDeleter> inner; |
| 81 |
}; |
| 82 |
|
| 83 |
#include "ICU4XDataProvider.hpp" |
| 84 |
#include "ICU4XScriptWithExtensionsBorrowed.hpp" |
| 85 |
#include "CodePointRangeIterator.hpp" |
| 86 |
|
| 87 |
inline diplomat::result<ICU4XScriptWithExtensions, ICU4XError> ICU4XScriptWithExtensions::create(const ICU4XDataProvider& provider) { |
| 88 |
auto diplomat_result_raw_out_value = capi::ICU4XScriptWithExtensions_create(provider.AsFFI()); |
| 89 |
diplomat::result<ICU4XScriptWithExtensions, ICU4XError> diplomat_result_out_value; |
| 90 |
if (diplomat_result_raw_out_value.is_ok) { |
| 91 |
diplomat_result_out_value = diplomat::Ok<ICU4XScriptWithExtensions>(ICU4XScriptWithExtensions(diplomat_result_raw_out_value.ok)); |
| 92 |
} else { |
| 93 |
diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); |
| 94 |
} |
| 95 |
return diplomat_result_out_value; |
| 96 |
} |
| 97 |
inline uint16_t ICU4XScriptWithExtensions::get_script_val(uint32_t code_point) const { |
| 98 |
return capi::ICU4XScriptWithExtensions_get_script_val(this->inner.get(), code_point); |
| 99 |
} |
| 100 |
inline bool ICU4XScriptWithExtensions::has_script(uint32_t code_point, uint16_t script) const { |
| 101 |
return capi::ICU4XScriptWithExtensions_has_script(this->inner.get(), code_point, script); |
| 102 |
} |
| 103 |
inline ICU4XScriptWithExtensionsBorrowed ICU4XScriptWithExtensions::as_borrowed() const { |
| 104 |
return ICU4XScriptWithExtensionsBorrowed(capi::ICU4XScriptWithExtensions_as_borrowed(this->inner.get())); |
| 105 |
} |
| 106 |
inline CodePointRangeIterator ICU4XScriptWithExtensions::iter_ranges_for_script(uint16_t script) const { |
| 107 |
return CodePointRangeIterator(capi::ICU4XScriptWithExtensions_iter_ranges_for_script(this->inner.get(), script)); |
| 108 |
} |
| 109 |
#endif |