| 1 |
#ifndef ICU4XBidiInfo_HPP |
| 2 |
#define ICU4XBidiInfo_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 "ICU4XBidiInfo.h" |
| 13 |
|
| 14 |
class ICU4XBidiParagraph; |
| 15 |
|
| 16 |
/** |
| 17 |
* A destruction policy for using ICU4XBidiInfo with std::unique_ptr. |
| 18 |
*/ |
| 19 |
struct ICU4XBidiInfoDeleter { |
| 20 |
void operator()(capi::ICU4XBidiInfo* l) const noexcept { |
| 21 |
capi::ICU4XBidiInfo_destroy(l); |
| 22 |
} |
| 23 |
}; |
| 24 |
|
| 25 |
/** |
| 26 |
* An object containing bidi information for a given string, produced by `for_text()` on `ICU4XBidi` |
| 27 |
* |
| 28 |
* See the [Rust documentation for `BidiInfo`](https://docs.rs/unicode_bidi/latest/unicode_bidi/struct.BidiInfo.html) for more information. |
| 29 |
*/ |
| 30 |
class ICU4XBidiInfo { |
| 31 |
public: |
| 32 |
|
| 33 |
/** |
| 34 |
* The number of paragraphs contained here |
| 35 |
*/ |
| 36 |
size_t paragraph_count() const; |
| 37 |
|
| 38 |
/** |
| 39 |
* Get the nth paragraph, returning `None` if out of bounds |
| 40 |
* |
| 41 |
* Lifetimes: `this` must live at least as long as the output. |
| 42 |
*/ |
| 43 |
std::optional<ICU4XBidiParagraph> paragraph_at(size_t n) const; |
| 44 |
|
| 45 |
/** |
| 46 |
* The number of bytes in this full text |
| 47 |
*/ |
| 48 |
size_t size() const; |
| 49 |
|
| 50 |
/** |
| 51 |
* Get the BIDI level at a particular byte index in the full text. |
| 52 |
* This integer is conceptually a `unicode_bidi::Level`, |
| 53 |
* and can be further inspected using the static methods on ICU4XBidi. |
| 54 |
* |
| 55 |
* Returns 0 (equivalent to `Level::ltr()`) on error |
| 56 |
*/ |
| 57 |
uint8_t level_at(size_t pos) const; |
| 58 |
inline const capi::ICU4XBidiInfo* AsFFI() const { return this->inner.get(); } |
| 59 |
inline capi::ICU4XBidiInfo* AsFFIMut() { return this->inner.get(); } |
| 60 |
inline explicit ICU4XBidiInfo(capi::ICU4XBidiInfo* i) : inner(i) {} |
| 61 |
ICU4XBidiInfo() = default; |
| 62 |
ICU4XBidiInfo(ICU4XBidiInfo&&) noexcept = default; |
| 63 |
ICU4XBidiInfo& operator=(ICU4XBidiInfo&& other) noexcept = default; |
| 64 |
private: |
| 65 |
std::unique_ptr<capi::ICU4XBidiInfo, ICU4XBidiInfoDeleter> inner; |
| 66 |
}; |
| 67 |
|
| 68 |
#include "ICU4XBidiParagraph.hpp" |
| 69 |
|
| 70 |
inline size_t ICU4XBidiInfo::paragraph_count() const { |
| 71 |
return capi::ICU4XBidiInfo_paragraph_count(this->inner.get()); |
| 72 |
} |
| 73 |
inline std::optional<ICU4XBidiParagraph> ICU4XBidiInfo::paragraph_at(size_t n) const { |
| 74 |
auto diplomat_optional_raw_out_value = capi::ICU4XBidiInfo_paragraph_at(this->inner.get(), n); |
| 75 |
std::optional<ICU4XBidiParagraph> diplomat_optional_out_value; |
| 76 |
if (diplomat_optional_raw_out_value != nullptr) { |
| 77 |
diplomat_optional_out_value = ICU4XBidiParagraph(diplomat_optional_raw_out_value); |
| 78 |
} else { |
| 79 |
diplomat_optional_out_value = std::nullopt; |
| 80 |
} |
| 81 |
return diplomat_optional_out_value; |
| 82 |
} |
| 83 |
inline size_t ICU4XBidiInfo::size() const { |
| 84 |
return capi::ICU4XBidiInfo_size(this->inner.get()); |
| 85 |
} |
| 86 |
inline uint8_t ICU4XBidiInfo::level_at(size_t pos) const { |
| 87 |
return capi::ICU4XBidiInfo_level_at(this->inner.get(), pos); |
| 88 |
} |
| 89 |
#endif |