| 1 |
#ifndef ICU4XList_HPP |
| 2 |
#define ICU4XList_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 "ICU4XList.h" |
| 13 |
|
| 14 |
class ICU4XList; |
| 15 |
|
| 16 |
/** |
| 17 |
* A destruction policy for using ICU4XList with std::unique_ptr. |
| 18 |
*/ |
| 19 |
struct ICU4XListDeleter { |
| 20 |
void operator()(capi::ICU4XList* l) const noexcept { |
| 21 |
capi::ICU4XList_destroy(l); |
| 22 |
} |
| 23 |
}; |
| 24 |
|
| 25 |
/** |
| 26 |
* A list of strings |
| 27 |
*/ |
| 28 |
class ICU4XList { |
| 29 |
public: |
| 30 |
|
| 31 |
/** |
| 32 |
* Create a new list of strings |
| 33 |
*/ |
| 34 |
static ICU4XList create(); |
| 35 |
|
| 36 |
/** |
| 37 |
* Create a new list of strings with preallocated space to hold |
| 38 |
* at least `capacity` elements |
| 39 |
*/ |
| 40 |
static ICU4XList create_with_capacity(size_t capacity); |
| 41 |
|
| 42 |
/** |
| 43 |
* Push a string to the list |
| 44 |
* |
| 45 |
* Ill-formed input is treated as if errors had been replaced with REPLACEMENT CHARACTERs according |
| 46 |
* to the WHATWG Encoding Standard. |
| 47 |
*/ |
| 48 |
void push(const std::string_view val); |
| 49 |
|
| 50 |
/** |
| 51 |
* The number of elements in this list |
| 52 |
*/ |
| 53 |
size_t len() const; |
| 54 |
|
| 55 |
/** |
| 56 |
* Whether this list is empty |
| 57 |
*/ |
| 58 |
bool is_empty() const; |
| 59 |
inline const capi::ICU4XList* AsFFI() const { return this->inner.get(); } |
| 60 |
inline capi::ICU4XList* AsFFIMut() { return this->inner.get(); } |
| 61 |
inline explicit ICU4XList(capi::ICU4XList* i) : inner(i) {} |
| 62 |
ICU4XList() = default; |
| 63 |
ICU4XList(ICU4XList&&) noexcept = default; |
| 64 |
ICU4XList& operator=(ICU4XList&& other) noexcept = default; |
| 65 |
private: |
| 66 |
std::unique_ptr<capi::ICU4XList, ICU4XListDeleter> inner; |
| 67 |
}; |
| 68 |
|
| 69 |
|
| 70 |
inline ICU4XList ICU4XList::create() { |
| 71 |
return ICU4XList(capi::ICU4XList_create()); |
| 72 |
} |
| 73 |
inline ICU4XList ICU4XList::create_with_capacity(size_t capacity) { |
| 74 |
return ICU4XList(capi::ICU4XList_create_with_capacity(capacity)); |
| 75 |
} |
| 76 |
inline void ICU4XList::push(const std::string_view val) { |
| 77 |
capi::ICU4XList_push(this->inner.get(), val.data(), val.size()); |
| 78 |
} |
| 79 |
inline size_t ICU4XList::len() const { |
| 80 |
return capi::ICU4XList_len(this->inner.get()); |
| 81 |
} |
| 82 |
inline bool ICU4XList::is_empty() const { |
| 83 |
return capi::ICU4XList_is_empty(this->inner.get()); |
| 84 |
} |
| 85 |
#endif |