| 1 |
#ifndef CodePointRangeIterator_HPP |
| 2 |
#define CodePointRangeIterator_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 "CodePointRangeIterator.h" |
| 13 |
|
| 14 |
struct CodePointRangeIteratorResult; |
| 15 |
|
| 16 |
/** |
| 17 |
* A destruction policy for using CodePointRangeIterator with std::unique_ptr. |
| 18 |
*/ |
| 19 |
struct CodePointRangeIteratorDeleter { |
| 20 |
void operator()(capi::CodePointRangeIterator* l) const noexcept { |
| 21 |
capi::CodePointRangeIterator_destroy(l); |
| 22 |
} |
| 23 |
}; |
| 24 |
|
| 25 |
/** |
| 26 |
* An iterator over code point ranges, produced by `ICU4XCodePointSetData` or |
| 27 |
* one of the `ICU4XCodePointMapData` types |
| 28 |
*/ |
| 29 |
class CodePointRangeIterator { |
| 30 |
public: |
| 31 |
|
| 32 |
/** |
| 33 |
* Advance the iterator by one and return the next range. |
| 34 |
* |
| 35 |
* If the iterator is out of items, `done` will be true |
| 36 |
*/ |
| 37 |
CodePointRangeIteratorResult next(); |
| 38 |
inline const capi::CodePointRangeIterator* AsFFI() const { return this->inner.get(); } |
| 39 |
inline capi::CodePointRangeIterator* AsFFIMut() { return this->inner.get(); } |
| 40 |
inline explicit CodePointRangeIterator(capi::CodePointRangeIterator* i) : inner(i) {} |
| 41 |
CodePointRangeIterator() = default; |
| 42 |
CodePointRangeIterator(CodePointRangeIterator&&) noexcept = default; |
| 43 |
CodePointRangeIterator& operator=(CodePointRangeIterator&& other) noexcept = default; |
| 44 |
private: |
| 45 |
std::unique_ptr<capi::CodePointRangeIterator, CodePointRangeIteratorDeleter> inner; |
| 46 |
}; |
| 47 |
|
| 48 |
#include "CodePointRangeIteratorResult.hpp" |
| 49 |
|
| 50 |
inline CodePointRangeIteratorResult CodePointRangeIterator::next() { |
| 51 |
capi::CodePointRangeIteratorResult diplomat_raw_struct_out_value = capi::CodePointRangeIterator_next(this->inner.get()); |
| 52 |
return CodePointRangeIteratorResult{ .start = std::move(diplomat_raw_struct_out_value.start), .end = std::move(diplomat_raw_struct_out_value.end), .done = std::move(diplomat_raw_struct_out_value.done) }; |
| 53 |
} |
| 54 |
#endif |