diff options
Diffstat (limited to 'intl/icu_capi/cpp/include')
311 files changed, 19678 insertions, 0 deletions
diff --git a/intl/icu_capi/cpp/include/CodePointRangeIterator.h b/intl/icu_capi/cpp/include/CodePointRangeIterator.h new file mode 100644 index 0000000000..36d6d23175 --- /dev/null +++ b/intl/icu_capi/cpp/include/CodePointRangeIterator.h @@ -0,0 +1,30 @@ +#ifndef CodePointRangeIterator_H +#define CodePointRangeIterator_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct CodePointRangeIterator CodePointRangeIterator; +#ifdef __cplusplus +} // namespace capi +#endif +#include "CodePointRangeIteratorResult.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +CodePointRangeIteratorResult CodePointRangeIterator_next(CodePointRangeIterator* self); +void CodePointRangeIterator_destroy(CodePointRangeIterator* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/CodePointRangeIterator.hpp b/intl/icu_capi/cpp/include/CodePointRangeIterator.hpp new file mode 100644 index 0000000000..3c2d5caef0 --- /dev/null +++ b/intl/icu_capi/cpp/include/CodePointRangeIterator.hpp @@ -0,0 +1,54 @@ +#ifndef CodePointRangeIterator_HPP +#define CodePointRangeIterator_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "CodePointRangeIterator.h" + +struct CodePointRangeIteratorResult; + +/** + * A destruction policy for using CodePointRangeIterator with std::unique_ptr. + */ +struct CodePointRangeIteratorDeleter { + void operator()(capi::CodePointRangeIterator* l) const noexcept { + capi::CodePointRangeIterator_destroy(l); + } +}; + +/** + * An iterator over code point ranges, produced by `ICU4XCodePointSetData` or + * one of the `ICU4XCodePointMapData` types + */ +class CodePointRangeIterator { + public: + + /** + * Advance the iterator by one and return the next range. + * + * If the iterator is out of items, `done` will be true + */ + CodePointRangeIteratorResult next(); + inline const capi::CodePointRangeIterator* AsFFI() const { return this->inner.get(); } + inline capi::CodePointRangeIterator* AsFFIMut() { return this->inner.get(); } + inline CodePointRangeIterator(capi::CodePointRangeIterator* i) : inner(i) {} + CodePointRangeIterator() = default; + CodePointRangeIterator(CodePointRangeIterator&&) noexcept = default; + CodePointRangeIterator& operator=(CodePointRangeIterator&& other) noexcept = default; + private: + std::unique_ptr<capi::CodePointRangeIterator, CodePointRangeIteratorDeleter> inner; +}; + +#include "CodePointRangeIteratorResult.hpp" + +inline CodePointRangeIteratorResult CodePointRangeIterator::next() { + capi::CodePointRangeIteratorResult diplomat_raw_struct_out_value = capi::CodePointRangeIterator_next(this->inner.get()); + 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) }; +} +#endif diff --git a/intl/icu_capi/cpp/include/CodePointRangeIteratorResult.h b/intl/icu_capi/cpp/include/CodePointRangeIteratorResult.h new file mode 100644 index 0000000000..846873be11 --- /dev/null +++ b/intl/icu_capi/cpp/include/CodePointRangeIteratorResult.h @@ -0,0 +1,32 @@ +#ifndef CodePointRangeIteratorResult_H +#define CodePointRangeIteratorResult_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct CodePointRangeIteratorResult { + uint32_t start; + uint32_t end; + bool done; +} CodePointRangeIteratorResult; +#ifdef __cplusplus +} // namespace capi +#endif +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +void CodePointRangeIteratorResult_destroy(CodePointRangeIteratorResult* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/CodePointRangeIteratorResult.hpp b/intl/icu_capi/cpp/include/CodePointRangeIteratorResult.hpp new file mode 100644 index 0000000000..086ddfce08 --- /dev/null +++ b/intl/icu_capi/cpp/include/CodePointRangeIteratorResult.hpp @@ -0,0 +1,33 @@ +#ifndef CodePointRangeIteratorResult_HPP +#define CodePointRangeIteratorResult_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "CodePointRangeIteratorResult.h" + + + +/** + * Result of a single iteration of [`CodePointRangeIterator`]. + * Logically can be considered to be an `Option<RangeInclusive<u32>>`, + * + * `start` and `end` represent an inclusive range of code points [start, end], + * and `done` will be true if the iterator has already finished. The last contentful + * iteration will NOT produce a range done=true, in other words `start` and `end` are useful + * values if and only if `done=false`. + */ +struct CodePointRangeIteratorResult { + public: + uint32_t start; + uint32_t end; + bool done; +}; + + +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XAnyCalendarKind.h b/intl/icu_capi/cpp/include/ICU4XAnyCalendarKind.h new file mode 100644 index 0000000000..329f381577 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XAnyCalendarKind.h @@ -0,0 +1,55 @@ +#ifndef ICU4XAnyCalendarKind_H +#define ICU4XAnyCalendarKind_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef enum ICU4XAnyCalendarKind { + ICU4XAnyCalendarKind_Iso = 0, + ICU4XAnyCalendarKind_Gregorian = 1, + ICU4XAnyCalendarKind_Buddhist = 2, + ICU4XAnyCalendarKind_Japanese = 3, + ICU4XAnyCalendarKind_JapaneseExtended = 4, + ICU4XAnyCalendarKind_Ethiopian = 5, + ICU4XAnyCalendarKind_EthiopianAmeteAlem = 6, + ICU4XAnyCalendarKind_Indian = 7, + ICU4XAnyCalendarKind_Coptic = 8, + ICU4XAnyCalendarKind_Dangi = 9, + ICU4XAnyCalendarKind_Chinese = 10, + ICU4XAnyCalendarKind_Hebrew = 11, + ICU4XAnyCalendarKind_IslamicCivil = 12, + ICU4XAnyCalendarKind_IslamicObservational = 13, + ICU4XAnyCalendarKind_IslamicTabular = 14, + ICU4XAnyCalendarKind_IslamicUmmAlQura = 15, + ICU4XAnyCalendarKind_Persian = 16, + ICU4XAnyCalendarKind_Roc = 17, +} ICU4XAnyCalendarKind; +#ifdef __cplusplus +} // namespace capi +#endif +#include "ICU4XLocale.h" +#include "diplomat_result_ICU4XAnyCalendarKind_void.h" +#include "diplomat_result_void_ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +diplomat_result_ICU4XAnyCalendarKind_void ICU4XAnyCalendarKind_get_for_locale(const ICU4XLocale* locale); + +diplomat_result_ICU4XAnyCalendarKind_void ICU4XAnyCalendarKind_get_for_bcp47(const char* s_data, size_t s_len); + +diplomat_result_void_ICU4XError ICU4XAnyCalendarKind_bcp47(ICU4XAnyCalendarKind self, DiplomatWriteable* write); +void ICU4XAnyCalendarKind_destroy(ICU4XAnyCalendarKind* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XAnyCalendarKind.hpp b/intl/icu_capi/cpp/include/ICU4XAnyCalendarKind.hpp new file mode 100644 index 0000000000..93210f455e --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XAnyCalendarKind.hpp @@ -0,0 +1,117 @@ +#ifndef ICU4XAnyCalendarKind_HPP +#define ICU4XAnyCalendarKind_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XAnyCalendarKind.h" + + + +/** + * The various calendar types currently supported by [`ICU4XCalendar`] + * + * See the [Rust documentation for `AnyCalendarKind`](https://docs.rs/icu/latest/icu/calendar/enum.AnyCalendarKind.html) for more information. + */ +enum struct ICU4XAnyCalendarKind { + + /** + * The kind of an Iso calendar + */ + Iso = 0, + + /** + * The kind of a Gregorian calendar + */ + Gregorian = 1, + + /** + * The kind of a Buddhist calendar + */ + Buddhist = 2, + + /** + * The kind of a Japanese calendar with modern eras + */ + Japanese = 3, + + /** + * The kind of a Japanese calendar with modern and historic eras + */ + JapaneseExtended = 4, + + /** + * The kind of an Ethiopian calendar, with Amete Mihret era + */ + Ethiopian = 5, + + /** + * The kind of an Ethiopian calendar, with Amete Alem era + */ + EthiopianAmeteAlem = 6, + + /** + * The kind of a Indian calendar + */ + Indian = 7, + + /** + * The kind of a Coptic calendar + */ + Coptic = 8, + + /** + * The kind of a Dangi calendar + */ + Dangi = 9, + + /** + * The kind of a Chinese calendar + */ + Chinese = 10, + + /** + * The kind of a Hebrew calendar + */ + Hebrew = 11, + + /** + * The kind of a Islamic civil calendar + */ + IslamicCivil = 12, + + /** + * The kind of a Islamic observational calendar + */ + IslamicObservational = 13, + + /** + * The kind of a Islamic tabular calendar + */ + IslamicTabular = 14, + + /** + * The kind of a Islamic Umm al-Qura calendar + */ + IslamicUmmAlQura = 15, + + /** + * The kind of a Persian calendar + */ + Persian = 16, + + /** + * The kind of a Roc calendar + */ + Roc = 17, +}; +class ICU4XLocale; +#include "ICU4XError.hpp" + +#include "ICU4XLocale.hpp" +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XBcp47ToIanaMapper.h b/intl/icu_capi/cpp/include/ICU4XBcp47ToIanaMapper.h new file mode 100644 index 0000000000..483afe1ec2 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XBcp47ToIanaMapper.h @@ -0,0 +1,34 @@ +#ifndef ICU4XBcp47ToIanaMapper_H +#define ICU4XBcp47ToIanaMapper_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XBcp47ToIanaMapper ICU4XBcp47ToIanaMapper; +#ifdef __cplusplus +} // namespace capi +#endif +#include "ICU4XDataProvider.h" +#include "diplomat_result_box_ICU4XBcp47ToIanaMapper_ICU4XError.h" +#include "diplomat_result_void_ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +diplomat_result_box_ICU4XBcp47ToIanaMapper_ICU4XError ICU4XBcp47ToIanaMapper_create(const ICU4XDataProvider* provider); + +diplomat_result_void_ICU4XError ICU4XBcp47ToIanaMapper_get(const ICU4XBcp47ToIanaMapper* self, const char* value_data, size_t value_len, DiplomatWriteable* write); +void ICU4XBcp47ToIanaMapper_destroy(ICU4XBcp47ToIanaMapper* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XBcp47ToIanaMapper.hpp b/intl/icu_capi/cpp/include/ICU4XBcp47ToIanaMapper.hpp new file mode 100644 index 0000000000..b8c303e79a --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XBcp47ToIanaMapper.hpp @@ -0,0 +1,98 @@ +#ifndef ICU4XBcp47ToIanaMapper_HPP +#define ICU4XBcp47ToIanaMapper_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XBcp47ToIanaMapper.h" + +class ICU4XDataProvider; +class ICU4XBcp47ToIanaMapper; +#include "ICU4XError.hpp" + +/** + * A destruction policy for using ICU4XBcp47ToIanaMapper with std::unique_ptr. + */ +struct ICU4XBcp47ToIanaMapperDeleter { + void operator()(capi::ICU4XBcp47ToIanaMapper* l) const noexcept { + capi::ICU4XBcp47ToIanaMapper_destroy(l); + } +}; + +/** + * An object capable of mapping from a BCP-47 time zone ID to an IANA ID. + * + * See the [Rust documentation for `IanaBcp47RoundTripMapper`](https://docs.rs/icu/latest/icu/timezone/struct.IanaBcp47RoundTripMapper.html) for more information. + */ +class ICU4XBcp47ToIanaMapper { + public: + + /** + * See the [Rust documentation for `new`](https://docs.rs/icu/latest/icu/timezone/struct.IanaBcp47RoundTripMapper.html#method.new) for more information. + */ + static diplomat::result<ICU4XBcp47ToIanaMapper, ICU4XError> create(const ICU4XDataProvider& provider); + + /** + * Writes out the canonical IANA time zone ID corresponding to the given BCP-47 ID. + * + * See the [Rust documentation for `bcp47_to_iana`](https://docs.rs/icu/latest/icu/datetime/time_zone/struct.IanaBcp47RoundTripMapper.html#method.bcp47_to_iana) for more information. + */ + template<typename W> diplomat::result<std::monostate, ICU4XError> get_to_writeable(const std::string_view value, W& write) const; + + /** + * Writes out the canonical IANA time zone ID corresponding to the given BCP-47 ID. + * + * See the [Rust documentation for `bcp47_to_iana`](https://docs.rs/icu/latest/icu/datetime/time_zone/struct.IanaBcp47RoundTripMapper.html#method.bcp47_to_iana) for more information. + */ + diplomat::result<std::string, ICU4XError> get(const std::string_view value) const; + inline const capi::ICU4XBcp47ToIanaMapper* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XBcp47ToIanaMapper* AsFFIMut() { return this->inner.get(); } + inline ICU4XBcp47ToIanaMapper(capi::ICU4XBcp47ToIanaMapper* i) : inner(i) {} + ICU4XBcp47ToIanaMapper() = default; + ICU4XBcp47ToIanaMapper(ICU4XBcp47ToIanaMapper&&) noexcept = default; + ICU4XBcp47ToIanaMapper& operator=(ICU4XBcp47ToIanaMapper&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XBcp47ToIanaMapper, ICU4XBcp47ToIanaMapperDeleter> inner; +}; + +#include "ICU4XDataProvider.hpp" + +inline diplomat::result<ICU4XBcp47ToIanaMapper, ICU4XError> ICU4XBcp47ToIanaMapper::create(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XBcp47ToIanaMapper_create(provider.AsFFI()); + diplomat::result<ICU4XBcp47ToIanaMapper, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XBcp47ToIanaMapper>(ICU4XBcp47ToIanaMapper(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XBcp47ToIanaMapper::get_to_writeable(const std::string_view value, W& write) const { + capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write); + auto diplomat_result_raw_out_value = capi::ICU4XBcp47ToIanaMapper_get(this->inner.get(), value.data(), value.size(), &write_writer); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<std::string, ICU4XError> ICU4XBcp47ToIanaMapper::get(const std::string_view value) const { + std::string diplomat_writeable_string; + capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); + auto diplomat_result_raw_out_value = capi::ICU4XBcp47ToIanaMapper_get(this->inner.get(), value.data(), value.size(), &diplomat_writeable_out); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string)); +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XBidi.h b/intl/icu_capi/cpp/include/ICU4XBidi.h new file mode 100644 index 0000000000..1ed7cfc8c2 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XBidi.h @@ -0,0 +1,45 @@ +#ifndef ICU4XBidi_H +#define ICU4XBidi_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XBidi ICU4XBidi; +#ifdef __cplusplus +} // namespace capi +#endif +#include "ICU4XDataProvider.h" +#include "diplomat_result_box_ICU4XBidi_ICU4XError.h" +#include "ICU4XBidiInfo.h" +#include "ICU4XReorderedIndexMap.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +diplomat_result_box_ICU4XBidi_ICU4XError ICU4XBidi_create(const ICU4XDataProvider* provider); + +ICU4XBidiInfo* ICU4XBidi_for_text(const ICU4XBidi* self, const char* text_data, size_t text_len, uint8_t default_level); + +ICU4XReorderedIndexMap* ICU4XBidi_reorder_visual(const ICU4XBidi* self, const uint8_t* levels_data, size_t levels_len); + +bool ICU4XBidi_level_is_rtl(uint8_t level); + +bool ICU4XBidi_level_is_ltr(uint8_t level); + +uint8_t ICU4XBidi_level_rtl(); + +uint8_t ICU4XBidi_level_ltr(); +void ICU4XBidi_destroy(ICU4XBidi* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XBidi.hpp b/intl/icu_capi/cpp/include/ICU4XBidi.hpp new file mode 100644 index 0000000000..00ab389d7b --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XBidi.hpp @@ -0,0 +1,142 @@ +#ifndef ICU4XBidi_HPP +#define ICU4XBidi_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XBidi.h" + +class ICU4XDataProvider; +class ICU4XBidi; +#include "ICU4XError.hpp" +class ICU4XBidiInfo; +class ICU4XReorderedIndexMap; + +/** + * A destruction policy for using ICU4XBidi with std::unique_ptr. + */ +struct ICU4XBidiDeleter { + void operator()(capi::ICU4XBidi* l) const noexcept { + capi::ICU4XBidi_destroy(l); + } +}; + +/** + * An ICU4X Bidi object, containing loaded bidi data + * + * See the [Rust documentation for `BidiClassAdapter`](https://docs.rs/icu/latest/icu/properties/bidi/struct.BidiClassAdapter.html) for more information. + */ +class ICU4XBidi { + public: + + /** + * Creates a new [`ICU4XBidi`] from locale data. + * + * See the [Rust documentation for `new`](https://docs.rs/icu/latest/icu/properties/bidi/struct.BidiClassAdapter.html#method.new) for more information. + */ + static diplomat::result<ICU4XBidi, ICU4XError> create(const ICU4XDataProvider& provider); + + /** + * Use the data loaded in this object to process a string and calculate bidi information + * + * Takes in a Level for the default level, if it is an invalid value it will default to LTR + * + * See the [Rust documentation for `new_with_data_source`](https://docs.rs/unicode_bidi/latest/unicode_bidi/struct.BidiInfo.html#method.new_with_data_source) for more information. + * + * Lifetimes: `text` must live at least as long as the output. + */ + ICU4XBidiInfo for_text(const std::string_view text, uint8_t default_level) const; + + /** + * Utility function for producing reorderings given a list of levels + * + * Produces a map saying which visual index maps to which source index. + * + * The levels array must not have values greater than 126 (this is the + * Bidi maximum explicit depth plus one). + * Failure to follow this invariant may lead to incorrect results, + * but is still safe. + * + * See the [Rust documentation for `reorder_visual`](https://docs.rs/unicode_bidi/latest/unicode_bidi/struct.BidiInfo.html#method.reorder_visual) for more information. + */ + ICU4XReorderedIndexMap reorder_visual(const diplomat::span<const uint8_t> levels) const; + + /** + * Check if a Level returned by level_at is an RTL level. + * + * Invalid levels (numbers greater than 125) will be assumed LTR + * + * See the [Rust documentation for `is_rtl`](https://docs.rs/unicode_bidi/latest/unicode_bidi/struct.Level.html#method.is_rtl) for more information. + */ + static bool level_is_rtl(uint8_t level); + + /** + * Check if a Level returned by level_at is an LTR level. + * + * Invalid levels (numbers greater than 125) will be assumed LTR + * + * See the [Rust documentation for `is_ltr`](https://docs.rs/unicode_bidi/latest/unicode_bidi/struct.Level.html#method.is_ltr) for more information. + */ + static bool level_is_ltr(uint8_t level); + + /** + * Get a basic RTL Level value + * + * See the [Rust documentation for `rtl`](https://docs.rs/unicode_bidi/latest/unicode_bidi/struct.Level.html#method.rtl) for more information. + */ + static uint8_t level_rtl(); + + /** + * Get a simple LTR Level value + * + * See the [Rust documentation for `ltr`](https://docs.rs/unicode_bidi/latest/unicode_bidi/struct.Level.html#method.ltr) for more information. + */ + static uint8_t level_ltr(); + inline const capi::ICU4XBidi* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XBidi* AsFFIMut() { return this->inner.get(); } + inline ICU4XBidi(capi::ICU4XBidi* i) : inner(i) {} + ICU4XBidi() = default; + ICU4XBidi(ICU4XBidi&&) noexcept = default; + ICU4XBidi& operator=(ICU4XBidi&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XBidi, ICU4XBidiDeleter> inner; +}; + +#include "ICU4XDataProvider.hpp" +#include "ICU4XBidiInfo.hpp" +#include "ICU4XReorderedIndexMap.hpp" + +inline diplomat::result<ICU4XBidi, ICU4XError> ICU4XBidi::create(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XBidi_create(provider.AsFFI()); + diplomat::result<ICU4XBidi, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XBidi>(ICU4XBidi(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline ICU4XBidiInfo ICU4XBidi::for_text(const std::string_view text, uint8_t default_level) const { + return ICU4XBidiInfo(capi::ICU4XBidi_for_text(this->inner.get(), text.data(), text.size(), default_level)); +} +inline ICU4XReorderedIndexMap ICU4XBidi::reorder_visual(const diplomat::span<const uint8_t> levels) const { + return ICU4XReorderedIndexMap(capi::ICU4XBidi_reorder_visual(this->inner.get(), levels.data(), levels.size())); +} +inline bool ICU4XBidi::level_is_rtl(uint8_t level) { + return capi::ICU4XBidi_level_is_rtl(level); +} +inline bool ICU4XBidi::level_is_ltr(uint8_t level) { + return capi::ICU4XBidi_level_is_ltr(level); +} +inline uint8_t ICU4XBidi::level_rtl() { + return capi::ICU4XBidi_level_rtl(); +} +inline uint8_t ICU4XBidi::level_ltr() { + return capi::ICU4XBidi_level_ltr(); +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XBidiDirection.h b/intl/icu_capi/cpp/include/ICU4XBidiDirection.h new file mode 100644 index 0000000000..33de81d6e9 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XBidiDirection.h @@ -0,0 +1,32 @@ +#ifndef ICU4XBidiDirection_H +#define ICU4XBidiDirection_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef enum ICU4XBidiDirection { + ICU4XBidiDirection_Ltr = 0, + ICU4XBidiDirection_Rtl = 1, + ICU4XBidiDirection_Mixed = 2, +} ICU4XBidiDirection; +#ifdef __cplusplus +} // namespace capi +#endif +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +void ICU4XBidiDirection_destroy(ICU4XBidiDirection* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XBidiDirection.hpp b/intl/icu_capi/cpp/include/ICU4XBidiDirection.hpp new file mode 100644 index 0000000000..ad21e51910 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XBidiDirection.hpp @@ -0,0 +1,21 @@ +#ifndef ICU4XBidiDirection_HPP +#define ICU4XBidiDirection_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XBidiDirection.h" + + +enum struct ICU4XBidiDirection { + Ltr = 0, + Rtl = 1, + Mixed = 2, +}; + +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XBidiInfo.h b/intl/icu_capi/cpp/include/ICU4XBidiInfo.h new file mode 100644 index 0000000000..02e8c21659 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XBidiInfo.h @@ -0,0 +1,36 @@ +#ifndef ICU4XBidiInfo_H +#define ICU4XBidiInfo_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XBidiInfo ICU4XBidiInfo; +#ifdef __cplusplus +} // namespace capi +#endif +#include "ICU4XBidiParagraph.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +size_t ICU4XBidiInfo_paragraph_count(const ICU4XBidiInfo* self); + +ICU4XBidiParagraph* ICU4XBidiInfo_paragraph_at(const ICU4XBidiInfo* self, size_t n); + +size_t ICU4XBidiInfo_size(const ICU4XBidiInfo* self); + +uint8_t ICU4XBidiInfo_level_at(const ICU4XBidiInfo* self, size_t pos); +void ICU4XBidiInfo_destroy(ICU4XBidiInfo* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XBidiInfo.hpp b/intl/icu_capi/cpp/include/ICU4XBidiInfo.hpp new file mode 100644 index 0000000000..c19ad630fb --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XBidiInfo.hpp @@ -0,0 +1,89 @@ +#ifndef ICU4XBidiInfo_HPP +#define ICU4XBidiInfo_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XBidiInfo.h" + +class ICU4XBidiParagraph; + +/** + * A destruction policy for using ICU4XBidiInfo with std::unique_ptr. + */ +struct ICU4XBidiInfoDeleter { + void operator()(capi::ICU4XBidiInfo* l) const noexcept { + capi::ICU4XBidiInfo_destroy(l); + } +}; + +/** + * An object containing bidi information for a given string, produced by `for_text()` on `ICU4XBidi` + * + * See the [Rust documentation for `BidiInfo`](https://docs.rs/unicode_bidi/latest/unicode_bidi/struct.BidiInfo.html) for more information. + */ +class ICU4XBidiInfo { + public: + + /** + * The number of paragraphs contained here + */ + size_t paragraph_count() const; + + /** + * Get the nth paragraph, returning `None` if out of bounds + * + * Lifetimes: `this` must live at least as long as the output. + */ + std::optional<ICU4XBidiParagraph> paragraph_at(size_t n) const; + + /** + * The number of bytes in this full text + */ + size_t size() const; + + /** + * Get the BIDI level at a particular byte index in the full text. + * This integer is conceptually a `unicode_bidi::Level`, + * and can be further inspected using the static methods on ICU4XBidi. + * + * Returns 0 (equivalent to `Level::ltr()`) on error + */ + uint8_t level_at(size_t pos) const; + inline const capi::ICU4XBidiInfo* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XBidiInfo* AsFFIMut() { return this->inner.get(); } + inline ICU4XBidiInfo(capi::ICU4XBidiInfo* i) : inner(i) {} + ICU4XBidiInfo() = default; + ICU4XBidiInfo(ICU4XBidiInfo&&) noexcept = default; + ICU4XBidiInfo& operator=(ICU4XBidiInfo&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XBidiInfo, ICU4XBidiInfoDeleter> inner; +}; + +#include "ICU4XBidiParagraph.hpp" + +inline size_t ICU4XBidiInfo::paragraph_count() const { + return capi::ICU4XBidiInfo_paragraph_count(this->inner.get()); +} +inline std::optional<ICU4XBidiParagraph> ICU4XBidiInfo::paragraph_at(size_t n) const { + auto diplomat_optional_raw_out_value = capi::ICU4XBidiInfo_paragraph_at(this->inner.get(), n); + std::optional<ICU4XBidiParagraph> diplomat_optional_out_value; + if (diplomat_optional_raw_out_value != nullptr) { + diplomat_optional_out_value = ICU4XBidiParagraph(diplomat_optional_raw_out_value); + } else { + diplomat_optional_out_value = std::nullopt; + } + return diplomat_optional_out_value; +} +inline size_t ICU4XBidiInfo::size() const { + return capi::ICU4XBidiInfo_size(this->inner.get()); +} +inline uint8_t ICU4XBidiInfo::level_at(size_t pos) const { + return capi::ICU4XBidiInfo_level_at(this->inner.get(), pos); +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XBidiParagraph.h b/intl/icu_capi/cpp/include/ICU4XBidiParagraph.h new file mode 100644 index 0000000000..269f940cc7 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XBidiParagraph.h @@ -0,0 +1,43 @@ +#ifndef ICU4XBidiParagraph_H +#define ICU4XBidiParagraph_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XBidiParagraph ICU4XBidiParagraph; +#ifdef __cplusplus +} // namespace capi +#endif +#include "diplomat_result_void_ICU4XError.h" +#include "ICU4XBidiDirection.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +diplomat_result_void_ICU4XError ICU4XBidiParagraph_set_paragraph_in_text(ICU4XBidiParagraph* self, size_t n); + +ICU4XBidiDirection ICU4XBidiParagraph_direction(const ICU4XBidiParagraph* self); + +size_t ICU4XBidiParagraph_size(const ICU4XBidiParagraph* self); + +size_t ICU4XBidiParagraph_range_start(const ICU4XBidiParagraph* self); + +size_t ICU4XBidiParagraph_range_end(const ICU4XBidiParagraph* self); + +diplomat_result_void_ICU4XError ICU4XBidiParagraph_reorder_line(const ICU4XBidiParagraph* self, size_t range_start, size_t range_end, DiplomatWriteable* out); + +uint8_t ICU4XBidiParagraph_level_at(const ICU4XBidiParagraph* self, size_t pos); +void ICU4XBidiParagraph_destroy(ICU4XBidiParagraph* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XBidiParagraph.hpp b/intl/icu_capi/cpp/include/ICU4XBidiParagraph.hpp new file mode 100644 index 0000000000..645390640b --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XBidiParagraph.hpp @@ -0,0 +1,150 @@ +#ifndef ICU4XBidiParagraph_HPP +#define ICU4XBidiParagraph_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XBidiParagraph.h" + +#include "ICU4XError.hpp" +#include "ICU4XBidiDirection.hpp" + +/** + * A destruction policy for using ICU4XBidiParagraph with std::unique_ptr. + */ +struct ICU4XBidiParagraphDeleter { + void operator()(capi::ICU4XBidiParagraph* l) const noexcept { + capi::ICU4XBidiParagraph_destroy(l); + } +}; + +/** + * Bidi information for a single processed paragraph + */ +class ICU4XBidiParagraph { + public: + + /** + * Given a paragraph index `n` within the surrounding text, this sets this + * object to the paragraph at that index. Returns `ICU4XError::OutOfBoundsError` when out of bounds. + * + * This is equivalent to calling `paragraph_at()` on `ICU4XBidiInfo` but doesn't + * create a new object + */ + diplomat::result<std::monostate, ICU4XError> set_paragraph_in_text(size_t n); + + /** + * The primary direction of this paragraph + * + * See the [Rust documentation for `level_at`](https://docs.rs/unicode_bidi/latest/unicode_bidi/struct.Paragraph.html#method.level_at) for more information. + */ + ICU4XBidiDirection direction() const; + + /** + * The number of bytes in this paragraph + * + * See the [Rust documentation for `len`](https://docs.rs/unicode_bidi/latest/unicode_bidi/struct.ParagraphInfo.html#method.len) for more information. + */ + size_t size() const; + + /** + * The start index of this paragraph within the source text + */ + size_t range_start() const; + + /** + * The end index of this paragraph within the source text + */ + size_t range_end() const; + + /** + * Reorder a line based on display order. The ranges are specified relative to the source text and must be contained + * within this paragraph's range. + * + * See the [Rust documentation for `level_at`](https://docs.rs/unicode_bidi/latest/unicode_bidi/struct.Paragraph.html#method.level_at) for more information. + */ + template<typename W> diplomat::result<std::monostate, ICU4XError> reorder_line_to_writeable(size_t range_start, size_t range_end, W& out) const; + + /** + * Reorder a line based on display order. The ranges are specified relative to the source text and must be contained + * within this paragraph's range. + * + * See the [Rust documentation for `level_at`](https://docs.rs/unicode_bidi/latest/unicode_bidi/struct.Paragraph.html#method.level_at) for more information. + */ + diplomat::result<std::string, ICU4XError> reorder_line(size_t range_start, size_t range_end) const; + + /** + * Get the BIDI level at a particular byte index in this paragraph. + * This integer is conceptually a `unicode_bidi::Level`, + * and can be further inspected using the static methods on ICU4XBidi. + * + * Returns 0 (equivalent to `Level::ltr()`) on error + * + * See the [Rust documentation for `level_at`](https://docs.rs/unicode_bidi/latest/unicode_bidi/struct.Paragraph.html#method.level_at) for more information. + */ + uint8_t level_at(size_t pos) const; + inline const capi::ICU4XBidiParagraph* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XBidiParagraph* AsFFIMut() { return this->inner.get(); } + inline ICU4XBidiParagraph(capi::ICU4XBidiParagraph* i) : inner(i) {} + ICU4XBidiParagraph() = default; + ICU4XBidiParagraph(ICU4XBidiParagraph&&) noexcept = default; + ICU4XBidiParagraph& operator=(ICU4XBidiParagraph&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XBidiParagraph, ICU4XBidiParagraphDeleter> inner; +}; + + +inline diplomat::result<std::monostate, ICU4XError> ICU4XBidiParagraph::set_paragraph_in_text(size_t n) { + auto diplomat_result_raw_out_value = capi::ICU4XBidiParagraph_set_paragraph_in_text(this->inner.get(), n); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline ICU4XBidiDirection ICU4XBidiParagraph::direction() const { + return static_cast<ICU4XBidiDirection>(capi::ICU4XBidiParagraph_direction(this->inner.get())); +} +inline size_t ICU4XBidiParagraph::size() const { + return capi::ICU4XBidiParagraph_size(this->inner.get()); +} +inline size_t ICU4XBidiParagraph::range_start() const { + return capi::ICU4XBidiParagraph_range_start(this->inner.get()); +} +inline size_t ICU4XBidiParagraph::range_end() const { + return capi::ICU4XBidiParagraph_range_end(this->inner.get()); +} +template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XBidiParagraph::reorder_line_to_writeable(size_t range_start, size_t range_end, W& out) const { + capi::DiplomatWriteable out_writer = diplomat::WriteableTrait<W>::Construct(out); + auto diplomat_result_raw_out_value = capi::ICU4XBidiParagraph_reorder_line(this->inner.get(), range_start, range_end, &out_writer); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<std::string, ICU4XError> ICU4XBidiParagraph::reorder_line(size_t range_start, size_t range_end) const { + std::string diplomat_writeable_string; + capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); + auto diplomat_result_raw_out_value = capi::ICU4XBidiParagraph_reorder_line(this->inner.get(), range_start, range_end, &diplomat_writeable_out); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string)); +} +inline uint8_t ICU4XBidiParagraph::level_at(size_t pos) const { + return capi::ICU4XBidiParagraph_level_at(this->inner.get(), pos); +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XCalendar.h b/intl/icu_capi/cpp/include/ICU4XCalendar.h new file mode 100644 index 0000000000..9ea6484b5f --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XCalendar.h @@ -0,0 +1,37 @@ +#ifndef ICU4XCalendar_H +#define ICU4XCalendar_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XCalendar ICU4XCalendar; +#ifdef __cplusplus +} // namespace capi +#endif +#include "ICU4XDataProvider.h" +#include "ICU4XLocale.h" +#include "diplomat_result_box_ICU4XCalendar_ICU4XError.h" +#include "ICU4XAnyCalendarKind.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +diplomat_result_box_ICU4XCalendar_ICU4XError ICU4XCalendar_create_for_locale(const ICU4XDataProvider* provider, const ICU4XLocale* locale); + +diplomat_result_box_ICU4XCalendar_ICU4XError ICU4XCalendar_create_for_kind(const ICU4XDataProvider* provider, ICU4XAnyCalendarKind kind); + +ICU4XAnyCalendarKind ICU4XCalendar_kind(const ICU4XCalendar* self); +void ICU4XCalendar_destroy(ICU4XCalendar* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XCalendar.hpp b/intl/icu_capi/cpp/include/ICU4XCalendar.hpp new file mode 100644 index 0000000000..e6ae0608c5 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XCalendar.hpp @@ -0,0 +1,91 @@ +#ifndef ICU4XCalendar_HPP +#define ICU4XCalendar_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XCalendar.h" + +class ICU4XDataProvider; +class ICU4XLocale; +class ICU4XCalendar; +#include "ICU4XError.hpp" +#include "ICU4XAnyCalendarKind.hpp" + +/** + * A destruction policy for using ICU4XCalendar with std::unique_ptr. + */ +struct ICU4XCalendarDeleter { + void operator()(capi::ICU4XCalendar* l) const noexcept { + capi::ICU4XCalendar_destroy(l); + } +}; + +/** + * See the [Rust documentation for `AnyCalendar`](https://docs.rs/icu/latest/icu/calendar/enum.AnyCalendar.html) for more information. + */ +class ICU4XCalendar { + public: + + /** + * Creates a new [`ICU4XCalendar`] from the specified date and time. + * + * See the [Rust documentation for `new_for_locale`](https://docs.rs/icu/latest/icu/calendar/enum.AnyCalendar.html#method.new_for_locale) for more information. + */ + static diplomat::result<ICU4XCalendar, ICU4XError> create_for_locale(const ICU4XDataProvider& provider, const ICU4XLocale& locale); + + /** + * Creates a new [`ICU4XCalendar`] from the specified date and time. + * + * See the [Rust documentation for `new`](https://docs.rs/icu/latest/icu/calendar/enum.AnyCalendar.html#method.new) for more information. + */ + static diplomat::result<ICU4XCalendar, ICU4XError> create_for_kind(const ICU4XDataProvider& provider, ICU4XAnyCalendarKind kind); + + /** + * Returns the kind of this calendar + * + * See the [Rust documentation for `kind`](https://docs.rs/icu/latest/icu/calendar/enum.AnyCalendar.html#method.kind) for more information. + */ + ICU4XAnyCalendarKind kind() const; + inline const capi::ICU4XCalendar* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XCalendar* AsFFIMut() { return this->inner.get(); } + inline ICU4XCalendar(capi::ICU4XCalendar* i) : inner(i) {} + ICU4XCalendar() = default; + ICU4XCalendar(ICU4XCalendar&&) noexcept = default; + ICU4XCalendar& operator=(ICU4XCalendar&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XCalendar, ICU4XCalendarDeleter> inner; +}; + +#include "ICU4XDataProvider.hpp" +#include "ICU4XLocale.hpp" + +inline diplomat::result<ICU4XCalendar, ICU4XError> ICU4XCalendar::create_for_locale(const ICU4XDataProvider& provider, const ICU4XLocale& locale) { + auto diplomat_result_raw_out_value = capi::ICU4XCalendar_create_for_locale(provider.AsFFI(), locale.AsFFI()); + diplomat::result<ICU4XCalendar, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCalendar>(ICU4XCalendar(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCalendar, ICU4XError> ICU4XCalendar::create_for_kind(const ICU4XDataProvider& provider, ICU4XAnyCalendarKind kind) { + auto diplomat_result_raw_out_value = capi::ICU4XCalendar_create_for_kind(provider.AsFFI(), static_cast<capi::ICU4XAnyCalendarKind>(kind)); + diplomat::result<ICU4XCalendar, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCalendar>(ICU4XCalendar(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline ICU4XAnyCalendarKind ICU4XCalendar::kind() const { + return static_cast<ICU4XAnyCalendarKind>(capi::ICU4XCalendar_kind(this->inner.get())); +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XCanonicalCombiningClassMap.h b/intl/icu_capi/cpp/include/ICU4XCanonicalCombiningClassMap.h new file mode 100644 index 0000000000..f0fc447ba0 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XCanonicalCombiningClassMap.h @@ -0,0 +1,35 @@ +#ifndef ICU4XCanonicalCombiningClassMap_H +#define ICU4XCanonicalCombiningClassMap_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XCanonicalCombiningClassMap ICU4XCanonicalCombiningClassMap; +#ifdef __cplusplus +} // namespace capi +#endif +#include "ICU4XDataProvider.h" +#include "diplomat_result_box_ICU4XCanonicalCombiningClassMap_ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +diplomat_result_box_ICU4XCanonicalCombiningClassMap_ICU4XError ICU4XCanonicalCombiningClassMap_create(const ICU4XDataProvider* provider); + +uint8_t ICU4XCanonicalCombiningClassMap_get(const ICU4XCanonicalCombiningClassMap* self, char32_t ch); + +uint8_t ICU4XCanonicalCombiningClassMap_get32(const ICU4XCanonicalCombiningClassMap* self, uint32_t ch); +void ICU4XCanonicalCombiningClassMap_destroy(ICU4XCanonicalCombiningClassMap* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XCanonicalCombiningClassMap.hpp b/intl/icu_capi/cpp/include/ICU4XCanonicalCombiningClassMap.hpp new file mode 100644 index 0000000000..e663d47824 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XCanonicalCombiningClassMap.hpp @@ -0,0 +1,83 @@ +#ifndef ICU4XCanonicalCombiningClassMap_HPP +#define ICU4XCanonicalCombiningClassMap_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XCanonicalCombiningClassMap.h" + +class ICU4XDataProvider; +class ICU4XCanonicalCombiningClassMap; +#include "ICU4XError.hpp" + +/** + * A destruction policy for using ICU4XCanonicalCombiningClassMap with std::unique_ptr. + */ +struct ICU4XCanonicalCombiningClassMapDeleter { + void operator()(capi::ICU4XCanonicalCombiningClassMap* l) const noexcept { + capi::ICU4XCanonicalCombiningClassMap_destroy(l); + } +}; + +/** + * Lookup of the Canonical_Combining_Class Unicode property + * + * See the [Rust documentation for `CanonicalCombiningClassMap`](https://docs.rs/icu/latest/icu/normalizer/properties/struct.CanonicalCombiningClassMap.html) for more information. + */ +class ICU4XCanonicalCombiningClassMap { + public: + + /** + * Construct a new ICU4XCanonicalCombiningClassMap instance for NFC + * + * See the [Rust documentation for `new`](https://docs.rs/icu/latest/icu/normalizer/properties/struct.CanonicalCombiningClassMap.html#method.new) for more information. + */ + static diplomat::result<ICU4XCanonicalCombiningClassMap, ICU4XError> create(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `get`](https://docs.rs/icu/latest/icu/normalizer/properties/struct.CanonicalCombiningClassMap.html#method.get) for more information. + * + * Additional information: [1](https://docs.rs/icu/latest/icu/properties/properties/struct.CanonicalCombiningClass.html) + */ + uint8_t get(char32_t ch) const; + + /** + * See the [Rust documentation for `get32`](https://docs.rs/icu/latest/icu/normalizer/properties/struct.CanonicalCombiningClassMap.html#method.get32) for more information. + * + * Additional information: [1](https://docs.rs/icu/latest/icu/properties/properties/struct.CanonicalCombiningClass.html) + */ + uint8_t get32(uint32_t ch) const; + inline const capi::ICU4XCanonicalCombiningClassMap* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XCanonicalCombiningClassMap* AsFFIMut() { return this->inner.get(); } + inline ICU4XCanonicalCombiningClassMap(capi::ICU4XCanonicalCombiningClassMap* i) : inner(i) {} + ICU4XCanonicalCombiningClassMap() = default; + ICU4XCanonicalCombiningClassMap(ICU4XCanonicalCombiningClassMap&&) noexcept = default; + ICU4XCanonicalCombiningClassMap& operator=(ICU4XCanonicalCombiningClassMap&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XCanonicalCombiningClassMap, ICU4XCanonicalCombiningClassMapDeleter> inner; +}; + +#include "ICU4XDataProvider.hpp" + +inline diplomat::result<ICU4XCanonicalCombiningClassMap, ICU4XError> ICU4XCanonicalCombiningClassMap::create(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCanonicalCombiningClassMap_create(provider.AsFFI()); + diplomat::result<ICU4XCanonicalCombiningClassMap, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCanonicalCombiningClassMap>(ICU4XCanonicalCombiningClassMap(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline uint8_t ICU4XCanonicalCombiningClassMap::get(char32_t ch) const { + return capi::ICU4XCanonicalCombiningClassMap_get(this->inner.get(), ch); +} +inline uint8_t ICU4XCanonicalCombiningClassMap::get32(uint32_t ch) const { + return capi::ICU4XCanonicalCombiningClassMap_get32(this->inner.get(), ch); +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XCanonicalComposition.h b/intl/icu_capi/cpp/include/ICU4XCanonicalComposition.h new file mode 100644 index 0000000000..e9ae621739 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XCanonicalComposition.h @@ -0,0 +1,33 @@ +#ifndef ICU4XCanonicalComposition_H +#define ICU4XCanonicalComposition_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XCanonicalComposition ICU4XCanonicalComposition; +#ifdef __cplusplus +} // namespace capi +#endif +#include "ICU4XDataProvider.h" +#include "diplomat_result_box_ICU4XCanonicalComposition_ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +diplomat_result_box_ICU4XCanonicalComposition_ICU4XError ICU4XCanonicalComposition_create(const ICU4XDataProvider* provider); + +char32_t ICU4XCanonicalComposition_compose(const ICU4XCanonicalComposition* self, char32_t starter, char32_t second); +void ICU4XCanonicalComposition_destroy(ICU4XCanonicalComposition* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XCanonicalComposition.hpp b/intl/icu_capi/cpp/include/ICU4XCanonicalComposition.hpp new file mode 100644 index 0000000000..f9e226f0f7 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XCanonicalComposition.hpp @@ -0,0 +1,76 @@ +#ifndef ICU4XCanonicalComposition_HPP +#define ICU4XCanonicalComposition_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XCanonicalComposition.h" + +class ICU4XDataProvider; +class ICU4XCanonicalComposition; +#include "ICU4XError.hpp" + +/** + * A destruction policy for using ICU4XCanonicalComposition with std::unique_ptr. + */ +struct ICU4XCanonicalCompositionDeleter { + void operator()(capi::ICU4XCanonicalComposition* l) const noexcept { + capi::ICU4XCanonicalComposition_destroy(l); + } +}; + +/** + * The raw canonical composition operation. + * + * Callers should generally use ICU4XComposingNormalizer unless they specifically need raw composition operations + * + * See the [Rust documentation for `CanonicalComposition`](https://docs.rs/icu/latest/icu/normalizer/properties/struct.CanonicalComposition.html) for more information. + */ +class ICU4XCanonicalComposition { + public: + + /** + * Construct a new ICU4XCanonicalComposition instance for NFC + * + * See the [Rust documentation for `new`](https://docs.rs/icu/latest/icu/normalizer/properties/struct.CanonicalComposition.html#method.new) for more information. + */ + static diplomat::result<ICU4XCanonicalComposition, ICU4XError> create(const ICU4XDataProvider& provider); + + /** + * Performs canonical composition (including Hangul) on a pair of characters + * or returns NUL if these characters don’t compose. Composition exclusions are taken into account. + * + * See the [Rust documentation for `compose`](https://docs.rs/icu/latest/icu/normalizer/properties/struct.CanonicalComposition.html#method.compose) for more information. + */ + char32_t compose(char32_t starter, char32_t second) const; + inline const capi::ICU4XCanonicalComposition* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XCanonicalComposition* AsFFIMut() { return this->inner.get(); } + inline ICU4XCanonicalComposition(capi::ICU4XCanonicalComposition* i) : inner(i) {} + ICU4XCanonicalComposition() = default; + ICU4XCanonicalComposition(ICU4XCanonicalComposition&&) noexcept = default; + ICU4XCanonicalComposition& operator=(ICU4XCanonicalComposition&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XCanonicalComposition, ICU4XCanonicalCompositionDeleter> inner; +}; + +#include "ICU4XDataProvider.hpp" + +inline diplomat::result<ICU4XCanonicalComposition, ICU4XError> ICU4XCanonicalComposition::create(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCanonicalComposition_create(provider.AsFFI()); + diplomat::result<ICU4XCanonicalComposition, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCanonicalComposition>(ICU4XCanonicalComposition(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline char32_t ICU4XCanonicalComposition::compose(char32_t starter, char32_t second) const { + return capi::ICU4XCanonicalComposition_compose(this->inner.get(), starter, second); +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XCanonicalDecomposition.h b/intl/icu_capi/cpp/include/ICU4XCanonicalDecomposition.h new file mode 100644 index 0000000000..d18d108b90 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XCanonicalDecomposition.h @@ -0,0 +1,34 @@ +#ifndef ICU4XCanonicalDecomposition_H +#define ICU4XCanonicalDecomposition_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XCanonicalDecomposition ICU4XCanonicalDecomposition; +#ifdef __cplusplus +} // namespace capi +#endif +#include "ICU4XDataProvider.h" +#include "diplomat_result_box_ICU4XCanonicalDecomposition_ICU4XError.h" +#include "ICU4XDecomposed.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +diplomat_result_box_ICU4XCanonicalDecomposition_ICU4XError ICU4XCanonicalDecomposition_create(const ICU4XDataProvider* provider); + +ICU4XDecomposed ICU4XCanonicalDecomposition_decompose(const ICU4XCanonicalDecomposition* self, char32_t c); +void ICU4XCanonicalDecomposition_destroy(ICU4XCanonicalDecomposition* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XCanonicalDecomposition.hpp b/intl/icu_capi/cpp/include/ICU4XCanonicalDecomposition.hpp new file mode 100644 index 0000000000..2bbf5abb82 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XCanonicalDecomposition.hpp @@ -0,0 +1,78 @@ +#ifndef ICU4XCanonicalDecomposition_HPP +#define ICU4XCanonicalDecomposition_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XCanonicalDecomposition.h" + +class ICU4XDataProvider; +class ICU4XCanonicalDecomposition; +#include "ICU4XError.hpp" +struct ICU4XDecomposed; + +/** + * A destruction policy for using ICU4XCanonicalDecomposition with std::unique_ptr. + */ +struct ICU4XCanonicalDecompositionDeleter { + void operator()(capi::ICU4XCanonicalDecomposition* l) const noexcept { + capi::ICU4XCanonicalDecomposition_destroy(l); + } +}; + +/** + * The raw (non-recursive) canonical decomposition operation. + * + * Callers should generally use ICU4XDecomposingNormalizer unless they specifically need raw composition operations + * + * See the [Rust documentation for `CanonicalDecomposition`](https://docs.rs/icu/latest/icu/normalizer/properties/struct.CanonicalDecomposition.html) for more information. + */ +class ICU4XCanonicalDecomposition { + public: + + /** + * Construct a new ICU4XCanonicalDecomposition instance for NFC + * + * See the [Rust documentation for `new`](https://docs.rs/icu/latest/icu/normalizer/properties/struct.CanonicalDecomposition.html#method.new) for more information. + */ + static diplomat::result<ICU4XCanonicalDecomposition, ICU4XError> create(const ICU4XDataProvider& provider); + + /** + * Performs non-recursive canonical decomposition (including for Hangul). + * + * See the [Rust documentation for `decompose`](https://docs.rs/icu/latest/icu/normalizer/properties/struct.CanonicalDecomposition.html#method.decompose) for more information. + */ + ICU4XDecomposed decompose(char32_t c) const; + inline const capi::ICU4XCanonicalDecomposition* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XCanonicalDecomposition* AsFFIMut() { return this->inner.get(); } + inline ICU4XCanonicalDecomposition(capi::ICU4XCanonicalDecomposition* i) : inner(i) {} + ICU4XCanonicalDecomposition() = default; + ICU4XCanonicalDecomposition(ICU4XCanonicalDecomposition&&) noexcept = default; + ICU4XCanonicalDecomposition& operator=(ICU4XCanonicalDecomposition&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XCanonicalDecomposition, ICU4XCanonicalDecompositionDeleter> inner; +}; + +#include "ICU4XDataProvider.hpp" +#include "ICU4XDecomposed.hpp" + +inline diplomat::result<ICU4XCanonicalDecomposition, ICU4XError> ICU4XCanonicalDecomposition::create(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCanonicalDecomposition_create(provider.AsFFI()); + diplomat::result<ICU4XCanonicalDecomposition, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCanonicalDecomposition>(ICU4XCanonicalDecomposition(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline ICU4XDecomposed ICU4XCanonicalDecomposition::decompose(char32_t c) const { + capi::ICU4XDecomposed diplomat_raw_struct_out_value = capi::ICU4XCanonicalDecomposition_decompose(this->inner.get(), c); + return ICU4XDecomposed{ .first = std::move(diplomat_raw_struct_out_value.first), .second = std::move(diplomat_raw_struct_out_value.second) }; +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XCaseMapCloser.h b/intl/icu_capi/cpp/include/ICU4XCaseMapCloser.h new file mode 100644 index 0000000000..ed2129006c --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XCaseMapCloser.h @@ -0,0 +1,36 @@ +#ifndef ICU4XCaseMapCloser_H +#define ICU4XCaseMapCloser_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XCaseMapCloser ICU4XCaseMapCloser; +#ifdef __cplusplus +} // namespace capi +#endif +#include "ICU4XDataProvider.h" +#include "diplomat_result_box_ICU4XCaseMapCloser_ICU4XError.h" +#include "ICU4XCodePointSetBuilder.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +diplomat_result_box_ICU4XCaseMapCloser_ICU4XError ICU4XCaseMapCloser_create(const ICU4XDataProvider* provider); + +void ICU4XCaseMapCloser_add_case_closure_to(const ICU4XCaseMapCloser* self, char32_t c, ICU4XCodePointSetBuilder* builder); + +bool ICU4XCaseMapCloser_add_string_case_closure_to(const ICU4XCaseMapCloser* self, const char* s_data, size_t s_len, ICU4XCodePointSetBuilder* builder); +void ICU4XCaseMapCloser_destroy(ICU4XCaseMapCloser* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XCaseMapCloser.hpp b/intl/icu_capi/cpp/include/ICU4XCaseMapCloser.hpp new file mode 100644 index 0000000000..a76167f2df --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XCaseMapCloser.hpp @@ -0,0 +1,87 @@ +#ifndef ICU4XCaseMapCloser_HPP +#define ICU4XCaseMapCloser_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XCaseMapCloser.h" + +class ICU4XDataProvider; +class ICU4XCaseMapCloser; +#include "ICU4XError.hpp" +class ICU4XCodePointSetBuilder; + +/** + * A destruction policy for using ICU4XCaseMapCloser with std::unique_ptr. + */ +struct ICU4XCaseMapCloserDeleter { + void operator()(capi::ICU4XCaseMapCloser* l) const noexcept { + capi::ICU4XCaseMapCloser_destroy(l); + } +}; + +/** + * See the [Rust documentation for `CaseMapCloser`](https://docs.rs/icu/latest/icu/casemap/struct.CaseMapCloser.html) for more information. + */ +class ICU4XCaseMapCloser { + public: + + /** + * Construct a new ICU4XCaseMapper instance + * + * See the [Rust documentation for `new`](https://docs.rs/icu/latest/icu/casemap/struct.CaseMapCloser.html#method.new) for more information. + */ + static diplomat::result<ICU4XCaseMapCloser, ICU4XError> create(const ICU4XDataProvider& provider); + + /** + * Adds all simple case mappings and the full case folding for `c` to `builder`. + * Also adds special case closure mappings. + * + * See the [Rust documentation for `add_case_closure_to`](https://docs.rs/icu/latest/icu/casemap/struct.CaseMapCloser.html#method.add_case_closure_to) for more information. + */ + void add_case_closure_to(char32_t c, ICU4XCodePointSetBuilder& builder) const; + + /** + * Finds all characters and strings which may casemap to `s` as their full case folding string + * and adds them to the set. + * + * Returns true if the string was found + * + * See the [Rust documentation for `add_string_case_closure_to`](https://docs.rs/icu/latest/icu/casemap/struct.CaseMapCloser.html#method.add_string_case_closure_to) for more information. + */ + bool add_string_case_closure_to(const std::string_view s, ICU4XCodePointSetBuilder& builder) const; + inline const capi::ICU4XCaseMapCloser* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XCaseMapCloser* AsFFIMut() { return this->inner.get(); } + inline ICU4XCaseMapCloser(capi::ICU4XCaseMapCloser* i) : inner(i) {} + ICU4XCaseMapCloser() = default; + ICU4XCaseMapCloser(ICU4XCaseMapCloser&&) noexcept = default; + ICU4XCaseMapCloser& operator=(ICU4XCaseMapCloser&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XCaseMapCloser, ICU4XCaseMapCloserDeleter> inner; +}; + +#include "ICU4XDataProvider.hpp" +#include "ICU4XCodePointSetBuilder.hpp" + +inline diplomat::result<ICU4XCaseMapCloser, ICU4XError> ICU4XCaseMapCloser::create(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCaseMapCloser_create(provider.AsFFI()); + diplomat::result<ICU4XCaseMapCloser, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCaseMapCloser>(ICU4XCaseMapCloser(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline void ICU4XCaseMapCloser::add_case_closure_to(char32_t c, ICU4XCodePointSetBuilder& builder) const { + capi::ICU4XCaseMapCloser_add_case_closure_to(this->inner.get(), c, builder.AsFFIMut()); +} +inline bool ICU4XCaseMapCloser::add_string_case_closure_to(const std::string_view s, ICU4XCodePointSetBuilder& builder) const { + return capi::ICU4XCaseMapCloser_add_string_case_closure_to(this->inner.get(), s.data(), s.size(), builder.AsFFIMut()); +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XCaseMapper.h b/intl/icu_capi/cpp/include/ICU4XCaseMapper.h new file mode 100644 index 0000000000..aef264f722 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XCaseMapper.h @@ -0,0 +1,57 @@ +#ifndef ICU4XCaseMapper_H +#define ICU4XCaseMapper_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XCaseMapper ICU4XCaseMapper; +#ifdef __cplusplus +} // namespace capi +#endif +#include "ICU4XDataProvider.h" +#include "diplomat_result_box_ICU4XCaseMapper_ICU4XError.h" +#include "ICU4XLocale.h" +#include "diplomat_result_void_ICU4XError.h" +#include "ICU4XTitlecaseOptionsV1.h" +#include "ICU4XCodePointSetBuilder.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +diplomat_result_box_ICU4XCaseMapper_ICU4XError ICU4XCaseMapper_create(const ICU4XDataProvider* provider); + +diplomat_result_void_ICU4XError ICU4XCaseMapper_lowercase(const ICU4XCaseMapper* self, const char* s_data, size_t s_len, const ICU4XLocale* locale, DiplomatWriteable* write); + +diplomat_result_void_ICU4XError ICU4XCaseMapper_uppercase(const ICU4XCaseMapper* self, const char* s_data, size_t s_len, const ICU4XLocale* locale, DiplomatWriteable* write); + +diplomat_result_void_ICU4XError ICU4XCaseMapper_titlecase_segment_with_only_case_data_v1(const ICU4XCaseMapper* self, const char* s_data, size_t s_len, const ICU4XLocale* locale, ICU4XTitlecaseOptionsV1 options, DiplomatWriteable* write); + +diplomat_result_void_ICU4XError ICU4XCaseMapper_fold(const ICU4XCaseMapper* self, const char* s_data, size_t s_len, DiplomatWriteable* write); + +diplomat_result_void_ICU4XError ICU4XCaseMapper_fold_turkic(const ICU4XCaseMapper* self, const char* s_data, size_t s_len, DiplomatWriteable* write); + +void ICU4XCaseMapper_add_case_closure_to(const ICU4XCaseMapper* self, char32_t c, ICU4XCodePointSetBuilder* builder); + +char32_t ICU4XCaseMapper_simple_lowercase(const ICU4XCaseMapper* self, char32_t ch); + +char32_t ICU4XCaseMapper_simple_uppercase(const ICU4XCaseMapper* self, char32_t ch); + +char32_t ICU4XCaseMapper_simple_titlecase(const ICU4XCaseMapper* self, char32_t ch); + +char32_t ICU4XCaseMapper_simple_fold(const ICU4XCaseMapper* self, char32_t ch); + +char32_t ICU4XCaseMapper_simple_fold_turkic(const ICU4XCaseMapper* self, char32_t ch); +void ICU4XCaseMapper_destroy(ICU4XCaseMapper* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XCaseMapper.hpp b/intl/icu_capi/cpp/include/ICU4XCaseMapper.hpp new file mode 100644 index 0000000000..ffb95b1c22 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XCaseMapper.hpp @@ -0,0 +1,352 @@ +#ifndef ICU4XCaseMapper_HPP +#define ICU4XCaseMapper_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XCaseMapper.h" + +class ICU4XDataProvider; +class ICU4XCaseMapper; +#include "ICU4XError.hpp" +class ICU4XLocale; +struct ICU4XTitlecaseOptionsV1; +class ICU4XCodePointSetBuilder; + +/** + * A destruction policy for using ICU4XCaseMapper with std::unique_ptr. + */ +struct ICU4XCaseMapperDeleter { + void operator()(capi::ICU4XCaseMapper* l) const noexcept { + capi::ICU4XCaseMapper_destroy(l); + } +}; + +/** + * See the [Rust documentation for `CaseMapper`](https://docs.rs/icu/latest/icu/casemap/struct.CaseMapper.html) for more information. + */ +class ICU4XCaseMapper { + public: + + /** + * Construct a new ICU4XCaseMapper instance + * + * See the [Rust documentation for `new`](https://docs.rs/icu/latest/icu/casemap/struct.CaseMapper.html#method.new) for more information. + */ + static diplomat::result<ICU4XCaseMapper, ICU4XError> create(const ICU4XDataProvider& provider); + + /** + * Returns the full lowercase mapping of the given string + * + * See the [Rust documentation for `lowercase`](https://docs.rs/icu/latest/icu/casemap/struct.CaseMapper.html#method.lowercase) for more information. + */ + template<typename W> diplomat::result<std::monostate, ICU4XError> lowercase_to_writeable(const std::string_view s, const ICU4XLocale& locale, W& write) const; + + /** + * Returns the full lowercase mapping of the given string + * + * See the [Rust documentation for `lowercase`](https://docs.rs/icu/latest/icu/casemap/struct.CaseMapper.html#method.lowercase) for more information. + */ + diplomat::result<std::string, ICU4XError> lowercase(const std::string_view s, const ICU4XLocale& locale) const; + + /** + * Returns the full uppercase mapping of the given string + * + * See the [Rust documentation for `uppercase`](https://docs.rs/icu/latest/icu/casemap/struct.CaseMapper.html#method.uppercase) for more information. + */ + template<typename W> diplomat::result<std::monostate, ICU4XError> uppercase_to_writeable(const std::string_view s, const ICU4XLocale& locale, W& write) const; + + /** + * Returns the full uppercase mapping of the given string + * + * See the [Rust documentation for `uppercase`](https://docs.rs/icu/latest/icu/casemap/struct.CaseMapper.html#method.uppercase) for more information. + */ + diplomat::result<std::string, ICU4XError> uppercase(const std::string_view s, const ICU4XLocale& locale) const; + + /** + * Returns the full titlecase mapping of the given string, performing head adjustment without + * loading additional data. + * (if head adjustment is enabled in the options) + * + * The `v1` refers to the version of the options struct, which may change as we add more options + * + * See the [Rust documentation for `titlecase_segment_with_only_case_data`](https://docs.rs/icu/latest/icu/casemap/struct.CaseMapper.html#method.titlecase_segment_with_only_case_data) for more information. + */ + template<typename W> diplomat::result<std::monostate, ICU4XError> titlecase_segment_with_only_case_data_v1_to_writeable(const std::string_view s, const ICU4XLocale& locale, ICU4XTitlecaseOptionsV1 options, W& write) const; + + /** + * Returns the full titlecase mapping of the given string, performing head adjustment without + * loading additional data. + * (if head adjustment is enabled in the options) + * + * The `v1` refers to the version of the options struct, which may change as we add more options + * + * See the [Rust documentation for `titlecase_segment_with_only_case_data`](https://docs.rs/icu/latest/icu/casemap/struct.CaseMapper.html#method.titlecase_segment_with_only_case_data) for more information. + */ + diplomat::result<std::string, ICU4XError> titlecase_segment_with_only_case_data_v1(const std::string_view s, const ICU4XLocale& locale, ICU4XTitlecaseOptionsV1 options) const; + + /** + * Case-folds the characters in the given string + * + * See the [Rust documentation for `fold`](https://docs.rs/icu/latest/icu/casemap/struct.CaseMapper.html#method.fold) for more information. + */ + template<typename W> diplomat::result<std::monostate, ICU4XError> fold_to_writeable(const std::string_view s, W& write) const; + + /** + * Case-folds the characters in the given string + * + * See the [Rust documentation for `fold`](https://docs.rs/icu/latest/icu/casemap/struct.CaseMapper.html#method.fold) for more information. + */ + diplomat::result<std::string, ICU4XError> fold(const std::string_view s) const; + + /** + * Case-folds the characters in the given string + * using Turkic (T) mappings for dotted/dotless I. + * + * See the [Rust documentation for `fold_turkic`](https://docs.rs/icu/latest/icu/casemap/struct.CaseMapper.html#method.fold_turkic) for more information. + */ + template<typename W> diplomat::result<std::monostate, ICU4XError> fold_turkic_to_writeable(const std::string_view s, W& write) const; + + /** + * Case-folds the characters in the given string + * using Turkic (T) mappings for dotted/dotless I. + * + * See the [Rust documentation for `fold_turkic`](https://docs.rs/icu/latest/icu/casemap/struct.CaseMapper.html#method.fold_turkic) for more information. + */ + diplomat::result<std::string, ICU4XError> fold_turkic(const std::string_view s) const; + + /** + * Adds all simple case mappings and the full case folding for `c` to `builder`. + * Also adds special case closure mappings. + * + * In other words, this adds all characters that this casemaps to, as + * well as all characters that may casemap to this one. + * + * Note that since ICU4XCodePointSetBuilder does not contain strings, this will + * ignore string mappings. + * + * Identical to the similarly named method on `ICU4XCaseMapCloser`, use that if you + * plan on using string case closure mappings too. + * + * See the [Rust documentation for `add_case_closure_to`](https://docs.rs/icu/latest/icu/casemap/struct.CaseMapper.html#method.add_case_closure_to) for more information. + */ + void add_case_closure_to(char32_t c, ICU4XCodePointSetBuilder& builder) const; + + /** + * Returns the simple lowercase mapping of the given character. + * + * This function only implements simple and common mappings. + * Full mappings, which can map one char to a string, are not included. + * For full mappings, use `ICU4XCaseMapper::lowercase`. + * + * See the [Rust documentation for `simple_lowercase`](https://docs.rs/icu/latest/icu/casemap/struct.CaseMapper.html#method.simple_lowercase) for more information. + */ + char32_t simple_lowercase(char32_t ch) const; + + /** + * Returns the simple uppercase mapping of the given character. + * + * This function only implements simple and common mappings. + * Full mappings, which can map one char to a string, are not included. + * For full mappings, use `ICU4XCaseMapper::uppercase`. + * + * See the [Rust documentation for `simple_uppercase`](https://docs.rs/icu/latest/icu/casemap/struct.CaseMapper.html#method.simple_uppercase) for more information. + */ + char32_t simple_uppercase(char32_t ch) const; + + /** + * Returns the simple titlecase mapping of the given character. + * + * This function only implements simple and common mappings. + * Full mappings, which can map one char to a string, are not included. + * For full mappings, use `ICU4XCaseMapper::titlecase_segment`. + * + * See the [Rust documentation for `simple_titlecase`](https://docs.rs/icu/latest/icu/casemap/struct.CaseMapper.html#method.simple_titlecase) for more information. + */ + char32_t simple_titlecase(char32_t ch) const; + + /** + * Returns the simple casefolding of the given character. + * + * This function only implements simple folding. + * For full folding, use `ICU4XCaseMapper::fold`. + * + * See the [Rust documentation for `simple_fold`](https://docs.rs/icu/latest/icu/casemap/struct.CaseMapper.html#method.simple_fold) for more information. + */ + char32_t simple_fold(char32_t ch) const; + + /** + * Returns the simple casefolding of the given character in the Turkic locale + * + * This function only implements simple folding. + * For full folding, use `ICU4XCaseMapper::fold_turkic`. + * + * See the [Rust documentation for `simple_fold_turkic`](https://docs.rs/icu/latest/icu/casemap/struct.CaseMapper.html#method.simple_fold_turkic) for more information. + */ + char32_t simple_fold_turkic(char32_t ch) const; + inline const capi::ICU4XCaseMapper* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XCaseMapper* AsFFIMut() { return this->inner.get(); } + inline ICU4XCaseMapper(capi::ICU4XCaseMapper* i) : inner(i) {} + ICU4XCaseMapper() = default; + ICU4XCaseMapper(ICU4XCaseMapper&&) noexcept = default; + ICU4XCaseMapper& operator=(ICU4XCaseMapper&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XCaseMapper, ICU4XCaseMapperDeleter> inner; +}; + +#include "ICU4XDataProvider.hpp" +#include "ICU4XLocale.hpp" +#include "ICU4XTitlecaseOptionsV1.hpp" +#include "ICU4XCodePointSetBuilder.hpp" + +inline diplomat::result<ICU4XCaseMapper, ICU4XError> ICU4XCaseMapper::create(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCaseMapper_create(provider.AsFFI()); + diplomat::result<ICU4XCaseMapper, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCaseMapper>(ICU4XCaseMapper(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XCaseMapper::lowercase_to_writeable(const std::string_view s, const ICU4XLocale& locale, W& write) const { + capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write); + auto diplomat_result_raw_out_value = capi::ICU4XCaseMapper_lowercase(this->inner.get(), s.data(), s.size(), locale.AsFFI(), &write_writer); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<std::string, ICU4XError> ICU4XCaseMapper::lowercase(const std::string_view s, const ICU4XLocale& locale) const { + std::string diplomat_writeable_string; + capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); + auto diplomat_result_raw_out_value = capi::ICU4XCaseMapper_lowercase(this->inner.get(), s.data(), s.size(), locale.AsFFI(), &diplomat_writeable_out); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string)); +} +template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XCaseMapper::uppercase_to_writeable(const std::string_view s, const ICU4XLocale& locale, W& write) const { + capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write); + auto diplomat_result_raw_out_value = capi::ICU4XCaseMapper_uppercase(this->inner.get(), s.data(), s.size(), locale.AsFFI(), &write_writer); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<std::string, ICU4XError> ICU4XCaseMapper::uppercase(const std::string_view s, const ICU4XLocale& locale) const { + std::string diplomat_writeable_string; + capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); + auto diplomat_result_raw_out_value = capi::ICU4XCaseMapper_uppercase(this->inner.get(), s.data(), s.size(), locale.AsFFI(), &diplomat_writeable_out); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string)); +} +template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XCaseMapper::titlecase_segment_with_only_case_data_v1_to_writeable(const std::string_view s, const ICU4XLocale& locale, ICU4XTitlecaseOptionsV1 options, W& write) const { + ICU4XTitlecaseOptionsV1 diplomat_wrapped_struct_options = options; + capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write); + auto diplomat_result_raw_out_value = capi::ICU4XCaseMapper_titlecase_segment_with_only_case_data_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); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<std::string, ICU4XError> ICU4XCaseMapper::titlecase_segment_with_only_case_data_v1(const std::string_view s, const ICU4XLocale& locale, ICU4XTitlecaseOptionsV1 options) const { + ICU4XTitlecaseOptionsV1 diplomat_wrapped_struct_options = options; + std::string diplomat_writeable_string; + capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); + auto diplomat_result_raw_out_value = capi::ICU4XCaseMapper_titlecase_segment_with_only_case_data_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); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string)); +} +template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XCaseMapper::fold_to_writeable(const std::string_view s, W& write) const { + capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write); + auto diplomat_result_raw_out_value = capi::ICU4XCaseMapper_fold(this->inner.get(), s.data(), s.size(), &write_writer); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<std::string, ICU4XError> ICU4XCaseMapper::fold(const std::string_view s) const { + std::string diplomat_writeable_string; + capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); + auto diplomat_result_raw_out_value = capi::ICU4XCaseMapper_fold(this->inner.get(), s.data(), s.size(), &diplomat_writeable_out); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string)); +} +template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XCaseMapper::fold_turkic_to_writeable(const std::string_view s, W& write) const { + capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write); + auto diplomat_result_raw_out_value = capi::ICU4XCaseMapper_fold_turkic(this->inner.get(), s.data(), s.size(), &write_writer); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<std::string, ICU4XError> ICU4XCaseMapper::fold_turkic(const std::string_view s) const { + std::string diplomat_writeable_string; + capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); + auto diplomat_result_raw_out_value = capi::ICU4XCaseMapper_fold_turkic(this->inner.get(), s.data(), s.size(), &diplomat_writeable_out); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string)); +} +inline void ICU4XCaseMapper::add_case_closure_to(char32_t c, ICU4XCodePointSetBuilder& builder) const { + capi::ICU4XCaseMapper_add_case_closure_to(this->inner.get(), c, builder.AsFFIMut()); +} +inline char32_t ICU4XCaseMapper::simple_lowercase(char32_t ch) const { + return capi::ICU4XCaseMapper_simple_lowercase(this->inner.get(), ch); +} +inline char32_t ICU4XCaseMapper::simple_uppercase(char32_t ch) const { + return capi::ICU4XCaseMapper_simple_uppercase(this->inner.get(), ch); +} +inline char32_t ICU4XCaseMapper::simple_titlecase(char32_t ch) const { + return capi::ICU4XCaseMapper_simple_titlecase(this->inner.get(), ch); +} +inline char32_t ICU4XCaseMapper::simple_fold(char32_t ch) const { + return capi::ICU4XCaseMapper_simple_fold(this->inner.get(), ch); +} +inline char32_t ICU4XCaseMapper::simple_fold_turkic(char32_t ch) const { + return capi::ICU4XCaseMapper_simple_fold_turkic(this->inner.get(), ch); +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XCodePointMapData16.h b/intl/icu_capi/cpp/include/ICU4XCodePointMapData16.h new file mode 100644 index 0000000000..19effe2d92 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XCodePointMapData16.h @@ -0,0 +1,43 @@ +#ifndef ICU4XCodePointMapData16_H +#define ICU4XCodePointMapData16_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XCodePointMapData16 ICU4XCodePointMapData16; +#ifdef __cplusplus +} // namespace capi +#endif +#include "CodePointRangeIterator.h" +#include "ICU4XCodePointSetData.h" +#include "ICU4XDataProvider.h" +#include "diplomat_result_box_ICU4XCodePointMapData16_ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +uint16_t ICU4XCodePointMapData16_get(const ICU4XCodePointMapData16* self, char32_t cp); + +uint16_t ICU4XCodePointMapData16_get32(const ICU4XCodePointMapData16* self, uint32_t cp); + +CodePointRangeIterator* ICU4XCodePointMapData16_iter_ranges_for_value(const ICU4XCodePointMapData16* self, uint16_t value); + +CodePointRangeIterator* ICU4XCodePointMapData16_iter_ranges_for_value_complemented(const ICU4XCodePointMapData16* self, uint16_t value); + +ICU4XCodePointSetData* ICU4XCodePointMapData16_get_set_for_value(const ICU4XCodePointMapData16* self, uint16_t value); + +diplomat_result_box_ICU4XCodePointMapData16_ICU4XError ICU4XCodePointMapData16_load_script(const ICU4XDataProvider* provider); +void ICU4XCodePointMapData16_destroy(ICU4XCodePointMapData16* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XCodePointMapData16.hpp b/intl/icu_capi/cpp/include/ICU4XCodePointMapData16.hpp new file mode 100644 index 0000000000..3bdefb51f6 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XCodePointMapData16.hpp @@ -0,0 +1,123 @@ +#ifndef ICU4XCodePointMapData16_HPP +#define ICU4XCodePointMapData16_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XCodePointMapData16.h" + +class CodePointRangeIterator; +class ICU4XCodePointSetData; +class ICU4XDataProvider; +class ICU4XCodePointMapData16; +#include "ICU4XError.hpp" + +/** + * A destruction policy for using ICU4XCodePointMapData16 with std::unique_ptr. + */ +struct ICU4XCodePointMapData16Deleter { + void operator()(capi::ICU4XCodePointMapData16* l) const noexcept { + capi::ICU4XCodePointMapData16_destroy(l); + } +}; + +/** + * An ICU4X Unicode Map Property object, capable of querying whether a code point (key) to obtain the Unicode property value, for a specific Unicode property. + * + * For properties whose values fit into 16 bits. + * + * See the [Rust documentation for `properties`](https://docs.rs/icu/latest/icu/properties/index.html) for more information. + * + * See the [Rust documentation for `CodePointMapData`](https://docs.rs/icu/latest/icu/properties/maps/struct.CodePointMapData.html) for more information. + * + * See the [Rust documentation for `CodePointMapDataBorrowed`](https://docs.rs/icu/latest/icu/properties/maps/struct.CodePointMapDataBorrowed.html) for more information. + */ +class ICU4XCodePointMapData16 { + public: + + /** + * Gets the value for a code point. + * + * See the [Rust documentation for `get`](https://docs.rs/icu/latest/icu/properties/maps/struct.CodePointMapDataBorrowed.html#method.get) for more information. + */ + uint16_t get(char32_t cp) const; + + /** + * Gets the value for a code point (specified as a 32 bit integer, in UTF-32) + */ + uint16_t get32(uint32_t cp) const; + + /** + * Produces an iterator over ranges of code points that map to `value` + * + * See the [Rust documentation for `iter_ranges_for_value`](https://docs.rs/icu/latest/icu/properties/maps/struct.CodePointMapDataBorrowed.html#method.iter_ranges_for_value) for more information. + * + * Lifetimes: `this` must live at least as long as the output. + */ + CodePointRangeIterator iter_ranges_for_value(uint16_t value) const; + + /** + * Produces an iterator over ranges of code points that do not map to `value` + * + * See the [Rust documentation for `iter_ranges_for_value_complemented`](https://docs.rs/icu/latest/icu/properties/maps/struct.CodePointMapDataBorrowed.html#method.iter_ranges_for_value_complemented) for more information. + * + * Lifetimes: `this` must live at least as long as the output. + */ + CodePointRangeIterator iter_ranges_for_value_complemented(uint16_t value) const; + + /** + * Gets a [`ICU4XCodePointSetData`] representing all entries in this map that map to the given value + * + * See the [Rust documentation for `get_set_for_value`](https://docs.rs/icu/latest/icu/properties/maps/struct.CodePointMapDataBorrowed.html#method.get_set_for_value) for more information. + */ + ICU4XCodePointSetData get_set_for_value(uint16_t value) const; + + /** + * See the [Rust documentation for `script`](https://docs.rs/icu/latest/icu/properties/maps/fn.script.html) for more information. + */ + static diplomat::result<ICU4XCodePointMapData16, ICU4XError> load_script(const ICU4XDataProvider& provider); + inline const capi::ICU4XCodePointMapData16* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XCodePointMapData16* AsFFIMut() { return this->inner.get(); } + inline ICU4XCodePointMapData16(capi::ICU4XCodePointMapData16* i) : inner(i) {} + ICU4XCodePointMapData16() = default; + ICU4XCodePointMapData16(ICU4XCodePointMapData16&&) noexcept = default; + ICU4XCodePointMapData16& operator=(ICU4XCodePointMapData16&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XCodePointMapData16, ICU4XCodePointMapData16Deleter> inner; +}; + +#include "CodePointRangeIterator.hpp" +#include "ICU4XCodePointSetData.hpp" +#include "ICU4XDataProvider.hpp" + +inline uint16_t ICU4XCodePointMapData16::get(char32_t cp) const { + return capi::ICU4XCodePointMapData16_get(this->inner.get(), cp); +} +inline uint16_t ICU4XCodePointMapData16::get32(uint32_t cp) const { + return capi::ICU4XCodePointMapData16_get32(this->inner.get(), cp); +} +inline CodePointRangeIterator ICU4XCodePointMapData16::iter_ranges_for_value(uint16_t value) const { + return CodePointRangeIterator(capi::ICU4XCodePointMapData16_iter_ranges_for_value(this->inner.get(), value)); +} +inline CodePointRangeIterator ICU4XCodePointMapData16::iter_ranges_for_value_complemented(uint16_t value) const { + return CodePointRangeIterator(capi::ICU4XCodePointMapData16_iter_ranges_for_value_complemented(this->inner.get(), value)); +} +inline ICU4XCodePointSetData ICU4XCodePointMapData16::get_set_for_value(uint16_t value) const { + return ICU4XCodePointSetData(capi::ICU4XCodePointMapData16_get_set_for_value(this->inner.get(), value)); +} +inline diplomat::result<ICU4XCodePointMapData16, ICU4XError> ICU4XCodePointMapData16::load_script(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointMapData16_load_script(provider.AsFFI()); + diplomat::result<ICU4XCodePointMapData16, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointMapData16>(ICU4XCodePointMapData16(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XCodePointMapData8.h b/intl/icu_capi/cpp/include/ICU4XCodePointMapData8.h new file mode 100644 index 0000000000..87fe8854b2 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XCodePointMapData8.h @@ -0,0 +1,61 @@ +#ifndef ICU4XCodePointMapData8_H +#define ICU4XCodePointMapData8_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XCodePointMapData8 ICU4XCodePointMapData8; +#ifdef __cplusplus +} // namespace capi +#endif +#include "CodePointRangeIterator.h" +#include "ICU4XCodePointSetData.h" +#include "ICU4XDataProvider.h" +#include "diplomat_result_box_ICU4XCodePointMapData8_ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +uint8_t ICU4XCodePointMapData8_get(const ICU4XCodePointMapData8* self, char32_t cp); + +uint8_t ICU4XCodePointMapData8_get32(const ICU4XCodePointMapData8* self, uint32_t cp); + +uint32_t ICU4XCodePointMapData8_general_category_to_mask(uint8_t gc); + +CodePointRangeIterator* ICU4XCodePointMapData8_iter_ranges_for_value(const ICU4XCodePointMapData8* self, uint8_t value); + +CodePointRangeIterator* ICU4XCodePointMapData8_iter_ranges_for_value_complemented(const ICU4XCodePointMapData8* self, uint8_t value); + +CodePointRangeIterator* ICU4XCodePointMapData8_iter_ranges_for_mask(const ICU4XCodePointMapData8* self, uint32_t mask); + +ICU4XCodePointSetData* ICU4XCodePointMapData8_get_set_for_value(const ICU4XCodePointMapData8* self, uint8_t value); + +diplomat_result_box_ICU4XCodePointMapData8_ICU4XError ICU4XCodePointMapData8_load_general_category(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointMapData8_ICU4XError ICU4XCodePointMapData8_load_bidi_class(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointMapData8_ICU4XError ICU4XCodePointMapData8_load_east_asian_width(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointMapData8_ICU4XError ICU4XCodePointMapData8_load_indic_syllabic_category(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointMapData8_ICU4XError ICU4XCodePointMapData8_load_line_break(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointMapData8_ICU4XError ICU4XCodePointMapData8_try_grapheme_cluster_break(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointMapData8_ICU4XError ICU4XCodePointMapData8_load_word_break(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointMapData8_ICU4XError ICU4XCodePointMapData8_load_sentence_break(const ICU4XDataProvider* provider); +void ICU4XCodePointMapData8_destroy(ICU4XCodePointMapData8* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XCodePointMapData8.hpp b/intl/icu_capi/cpp/include/ICU4XCodePointMapData8.hpp new file mode 100644 index 0000000000..7631375f15 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XCodePointMapData8.hpp @@ -0,0 +1,259 @@ +#ifndef ICU4XCodePointMapData8_HPP +#define ICU4XCodePointMapData8_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XCodePointMapData8.h" + +class CodePointRangeIterator; +class ICU4XCodePointSetData; +class ICU4XDataProvider; +class ICU4XCodePointMapData8; +#include "ICU4XError.hpp" + +/** + * A destruction policy for using ICU4XCodePointMapData8 with std::unique_ptr. + */ +struct ICU4XCodePointMapData8Deleter { + void operator()(capi::ICU4XCodePointMapData8* l) const noexcept { + capi::ICU4XCodePointMapData8_destroy(l); + } +}; + +/** + * An ICU4X Unicode Map Property object, capable of querying whether a code point (key) to obtain the Unicode property value, for a specific Unicode property. + * + * For properties whose values fit into 8 bits. + * + * See the [Rust documentation for `properties`](https://docs.rs/icu/latest/icu/properties/index.html) for more information. + * + * See the [Rust documentation for `CodePointMapData`](https://docs.rs/icu/latest/icu/properties/maps/struct.CodePointMapData.html) for more information. + * + * See the [Rust documentation for `CodePointMapDataBorrowed`](https://docs.rs/icu/latest/icu/properties/maps/struct.CodePointMapDataBorrowed.html) for more information. + */ +class ICU4XCodePointMapData8 { + public: + + /** + * Gets the value for a code point. + * + * See the [Rust documentation for `get`](https://docs.rs/icu/latest/icu/properties/maps/struct.CodePointMapDataBorrowed.html#method.get) for more information. + */ + uint8_t get(char32_t cp) const; + + /** + * Gets the value for a code point (specified as a 32 bit integer, in UTF-32) + */ + uint8_t get32(uint32_t cp) const; + + /** + * Converts a general category to its corresponding mask value + * + * Nonexistant general categories will map to the empty mask + * + * See the [Rust documentation for `GeneralCategoryGroup`](https://docs.rs/icu/latest/icu/properties/struct.GeneralCategoryGroup.html) for more information. + */ + static uint32_t general_category_to_mask(uint8_t gc); + + /** + * Produces an iterator over ranges of code points that map to `value` + * + * See the [Rust documentation for `iter_ranges_for_value`](https://docs.rs/icu/latest/icu/properties/maps/struct.CodePointMapDataBorrowed.html#method.iter_ranges_for_value) for more information. + * + * Lifetimes: `this` must live at least as long as the output. + */ + CodePointRangeIterator iter_ranges_for_value(uint8_t value) const; + + /** + * Produces an iterator over ranges of code points that do not map to `value` + * + * See the [Rust documentation for `iter_ranges_for_value_complemented`](https://docs.rs/icu/latest/icu/properties/maps/struct.CodePointMapDataBorrowed.html#method.iter_ranges_for_value_complemented) for more information. + * + * Lifetimes: `this` must live at least as long as the output. + */ + CodePointRangeIterator iter_ranges_for_value_complemented(uint8_t value) const; + + /** + * Given a mask value (the nth bit marks property value = n), produce an iterator over ranges of code points + * whose property values are contained in the mask. + * + * The main mask property supported is that for General_Category, which can be obtained via `general_category_to_mask()` or + * by using `ICU4XGeneralCategoryNameToMaskMapper` + * + * Should only be used on maps for properties with values less than 32 (like Generak_Category), + * other maps will have unpredictable results + * + * See the [Rust documentation for `iter_ranges_for_group`](https://docs.rs/icu/latest/icu/properties/maps/struct.CodePointMapDataBorrowed.html#method.iter_ranges_for_group) for more information. + * + * Lifetimes: `this` must live at least as long as the output. + */ + CodePointRangeIterator iter_ranges_for_mask(uint32_t mask) const; + + /** + * Gets a [`ICU4XCodePointSetData`] representing all entries in this map that map to the given value + * + * See the [Rust documentation for `get_set_for_value`](https://docs.rs/icu/latest/icu/properties/maps/struct.CodePointMapDataBorrowed.html#method.get_set_for_value) for more information. + */ + ICU4XCodePointSetData get_set_for_value(uint8_t value) const; + + /** + * See the [Rust documentation for `general_category`](https://docs.rs/icu/latest/icu/properties/maps/fn.general_category.html) for more information. + */ + static diplomat::result<ICU4XCodePointMapData8, ICU4XError> load_general_category(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `bidi_class`](https://docs.rs/icu/latest/icu/properties/maps/fn.bidi_class.html) for more information. + */ + static diplomat::result<ICU4XCodePointMapData8, ICU4XError> load_bidi_class(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `east_asian_width`](https://docs.rs/icu/latest/icu/properties/maps/fn.east_asian_width.html) for more information. + */ + static diplomat::result<ICU4XCodePointMapData8, ICU4XError> load_east_asian_width(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `indic_syllabic_category`](https://docs.rs/icu/latest/icu/properties/maps/fn.indic_syllabic_category.html) for more information. + */ + static diplomat::result<ICU4XCodePointMapData8, ICU4XError> load_indic_syllabic_category(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `line_break`](https://docs.rs/icu/latest/icu/properties/maps/fn.line_break.html) for more information. + */ + static diplomat::result<ICU4XCodePointMapData8, ICU4XError> load_line_break(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `grapheme_cluster_break`](https://docs.rs/icu/latest/icu/properties/maps/fn.grapheme_cluster_break.html) for more information. + */ + static diplomat::result<ICU4XCodePointMapData8, ICU4XError> try_grapheme_cluster_break(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `word_break`](https://docs.rs/icu/latest/icu/properties/maps/fn.word_break.html) for more information. + */ + static diplomat::result<ICU4XCodePointMapData8, ICU4XError> load_word_break(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `sentence_break`](https://docs.rs/icu/latest/icu/properties/maps/fn.sentence_break.html) for more information. + */ + static diplomat::result<ICU4XCodePointMapData8, ICU4XError> load_sentence_break(const ICU4XDataProvider& provider); + inline const capi::ICU4XCodePointMapData8* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XCodePointMapData8* AsFFIMut() { return this->inner.get(); } + inline ICU4XCodePointMapData8(capi::ICU4XCodePointMapData8* i) : inner(i) {} + ICU4XCodePointMapData8() = default; + ICU4XCodePointMapData8(ICU4XCodePointMapData8&&) noexcept = default; + ICU4XCodePointMapData8& operator=(ICU4XCodePointMapData8&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XCodePointMapData8, ICU4XCodePointMapData8Deleter> inner; +}; + +#include "CodePointRangeIterator.hpp" +#include "ICU4XCodePointSetData.hpp" +#include "ICU4XDataProvider.hpp" + +inline uint8_t ICU4XCodePointMapData8::get(char32_t cp) const { + return capi::ICU4XCodePointMapData8_get(this->inner.get(), cp); +} +inline uint8_t ICU4XCodePointMapData8::get32(uint32_t cp) const { + return capi::ICU4XCodePointMapData8_get32(this->inner.get(), cp); +} +inline uint32_t ICU4XCodePointMapData8::general_category_to_mask(uint8_t gc) { + return capi::ICU4XCodePointMapData8_general_category_to_mask(gc); +} +inline CodePointRangeIterator ICU4XCodePointMapData8::iter_ranges_for_value(uint8_t value) const { + return CodePointRangeIterator(capi::ICU4XCodePointMapData8_iter_ranges_for_value(this->inner.get(), value)); +} +inline CodePointRangeIterator ICU4XCodePointMapData8::iter_ranges_for_value_complemented(uint8_t value) const { + return CodePointRangeIterator(capi::ICU4XCodePointMapData8_iter_ranges_for_value_complemented(this->inner.get(), value)); +} +inline CodePointRangeIterator ICU4XCodePointMapData8::iter_ranges_for_mask(uint32_t mask) const { + return CodePointRangeIterator(capi::ICU4XCodePointMapData8_iter_ranges_for_mask(this->inner.get(), mask)); +} +inline ICU4XCodePointSetData ICU4XCodePointMapData8::get_set_for_value(uint8_t value) const { + return ICU4XCodePointSetData(capi::ICU4XCodePointMapData8_get_set_for_value(this->inner.get(), value)); +} +inline diplomat::result<ICU4XCodePointMapData8, ICU4XError> ICU4XCodePointMapData8::load_general_category(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointMapData8_load_general_category(provider.AsFFI()); + diplomat::result<ICU4XCodePointMapData8, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointMapData8>(ICU4XCodePointMapData8(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointMapData8, ICU4XError> ICU4XCodePointMapData8::load_bidi_class(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointMapData8_load_bidi_class(provider.AsFFI()); + diplomat::result<ICU4XCodePointMapData8, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointMapData8>(ICU4XCodePointMapData8(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointMapData8, ICU4XError> ICU4XCodePointMapData8::load_east_asian_width(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointMapData8_load_east_asian_width(provider.AsFFI()); + diplomat::result<ICU4XCodePointMapData8, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointMapData8>(ICU4XCodePointMapData8(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointMapData8, ICU4XError> ICU4XCodePointMapData8::load_indic_syllabic_category(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointMapData8_load_indic_syllabic_category(provider.AsFFI()); + diplomat::result<ICU4XCodePointMapData8, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointMapData8>(ICU4XCodePointMapData8(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointMapData8, ICU4XError> ICU4XCodePointMapData8::load_line_break(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointMapData8_load_line_break(provider.AsFFI()); + diplomat::result<ICU4XCodePointMapData8, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointMapData8>(ICU4XCodePointMapData8(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointMapData8, ICU4XError> ICU4XCodePointMapData8::try_grapheme_cluster_break(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointMapData8_try_grapheme_cluster_break(provider.AsFFI()); + diplomat::result<ICU4XCodePointMapData8, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointMapData8>(ICU4XCodePointMapData8(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointMapData8, ICU4XError> ICU4XCodePointMapData8::load_word_break(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointMapData8_load_word_break(provider.AsFFI()); + diplomat::result<ICU4XCodePointMapData8, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointMapData8>(ICU4XCodePointMapData8(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointMapData8, ICU4XError> ICU4XCodePointMapData8::load_sentence_break(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointMapData8_load_sentence_break(provider.AsFFI()); + diplomat::result<ICU4XCodePointMapData8, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointMapData8>(ICU4XCodePointMapData8(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XCodePointSetBuilder.h b/intl/icu_capi/cpp/include/ICU4XCodePointSetBuilder.h new file mode 100644 index 0000000000..d36697c7cf --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XCodePointSetBuilder.h @@ -0,0 +1,64 @@ +#ifndef ICU4XCodePointSetBuilder_H +#define ICU4XCodePointSetBuilder_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XCodePointSetBuilder ICU4XCodePointSetBuilder; +#ifdef __cplusplus +} // namespace capi +#endif +#include "ICU4XCodePointSetData.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +ICU4XCodePointSetBuilder* ICU4XCodePointSetBuilder_create(); + +ICU4XCodePointSetData* ICU4XCodePointSetBuilder_build(ICU4XCodePointSetBuilder* self); + +void ICU4XCodePointSetBuilder_complement(ICU4XCodePointSetBuilder* self); + +bool ICU4XCodePointSetBuilder_is_empty(const ICU4XCodePointSetBuilder* self); + +void ICU4XCodePointSetBuilder_add_char(ICU4XCodePointSetBuilder* self, char32_t ch); + +void ICU4XCodePointSetBuilder_add_u32(ICU4XCodePointSetBuilder* self, uint32_t ch); + +void ICU4XCodePointSetBuilder_add_inclusive_range(ICU4XCodePointSetBuilder* self, char32_t start, char32_t end); + +void ICU4XCodePointSetBuilder_add_inclusive_range_u32(ICU4XCodePointSetBuilder* self, uint32_t start, uint32_t end); + +void ICU4XCodePointSetBuilder_add_set(ICU4XCodePointSetBuilder* self, const ICU4XCodePointSetData* data); + +void ICU4XCodePointSetBuilder_remove_char(ICU4XCodePointSetBuilder* self, char32_t ch); + +void ICU4XCodePointSetBuilder_remove_inclusive_range(ICU4XCodePointSetBuilder* self, char32_t start, char32_t end); + +void ICU4XCodePointSetBuilder_remove_set(ICU4XCodePointSetBuilder* self, const ICU4XCodePointSetData* data); + +void ICU4XCodePointSetBuilder_retain_char(ICU4XCodePointSetBuilder* self, char32_t ch); + +void ICU4XCodePointSetBuilder_retain_inclusive_range(ICU4XCodePointSetBuilder* self, char32_t start, char32_t end); + +void ICU4XCodePointSetBuilder_retain_set(ICU4XCodePointSetBuilder* self, const ICU4XCodePointSetData* data); + +void ICU4XCodePointSetBuilder_complement_char(ICU4XCodePointSetBuilder* self, char32_t ch); + +void ICU4XCodePointSetBuilder_complement_inclusive_range(ICU4XCodePointSetBuilder* self, char32_t start, char32_t end); + +void ICU4XCodePointSetBuilder_complement_set(ICU4XCodePointSetBuilder* self, const ICU4XCodePointSetData* data); +void ICU4XCodePointSetBuilder_destroy(ICU4XCodePointSetBuilder* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XCodePointSetBuilder.hpp b/intl/icu_capi/cpp/include/ICU4XCodePointSetBuilder.hpp new file mode 100644 index 0000000000..bf77eb56a4 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XCodePointSetBuilder.hpp @@ -0,0 +1,233 @@ +#ifndef ICU4XCodePointSetBuilder_HPP +#define ICU4XCodePointSetBuilder_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XCodePointSetBuilder.h" + +class ICU4XCodePointSetBuilder; +class ICU4XCodePointSetData; + +/** + * A destruction policy for using ICU4XCodePointSetBuilder with std::unique_ptr. + */ +struct ICU4XCodePointSetBuilderDeleter { + void operator()(capi::ICU4XCodePointSetBuilder* l) const noexcept { + capi::ICU4XCodePointSetBuilder_destroy(l); + } +}; + +/** + * See the [Rust documentation for `CodePointInversionListBuilder`](https://docs.rs/icu/latest/icu/collections/codepointinvlist/struct.CodePointInversionListBuilder.html) for more information. + */ +class ICU4XCodePointSetBuilder { + public: + + /** + * Make a new set builder containing nothing + * + * See the [Rust documentation for `new`](https://docs.rs/icu/latest/icu/collections/codepointinvlist/struct.CodePointInversionListBuilder.html#method.new) for more information. + */ + static ICU4XCodePointSetBuilder create(); + + /** + * Build this into a set + * + * This object is repopulated with an empty builder + * + * See the [Rust documentation for `build`](https://docs.rs/icu/latest/icu/collections/codepointinvlist/struct.CodePointInversionListBuilder.html#method.build) for more information. + */ + ICU4XCodePointSetData build(); + + /** + * Complements this set + * + * (Elements in this set are removed and vice versa) + * + * See the [Rust documentation for `complement`](https://docs.rs/icu/latest/icu/collections/codepointinvlist/struct.CodePointInversionListBuilder.html#method.complement) for more information. + */ + void complement(); + + /** + * Returns whether this set is empty + * + * See the [Rust documentation for `is_empty`](https://docs.rs/icu/latest/icu/collections/codepointinvlist/struct.CodePointInversionListBuilder.html#method.is_empty) for more information. + */ + bool is_empty() const; + + /** + * Add a single character to the set + * + * See the [Rust documentation for `add_char`](https://docs.rs/icu/latest/icu/collections/codepointinvlist/struct.CodePointInversionListBuilder.html#method.add_char) for more information. + */ + void add_char(char32_t ch); + + /** + * Add a single u32 value to the set + * + * See the [Rust documentation for `add_u32`](https://docs.rs/icu/latest/icu/collections/codepointinvlist/struct.CodePointInversionListBuilder.html#method.add_u32) for more information. + */ + void add_u32(uint32_t ch); + + /** + * Add an inclusive range of characters to the set + * + * See the [Rust documentation for `add_range`](https://docs.rs/icu/latest/icu/collections/codepointinvlist/struct.CodePointInversionListBuilder.html#method.add_range) for more information. + */ + void add_inclusive_range(char32_t start, char32_t end); + + /** + * Add an inclusive range of u32s to the set + * + * See the [Rust documentation for `add_range_u32`](https://docs.rs/icu/latest/icu/collections/codepointinvlist/struct.CodePointInversionListBuilder.html#method.add_range_u32) for more information. + */ + void add_inclusive_range_u32(uint32_t start, uint32_t end); + + /** + * Add all elements that belong to the provided set to the set + * + * See the [Rust documentation for `add_set`](https://docs.rs/icu/latest/icu/collections/codepointinvlist/struct.CodePointInversionListBuilder.html#method.add_set) for more information. + */ + void add_set(const ICU4XCodePointSetData& data); + + /** + * Remove a single character to the set + * + * See the [Rust documentation for `remove_char`](https://docs.rs/icu/latest/icu/collections/codepointinvlist/struct.CodePointInversionListBuilder.html#method.remove_char) for more information. + */ + void remove_char(char32_t ch); + + /** + * Remove an inclusive range of characters from the set + * + * See the [Rust documentation for `remove_range`](https://docs.rs/icu/latest/icu/collections/codepointinvlist/struct.CodePointInversionListBuilder.html#method.remove_range) for more information. + */ + void remove_inclusive_range(char32_t start, char32_t end); + + /** + * Remove all elements that belong to the provided set from the set + * + * See the [Rust documentation for `remove_set`](https://docs.rs/icu/latest/icu/collections/codepointinvlist/struct.CodePointInversionListBuilder.html#method.remove_set) for more information. + */ + void remove_set(const ICU4XCodePointSetData& data); + + /** + * Removes all elements from the set except a single character + * + * See the [Rust documentation for `retain_char`](https://docs.rs/icu/latest/icu/collections/codepointinvlist/struct.CodePointInversionListBuilder.html#method.retain_char) for more information. + */ + void retain_char(char32_t ch); + + /** + * Removes all elements from the set except an inclusive range of characters f + * + * See the [Rust documentation for `retain_range`](https://docs.rs/icu/latest/icu/collections/codepointinvlist/struct.CodePointInversionListBuilder.html#method.retain_range) for more information. + */ + void retain_inclusive_range(char32_t start, char32_t end); + + /** + * Removes all elements from the set except all elements in the provided set + * + * See the [Rust documentation for `retain_set`](https://docs.rs/icu/latest/icu/collections/codepointinvlist/struct.CodePointInversionListBuilder.html#method.retain_set) for more information. + */ + void retain_set(const ICU4XCodePointSetData& data); + + /** + * Complement a single character to the set + * + * (Characters which are in this set are removed and vice versa) + * + * See the [Rust documentation for `complement_char`](https://docs.rs/icu/latest/icu/collections/codepointinvlist/struct.CodePointInversionListBuilder.html#method.complement_char) for more information. + */ + void complement_char(char32_t ch); + + /** + * Complement an inclusive range of characters from the set + * + * (Characters which are in this set are removed and vice versa) + * + * See the [Rust documentation for `complement_range`](https://docs.rs/icu/latest/icu/collections/codepointinvlist/struct.CodePointInversionListBuilder.html#method.complement_range) for more information. + */ + void complement_inclusive_range(char32_t start, char32_t end); + + /** + * Complement all elements that belong to the provided set from the set + * + * (Characters which are in this set are removed and vice versa) + * + * See the [Rust documentation for `complement_set`](https://docs.rs/icu/latest/icu/collections/codepointinvlist/struct.CodePointInversionListBuilder.html#method.complement_set) for more information. + */ + void complement_set(const ICU4XCodePointSetData& data); + inline const capi::ICU4XCodePointSetBuilder* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XCodePointSetBuilder* AsFFIMut() { return this->inner.get(); } + inline ICU4XCodePointSetBuilder(capi::ICU4XCodePointSetBuilder* i) : inner(i) {} + ICU4XCodePointSetBuilder() = default; + ICU4XCodePointSetBuilder(ICU4XCodePointSetBuilder&&) noexcept = default; + ICU4XCodePointSetBuilder& operator=(ICU4XCodePointSetBuilder&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XCodePointSetBuilder, ICU4XCodePointSetBuilderDeleter> inner; +}; + +#include "ICU4XCodePointSetData.hpp" + +inline ICU4XCodePointSetBuilder ICU4XCodePointSetBuilder::create() { + return ICU4XCodePointSetBuilder(capi::ICU4XCodePointSetBuilder_create()); +} +inline ICU4XCodePointSetData ICU4XCodePointSetBuilder::build() { + return ICU4XCodePointSetData(capi::ICU4XCodePointSetBuilder_build(this->inner.get())); +} +inline void ICU4XCodePointSetBuilder::complement() { + capi::ICU4XCodePointSetBuilder_complement(this->inner.get()); +} +inline bool ICU4XCodePointSetBuilder::is_empty() const { + return capi::ICU4XCodePointSetBuilder_is_empty(this->inner.get()); +} +inline void ICU4XCodePointSetBuilder::add_char(char32_t ch) { + capi::ICU4XCodePointSetBuilder_add_char(this->inner.get(), ch); +} +inline void ICU4XCodePointSetBuilder::add_u32(uint32_t ch) { + capi::ICU4XCodePointSetBuilder_add_u32(this->inner.get(), ch); +} +inline void ICU4XCodePointSetBuilder::add_inclusive_range(char32_t start, char32_t end) { + capi::ICU4XCodePointSetBuilder_add_inclusive_range(this->inner.get(), start, end); +} +inline void ICU4XCodePointSetBuilder::add_inclusive_range_u32(uint32_t start, uint32_t end) { + capi::ICU4XCodePointSetBuilder_add_inclusive_range_u32(this->inner.get(), start, end); +} +inline void ICU4XCodePointSetBuilder::add_set(const ICU4XCodePointSetData& data) { + capi::ICU4XCodePointSetBuilder_add_set(this->inner.get(), data.AsFFI()); +} +inline void ICU4XCodePointSetBuilder::remove_char(char32_t ch) { + capi::ICU4XCodePointSetBuilder_remove_char(this->inner.get(), ch); +} +inline void ICU4XCodePointSetBuilder::remove_inclusive_range(char32_t start, char32_t end) { + capi::ICU4XCodePointSetBuilder_remove_inclusive_range(this->inner.get(), start, end); +} +inline void ICU4XCodePointSetBuilder::remove_set(const ICU4XCodePointSetData& data) { + capi::ICU4XCodePointSetBuilder_remove_set(this->inner.get(), data.AsFFI()); +} +inline void ICU4XCodePointSetBuilder::retain_char(char32_t ch) { + capi::ICU4XCodePointSetBuilder_retain_char(this->inner.get(), ch); +} +inline void ICU4XCodePointSetBuilder::retain_inclusive_range(char32_t start, char32_t end) { + capi::ICU4XCodePointSetBuilder_retain_inclusive_range(this->inner.get(), start, end); +} +inline void ICU4XCodePointSetBuilder::retain_set(const ICU4XCodePointSetData& data) { + capi::ICU4XCodePointSetBuilder_retain_set(this->inner.get(), data.AsFFI()); +} +inline void ICU4XCodePointSetBuilder::complement_char(char32_t ch) { + capi::ICU4XCodePointSetBuilder_complement_char(this->inner.get(), ch); +} +inline void ICU4XCodePointSetBuilder::complement_inclusive_range(char32_t start, char32_t end) { + capi::ICU4XCodePointSetBuilder_complement_inclusive_range(this->inner.get(), start, end); +} +inline void ICU4XCodePointSetBuilder::complement_set(const ICU4XCodePointSetData& data) { + capi::ICU4XCodePointSetBuilder_complement_set(this->inner.get(), data.AsFFI()); +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XCodePointSetData.h b/intl/icu_capi/cpp/include/ICU4XCodePointSetData.h new file mode 100644 index 0000000000..10356e90b7 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XCodePointSetData.h @@ -0,0 +1,172 @@ +#ifndef ICU4XCodePointSetData_H +#define ICU4XCodePointSetData_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XCodePointSetData ICU4XCodePointSetData; +#ifdef __cplusplus +} // namespace capi +#endif +#include "CodePointRangeIterator.h" +#include "ICU4XDataProvider.h" +#include "diplomat_result_box_ICU4XCodePointSetData_ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +bool ICU4XCodePointSetData_contains(const ICU4XCodePointSetData* self, char32_t cp); + +bool ICU4XCodePointSetData_contains32(const ICU4XCodePointSetData* self, uint32_t cp); + +CodePointRangeIterator* ICU4XCodePointSetData_iter_ranges(const ICU4XCodePointSetData* self); + +CodePointRangeIterator* ICU4XCodePointSetData_iter_ranges_complemented(const ICU4XCodePointSetData* self); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_for_general_category_group(const ICU4XDataProvider* provider, uint32_t group); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_ascii_hex_digit(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_alnum(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_alphabetic(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_bidi_control(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_bidi_mirrored(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_blank(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_cased(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_case_ignorable(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_full_composition_exclusion(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_changes_when_casefolded(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_changes_when_casemapped(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_changes_when_nfkc_casefolded(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_changes_when_lowercased(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_changes_when_titlecased(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_changes_when_uppercased(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_dash(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_deprecated(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_default_ignorable_code_point(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_diacritic(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_emoji_modifier_base(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_emoji_component(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_emoji_modifier(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_emoji(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_emoji_presentation(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_extender(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_extended_pictographic(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_graph(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_grapheme_base(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_grapheme_extend(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_grapheme_link(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_hex_digit(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_hyphen(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_id_continue(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_ideographic(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_id_start(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_ids_binary_operator(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_ids_trinary_operator(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_join_control(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_logical_order_exception(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_lowercase(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_math(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_noncharacter_code_point(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_nfc_inert(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_nfd_inert(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_nfkc_inert(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_nfkd_inert(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_pattern_syntax(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_pattern_white_space(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_prepended_concatenation_mark(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_print(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_quotation_mark(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_radical(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_regional_indicator(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_soft_dotted(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_segment_starter(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_case_sensitive(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_sentence_terminal(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_terminal_punctuation(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_unified_ideograph(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_uppercase(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_variation_selector(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_white_space(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_xdigit(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_xid_continue(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_xid_start(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XCodePointSetData_ICU4XError ICU4XCodePointSetData_load_for_ecma262(const ICU4XDataProvider* provider, const char* property_name_data, size_t property_name_len); +void ICU4XCodePointSetData_destroy(ICU4XCodePointSetData* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XCodePointSetData.hpp b/intl/icu_capi/cpp/include/ICU4XCodePointSetData.hpp new file mode 100644 index 0000000000..64b32e2e97 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XCodePointSetData.hpp @@ -0,0 +1,1109 @@ +#ifndef ICU4XCodePointSetData_HPP +#define ICU4XCodePointSetData_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XCodePointSetData.h" + +class CodePointRangeIterator; +class ICU4XDataProvider; +class ICU4XCodePointSetData; +#include "ICU4XError.hpp" + +/** + * A destruction policy for using ICU4XCodePointSetData with std::unique_ptr. + */ +struct ICU4XCodePointSetDataDeleter { + void operator()(capi::ICU4XCodePointSetData* l) const noexcept { + capi::ICU4XCodePointSetData_destroy(l); + } +}; + +/** + * An ICU4X Unicode Set Property object, capable of querying whether a code point is contained in a set based on a Unicode property. + * + * See the [Rust documentation for `properties`](https://docs.rs/icu/latest/icu/properties/index.html) for more information. + * + * See the [Rust documentation for `CodePointSetData`](https://docs.rs/icu/latest/icu/properties/sets/struct.CodePointSetData.html) for more information. + * + * See the [Rust documentation for `CodePointSetDataBorrowed`](https://docs.rs/icu/latest/icu/properties/sets/struct.CodePointSetDataBorrowed.html) for more information. + */ +class ICU4XCodePointSetData { + public: + + /** + * Checks whether the code point is in the set. + * + * See the [Rust documentation for `contains`](https://docs.rs/icu/latest/icu/properties/sets/struct.CodePointSetDataBorrowed.html#method.contains) for more information. + */ + bool contains(char32_t cp) const; + + /** + * Checks whether the code point (specified as a 32 bit integer, in UTF-32) is in the set. + */ + bool contains32(uint32_t cp) const; + + /** + * Produces an iterator over ranges of code points contained in this set + * + * See the [Rust documentation for `iter_ranges`](https://docs.rs/icu/latest/icu/properties/sets/struct.CodePointSetDataBorrowed.html#method.iter_ranges) for more information. + * + * Lifetimes: `this` must live at least as long as the output. + */ + CodePointRangeIterator iter_ranges() const; + + /** + * Produces an iterator over ranges of code points not contained in this set + * + * See the [Rust documentation for `iter_ranges_complemented`](https://docs.rs/icu/latest/icu/properties/sets/struct.CodePointSetDataBorrowed.html#method.iter_ranges_complemented) for more information. + * + * Lifetimes: `this` must live at least as long as the output. + */ + CodePointRangeIterator iter_ranges_complemented() const; + + /** + * which is a mask with the same format as the `U_GC_XX_MASK` mask in ICU4C + * + * See the [Rust documentation for `for_general_category_group`](https://docs.rs/icu/latest/icu/properties/sets/fn.for_general_category_group.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_for_general_category_group(const ICU4XDataProvider& provider, uint32_t group); + + /** + * See the [Rust documentation for `ascii_hex_digit`](https://docs.rs/icu/latest/icu/properties/sets/fn.ascii_hex_digit.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_ascii_hex_digit(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `alnum`](https://docs.rs/icu/latest/icu/properties/sets/fn.alnum.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_alnum(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `alphabetic`](https://docs.rs/icu/latest/icu/properties/sets/fn.alphabetic.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_alphabetic(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `bidi_control`](https://docs.rs/icu/latest/icu/properties/sets/fn.bidi_control.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_bidi_control(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `bidi_mirrored`](https://docs.rs/icu/latest/icu/properties/sets/fn.bidi_mirrored.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_bidi_mirrored(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `blank`](https://docs.rs/icu/latest/icu/properties/sets/fn.blank.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_blank(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `cased`](https://docs.rs/icu/latest/icu/properties/sets/fn.cased.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_cased(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `case_ignorable`](https://docs.rs/icu/latest/icu/properties/sets/fn.case_ignorable.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_case_ignorable(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `full_composition_exclusion`](https://docs.rs/icu/latest/icu/properties/sets/fn.full_composition_exclusion.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_full_composition_exclusion(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `changes_when_casefolded`](https://docs.rs/icu/latest/icu/properties/sets/fn.changes_when_casefolded.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_changes_when_casefolded(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `changes_when_casemapped`](https://docs.rs/icu/latest/icu/properties/sets/fn.changes_when_casemapped.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_changes_when_casemapped(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `changes_when_nfkc_casefolded`](https://docs.rs/icu/latest/icu/properties/sets/fn.changes_when_nfkc_casefolded.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_changes_when_nfkc_casefolded(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `changes_when_lowercased`](https://docs.rs/icu/latest/icu/properties/sets/fn.changes_when_lowercased.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_changes_when_lowercased(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `changes_when_titlecased`](https://docs.rs/icu/latest/icu/properties/sets/fn.changes_when_titlecased.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_changes_when_titlecased(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `changes_when_uppercased`](https://docs.rs/icu/latest/icu/properties/sets/fn.changes_when_uppercased.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_changes_when_uppercased(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `dash`](https://docs.rs/icu/latest/icu/properties/sets/fn.dash.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_dash(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `deprecated`](https://docs.rs/icu/latest/icu/properties/sets/fn.deprecated.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_deprecated(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `default_ignorable_code_point`](https://docs.rs/icu/latest/icu/properties/sets/fn.default_ignorable_code_point.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_default_ignorable_code_point(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `diacritic`](https://docs.rs/icu/latest/icu/properties/sets/fn.diacritic.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_diacritic(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `emoji_modifier_base`](https://docs.rs/icu/latest/icu/properties/sets/fn.emoji_modifier_base.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_emoji_modifier_base(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `emoji_component`](https://docs.rs/icu/latest/icu/properties/sets/fn.emoji_component.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_emoji_component(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `emoji_modifier`](https://docs.rs/icu/latest/icu/properties/sets/fn.emoji_modifier.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_emoji_modifier(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `emoji`](https://docs.rs/icu/latest/icu/properties/sets/fn.emoji.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_emoji(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `emoji_presentation`](https://docs.rs/icu/latest/icu/properties/sets/fn.emoji_presentation.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_emoji_presentation(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `extender`](https://docs.rs/icu/latest/icu/properties/sets/fn.extender.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_extender(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `extended_pictographic`](https://docs.rs/icu/latest/icu/properties/sets/fn.extended_pictographic.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_extended_pictographic(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `graph`](https://docs.rs/icu/latest/icu/properties/sets/fn.graph.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_graph(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `grapheme_base`](https://docs.rs/icu/latest/icu/properties/sets/fn.grapheme_base.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_grapheme_base(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `grapheme_extend`](https://docs.rs/icu/latest/icu/properties/sets/fn.grapheme_extend.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_grapheme_extend(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `grapheme_link`](https://docs.rs/icu/latest/icu/properties/sets/fn.grapheme_link.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_grapheme_link(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `hex_digit`](https://docs.rs/icu/latest/icu/properties/sets/fn.hex_digit.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_hex_digit(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `hyphen`](https://docs.rs/icu/latest/icu/properties/sets/fn.hyphen.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_hyphen(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `id_continue`](https://docs.rs/icu/latest/icu/properties/sets/fn.id_continue.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_id_continue(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `ideographic`](https://docs.rs/icu/latest/icu/properties/sets/fn.ideographic.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_ideographic(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `id_start`](https://docs.rs/icu/latest/icu/properties/sets/fn.id_start.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_id_start(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `ids_binary_operator`](https://docs.rs/icu/latest/icu/properties/sets/fn.ids_binary_operator.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_ids_binary_operator(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `ids_trinary_operator`](https://docs.rs/icu/latest/icu/properties/sets/fn.ids_trinary_operator.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_ids_trinary_operator(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `join_control`](https://docs.rs/icu/latest/icu/properties/sets/fn.join_control.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_join_control(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `logical_order_exception`](https://docs.rs/icu/latest/icu/properties/sets/fn.logical_order_exception.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_logical_order_exception(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `lowercase`](https://docs.rs/icu/latest/icu/properties/sets/fn.lowercase.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_lowercase(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `math`](https://docs.rs/icu/latest/icu/properties/sets/fn.math.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_math(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `noncharacter_code_point`](https://docs.rs/icu/latest/icu/properties/sets/fn.noncharacter_code_point.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_noncharacter_code_point(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `nfc_inert`](https://docs.rs/icu/latest/icu/properties/sets/fn.nfc_inert.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_nfc_inert(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `nfd_inert`](https://docs.rs/icu/latest/icu/properties/sets/fn.nfd_inert.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_nfd_inert(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `nfkc_inert`](https://docs.rs/icu/latest/icu/properties/sets/fn.nfkc_inert.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_nfkc_inert(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `nfkd_inert`](https://docs.rs/icu/latest/icu/properties/sets/fn.nfkd_inert.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_nfkd_inert(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `pattern_syntax`](https://docs.rs/icu/latest/icu/properties/sets/fn.pattern_syntax.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_pattern_syntax(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `pattern_white_space`](https://docs.rs/icu/latest/icu/properties/sets/fn.pattern_white_space.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_pattern_white_space(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `prepended_concatenation_mark`](https://docs.rs/icu/latest/icu/properties/sets/fn.prepended_concatenation_mark.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_prepended_concatenation_mark(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `print`](https://docs.rs/icu/latest/icu/properties/sets/fn.print.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_print(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `quotation_mark`](https://docs.rs/icu/latest/icu/properties/sets/fn.quotation_mark.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_quotation_mark(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `radical`](https://docs.rs/icu/latest/icu/properties/sets/fn.radical.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_radical(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `regional_indicator`](https://docs.rs/icu/latest/icu/properties/sets/fn.regional_indicator.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_regional_indicator(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `soft_dotted`](https://docs.rs/icu/latest/icu/properties/sets/fn.soft_dotted.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_soft_dotted(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `segment_starter`](https://docs.rs/icu/latest/icu/properties/sets/fn.segment_starter.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_segment_starter(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `case_sensitive`](https://docs.rs/icu/latest/icu/properties/sets/fn.case_sensitive.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_case_sensitive(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `sentence_terminal`](https://docs.rs/icu/latest/icu/properties/sets/fn.sentence_terminal.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_sentence_terminal(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `terminal_punctuation`](https://docs.rs/icu/latest/icu/properties/sets/fn.terminal_punctuation.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_terminal_punctuation(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `unified_ideograph`](https://docs.rs/icu/latest/icu/properties/sets/fn.unified_ideograph.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_unified_ideograph(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `uppercase`](https://docs.rs/icu/latest/icu/properties/sets/fn.uppercase.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_uppercase(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `variation_selector`](https://docs.rs/icu/latest/icu/properties/sets/fn.variation_selector.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_variation_selector(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `white_space`](https://docs.rs/icu/latest/icu/properties/sets/fn.white_space.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_white_space(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `xdigit`](https://docs.rs/icu/latest/icu/properties/sets/fn.xdigit.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_xdigit(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `xid_continue`](https://docs.rs/icu/latest/icu/properties/sets/fn.xid_continue.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_xid_continue(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `xid_start`](https://docs.rs/icu/latest/icu/properties/sets/fn.xid_start.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_xid_start(const ICU4XDataProvider& provider); + + /** + * Loads data for a property specified as a string as long as it is one of the + * [ECMA-262 binary properties][ecma] (not including Any, ASCII, and Assigned pseudoproperties). + * + * Returns `ICU4XError::PropertyUnexpectedPropertyNameError` in case the string does not + * match any property in the list + * + * [ecma]: https://tc39.es/ecma262/#table-binary-unicode-properties + * + * See the [Rust documentation for `for_ecma262`](https://docs.rs/icu/latest/icu/properties/sets/fn.for_ecma262.html) for more information. + */ + static diplomat::result<ICU4XCodePointSetData, ICU4XError> load_for_ecma262(const ICU4XDataProvider& provider, const std::string_view property_name); + inline const capi::ICU4XCodePointSetData* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XCodePointSetData* AsFFIMut() { return this->inner.get(); } + inline ICU4XCodePointSetData(capi::ICU4XCodePointSetData* i) : inner(i) {} + ICU4XCodePointSetData() = default; + ICU4XCodePointSetData(ICU4XCodePointSetData&&) noexcept = default; + ICU4XCodePointSetData& operator=(ICU4XCodePointSetData&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XCodePointSetData, ICU4XCodePointSetDataDeleter> inner; +}; + +#include "CodePointRangeIterator.hpp" +#include "ICU4XDataProvider.hpp" + +inline bool ICU4XCodePointSetData::contains(char32_t cp) const { + return capi::ICU4XCodePointSetData_contains(this->inner.get(), cp); +} +inline bool ICU4XCodePointSetData::contains32(uint32_t cp) const { + return capi::ICU4XCodePointSetData_contains32(this->inner.get(), cp); +} +inline CodePointRangeIterator ICU4XCodePointSetData::iter_ranges() const { + return CodePointRangeIterator(capi::ICU4XCodePointSetData_iter_ranges(this->inner.get())); +} +inline CodePointRangeIterator ICU4XCodePointSetData::iter_ranges_complemented() const { + return CodePointRangeIterator(capi::ICU4XCodePointSetData_iter_ranges_complemented(this->inner.get())); +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_for_general_category_group(const ICU4XDataProvider& provider, uint32_t group) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_for_general_category_group(provider.AsFFI(), group); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_ascii_hex_digit(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_ascii_hex_digit(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_alnum(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_alnum(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_alphabetic(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_alphabetic(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_bidi_control(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_bidi_control(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_bidi_mirrored(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_bidi_mirrored(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_blank(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_blank(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_cased(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_cased(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_case_ignorable(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_case_ignorable(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_full_composition_exclusion(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_full_composition_exclusion(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_changes_when_casefolded(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_changes_when_casefolded(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_changes_when_casemapped(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_changes_when_casemapped(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_changes_when_nfkc_casefolded(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_changes_when_nfkc_casefolded(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_changes_when_lowercased(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_changes_when_lowercased(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_changes_when_titlecased(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_changes_when_titlecased(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_changes_when_uppercased(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_changes_when_uppercased(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_dash(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_dash(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_deprecated(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_deprecated(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_default_ignorable_code_point(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_default_ignorable_code_point(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_diacritic(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_diacritic(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_emoji_modifier_base(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_emoji_modifier_base(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_emoji_component(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_emoji_component(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_emoji_modifier(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_emoji_modifier(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_emoji(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_emoji(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_emoji_presentation(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_emoji_presentation(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_extender(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_extender(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_extended_pictographic(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_extended_pictographic(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_graph(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_graph(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_grapheme_base(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_grapheme_base(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_grapheme_extend(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_grapheme_extend(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_grapheme_link(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_grapheme_link(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_hex_digit(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_hex_digit(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_hyphen(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_hyphen(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_id_continue(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_id_continue(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_ideographic(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_ideographic(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_id_start(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_id_start(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_ids_binary_operator(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_ids_binary_operator(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_ids_trinary_operator(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_ids_trinary_operator(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_join_control(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_join_control(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_logical_order_exception(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_logical_order_exception(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_lowercase(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_lowercase(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_math(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_math(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_noncharacter_code_point(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_noncharacter_code_point(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_nfc_inert(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_nfc_inert(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_nfd_inert(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_nfd_inert(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_nfkc_inert(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_nfkc_inert(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_nfkd_inert(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_nfkd_inert(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_pattern_syntax(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_pattern_syntax(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_pattern_white_space(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_pattern_white_space(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_prepended_concatenation_mark(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_prepended_concatenation_mark(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_print(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_print(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_quotation_mark(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_quotation_mark(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_radical(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_radical(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_regional_indicator(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_regional_indicator(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_soft_dotted(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_soft_dotted(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_segment_starter(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_segment_starter(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_case_sensitive(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_case_sensitive(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_sentence_terminal(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_sentence_terminal(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_terminal_punctuation(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_terminal_punctuation(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_unified_ideograph(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_unified_ideograph(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_uppercase(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_uppercase(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_variation_selector(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_variation_selector(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_white_space(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_white_space(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_xdigit(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_xdigit(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_xid_continue(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_xid_continue(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_xid_start(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_xid_start(provider.AsFFI()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XCodePointSetData, ICU4XError> ICU4XCodePointSetData::load_for_ecma262(const ICU4XDataProvider& provider, const std::string_view property_name) { + auto diplomat_result_raw_out_value = capi::ICU4XCodePointSetData_load_for_ecma262(provider.AsFFI(), property_name.data(), property_name.size()); + diplomat::result<ICU4XCodePointSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCodePointSetData>(ICU4XCodePointSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XCollator.h b/intl/icu_capi/cpp/include/ICU4XCollator.h new file mode 100644 index 0000000000..973c2cedd9 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XCollator.h @@ -0,0 +1,40 @@ +#ifndef ICU4XCollator_H +#define ICU4XCollator_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XCollator ICU4XCollator; +#ifdef __cplusplus +} // namespace capi +#endif +#include "ICU4XDataProvider.h" +#include "ICU4XLocale.h" +#include "ICU4XCollatorOptionsV1.h" +#include "diplomat_result_box_ICU4XCollator_ICU4XError.h" +#include "ICU4XOrdering.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +diplomat_result_box_ICU4XCollator_ICU4XError ICU4XCollator_create_v1(const ICU4XDataProvider* provider, const ICU4XLocale* locale, ICU4XCollatorOptionsV1 options); + +ICU4XOrdering ICU4XCollator_compare(const ICU4XCollator* self, const char* left_data, size_t left_len, const char* right_data, size_t right_len); + +ICU4XOrdering ICU4XCollator_compare_valid_utf8(const ICU4XCollator* self, const char* left_data, size_t left_len, const char* right_data, size_t right_len); + +ICU4XOrdering ICU4XCollator_compare_utf16(const ICU4XCollator* self, const uint16_t* left_data, size_t left_len, const uint16_t* right_data, size_t right_len); +void ICU4XCollator_destroy(ICU4XCollator* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XCollator.hpp b/intl/icu_capi/cpp/include/ICU4XCollator.hpp new file mode 100644 index 0000000000..d661661f5a --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XCollator.hpp @@ -0,0 +1,105 @@ +#ifndef ICU4XCollator_HPP +#define ICU4XCollator_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XCollator.h" + +class ICU4XDataProvider; +class ICU4XLocale; +struct ICU4XCollatorOptionsV1; +class ICU4XCollator; +#include "ICU4XError.hpp" +#include "ICU4XOrdering.hpp" + +/** + * A destruction policy for using ICU4XCollator with std::unique_ptr. + */ +struct ICU4XCollatorDeleter { + void operator()(capi::ICU4XCollator* l) const noexcept { + capi::ICU4XCollator_destroy(l); + } +}; + +/** + * See the [Rust documentation for `Collator`](https://docs.rs/icu/latest/icu/collator/struct.Collator.html) for more information. + */ +class ICU4XCollator { + public: + + /** + * Construct a new Collator instance. + * + * See the [Rust documentation for `try_new`](https://docs.rs/icu/latest/icu/collator/struct.Collator.html#method.try_new) for more information. + */ + static diplomat::result<ICU4XCollator, ICU4XError> create_v1(const ICU4XDataProvider& provider, const ICU4XLocale& locale, ICU4XCollatorOptionsV1 options); + + /** + * Compare potentially ill-formed UTF-8 strings. + * + * Ill-formed input is compared + * as if errors had been replaced with REPLACEMENT CHARACTERs according + * to the WHATWG Encoding Standard. + * + * See the [Rust documentation for `compare_utf8`](https://docs.rs/icu/latest/icu/collator/struct.Collator.html#method.compare_utf8) for more information. + */ + ICU4XOrdering compare(const std::string_view left, const std::string_view right) const; + + /** + * Compare guaranteed well-formed UTF-8 strings. + * + * Note: In C++, passing ill-formed UTF-8 strings is undefined behavior + * (and may be memory-unsafe to do so, too). + * + * See the [Rust documentation for `compare`](https://docs.rs/icu/latest/icu/collator/struct.Collator.html#method.compare) for more information. + */ + ICU4XOrdering compare_valid_utf8(const std::string_view left, const std::string_view right) const; + + /** + * Compare potentially ill-formed UTF-16 strings, with unpaired surrogates + * compared as REPLACEMENT CHARACTER. + * + * See the [Rust documentation for `compare_utf16`](https://docs.rs/icu/latest/icu/collator/struct.Collator.html#method.compare_utf16) for more information. + */ + ICU4XOrdering compare_utf16(const diplomat::span<const uint16_t> left, const diplomat::span<const uint16_t> right) const; + inline const capi::ICU4XCollator* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XCollator* AsFFIMut() { return this->inner.get(); } + inline ICU4XCollator(capi::ICU4XCollator* i) : inner(i) {} + ICU4XCollator() = default; + ICU4XCollator(ICU4XCollator&&) noexcept = default; + ICU4XCollator& operator=(ICU4XCollator&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XCollator, ICU4XCollatorDeleter> inner; +}; + +#include "ICU4XDataProvider.hpp" +#include "ICU4XLocale.hpp" +#include "ICU4XCollatorOptionsV1.hpp" + +inline diplomat::result<ICU4XCollator, ICU4XError> ICU4XCollator::create_v1(const ICU4XDataProvider& provider, const ICU4XLocale& locale, ICU4XCollatorOptionsV1 options) { + ICU4XCollatorOptionsV1 diplomat_wrapped_struct_options = options; + auto diplomat_result_raw_out_value = capi::ICU4XCollator_create_v1(provider.AsFFI(), locale.AsFFI(), capi::ICU4XCollatorOptionsV1{ .strength = static_cast<capi::ICU4XCollatorStrength>(diplomat_wrapped_struct_options.strength), .alternate_handling = static_cast<capi::ICU4XCollatorAlternateHandling>(diplomat_wrapped_struct_options.alternate_handling), .case_first = static_cast<capi::ICU4XCollatorCaseFirst>(diplomat_wrapped_struct_options.case_first), .max_variable = static_cast<capi::ICU4XCollatorMaxVariable>(diplomat_wrapped_struct_options.max_variable), .case_level = static_cast<capi::ICU4XCollatorCaseLevel>(diplomat_wrapped_struct_options.case_level), .numeric = static_cast<capi::ICU4XCollatorNumeric>(diplomat_wrapped_struct_options.numeric), .backward_second_level = static_cast<capi::ICU4XCollatorBackwardSecondLevel>(diplomat_wrapped_struct_options.backward_second_level) }); + diplomat::result<ICU4XCollator, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCollator>(ICU4XCollator(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline ICU4XOrdering ICU4XCollator::compare(const std::string_view left, const std::string_view right) const { + return static_cast<ICU4XOrdering>(capi::ICU4XCollator_compare(this->inner.get(), left.data(), left.size(), right.data(), right.size())); +} +inline ICU4XOrdering ICU4XCollator::compare_valid_utf8(const std::string_view left, const std::string_view right) const { + return static_cast<ICU4XOrdering>(capi::ICU4XCollator_compare_valid_utf8(this->inner.get(), left.data(), left.size(), right.data(), right.size())); +} +inline ICU4XOrdering ICU4XCollator::compare_utf16(const diplomat::span<const uint16_t> left, const diplomat::span<const uint16_t> right) const { + return static_cast<ICU4XOrdering>(capi::ICU4XCollator_compare_utf16(this->inner.get(), left.data(), left.size(), right.data(), right.size())); +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XCollatorAlternateHandling.h b/intl/icu_capi/cpp/include/ICU4XCollatorAlternateHandling.h new file mode 100644 index 0000000000..dfc3d595eb --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XCollatorAlternateHandling.h @@ -0,0 +1,32 @@ +#ifndef ICU4XCollatorAlternateHandling_H +#define ICU4XCollatorAlternateHandling_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef enum ICU4XCollatorAlternateHandling { + ICU4XCollatorAlternateHandling_Auto = 0, + ICU4XCollatorAlternateHandling_NonIgnorable = 1, + ICU4XCollatorAlternateHandling_Shifted = 2, +} ICU4XCollatorAlternateHandling; +#ifdef __cplusplus +} // namespace capi +#endif +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +void ICU4XCollatorAlternateHandling_destroy(ICU4XCollatorAlternateHandling* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XCollatorAlternateHandling.hpp b/intl/icu_capi/cpp/include/ICU4XCollatorAlternateHandling.hpp new file mode 100644 index 0000000000..957bdac780 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XCollatorAlternateHandling.hpp @@ -0,0 +1,25 @@ +#ifndef ICU4XCollatorAlternateHandling_HPP +#define ICU4XCollatorAlternateHandling_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XCollatorAlternateHandling.h" + + + +/** + * See the [Rust documentation for `AlternateHandling`](https://docs.rs/icu/latest/icu/collator/enum.AlternateHandling.html) for more information. + */ +enum struct ICU4XCollatorAlternateHandling { + Auto = 0, + NonIgnorable = 1, + Shifted = 2, +}; + +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XCollatorBackwardSecondLevel.h b/intl/icu_capi/cpp/include/ICU4XCollatorBackwardSecondLevel.h new file mode 100644 index 0000000000..659f9b2f10 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XCollatorBackwardSecondLevel.h @@ -0,0 +1,32 @@ +#ifndef ICU4XCollatorBackwardSecondLevel_H +#define ICU4XCollatorBackwardSecondLevel_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef enum ICU4XCollatorBackwardSecondLevel { + ICU4XCollatorBackwardSecondLevel_Auto = 0, + ICU4XCollatorBackwardSecondLevel_Off = 1, + ICU4XCollatorBackwardSecondLevel_On = 2, +} ICU4XCollatorBackwardSecondLevel; +#ifdef __cplusplus +} // namespace capi +#endif +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +void ICU4XCollatorBackwardSecondLevel_destroy(ICU4XCollatorBackwardSecondLevel* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XCollatorBackwardSecondLevel.hpp b/intl/icu_capi/cpp/include/ICU4XCollatorBackwardSecondLevel.hpp new file mode 100644 index 0000000000..7bd601a59f --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XCollatorBackwardSecondLevel.hpp @@ -0,0 +1,25 @@ +#ifndef ICU4XCollatorBackwardSecondLevel_HPP +#define ICU4XCollatorBackwardSecondLevel_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XCollatorBackwardSecondLevel.h" + + + +/** + * See the [Rust documentation for `BackwardSecondLevel`](https://docs.rs/icu/latest/icu/collator/enum.BackwardSecondLevel.html) for more information. + */ +enum struct ICU4XCollatorBackwardSecondLevel { + Auto = 0, + Off = 1, + On = 2, +}; + +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XCollatorCaseFirst.h b/intl/icu_capi/cpp/include/ICU4XCollatorCaseFirst.h new file mode 100644 index 0000000000..c01eb216d0 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XCollatorCaseFirst.h @@ -0,0 +1,33 @@ +#ifndef ICU4XCollatorCaseFirst_H +#define ICU4XCollatorCaseFirst_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef enum ICU4XCollatorCaseFirst { + ICU4XCollatorCaseFirst_Auto = 0, + ICU4XCollatorCaseFirst_Off = 1, + ICU4XCollatorCaseFirst_LowerFirst = 2, + ICU4XCollatorCaseFirst_UpperFirst = 3, +} ICU4XCollatorCaseFirst; +#ifdef __cplusplus +} // namespace capi +#endif +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +void ICU4XCollatorCaseFirst_destroy(ICU4XCollatorCaseFirst* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XCollatorCaseFirst.hpp b/intl/icu_capi/cpp/include/ICU4XCollatorCaseFirst.hpp new file mode 100644 index 0000000000..680e3e9f9a --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XCollatorCaseFirst.hpp @@ -0,0 +1,26 @@ +#ifndef ICU4XCollatorCaseFirst_HPP +#define ICU4XCollatorCaseFirst_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XCollatorCaseFirst.h" + + + +/** + * See the [Rust documentation for `CaseFirst`](https://docs.rs/icu/latest/icu/collator/enum.CaseFirst.html) for more information. + */ +enum struct ICU4XCollatorCaseFirst { + Auto = 0, + Off = 1, + LowerFirst = 2, + UpperFirst = 3, +}; + +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XCollatorCaseLevel.h b/intl/icu_capi/cpp/include/ICU4XCollatorCaseLevel.h new file mode 100644 index 0000000000..cbf6865967 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XCollatorCaseLevel.h @@ -0,0 +1,32 @@ +#ifndef ICU4XCollatorCaseLevel_H +#define ICU4XCollatorCaseLevel_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef enum ICU4XCollatorCaseLevel { + ICU4XCollatorCaseLevel_Auto = 0, + ICU4XCollatorCaseLevel_Off = 1, + ICU4XCollatorCaseLevel_On = 2, +} ICU4XCollatorCaseLevel; +#ifdef __cplusplus +} // namespace capi +#endif +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +void ICU4XCollatorCaseLevel_destroy(ICU4XCollatorCaseLevel* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XCollatorCaseLevel.hpp b/intl/icu_capi/cpp/include/ICU4XCollatorCaseLevel.hpp new file mode 100644 index 0000000000..849f891591 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XCollatorCaseLevel.hpp @@ -0,0 +1,25 @@ +#ifndef ICU4XCollatorCaseLevel_HPP +#define ICU4XCollatorCaseLevel_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XCollatorCaseLevel.h" + + + +/** + * See the [Rust documentation for `CaseLevel`](https://docs.rs/icu/latest/icu/collator/enum.CaseLevel.html) for more information. + */ +enum struct ICU4XCollatorCaseLevel { + Auto = 0, + Off = 1, + On = 2, +}; + +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XCollatorMaxVariable.h b/intl/icu_capi/cpp/include/ICU4XCollatorMaxVariable.h new file mode 100644 index 0000000000..0e5a3a516f --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XCollatorMaxVariable.h @@ -0,0 +1,34 @@ +#ifndef ICU4XCollatorMaxVariable_H +#define ICU4XCollatorMaxVariable_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef enum ICU4XCollatorMaxVariable { + ICU4XCollatorMaxVariable_Auto = 0, + ICU4XCollatorMaxVariable_Space = 1, + ICU4XCollatorMaxVariable_Punctuation = 2, + ICU4XCollatorMaxVariable_Symbol = 3, + ICU4XCollatorMaxVariable_Currency = 4, +} ICU4XCollatorMaxVariable; +#ifdef __cplusplus +} // namespace capi +#endif +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +void ICU4XCollatorMaxVariable_destroy(ICU4XCollatorMaxVariable* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XCollatorMaxVariable.hpp b/intl/icu_capi/cpp/include/ICU4XCollatorMaxVariable.hpp new file mode 100644 index 0000000000..6092118851 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XCollatorMaxVariable.hpp @@ -0,0 +1,27 @@ +#ifndef ICU4XCollatorMaxVariable_HPP +#define ICU4XCollatorMaxVariable_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XCollatorMaxVariable.h" + + + +/** + * See the [Rust documentation for `MaxVariable`](https://docs.rs/icu/latest/icu/collator/enum.MaxVariable.html) for more information. + */ +enum struct ICU4XCollatorMaxVariable { + Auto = 0, + Space = 1, + Punctuation = 2, + Symbol = 3, + Currency = 4, +}; + +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XCollatorNumeric.h b/intl/icu_capi/cpp/include/ICU4XCollatorNumeric.h new file mode 100644 index 0000000000..4dd2ec0408 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XCollatorNumeric.h @@ -0,0 +1,32 @@ +#ifndef ICU4XCollatorNumeric_H +#define ICU4XCollatorNumeric_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef enum ICU4XCollatorNumeric { + ICU4XCollatorNumeric_Auto = 0, + ICU4XCollatorNumeric_Off = 1, + ICU4XCollatorNumeric_On = 2, +} ICU4XCollatorNumeric; +#ifdef __cplusplus +} // namespace capi +#endif +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +void ICU4XCollatorNumeric_destroy(ICU4XCollatorNumeric* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XCollatorNumeric.hpp b/intl/icu_capi/cpp/include/ICU4XCollatorNumeric.hpp new file mode 100644 index 0000000000..1c60a7102f --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XCollatorNumeric.hpp @@ -0,0 +1,25 @@ +#ifndef ICU4XCollatorNumeric_HPP +#define ICU4XCollatorNumeric_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XCollatorNumeric.h" + + + +/** + * See the [Rust documentation for `Numeric`](https://docs.rs/icu/latest/icu/collator/enum.Numeric.html) for more information. + */ +enum struct ICU4XCollatorNumeric { + Auto = 0, + Off = 1, + On = 2, +}; + +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XCollatorOptionsV1.h b/intl/icu_capi/cpp/include/ICU4XCollatorOptionsV1.h new file mode 100644 index 0000000000..dc73557efe --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XCollatorOptionsV1.h @@ -0,0 +1,50 @@ +#ifndef ICU4XCollatorOptionsV1_H +#define ICU4XCollatorOptionsV1_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#include "ICU4XCollatorStrength.h" +#include "ICU4XCollatorAlternateHandling.h" +#include "ICU4XCollatorCaseFirst.h" +#include "ICU4XCollatorMaxVariable.h" +#include "ICU4XCollatorCaseLevel.h" +#include "ICU4XCollatorNumeric.h" +#include "ICU4XCollatorBackwardSecondLevel.h" +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XCollatorOptionsV1 { + ICU4XCollatorStrength strength; + ICU4XCollatorAlternateHandling alternate_handling; + ICU4XCollatorCaseFirst case_first; + ICU4XCollatorMaxVariable max_variable; + ICU4XCollatorCaseLevel case_level; + ICU4XCollatorNumeric numeric; + ICU4XCollatorBackwardSecondLevel backward_second_level; +} ICU4XCollatorOptionsV1; +#ifdef __cplusplus +} // namespace capi +#endif +#include "ICU4XCollatorStrength.h" +#include "ICU4XCollatorAlternateHandling.h" +#include "ICU4XCollatorCaseFirst.h" +#include "ICU4XCollatorMaxVariable.h" +#include "ICU4XCollatorCaseLevel.h" +#include "ICU4XCollatorNumeric.h" +#include "ICU4XCollatorBackwardSecondLevel.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +void ICU4XCollatorOptionsV1_destroy(ICU4XCollatorOptionsV1* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XCollatorOptionsV1.hpp b/intl/icu_capi/cpp/include/ICU4XCollatorOptionsV1.hpp new file mode 100644 index 0000000000..cc646c2154 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XCollatorOptionsV1.hpp @@ -0,0 +1,38 @@ +#ifndef ICU4XCollatorOptionsV1_HPP +#define ICU4XCollatorOptionsV1_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XCollatorOptionsV1.h" + +#include "ICU4XCollatorStrength.hpp" +#include "ICU4XCollatorAlternateHandling.hpp" +#include "ICU4XCollatorCaseFirst.hpp" +#include "ICU4XCollatorMaxVariable.hpp" +#include "ICU4XCollatorCaseLevel.hpp" +#include "ICU4XCollatorNumeric.hpp" +#include "ICU4XCollatorBackwardSecondLevel.hpp" + + +/** + * See the [Rust documentation for `CollatorOptions`](https://docs.rs/icu/latest/icu/collator/struct.CollatorOptions.html) for more information. + */ +struct ICU4XCollatorOptionsV1 { + public: + ICU4XCollatorStrength strength; + ICU4XCollatorAlternateHandling alternate_handling; + ICU4XCollatorCaseFirst case_first; + ICU4XCollatorMaxVariable max_variable; + ICU4XCollatorCaseLevel case_level; + ICU4XCollatorNumeric numeric; + ICU4XCollatorBackwardSecondLevel backward_second_level; +}; + + +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XCollatorStrength.h b/intl/icu_capi/cpp/include/ICU4XCollatorStrength.h new file mode 100644 index 0000000000..f230214feb --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XCollatorStrength.h @@ -0,0 +1,35 @@ +#ifndef ICU4XCollatorStrength_H +#define ICU4XCollatorStrength_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef enum ICU4XCollatorStrength { + ICU4XCollatorStrength_Auto = 0, + ICU4XCollatorStrength_Primary = 1, + ICU4XCollatorStrength_Secondary = 2, + ICU4XCollatorStrength_Tertiary = 3, + ICU4XCollatorStrength_Quaternary = 4, + ICU4XCollatorStrength_Identical = 5, +} ICU4XCollatorStrength; +#ifdef __cplusplus +} // namespace capi +#endif +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +void ICU4XCollatorStrength_destroy(ICU4XCollatorStrength* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XCollatorStrength.hpp b/intl/icu_capi/cpp/include/ICU4XCollatorStrength.hpp new file mode 100644 index 0000000000..3fdebcd1f4 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XCollatorStrength.hpp @@ -0,0 +1,28 @@ +#ifndef ICU4XCollatorStrength_HPP +#define ICU4XCollatorStrength_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XCollatorStrength.h" + + + +/** + * See the [Rust documentation for `Strength`](https://docs.rs/icu/latest/icu/collator/enum.Strength.html) for more information. + */ +enum struct ICU4XCollatorStrength { + Auto = 0, + Primary = 1, + Secondary = 2, + Tertiary = 3, + Quaternary = 4, + Identical = 5, +}; + +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XComposingNormalizer.h b/intl/icu_capi/cpp/include/ICU4XComposingNormalizer.h new file mode 100644 index 0000000000..1798af0d8e --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XComposingNormalizer.h @@ -0,0 +1,38 @@ +#ifndef ICU4XComposingNormalizer_H +#define ICU4XComposingNormalizer_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XComposingNormalizer ICU4XComposingNormalizer; +#ifdef __cplusplus +} // namespace capi +#endif +#include "ICU4XDataProvider.h" +#include "diplomat_result_box_ICU4XComposingNormalizer_ICU4XError.h" +#include "diplomat_result_void_ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +diplomat_result_box_ICU4XComposingNormalizer_ICU4XError ICU4XComposingNormalizer_create_nfc(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XComposingNormalizer_ICU4XError ICU4XComposingNormalizer_create_nfkc(const ICU4XDataProvider* provider); + +diplomat_result_void_ICU4XError ICU4XComposingNormalizer_normalize(const ICU4XComposingNormalizer* self, const char* s_data, size_t s_len, DiplomatWriteable* write); + +bool ICU4XComposingNormalizer_is_normalized(const ICU4XComposingNormalizer* self, const char* s_data, size_t s_len); +void ICU4XComposingNormalizer_destroy(ICU4XComposingNormalizer* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XComposingNormalizer.hpp b/intl/icu_capi/cpp/include/ICU4XComposingNormalizer.hpp new file mode 100644 index 0000000000..c1a1dcc417 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XComposingNormalizer.hpp @@ -0,0 +1,131 @@ +#ifndef ICU4XComposingNormalizer_HPP +#define ICU4XComposingNormalizer_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XComposingNormalizer.h" + +class ICU4XDataProvider; +class ICU4XComposingNormalizer; +#include "ICU4XError.hpp" + +/** + * A destruction policy for using ICU4XComposingNormalizer with std::unique_ptr. + */ +struct ICU4XComposingNormalizerDeleter { + void operator()(capi::ICU4XComposingNormalizer* l) const noexcept { + capi::ICU4XComposingNormalizer_destroy(l); + } +}; + +/** + * See the [Rust documentation for `ComposingNormalizer`](https://docs.rs/icu/latest/icu/normalizer/struct.ComposingNormalizer.html) for more information. + */ +class ICU4XComposingNormalizer { + public: + + /** + * Construct a new ICU4XComposingNormalizer instance for NFC + * + * See the [Rust documentation for `new_nfc`](https://docs.rs/icu/latest/icu/normalizer/struct.ComposingNormalizer.html#method.new_nfc) for more information. + */ + static diplomat::result<ICU4XComposingNormalizer, ICU4XError> create_nfc(const ICU4XDataProvider& provider); + + /** + * Construct a new ICU4XComposingNormalizer instance for NFKC + * + * See the [Rust documentation for `new_nfkc`](https://docs.rs/icu/latest/icu/normalizer/struct.ComposingNormalizer.html#method.new_nfkc) for more information. + */ + static diplomat::result<ICU4XComposingNormalizer, ICU4XError> create_nfkc(const ICU4XDataProvider& provider); + + /** + * Normalize a (potentially ill-formed) UTF8 string + * + * Errors are mapped to REPLACEMENT CHARACTER + * + * See the [Rust documentation for `normalize_utf8`](https://docs.rs/icu/latest/icu/normalizer/struct.ComposingNormalizer.html#method.normalize_utf8) for more information. + */ + template<typename W> diplomat::result<std::monostate, ICU4XError> normalize_to_writeable(const std::string_view s, W& write) const; + + /** + * Normalize a (potentially ill-formed) UTF8 string + * + * Errors are mapped to REPLACEMENT CHARACTER + * + * See the [Rust documentation for `normalize_utf8`](https://docs.rs/icu/latest/icu/normalizer/struct.ComposingNormalizer.html#method.normalize_utf8) for more information. + */ + diplomat::result<std::string, ICU4XError> normalize(const std::string_view s) const; + + /** + * Check if a (potentially ill-formed) UTF8 string is normalized + * + * Errors are mapped to REPLACEMENT CHARACTER + * + * See the [Rust documentation for `is_normalized_utf8`](https://docs.rs/icu/latest/icu/normalizer/struct.ComposingNormalizer.html#method.is_normalized_utf8) for more information. + */ + bool is_normalized(const std::string_view s) const; + inline const capi::ICU4XComposingNormalizer* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XComposingNormalizer* AsFFIMut() { return this->inner.get(); } + inline ICU4XComposingNormalizer(capi::ICU4XComposingNormalizer* i) : inner(i) {} + ICU4XComposingNormalizer() = default; + ICU4XComposingNormalizer(ICU4XComposingNormalizer&&) noexcept = default; + ICU4XComposingNormalizer& operator=(ICU4XComposingNormalizer&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XComposingNormalizer, ICU4XComposingNormalizerDeleter> inner; +}; + +#include "ICU4XDataProvider.hpp" + +inline diplomat::result<ICU4XComposingNormalizer, ICU4XError> ICU4XComposingNormalizer::create_nfc(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XComposingNormalizer_create_nfc(provider.AsFFI()); + diplomat::result<ICU4XComposingNormalizer, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XComposingNormalizer>(ICU4XComposingNormalizer(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XComposingNormalizer, ICU4XError> ICU4XComposingNormalizer::create_nfkc(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XComposingNormalizer_create_nfkc(provider.AsFFI()); + diplomat::result<ICU4XComposingNormalizer, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XComposingNormalizer>(ICU4XComposingNormalizer(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XComposingNormalizer::normalize_to_writeable(const std::string_view s, W& write) const { + capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write); + auto diplomat_result_raw_out_value = capi::ICU4XComposingNormalizer_normalize(this->inner.get(), s.data(), s.size(), &write_writer); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<std::string, ICU4XError> ICU4XComposingNormalizer::normalize(const std::string_view s) const { + std::string diplomat_writeable_string; + capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); + auto diplomat_result_raw_out_value = capi::ICU4XComposingNormalizer_normalize(this->inner.get(), s.data(), s.size(), &diplomat_writeable_out); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string)); +} +inline bool ICU4XComposingNormalizer::is_normalized(const std::string_view s) const { + return capi::ICU4XComposingNormalizer_is_normalized(this->inner.get(), s.data(), s.size()); +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XCustomTimeZone.h b/intl/icu_capi/cpp/include/ICU4XCustomTimeZone.h new file mode 100644 index 0000000000..422b7fa382 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XCustomTimeZone.h @@ -0,0 +1,84 @@ +#ifndef ICU4XCustomTimeZone_H +#define ICU4XCustomTimeZone_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XCustomTimeZone ICU4XCustomTimeZone; +#ifdef __cplusplus +} // namespace capi +#endif +#include "diplomat_result_box_ICU4XCustomTimeZone_ICU4XError.h" +#include "diplomat_result_void_ICU4XError.h" +#include "diplomat_result_int32_t_ICU4XError.h" +#include "diplomat_result_bool_ICU4XError.h" +#include "ICU4XIanaToBcp47Mapper.h" +#include "ICU4XMetazoneCalculator.h" +#include "ICU4XIsoDateTime.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +diplomat_result_box_ICU4XCustomTimeZone_ICU4XError ICU4XCustomTimeZone_create_from_string(const char* s_data, size_t s_len); + +ICU4XCustomTimeZone* ICU4XCustomTimeZone_create_empty(); + +ICU4XCustomTimeZone* ICU4XCustomTimeZone_create_utc(); + +diplomat_result_void_ICU4XError ICU4XCustomTimeZone_try_set_gmt_offset_seconds(ICU4XCustomTimeZone* self, int32_t offset_seconds); + +void ICU4XCustomTimeZone_clear_gmt_offset(ICU4XCustomTimeZone* self); + +diplomat_result_int32_t_ICU4XError ICU4XCustomTimeZone_gmt_offset_seconds(const ICU4XCustomTimeZone* self); + +diplomat_result_bool_ICU4XError ICU4XCustomTimeZone_is_gmt_offset_positive(const ICU4XCustomTimeZone* self); + +diplomat_result_bool_ICU4XError ICU4XCustomTimeZone_is_gmt_offset_zero(const ICU4XCustomTimeZone* self); + +diplomat_result_bool_ICU4XError ICU4XCustomTimeZone_gmt_offset_has_minutes(const ICU4XCustomTimeZone* self); + +diplomat_result_bool_ICU4XError ICU4XCustomTimeZone_gmt_offset_has_seconds(const ICU4XCustomTimeZone* self); + +diplomat_result_void_ICU4XError ICU4XCustomTimeZone_try_set_time_zone_id(ICU4XCustomTimeZone* self, const char* id_data, size_t id_len); + +diplomat_result_void_ICU4XError ICU4XCustomTimeZone_try_set_iana_time_zone_id(ICU4XCustomTimeZone* self, const ICU4XIanaToBcp47Mapper* mapper, const char* id_data, size_t id_len); + +void ICU4XCustomTimeZone_clear_time_zone_id(ICU4XCustomTimeZone* self); + +diplomat_result_void_ICU4XError ICU4XCustomTimeZone_time_zone_id(const ICU4XCustomTimeZone* self, DiplomatWriteable* write); + +diplomat_result_void_ICU4XError ICU4XCustomTimeZone_try_set_metazone_id(ICU4XCustomTimeZone* self, const char* id_data, size_t id_len); + +void ICU4XCustomTimeZone_clear_metazone_id(ICU4XCustomTimeZone* self); + +diplomat_result_void_ICU4XError ICU4XCustomTimeZone_metazone_id(const ICU4XCustomTimeZone* self, DiplomatWriteable* write); + +diplomat_result_void_ICU4XError ICU4XCustomTimeZone_try_set_zone_variant(ICU4XCustomTimeZone* self, const char* id_data, size_t id_len); + +void ICU4XCustomTimeZone_clear_zone_variant(ICU4XCustomTimeZone* self); + +diplomat_result_void_ICU4XError ICU4XCustomTimeZone_zone_variant(const ICU4XCustomTimeZone* self, DiplomatWriteable* write); + +void ICU4XCustomTimeZone_set_standard_time(ICU4XCustomTimeZone* self); + +void ICU4XCustomTimeZone_set_daylight_time(ICU4XCustomTimeZone* self); + +diplomat_result_bool_ICU4XError ICU4XCustomTimeZone_is_standard_time(const ICU4XCustomTimeZone* self); + +diplomat_result_bool_ICU4XError ICU4XCustomTimeZone_is_daylight_time(const ICU4XCustomTimeZone* self); + +void ICU4XCustomTimeZone_maybe_calculate_metazone(ICU4XCustomTimeZone* self, const ICU4XMetazoneCalculator* metazone_calculator, const ICU4XIsoDateTime* local_datetime); +void ICU4XCustomTimeZone_destroy(ICU4XCustomTimeZone* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XCustomTimeZone.hpp b/intl/icu_capi/cpp/include/ICU4XCustomTimeZone.hpp new file mode 100644 index 0000000000..f3bea2d494 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XCustomTimeZone.hpp @@ -0,0 +1,547 @@ +#ifndef ICU4XCustomTimeZone_HPP +#define ICU4XCustomTimeZone_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XCustomTimeZone.h" + +class ICU4XCustomTimeZone; +#include "ICU4XError.hpp" +class ICU4XIanaToBcp47Mapper; +class ICU4XMetazoneCalculator; +class ICU4XIsoDateTime; + +/** + * A destruction policy for using ICU4XCustomTimeZone with std::unique_ptr. + */ +struct ICU4XCustomTimeZoneDeleter { + void operator()(capi::ICU4XCustomTimeZone* l) const noexcept { + capi::ICU4XCustomTimeZone_destroy(l); + } +}; + +/** + * See the [Rust documentation for `CustomTimeZone`](https://docs.rs/icu/latest/icu/timezone/struct.CustomTimeZone.html) for more information. + */ +class ICU4XCustomTimeZone { + public: + + /** + * Creates a time zone from an offset string. + * + * See the [Rust documentation for `from_str`](https://docs.rs/icu/latest/icu/timezone/struct.CustomTimeZone.html#method.from_str) for more information. + */ + static diplomat::result<ICU4XCustomTimeZone, ICU4XError> create_from_string(const std::string_view s); + + /** + * Creates a time zone with no information. + * + * See the [Rust documentation for `new_empty`](https://docs.rs/icu/latest/icu/timezone/struct.CustomTimeZone.html#method.new_empty) for more information. + */ + static ICU4XCustomTimeZone create_empty(); + + /** + * Creates a time zone for UTC. + * + * See the [Rust documentation for `utc`](https://docs.rs/icu/latest/icu/timezone/struct.CustomTimeZone.html#method.utc) for more information. + */ + static ICU4XCustomTimeZone create_utc(); + + /** + * Sets the `gmt_offset` field from offset seconds. + * + * Errors if the offset seconds are out of range. + * + * See the [Rust documentation for `try_from_offset_seconds`](https://docs.rs/icu/latest/icu/timezone/struct.GmtOffset.html#method.try_from_offset_seconds) for more information. + * + * Additional information: [1](https://docs.rs/icu/latest/icu/timezone/struct.GmtOffset.html) + */ + diplomat::result<std::monostate, ICU4XError> try_set_gmt_offset_seconds(int32_t offset_seconds); + + /** + * Clears the `gmt_offset` field. + * + * See the [Rust documentation for `offset_seconds`](https://docs.rs/icu/latest/icu/timezone/struct.GmtOffset.html#method.offset_seconds) for more information. + * + * Additional information: [1](https://docs.rs/icu/latest/icu/timezone/struct.GmtOffset.html) + */ + void clear_gmt_offset(); + + /** + * Returns the value of the `gmt_offset` field as offset seconds. + * + * Errors if the `gmt_offset` field is empty. + * + * See the [Rust documentation for `offset_seconds`](https://docs.rs/icu/latest/icu/timezone/struct.GmtOffset.html#method.offset_seconds) for more information. + * + * Additional information: [1](https://docs.rs/icu/latest/icu/timezone/struct.GmtOffset.html) + */ + diplomat::result<int32_t, ICU4XError> gmt_offset_seconds() const; + + /** + * Returns whether the `gmt_offset` field is positive. + * + * Errors if the `gmt_offset` field is empty. + * + * See the [Rust documentation for `is_positive`](https://docs.rs/icu/latest/icu/timezone/struct.GmtOffset.html#method.is_positive) for more information. + */ + diplomat::result<bool, ICU4XError> is_gmt_offset_positive() const; + + /** + * Returns whether the `gmt_offset` field is zero. + * + * Errors if the `gmt_offset` field is empty (which is not the same as zero). + * + * See the [Rust documentation for `is_zero`](https://docs.rs/icu/latest/icu/timezone/struct.GmtOffset.html#method.is_zero) for more information. + */ + diplomat::result<bool, ICU4XError> is_gmt_offset_zero() const; + + /** + * Returns whether the `gmt_offset` field has nonzero minutes. + * + * Errors if the `gmt_offset` field is empty. + * + * See the [Rust documentation for `has_minutes`](https://docs.rs/icu/latest/icu/timezone/struct.GmtOffset.html#method.has_minutes) for more information. + */ + diplomat::result<bool, ICU4XError> gmt_offset_has_minutes() const; + + /** + * Returns whether the `gmt_offset` field has nonzero seconds. + * + * Errors if the `gmt_offset` field is empty. + * + * See the [Rust documentation for `has_seconds`](https://docs.rs/icu/latest/icu/timezone/struct.GmtOffset.html#method.has_seconds) for more information. + */ + diplomat::result<bool, ICU4XError> gmt_offset_has_seconds() const; + + /** + * Sets the `time_zone_id` field from a BCP-47 string. + * + * Errors if the string is not a valid BCP-47 time zone ID. + * + * See the [Rust documentation for `time_zone_id`](https://docs.rs/icu/latest/icu/timezone/struct.CustomTimeZone.html#structfield.time_zone_id) for more information. + * + * Additional information: [1](https://docs.rs/icu/latest/icu/timezone/struct.TimeZoneBcp47Id.html) + */ + diplomat::result<std::monostate, ICU4XError> try_set_time_zone_id(const std::string_view id); + + /** + * Sets the `time_zone_id` field from an IANA string by looking up + * the corresponding BCP-47 string. + * + * Errors if the string is not a valid BCP-47 time zone ID. + * + * See the [Rust documentation for `get`](https://docs.rs/icu/latest/icu/timezone/struct.IanaToBcp47MapperBorrowed.html#method.get) for more information. + */ + diplomat::result<std::monostate, ICU4XError> try_set_iana_time_zone_id(const ICU4XIanaToBcp47Mapper& mapper, const std::string_view id); + + /** + * Clears the `time_zone_id` field. + * + * See the [Rust documentation for `time_zone_id`](https://docs.rs/icu/latest/icu/timezone/struct.CustomTimeZone.html#structfield.time_zone_id) for more information. + * + * Additional information: [1](https://docs.rs/icu/latest/icu/timezone/struct.TimeZoneBcp47Id.html) + */ + void clear_time_zone_id(); + + /** + * Writes the value of the `time_zone_id` field as a string. + * + * Errors if the `time_zone_id` field is empty. + * + * See the [Rust documentation for `time_zone_id`](https://docs.rs/icu/latest/icu/timezone/struct.CustomTimeZone.html#structfield.time_zone_id) for more information. + * + * Additional information: [1](https://docs.rs/icu/latest/icu/timezone/struct.TimeZoneBcp47Id.html) + */ + template<typename W> diplomat::result<std::monostate, ICU4XError> time_zone_id_to_writeable(W& write) const; + + /** + * Writes the value of the `time_zone_id` field as a string. + * + * Errors if the `time_zone_id` field is empty. + * + * See the [Rust documentation for `time_zone_id`](https://docs.rs/icu/latest/icu/timezone/struct.CustomTimeZone.html#structfield.time_zone_id) for more information. + * + * Additional information: [1](https://docs.rs/icu/latest/icu/timezone/struct.TimeZoneBcp47Id.html) + */ + diplomat::result<std::string, ICU4XError> time_zone_id() const; + + /** + * Sets the `metazone_id` field from a string. + * + * Errors if the string is not a valid BCP-47 metazone ID. + * + * See the [Rust documentation for `metazone_id`](https://docs.rs/icu/latest/icu/timezone/struct.CustomTimeZone.html#structfield.metazone_id) for more information. + * + * Additional information: [1](https://docs.rs/icu/latest/icu/timezone/struct.MetazoneId.html) + */ + diplomat::result<std::monostate, ICU4XError> try_set_metazone_id(const std::string_view id); + + /** + * Clears the `metazone_id` field. + * + * See the [Rust documentation for `metazone_id`](https://docs.rs/icu/latest/icu/timezone/struct.CustomTimeZone.html#structfield.metazone_id) for more information. + * + * Additional information: [1](https://docs.rs/icu/latest/icu/timezone/struct.MetazoneId.html) + */ + void clear_metazone_id(); + + /** + * Writes the value of the `metazone_id` field as a string. + * + * Errors if the `metazone_id` field is empty. + * + * See the [Rust documentation for `metazone_id`](https://docs.rs/icu/latest/icu/timezone/struct.CustomTimeZone.html#structfield.metazone_id) for more information. + * + * Additional information: [1](https://docs.rs/icu/latest/icu/timezone/struct.MetazoneId.html) + */ + template<typename W> diplomat::result<std::monostate, ICU4XError> metazone_id_to_writeable(W& write) const; + + /** + * Writes the value of the `metazone_id` field as a string. + * + * Errors if the `metazone_id` field is empty. + * + * See the [Rust documentation for `metazone_id`](https://docs.rs/icu/latest/icu/timezone/struct.CustomTimeZone.html#structfield.metazone_id) for more information. + * + * Additional information: [1](https://docs.rs/icu/latest/icu/timezone/struct.MetazoneId.html) + */ + diplomat::result<std::string, ICU4XError> metazone_id() const; + + /** + * Sets the `zone_variant` field from a string. + * + * Errors if the string is not a valid zone variant. + * + * See the [Rust documentation for `zone_variant`](https://docs.rs/icu/latest/icu/timezone/struct.CustomTimeZone.html#structfield.zone_variant) for more information. + * + * Additional information: [1](https://docs.rs/icu/latest/icu/timezone/struct.ZoneVariant.html) + */ + diplomat::result<std::monostate, ICU4XError> try_set_zone_variant(const std::string_view id); + + /** + * Clears the `zone_variant` field. + * + * See the [Rust documentation for `zone_variant`](https://docs.rs/icu/latest/icu/timezone/struct.CustomTimeZone.html#structfield.zone_variant) for more information. + * + * Additional information: [1](https://docs.rs/icu/latest/icu/timezone/struct.ZoneVariant.html) + */ + void clear_zone_variant(); + + /** + * Writes the value of the `zone_variant` field as a string. + * + * Errors if the `zone_variant` field is empty. + * + * See the [Rust documentation for `zone_variant`](https://docs.rs/icu/latest/icu/timezone/struct.CustomTimeZone.html#structfield.zone_variant) for more information. + * + * Additional information: [1](https://docs.rs/icu/latest/icu/timezone/struct.ZoneVariant.html) + */ + template<typename W> diplomat::result<std::monostate, ICU4XError> zone_variant_to_writeable(W& write) const; + + /** + * Writes the value of the `zone_variant` field as a string. + * + * Errors if the `zone_variant` field is empty. + * + * See the [Rust documentation for `zone_variant`](https://docs.rs/icu/latest/icu/timezone/struct.CustomTimeZone.html#structfield.zone_variant) for more information. + * + * Additional information: [1](https://docs.rs/icu/latest/icu/timezone/struct.ZoneVariant.html) + */ + diplomat::result<std::string, ICU4XError> zone_variant() const; + + /** + * Sets the `zone_variant` field to standard time. + * + * See the [Rust documentation for `standard`](https://docs.rs/icu/latest/icu/timezone/struct.ZoneVariant.html#method.standard) for more information. + * + * Additional information: [1](https://docs.rs/icu/latest/icu/timezone/struct.CustomTimeZone.html#structfield.zone_variant) + */ + void set_standard_time(); + + /** + * Sets the `zone_variant` field to daylight time. + * + * See the [Rust documentation for `daylight`](https://docs.rs/icu/latest/icu/timezone/struct.ZoneVariant.html#method.daylight) for more information. + * + * Additional information: [1](https://docs.rs/icu/latest/icu/timezone/struct.CustomTimeZone.html#structfield.zone_variant) + */ + void set_daylight_time(); + + /** + * Returns whether the `zone_variant` field is standard time. + * + * Errors if the `zone_variant` field is empty. + * + * See the [Rust documentation for `standard`](https://docs.rs/icu/latest/icu/timezone/struct.ZoneVariant.html#method.standard) for more information. + * + * Additional information: [1](https://docs.rs/icu/latest/icu/timezone/struct.CustomTimeZone.html#structfield.zone_variant) + */ + diplomat::result<bool, ICU4XError> is_standard_time() const; + + /** + * Returns whether the `zone_variant` field is daylight time. + * + * Errors if the `zone_variant` field is empty. + * + * See the [Rust documentation for `daylight`](https://docs.rs/icu/latest/icu/timezone/struct.ZoneVariant.html#method.daylight) for more information. + * + * Additional information: [1](https://docs.rs/icu/latest/icu/timezone/struct.CustomTimeZone.html#structfield.zone_variant) + */ + diplomat::result<bool, ICU4XError> is_daylight_time() const; + + /** + * Sets the metazone based on the time zone and the local timestamp. + * + * See the [Rust documentation for `maybe_calculate_metazone`](https://docs.rs/icu/latest/icu/timezone/struct.CustomTimeZone.html#method.maybe_calculate_metazone) for more information. + * + * Additional information: [1](https://docs.rs/icu/latest/icu/timezone/struct.MetazoneCalculator.html#method.compute_metazone_from_time_zone) + */ + void maybe_calculate_metazone(const ICU4XMetazoneCalculator& metazone_calculator, const ICU4XIsoDateTime& local_datetime); + inline const capi::ICU4XCustomTimeZone* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XCustomTimeZone* AsFFIMut() { return this->inner.get(); } + inline ICU4XCustomTimeZone(capi::ICU4XCustomTimeZone* i) : inner(i) {} + ICU4XCustomTimeZone() = default; + ICU4XCustomTimeZone(ICU4XCustomTimeZone&&) noexcept = default; + ICU4XCustomTimeZone& operator=(ICU4XCustomTimeZone&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XCustomTimeZone, ICU4XCustomTimeZoneDeleter> inner; +}; + +#include "ICU4XIanaToBcp47Mapper.hpp" +#include "ICU4XMetazoneCalculator.hpp" +#include "ICU4XIsoDateTime.hpp" + +inline diplomat::result<ICU4XCustomTimeZone, ICU4XError> ICU4XCustomTimeZone::create_from_string(const std::string_view s) { + auto diplomat_result_raw_out_value = capi::ICU4XCustomTimeZone_create_from_string(s.data(), s.size()); + diplomat::result<ICU4XCustomTimeZone, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XCustomTimeZone>(ICU4XCustomTimeZone(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline ICU4XCustomTimeZone ICU4XCustomTimeZone::create_empty() { + return ICU4XCustomTimeZone(capi::ICU4XCustomTimeZone_create_empty()); +} +inline ICU4XCustomTimeZone ICU4XCustomTimeZone::create_utc() { + return ICU4XCustomTimeZone(capi::ICU4XCustomTimeZone_create_utc()); +} +inline diplomat::result<std::monostate, ICU4XError> ICU4XCustomTimeZone::try_set_gmt_offset_seconds(int32_t offset_seconds) { + auto diplomat_result_raw_out_value = capi::ICU4XCustomTimeZone_try_set_gmt_offset_seconds(this->inner.get(), offset_seconds); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline void ICU4XCustomTimeZone::clear_gmt_offset() { + capi::ICU4XCustomTimeZone_clear_gmt_offset(this->inner.get()); +} +inline diplomat::result<int32_t, ICU4XError> ICU4XCustomTimeZone::gmt_offset_seconds() const { + auto diplomat_result_raw_out_value = capi::ICU4XCustomTimeZone_gmt_offset_seconds(this->inner.get()); + diplomat::result<int32_t, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<int32_t>(diplomat_result_raw_out_value.ok); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<bool, ICU4XError> ICU4XCustomTimeZone::is_gmt_offset_positive() const { + auto diplomat_result_raw_out_value = capi::ICU4XCustomTimeZone_is_gmt_offset_positive(this->inner.get()); + diplomat::result<bool, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<bool>(diplomat_result_raw_out_value.ok); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<bool, ICU4XError> ICU4XCustomTimeZone::is_gmt_offset_zero() const { + auto diplomat_result_raw_out_value = capi::ICU4XCustomTimeZone_is_gmt_offset_zero(this->inner.get()); + diplomat::result<bool, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<bool>(diplomat_result_raw_out_value.ok); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<bool, ICU4XError> ICU4XCustomTimeZone::gmt_offset_has_minutes() const { + auto diplomat_result_raw_out_value = capi::ICU4XCustomTimeZone_gmt_offset_has_minutes(this->inner.get()); + diplomat::result<bool, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<bool>(diplomat_result_raw_out_value.ok); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<bool, ICU4XError> ICU4XCustomTimeZone::gmt_offset_has_seconds() const { + auto diplomat_result_raw_out_value = capi::ICU4XCustomTimeZone_gmt_offset_has_seconds(this->inner.get()); + diplomat::result<bool, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<bool>(diplomat_result_raw_out_value.ok); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<std::monostate, ICU4XError> ICU4XCustomTimeZone::try_set_time_zone_id(const std::string_view id) { + auto diplomat_result_raw_out_value = capi::ICU4XCustomTimeZone_try_set_time_zone_id(this->inner.get(), id.data(), id.size()); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<std::monostate, ICU4XError> ICU4XCustomTimeZone::try_set_iana_time_zone_id(const ICU4XIanaToBcp47Mapper& mapper, const std::string_view id) { + auto diplomat_result_raw_out_value = capi::ICU4XCustomTimeZone_try_set_iana_time_zone_id(this->inner.get(), mapper.AsFFI(), id.data(), id.size()); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline void ICU4XCustomTimeZone::clear_time_zone_id() { + capi::ICU4XCustomTimeZone_clear_time_zone_id(this->inner.get()); +} +template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XCustomTimeZone::time_zone_id_to_writeable(W& write) const { + capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write); + auto diplomat_result_raw_out_value = capi::ICU4XCustomTimeZone_time_zone_id(this->inner.get(), &write_writer); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<std::string, ICU4XError> ICU4XCustomTimeZone::time_zone_id() const { + std::string diplomat_writeable_string; + capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); + auto diplomat_result_raw_out_value = capi::ICU4XCustomTimeZone_time_zone_id(this->inner.get(), &diplomat_writeable_out); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string)); +} +inline diplomat::result<std::monostate, ICU4XError> ICU4XCustomTimeZone::try_set_metazone_id(const std::string_view id) { + auto diplomat_result_raw_out_value = capi::ICU4XCustomTimeZone_try_set_metazone_id(this->inner.get(), id.data(), id.size()); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline void ICU4XCustomTimeZone::clear_metazone_id() { + capi::ICU4XCustomTimeZone_clear_metazone_id(this->inner.get()); +} +template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XCustomTimeZone::metazone_id_to_writeable(W& write) const { + capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write); + auto diplomat_result_raw_out_value = capi::ICU4XCustomTimeZone_metazone_id(this->inner.get(), &write_writer); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<std::string, ICU4XError> ICU4XCustomTimeZone::metazone_id() const { + std::string diplomat_writeable_string; + capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); + auto diplomat_result_raw_out_value = capi::ICU4XCustomTimeZone_metazone_id(this->inner.get(), &diplomat_writeable_out); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string)); +} +inline diplomat::result<std::monostate, ICU4XError> ICU4XCustomTimeZone::try_set_zone_variant(const std::string_view id) { + auto diplomat_result_raw_out_value = capi::ICU4XCustomTimeZone_try_set_zone_variant(this->inner.get(), id.data(), id.size()); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline void ICU4XCustomTimeZone::clear_zone_variant() { + capi::ICU4XCustomTimeZone_clear_zone_variant(this->inner.get()); +} +template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XCustomTimeZone::zone_variant_to_writeable(W& write) const { + capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write); + auto diplomat_result_raw_out_value = capi::ICU4XCustomTimeZone_zone_variant(this->inner.get(), &write_writer); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<std::string, ICU4XError> ICU4XCustomTimeZone::zone_variant() const { + std::string diplomat_writeable_string; + capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); + auto diplomat_result_raw_out_value = capi::ICU4XCustomTimeZone_zone_variant(this->inner.get(), &diplomat_writeable_out); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string)); +} +inline void ICU4XCustomTimeZone::set_standard_time() { + capi::ICU4XCustomTimeZone_set_standard_time(this->inner.get()); +} +inline void ICU4XCustomTimeZone::set_daylight_time() { + capi::ICU4XCustomTimeZone_set_daylight_time(this->inner.get()); +} +inline diplomat::result<bool, ICU4XError> ICU4XCustomTimeZone::is_standard_time() const { + auto diplomat_result_raw_out_value = capi::ICU4XCustomTimeZone_is_standard_time(this->inner.get()); + diplomat::result<bool, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<bool>(diplomat_result_raw_out_value.ok); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<bool, ICU4XError> ICU4XCustomTimeZone::is_daylight_time() const { + auto diplomat_result_raw_out_value = capi::ICU4XCustomTimeZone_is_daylight_time(this->inner.get()); + diplomat::result<bool, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<bool>(diplomat_result_raw_out_value.ok); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline void ICU4XCustomTimeZone::maybe_calculate_metazone(const ICU4XMetazoneCalculator& metazone_calculator, const ICU4XIsoDateTime& local_datetime) { + capi::ICU4XCustomTimeZone_maybe_calculate_metazone(this->inner.get(), metazone_calculator.AsFFI(), local_datetime.AsFFI()); +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XDataProvider.h b/intl/icu_capi/cpp/include/ICU4XDataProvider.h new file mode 100644 index 0000000000..8d7700e224 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XDataProvider.h @@ -0,0 +1,48 @@ +#ifndef ICU4XDataProvider_H +#define ICU4XDataProvider_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XDataProvider ICU4XDataProvider; +#ifdef __cplusplus +} // namespace capi +#endif +#include "diplomat_result_box_ICU4XDataProvider_ICU4XError.h" +#include "diplomat_result_void_ICU4XError.h" +#include "ICU4XLocaleFallbacker.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +ICU4XDataProvider* ICU4XDataProvider_create_compiled(); + +diplomat_result_box_ICU4XDataProvider_ICU4XError ICU4XDataProvider_create_fs(const char* path_data, size_t path_len); + +ICU4XDataProvider* ICU4XDataProvider_create_test(); + +diplomat_result_box_ICU4XDataProvider_ICU4XError ICU4XDataProvider_create_from_byte_slice(const uint8_t* blob_data, size_t blob_len); + +ICU4XDataProvider* ICU4XDataProvider_create_empty(); + +diplomat_result_void_ICU4XError ICU4XDataProvider_fork_by_key(ICU4XDataProvider* self, ICU4XDataProvider* other); + +diplomat_result_void_ICU4XError ICU4XDataProvider_fork_by_locale(ICU4XDataProvider* self, ICU4XDataProvider* other); + +diplomat_result_void_ICU4XError ICU4XDataProvider_enable_locale_fallback(ICU4XDataProvider* self); + +diplomat_result_void_ICU4XError ICU4XDataProvider_enable_locale_fallback_with(ICU4XDataProvider* self, const ICU4XLocaleFallbacker* fallbacker); +void ICU4XDataProvider_destroy(ICU4XDataProvider* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XDataProvider.hpp b/intl/icu_capi/cpp/include/ICU4XDataProvider.hpp new file mode 100644 index 0000000000..b007076aca --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XDataProvider.hpp @@ -0,0 +1,196 @@ +#ifndef ICU4XDataProvider_HPP +#define ICU4XDataProvider_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XDataProvider.h" + +class ICU4XDataProvider; +#include "ICU4XError.hpp" +class ICU4XLocaleFallbacker; + +/** + * A destruction policy for using ICU4XDataProvider with std::unique_ptr. + */ +struct ICU4XDataProviderDeleter { + void operator()(capi::ICU4XDataProvider* l) const noexcept { + capi::ICU4XDataProvider_destroy(l); + } +}; + +/** + * An ICU4X data provider, capable of loading ICU4X data keys from some source. + * + * See the [Rust documentation for `icu_provider`](https://docs.rs/icu_provider/latest/icu_provider/index.html) for more information. + */ +class ICU4XDataProvider { + public: + + /** + * Constructs an [`ICU4XDataProvider`] that uses compiled data. + * + * Requires the `compiled_data` feature. + * + * This provider cannot be modified or combined with other providers, so `enable_fallback`, + * `enabled_fallback_with`, `fork_by_locale`, and `fork_by_key` will return `Err`s. + */ + static ICU4XDataProvider create_compiled(); + + /** + * Constructs an `FsDataProvider` and returns it as an [`ICU4XDataProvider`]. + * Requires the `provider_fs` Cargo feature. + * Not supported in WASM. + * + * See the [Rust documentation for `FsDataProvider`](https://docs.rs/icu_provider_fs/latest/icu_provider_fs/struct.FsDataProvider.html) for more information. + */ + static diplomat::result<ICU4XDataProvider, ICU4XError> create_fs(const std::string_view path); + + /** + * Deprecated + * + * Use `create_compiled()`. + */ + static ICU4XDataProvider create_test(); + + /** + * Constructs a `BlobDataProvider` and returns it as an [`ICU4XDataProvider`]. + * + * See the [Rust documentation for `BlobDataProvider`](https://docs.rs/icu_provider_blob/latest/icu_provider_blob/struct.BlobDataProvider.html) for more information. + * + * Lifetimes: `blob` must live for the duration of the program. + */ + static diplomat::result<ICU4XDataProvider, ICU4XError> create_from_byte_slice(const diplomat::span<const uint8_t> blob); + + /** + * Constructs an empty [`ICU4XDataProvider`]. + * + * See the [Rust documentation for `EmptyDataProvider`](https://docs.rs/icu_provider_adapters/latest/icu_provider_adapters/empty/struct.EmptyDataProvider.html) for more information. + */ + static ICU4XDataProvider create_empty(); + + /** + * Creates a provider that tries the current provider and then, if the current provider + * doesn't support the data key, another provider `other`. + * + * This takes ownership of the `other` provider, leaving an empty provider in its place. + * + * The providers must be the same type (Any or Buffer). This condition is satisfied if + * both providers originate from the same constructor, such as `create_from_byte_slice` + * or `create_fs`. If the condition is not upheld, a runtime error occurs. + * + * See the [Rust documentation for `ForkByKeyProvider`](https://docs.rs/icu_provider_adapters/latest/icu_provider_adapters/fork/type.ForkByKeyProvider.html) for more information. + */ + diplomat::result<std::monostate, ICU4XError> fork_by_key(ICU4XDataProvider& other); + + /** + * Same as `fork_by_key` but forks by locale instead of key. + * + * See the [Rust documentation for `MissingLocalePredicate`](https://docs.rs/icu_provider_adapters/latest/icu_provider_adapters/fork/predicates/struct.MissingLocalePredicate.html) for more information. + */ + diplomat::result<std::monostate, ICU4XError> fork_by_locale(ICU4XDataProvider& other); + + /** + * Enables locale fallbacking for data requests made to this provider. + * + * Note that the test provider (from `create_test`) already has fallbacking enabled. + * + * See the [Rust documentation for `try_new`](https://docs.rs/icu_provider_adapters/latest/icu_provider_adapters/fallback/struct.LocaleFallbackProvider.html#method.try_new) for more information. + * + * Additional information: [1](https://docs.rs/icu_provider_adapters/latest/icu_provider_adapters/fallback/struct.LocaleFallbackProvider.html) + */ + diplomat::result<std::monostate, ICU4XError> enable_locale_fallback(); + + /** + * See the [Rust documentation for `new_with_fallbacker`](https://docs.rs/icu_provider_adapters/latest/icu_provider_adapters/fallback/struct.LocaleFallbackProvider.html#method.new_with_fallbacker) for more information. + * + * Additional information: [1](https://docs.rs/icu_provider_adapters/latest/icu_provider_adapters/fallback/struct.LocaleFallbackProvider.html) + */ + diplomat::result<std::monostate, ICU4XError> enable_locale_fallback_with(const ICU4XLocaleFallbacker& fallbacker); + inline const capi::ICU4XDataProvider* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XDataProvider* AsFFIMut() { return this->inner.get(); } + inline explicit ICU4XDataProvider(capi::ICU4XDataProvider* i) : inner(i) {} + ICU4XDataProvider() = default; + ICU4XDataProvider(ICU4XDataProvider&&) noexcept = default; + ICU4XDataProvider& operator=(ICU4XDataProvider&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XDataProvider, ICU4XDataProviderDeleter> inner; +}; + +#include "ICU4XLocaleFallbacker.hpp" + +inline ICU4XDataProvider ICU4XDataProvider::create_compiled() { + return ICU4XDataProvider(capi::ICU4XDataProvider_create_compiled()); +} +inline diplomat::result<ICU4XDataProvider, ICU4XError> ICU4XDataProvider::create_fs(const std::string_view path) { + auto diplomat_result_raw_out_value = capi::ICU4XDataProvider_create_fs(path.data(), path.size()); + diplomat::result<ICU4XDataProvider, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XDataProvider>(ICU4XDataProvider(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline ICU4XDataProvider ICU4XDataProvider::create_test() { + return ICU4XDataProvider(capi::ICU4XDataProvider_create_test()); +} +inline diplomat::result<ICU4XDataProvider, ICU4XError> ICU4XDataProvider::create_from_byte_slice(const diplomat::span<const uint8_t> blob) { + auto diplomat_result_raw_out_value = capi::ICU4XDataProvider_create_from_byte_slice(blob.data(), blob.size()); + diplomat::result<ICU4XDataProvider, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XDataProvider>(ICU4XDataProvider(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline ICU4XDataProvider ICU4XDataProvider::create_empty() { + return ICU4XDataProvider(capi::ICU4XDataProvider_create_empty()); +} +inline diplomat::result<std::monostate, ICU4XError> ICU4XDataProvider::fork_by_key(ICU4XDataProvider& other) { + auto diplomat_result_raw_out_value = capi::ICU4XDataProvider_fork_by_key(this->inner.get(), other.AsFFIMut()); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<std::monostate, ICU4XError> ICU4XDataProvider::fork_by_locale(ICU4XDataProvider& other) { + auto diplomat_result_raw_out_value = capi::ICU4XDataProvider_fork_by_locale(this->inner.get(), other.AsFFIMut()); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<std::monostate, ICU4XError> ICU4XDataProvider::enable_locale_fallback() { + auto diplomat_result_raw_out_value = capi::ICU4XDataProvider_enable_locale_fallback(this->inner.get()); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<std::monostate, ICU4XError> ICU4XDataProvider::enable_locale_fallback_with(const ICU4XLocaleFallbacker& fallbacker) { + auto diplomat_result_raw_out_value = capi::ICU4XDataProvider_enable_locale_fallback_with(this->inner.get(), fallbacker.AsFFI()); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XDataStruct.h b/intl/icu_capi/cpp/include/ICU4XDataStruct.h new file mode 100644 index 0000000000..a07ff02fb8 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XDataStruct.h @@ -0,0 +1,30 @@ +#ifndef ICU4XDataStruct_H +#define ICU4XDataStruct_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XDataStruct ICU4XDataStruct; +#ifdef __cplusplus +} // namespace capi +#endif +#include "diplomat_result_box_ICU4XDataStruct_ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +diplomat_result_box_ICU4XDataStruct_ICU4XError ICU4XDataStruct_create_decimal_symbols_v1(const char* plus_sign_prefix_data, size_t plus_sign_prefix_len, const char* plus_sign_suffix_data, size_t plus_sign_suffix_len, const char* minus_sign_prefix_data, size_t minus_sign_prefix_len, const char* minus_sign_suffix_data, size_t minus_sign_suffix_len, const char* decimal_separator_data, size_t decimal_separator_len, const char* grouping_separator_data, size_t grouping_separator_len, uint8_t primary_group_size, uint8_t secondary_group_size, uint8_t min_group_size, const char32_t* digits_data, size_t digits_len); +void ICU4XDataStruct_destroy(ICU4XDataStruct* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XDataStruct.hpp b/intl/icu_capi/cpp/include/ICU4XDataStruct.hpp new file mode 100644 index 0000000000..877de4400a --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XDataStruct.hpp @@ -0,0 +1,63 @@ +#ifndef ICU4XDataStruct_HPP +#define ICU4XDataStruct_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XDataStruct.h" + +class ICU4XDataStruct; +#include "ICU4XError.hpp" + +/** + * A destruction policy for using ICU4XDataStruct with std::unique_ptr. + */ +struct ICU4XDataStructDeleter { + void operator()(capi::ICU4XDataStruct* l) const noexcept { + capi::ICU4XDataStruct_destroy(l); + } +}; + +/** + * A generic data struct to be used by ICU4X + * + * This can be used to construct a StructDataProvider. + */ +class ICU4XDataStruct { + public: + + /** + * Construct a new DecimalSymbolsV1 data struct. + * + * C++ users: All string arguments must be valid UTF8 + * + * See the [Rust documentation for `DecimalSymbolsV1`](https://docs.rs/icu/latest/icu/decimal/provider/struct.DecimalSymbolsV1.html) for more information. + */ + static diplomat::result<ICU4XDataStruct, ICU4XError> create_decimal_symbols_v1(const std::string_view plus_sign_prefix, const std::string_view plus_sign_suffix, const std::string_view minus_sign_prefix, const std::string_view minus_sign_suffix, const std::string_view decimal_separator, const std::string_view grouping_separator, uint8_t primary_group_size, uint8_t secondary_group_size, uint8_t min_group_size, const diplomat::span<const char32_t> digits); + inline const capi::ICU4XDataStruct* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XDataStruct* AsFFIMut() { return this->inner.get(); } + inline ICU4XDataStruct(capi::ICU4XDataStruct* i) : inner(i) {} + ICU4XDataStruct() = default; + ICU4XDataStruct(ICU4XDataStruct&&) noexcept = default; + ICU4XDataStruct& operator=(ICU4XDataStruct&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XDataStruct, ICU4XDataStructDeleter> inner; +}; + + +inline diplomat::result<ICU4XDataStruct, ICU4XError> ICU4XDataStruct::create_decimal_symbols_v1(const std::string_view plus_sign_prefix, const std::string_view plus_sign_suffix, const std::string_view minus_sign_prefix, const std::string_view minus_sign_suffix, const std::string_view decimal_separator, const std::string_view grouping_separator, uint8_t primary_group_size, uint8_t secondary_group_size, uint8_t min_group_size, const diplomat::span<const char32_t> digits) { + auto diplomat_result_raw_out_value = capi::ICU4XDataStruct_create_decimal_symbols_v1(plus_sign_prefix.data(), plus_sign_prefix.size(), plus_sign_suffix.data(), plus_sign_suffix.size(), minus_sign_prefix.data(), minus_sign_prefix.size(), minus_sign_suffix.data(), minus_sign_suffix.size(), decimal_separator.data(), decimal_separator.size(), grouping_separator.data(), grouping_separator.size(), primary_group_size, secondary_group_size, min_group_size, digits.data(), digits.size()); + diplomat::result<ICU4XDataStruct, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XDataStruct>(ICU4XDataStruct(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XDate.h b/intl/icu_capi/cpp/include/ICU4XDate.h new file mode 100644 index 0000000000..f5a0c06de6 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XDate.h @@ -0,0 +1,66 @@ +#ifndef ICU4XDate_H +#define ICU4XDate_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XDate ICU4XDate; +#ifdef __cplusplus +} // namespace capi +#endif +#include "ICU4XCalendar.h" +#include "diplomat_result_box_ICU4XDate_ICU4XError.h" +#include "ICU4XIsoDate.h" +#include "ICU4XIsoWeekday.h" +#include "ICU4XWeekCalculator.h" +#include "diplomat_result_ICU4XWeekOf_ICU4XError.h" +#include "diplomat_result_void_ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +diplomat_result_box_ICU4XDate_ICU4XError ICU4XDate_create_from_iso_in_calendar(int32_t year, uint8_t month, uint8_t day, const ICU4XCalendar* calendar); + +diplomat_result_box_ICU4XDate_ICU4XError ICU4XDate_create_from_codes_in_calendar(const char* era_code_data, size_t era_code_len, int32_t year, const char* month_code_data, size_t month_code_len, uint8_t day, const ICU4XCalendar* calendar); + +ICU4XDate* ICU4XDate_to_calendar(const ICU4XDate* self, const ICU4XCalendar* calendar); + +ICU4XIsoDate* ICU4XDate_to_iso(const ICU4XDate* self); + +uint32_t ICU4XDate_day_of_month(const ICU4XDate* self); + +ICU4XIsoWeekday ICU4XDate_day_of_week(const ICU4XDate* self); + +uint32_t ICU4XDate_week_of_month(const ICU4XDate* self, ICU4XIsoWeekday first_weekday); + +diplomat_result_ICU4XWeekOf_ICU4XError ICU4XDate_week_of_year(const ICU4XDate* self, const ICU4XWeekCalculator* calculator); + +uint32_t ICU4XDate_ordinal_month(const ICU4XDate* self); + +diplomat_result_void_ICU4XError ICU4XDate_month_code(const ICU4XDate* self, DiplomatWriteable* write); + +int32_t ICU4XDate_year_in_era(const ICU4XDate* self); + +diplomat_result_void_ICU4XError ICU4XDate_era(const ICU4XDate* self, DiplomatWriteable* write); + +uint8_t ICU4XDate_months_in_year(const ICU4XDate* self); + +uint8_t ICU4XDate_days_in_month(const ICU4XDate* self); + +uint16_t ICU4XDate_days_in_year(const ICU4XDate* self); + +ICU4XCalendar* ICU4XDate_calendar(const ICU4XDate* self); +void ICU4XDate_destroy(ICU4XDate* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XDate.hpp b/intl/icu_capi/cpp/include/ICU4XDate.hpp new file mode 100644 index 0000000000..ef23cc31a8 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XDate.hpp @@ -0,0 +1,303 @@ +#ifndef ICU4XDate_HPP +#define ICU4XDate_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XDate.h" + +class ICU4XCalendar; +class ICU4XDate; +#include "ICU4XError.hpp" +class ICU4XIsoDate; +#include "ICU4XIsoWeekday.hpp" +class ICU4XWeekCalculator; +struct ICU4XWeekOf; + +/** + * A destruction policy for using ICU4XDate with std::unique_ptr. + */ +struct ICU4XDateDeleter { + void operator()(capi::ICU4XDate* l) const noexcept { + capi::ICU4XDate_destroy(l); + } +}; + +/** + * An ICU4X Date object capable of containing a date and time for any calendar. + * + * See the [Rust documentation for `Date`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html) for more information. + */ +class ICU4XDate { + public: + + /** + * Creates a new [`ICU4XDate`] representing the ISO date and time + * given but in a given calendar + * + * See the [Rust documentation for `new_from_iso`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.new_from_iso) for more information. + */ + static diplomat::result<ICU4XDate, ICU4XError> create_from_iso_in_calendar(int32_t year, uint8_t month, uint8_t day, const ICU4XCalendar& calendar); + + /** + * Creates a new [`ICU4XDate`] from the given codes, which are interpreted in the given calendar system + * + * See the [Rust documentation for `try_new_from_codes`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.try_new_from_codes) for more information. + */ + static diplomat::result<ICU4XDate, ICU4XError> create_from_codes_in_calendar(const std::string_view era_code, int32_t year, const std::string_view month_code, uint8_t day, const ICU4XCalendar& calendar); + + /** + * Convert this date to one in a different calendar + * + * See the [Rust documentation for `to_calendar`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.to_calendar) for more information. + */ + ICU4XDate to_calendar(const ICU4XCalendar& calendar) const; + + /** + * Converts this date to ISO + * + * See the [Rust documentation for `to_iso`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.to_iso) for more information. + */ + ICU4XIsoDate to_iso() const; + + /** + * Returns the 1-indexed day in the month for this date + * + * See the [Rust documentation for `day_of_month`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.day_of_month) for more information. + */ + uint32_t day_of_month() const; + + /** + * Returns the day in the week for this day + * + * See the [Rust documentation for `day_of_week`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.day_of_week) for more information. + */ + ICU4XIsoWeekday day_of_week() const; + + /** + * Returns the week number in this month, 1-indexed, based on what + * is considered the first day of the week (often a locale preference). + * + * `first_weekday` can be obtained via `first_weekday()` on [`ICU4XWeekCalculator`] + * + * See the [Rust documentation for `week_of_month`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.week_of_month) for more information. + */ + uint32_t week_of_month(ICU4XIsoWeekday first_weekday) const; + + /** + * Returns the week number in this year, using week data + * + * See the [Rust documentation for `week_of_year`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.week_of_year) for more information. + */ + diplomat::result<ICU4XWeekOf, ICU4XError> week_of_year(const ICU4XWeekCalculator& calculator) const; + + /** + * Returns 1-indexed number of the month of this date in its year + * + * Note that for lunar calendars this may not lead to the same month + * having the same ordinal month across years; use month_code if you care + * about month identity. + * + * See the [Rust documentation for `month`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.month) for more information. + */ + uint32_t ordinal_month() const; + + /** + * Returns the month code for this date. Typically something + * like "M01", "M02", but can be more complicated for lunar calendars. + * + * See the [Rust documentation for `month`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.month) for more information. + */ + template<typename W> diplomat::result<std::monostate, ICU4XError> month_code_to_writeable(W& write) const; + + /** + * Returns the month code for this date. Typically something + * like "M01", "M02", but can be more complicated for lunar calendars. + * + * See the [Rust documentation for `month`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.month) for more information. + */ + diplomat::result<std::string, ICU4XError> month_code() const; + + /** + * Returns the year number in the current era for this date + * + * See the [Rust documentation for `year`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.year) for more information. + */ + int32_t year_in_era() const; + + /** + * Returns the era for this date, + * + * See the [Rust documentation for `year`](https://docs.rs/icu/latest/icu/struct.Date.html#method.year) for more information. + * + * Additional information: [1](https://docs.rs/icu/latest/icu/types/struct.Era.html) + */ + template<typename W> diplomat::result<std::monostate, ICU4XError> era_to_writeable(W& write) const; + + /** + * Returns the era for this date, + * + * See the [Rust documentation for `year`](https://docs.rs/icu/latest/icu/struct.Date.html#method.year) for more information. + * + * Additional information: [1](https://docs.rs/icu/latest/icu/types/struct.Era.html) + */ + diplomat::result<std::string, ICU4XError> era() const; + + /** + * Returns the number of months in the year represented by this date + * + * See the [Rust documentation for `months_in_year`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.months_in_year) for more information. + */ + uint8_t months_in_year() const; + + /** + * Returns the number of days in the month represented by this date + * + * See the [Rust documentation for `days_in_month`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.days_in_month) for more information. + */ + uint8_t days_in_month() const; + + /** + * Returns the number of days in the year represented by this date + * + * See the [Rust documentation for `days_in_year`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.days_in_year) for more information. + */ + uint16_t days_in_year() const; + + /** + * Returns the [`ICU4XCalendar`] object backing this date + * + * See the [Rust documentation for `calendar`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.calendar) for more information. + */ + ICU4XCalendar calendar() const; + inline const capi::ICU4XDate* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XDate* AsFFIMut() { return this->inner.get(); } + inline ICU4XDate(capi::ICU4XDate* i) : inner(i) {} + ICU4XDate() = default; + ICU4XDate(ICU4XDate&&) noexcept = default; + ICU4XDate& operator=(ICU4XDate&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XDate, ICU4XDateDeleter> inner; +}; + +#include "ICU4XCalendar.hpp" +#include "ICU4XIsoDate.hpp" +#include "ICU4XWeekCalculator.hpp" +#include "ICU4XWeekOf.hpp" + +inline diplomat::result<ICU4XDate, ICU4XError> ICU4XDate::create_from_iso_in_calendar(int32_t year, uint8_t month, uint8_t day, const ICU4XCalendar& calendar) { + auto diplomat_result_raw_out_value = capi::ICU4XDate_create_from_iso_in_calendar(year, month, day, calendar.AsFFI()); + diplomat::result<ICU4XDate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XDate>(ICU4XDate(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XDate, ICU4XError> ICU4XDate::create_from_codes_in_calendar(const std::string_view era_code, int32_t year, const std::string_view month_code, uint8_t day, const ICU4XCalendar& calendar) { + auto diplomat_result_raw_out_value = capi::ICU4XDate_create_from_codes_in_calendar(era_code.data(), era_code.size(), year, month_code.data(), month_code.size(), day, calendar.AsFFI()); + diplomat::result<ICU4XDate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XDate>(ICU4XDate(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline ICU4XDate ICU4XDate::to_calendar(const ICU4XCalendar& calendar) const { + return ICU4XDate(capi::ICU4XDate_to_calendar(this->inner.get(), calendar.AsFFI())); +} +inline ICU4XIsoDate ICU4XDate::to_iso() const { + return ICU4XIsoDate(capi::ICU4XDate_to_iso(this->inner.get())); +} +inline uint32_t ICU4XDate::day_of_month() const { + return capi::ICU4XDate_day_of_month(this->inner.get()); +} +inline ICU4XIsoWeekday ICU4XDate::day_of_week() const { + return static_cast<ICU4XIsoWeekday>(capi::ICU4XDate_day_of_week(this->inner.get())); +} +inline uint32_t ICU4XDate::week_of_month(ICU4XIsoWeekday first_weekday) const { + return capi::ICU4XDate_week_of_month(this->inner.get(), static_cast<capi::ICU4XIsoWeekday>(first_weekday)); +} +inline diplomat::result<ICU4XWeekOf, ICU4XError> ICU4XDate::week_of_year(const ICU4XWeekCalculator& calculator) const { + auto diplomat_result_raw_out_value = capi::ICU4XDate_week_of_year(this->inner.get(), calculator.AsFFI()); + diplomat::result<ICU4XWeekOf, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + capi::ICU4XWeekOf diplomat_raw_struct_out_value = diplomat_result_raw_out_value.ok; + diplomat_result_out_value = diplomat::Ok<ICU4XWeekOf>(ICU4XWeekOf{ .week = std::move(diplomat_raw_struct_out_value.week), .unit = std::move(static_cast<ICU4XWeekRelativeUnit>(diplomat_raw_struct_out_value.unit)) }); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline uint32_t ICU4XDate::ordinal_month() const { + return capi::ICU4XDate_ordinal_month(this->inner.get()); +} +template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XDate::month_code_to_writeable(W& write) const { + capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write); + auto diplomat_result_raw_out_value = capi::ICU4XDate_month_code(this->inner.get(), &write_writer); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<std::string, ICU4XError> ICU4XDate::month_code() const { + std::string diplomat_writeable_string; + capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); + auto diplomat_result_raw_out_value = capi::ICU4XDate_month_code(this->inner.get(), &diplomat_writeable_out); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string)); +} +inline int32_t ICU4XDate::year_in_era() const { + return capi::ICU4XDate_year_in_era(this->inner.get()); +} +template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XDate::era_to_writeable(W& write) const { + capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write); + auto diplomat_result_raw_out_value = capi::ICU4XDate_era(this->inner.get(), &write_writer); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<std::string, ICU4XError> ICU4XDate::era() const { + std::string diplomat_writeable_string; + capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); + auto diplomat_result_raw_out_value = capi::ICU4XDate_era(this->inner.get(), &diplomat_writeable_out); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string)); +} +inline uint8_t ICU4XDate::months_in_year() const { + return capi::ICU4XDate_months_in_year(this->inner.get()); +} +inline uint8_t ICU4XDate::days_in_month() const { + return capi::ICU4XDate_days_in_month(this->inner.get()); +} +inline uint16_t ICU4XDate::days_in_year() const { + return capi::ICU4XDate_days_in_year(this->inner.get()); +} +inline ICU4XCalendar ICU4XDate::calendar() const { + return ICU4XCalendar(capi::ICU4XDate_calendar(this->inner.get())); +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XDateFormatter.h b/intl/icu_capi/cpp/include/ICU4XDateFormatter.h new file mode 100644 index 0000000000..8dc5316e47 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XDateFormatter.h @@ -0,0 +1,46 @@ +#ifndef ICU4XDateFormatter_H +#define ICU4XDateFormatter_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XDateFormatter ICU4XDateFormatter; +#ifdef __cplusplus +} // namespace capi +#endif +#include "ICU4XDataProvider.h" +#include "ICU4XLocale.h" +#include "ICU4XDateLength.h" +#include "diplomat_result_box_ICU4XDateFormatter_ICU4XError.h" +#include "ICU4XDate.h" +#include "diplomat_result_void_ICU4XError.h" +#include "ICU4XIsoDate.h" +#include "ICU4XDateTime.h" +#include "ICU4XIsoDateTime.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +diplomat_result_box_ICU4XDateFormatter_ICU4XError ICU4XDateFormatter_create_with_length(const ICU4XDataProvider* provider, const ICU4XLocale* locale, ICU4XDateLength date_length); + +diplomat_result_void_ICU4XError ICU4XDateFormatter_format_date(const ICU4XDateFormatter* self, const ICU4XDate* value, DiplomatWriteable* write); + +diplomat_result_void_ICU4XError ICU4XDateFormatter_format_iso_date(const ICU4XDateFormatter* self, const ICU4XIsoDate* value, DiplomatWriteable* write); + +diplomat_result_void_ICU4XError ICU4XDateFormatter_format_datetime(const ICU4XDateFormatter* self, const ICU4XDateTime* value, DiplomatWriteable* write); + +diplomat_result_void_ICU4XError ICU4XDateFormatter_format_iso_datetime(const ICU4XDateFormatter* self, const ICU4XIsoDateTime* value, DiplomatWriteable* write); +void ICU4XDateFormatter_destroy(ICU4XDateFormatter* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XDateFormatter.hpp b/intl/icu_capi/cpp/include/ICU4XDateFormatter.hpp new file mode 100644 index 0000000000..13525b0cc6 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XDateFormatter.hpp @@ -0,0 +1,231 @@ +#ifndef ICU4XDateFormatter_HPP +#define ICU4XDateFormatter_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XDateFormatter.h" + +class ICU4XDataProvider; +class ICU4XLocale; +#include "ICU4XDateLength.hpp" +class ICU4XDateFormatter; +#include "ICU4XError.hpp" +class ICU4XDate; +class ICU4XIsoDate; +class ICU4XDateTime; +class ICU4XIsoDateTime; + +/** + * A destruction policy for using ICU4XDateFormatter with std::unique_ptr. + */ +struct ICU4XDateFormatterDeleter { + void operator()(capi::ICU4XDateFormatter* l) const noexcept { + capi::ICU4XDateFormatter_destroy(l); + } +}; + +/** + * An ICU4X DateFormatter object capable of formatting a [`ICU4XDate`] as a string, + * using some calendar specified at runtime in the locale. + * + * See the [Rust documentation for `DateFormatter`](https://docs.rs/icu/latest/icu/datetime/struct.DateFormatter.html) for more information. + */ +class ICU4XDateFormatter { + public: + + /** + * Creates a new [`ICU4XDateFormatter`] from locale data. + * + * See the [Rust documentation for `try_new_with_length`](https://docs.rs/icu/latest/icu/datetime/struct.DateFormatter.html#method.try_new_with_length) for more information. + */ + static diplomat::result<ICU4XDateFormatter, ICU4XError> create_with_length(const ICU4XDataProvider& provider, const ICU4XLocale& locale, ICU4XDateLength date_length); + + /** + * Formats a [`ICU4XDate`] to a string. + * + * See the [Rust documentation for `format`](https://docs.rs/icu/latest/icu/datetime/struct.DateFormatter.html#method.format) for more information. + */ + template<typename W> diplomat::result<std::monostate, ICU4XError> format_date_to_writeable(const ICU4XDate& value, W& write) const; + + /** + * Formats a [`ICU4XDate`] to a string. + * + * See the [Rust documentation for `format`](https://docs.rs/icu/latest/icu/datetime/struct.DateFormatter.html#method.format) for more information. + */ + diplomat::result<std::string, ICU4XError> format_date(const ICU4XDate& value) const; + + /** + * Formats a [`ICU4XIsoDate`] to a string. + * + * Will convert to this formatter's calendar first + * + * See the [Rust documentation for `format`](https://docs.rs/icu/latest/icu/datetime/struct.DateFormatter.html#method.format) for more information. + */ + template<typename W> diplomat::result<std::monostate, ICU4XError> format_iso_date_to_writeable(const ICU4XIsoDate& value, W& write) const; + + /** + * Formats a [`ICU4XIsoDate`] to a string. + * + * Will convert to this formatter's calendar first + * + * See the [Rust documentation for `format`](https://docs.rs/icu/latest/icu/datetime/struct.DateFormatter.html#method.format) for more information. + */ + diplomat::result<std::string, ICU4XError> format_iso_date(const ICU4XIsoDate& value) const; + + /** + * Formats a [`ICU4XDateTime`] to a string. + * + * See the [Rust documentation for `format`](https://docs.rs/icu/latest/icu/datetime/struct.DateFormatter.html#method.format) for more information. + */ + template<typename W> diplomat::result<std::monostate, ICU4XError> format_datetime_to_writeable(const ICU4XDateTime& value, W& write) const; + + /** + * Formats a [`ICU4XDateTime`] to a string. + * + * See the [Rust documentation for `format`](https://docs.rs/icu/latest/icu/datetime/struct.DateFormatter.html#method.format) for more information. + */ + diplomat::result<std::string, ICU4XError> format_datetime(const ICU4XDateTime& value) const; + + /** + * Formats a [`ICU4XIsoDateTime`] to a string. + * + * Will convert to this formatter's calendar first + * + * See the [Rust documentation for `format`](https://docs.rs/icu/latest/icu/datetime/struct.DateFormatter.html#method.format) for more information. + */ + template<typename W> diplomat::result<std::monostate, ICU4XError> format_iso_datetime_to_writeable(const ICU4XIsoDateTime& value, W& write) const; + + /** + * Formats a [`ICU4XIsoDateTime`] to a string. + * + * Will convert to this formatter's calendar first + * + * See the [Rust documentation for `format`](https://docs.rs/icu/latest/icu/datetime/struct.DateFormatter.html#method.format) for more information. + */ + diplomat::result<std::string, ICU4XError> format_iso_datetime(const ICU4XIsoDateTime& value) const; + inline const capi::ICU4XDateFormatter* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XDateFormatter* AsFFIMut() { return this->inner.get(); } + inline ICU4XDateFormatter(capi::ICU4XDateFormatter* i) : inner(i) {} + ICU4XDateFormatter() = default; + ICU4XDateFormatter(ICU4XDateFormatter&&) noexcept = default; + ICU4XDateFormatter& operator=(ICU4XDateFormatter&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XDateFormatter, ICU4XDateFormatterDeleter> inner; +}; + +#include "ICU4XDataProvider.hpp" +#include "ICU4XLocale.hpp" +#include "ICU4XDate.hpp" +#include "ICU4XIsoDate.hpp" +#include "ICU4XDateTime.hpp" +#include "ICU4XIsoDateTime.hpp" + +inline diplomat::result<ICU4XDateFormatter, ICU4XError> ICU4XDateFormatter::create_with_length(const ICU4XDataProvider& provider, const ICU4XLocale& locale, ICU4XDateLength date_length) { + auto diplomat_result_raw_out_value = capi::ICU4XDateFormatter_create_with_length(provider.AsFFI(), locale.AsFFI(), static_cast<capi::ICU4XDateLength>(date_length)); + diplomat::result<ICU4XDateFormatter, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XDateFormatter>(ICU4XDateFormatter(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XDateFormatter::format_date_to_writeable(const ICU4XDate& value, W& write) const { + capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write); + auto diplomat_result_raw_out_value = capi::ICU4XDateFormatter_format_date(this->inner.get(), value.AsFFI(), &write_writer); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<std::string, ICU4XError> ICU4XDateFormatter::format_date(const ICU4XDate& value) const { + std::string diplomat_writeable_string; + capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); + auto diplomat_result_raw_out_value = capi::ICU4XDateFormatter_format_date(this->inner.get(), value.AsFFI(), &diplomat_writeable_out); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string)); +} +template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XDateFormatter::format_iso_date_to_writeable(const ICU4XIsoDate& value, W& write) const { + capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write); + auto diplomat_result_raw_out_value = capi::ICU4XDateFormatter_format_iso_date(this->inner.get(), value.AsFFI(), &write_writer); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<std::string, ICU4XError> ICU4XDateFormatter::format_iso_date(const ICU4XIsoDate& value) const { + std::string diplomat_writeable_string; + capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); + auto diplomat_result_raw_out_value = capi::ICU4XDateFormatter_format_iso_date(this->inner.get(), value.AsFFI(), &diplomat_writeable_out); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string)); +} +template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XDateFormatter::format_datetime_to_writeable(const ICU4XDateTime& value, W& write) const { + capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write); + auto diplomat_result_raw_out_value = capi::ICU4XDateFormatter_format_datetime(this->inner.get(), value.AsFFI(), &write_writer); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<std::string, ICU4XError> ICU4XDateFormatter::format_datetime(const ICU4XDateTime& value) const { + std::string diplomat_writeable_string; + capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); + auto diplomat_result_raw_out_value = capi::ICU4XDateFormatter_format_datetime(this->inner.get(), value.AsFFI(), &diplomat_writeable_out); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string)); +} +template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XDateFormatter::format_iso_datetime_to_writeable(const ICU4XIsoDateTime& value, W& write) const { + capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write); + auto diplomat_result_raw_out_value = capi::ICU4XDateFormatter_format_iso_datetime(this->inner.get(), value.AsFFI(), &write_writer); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<std::string, ICU4XError> ICU4XDateFormatter::format_iso_datetime(const ICU4XIsoDateTime& value) const { + std::string diplomat_writeable_string; + capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); + auto diplomat_result_raw_out_value = capi::ICU4XDateFormatter_format_iso_datetime(this->inner.get(), value.AsFFI(), &diplomat_writeable_out); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string)); +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XDateLength.h b/intl/icu_capi/cpp/include/ICU4XDateLength.h new file mode 100644 index 0000000000..b2ca918233 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XDateLength.h @@ -0,0 +1,33 @@ +#ifndef ICU4XDateLength_H +#define ICU4XDateLength_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef enum ICU4XDateLength { + ICU4XDateLength_Full = 0, + ICU4XDateLength_Long = 1, + ICU4XDateLength_Medium = 2, + ICU4XDateLength_Short = 3, +} ICU4XDateLength; +#ifdef __cplusplus +} // namespace capi +#endif +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +void ICU4XDateLength_destroy(ICU4XDateLength* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XDateLength.hpp b/intl/icu_capi/cpp/include/ICU4XDateLength.hpp new file mode 100644 index 0000000000..8e7edd4d64 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XDateLength.hpp @@ -0,0 +1,26 @@ +#ifndef ICU4XDateLength_HPP +#define ICU4XDateLength_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XDateLength.h" + + + +/** + * See the [Rust documentation for `Date`](https://docs.rs/icu/latest/icu/datetime/options/length/enum.Date.html) for more information. + */ +enum struct ICU4XDateLength { + Full = 0, + Long = 1, + Medium = 2, + Short = 3, +}; + +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XDateTime.h b/intl/icu_capi/cpp/include/ICU4XDateTime.h new file mode 100644 index 0000000000..adb0a19798 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XDateTime.h @@ -0,0 +1,82 @@ +#ifndef ICU4XDateTime_H +#define ICU4XDateTime_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XDateTime ICU4XDateTime; +#ifdef __cplusplus +} // namespace capi +#endif +#include "ICU4XCalendar.h" +#include "diplomat_result_box_ICU4XDateTime_ICU4XError.h" +#include "ICU4XDate.h" +#include "ICU4XTime.h" +#include "ICU4XIsoDateTime.h" +#include "ICU4XIsoWeekday.h" +#include "ICU4XWeekCalculator.h" +#include "diplomat_result_ICU4XWeekOf_ICU4XError.h" +#include "diplomat_result_void_ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +diplomat_result_box_ICU4XDateTime_ICU4XError ICU4XDateTime_create_from_iso_in_calendar(int32_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second, uint32_t nanosecond, const ICU4XCalendar* calendar); + +diplomat_result_box_ICU4XDateTime_ICU4XError ICU4XDateTime_create_from_codes_in_calendar(const char* era_code_data, size_t era_code_len, int32_t year, const char* month_code_data, size_t month_code_len, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second, uint32_t nanosecond, const ICU4XCalendar* calendar); + +ICU4XDateTime* ICU4XDateTime_create_from_date_and_time(const ICU4XDate* date, const ICU4XTime* time); + +ICU4XDate* ICU4XDateTime_date(const ICU4XDateTime* self); + +ICU4XTime* ICU4XDateTime_time(const ICU4XDateTime* self); + +ICU4XIsoDateTime* ICU4XDateTime_to_iso(const ICU4XDateTime* self); + +ICU4XDateTime* ICU4XDateTime_to_calendar(const ICU4XDateTime* self, const ICU4XCalendar* calendar); + +uint8_t ICU4XDateTime_hour(const ICU4XDateTime* self); + +uint8_t ICU4XDateTime_minute(const ICU4XDateTime* self); + +uint8_t ICU4XDateTime_second(const ICU4XDateTime* self); + +uint32_t ICU4XDateTime_nanosecond(const ICU4XDateTime* self); + +uint32_t ICU4XDateTime_day_of_month(const ICU4XDateTime* self); + +ICU4XIsoWeekday ICU4XDateTime_day_of_week(const ICU4XDateTime* self); + +uint32_t ICU4XDateTime_week_of_month(const ICU4XDateTime* self, ICU4XIsoWeekday first_weekday); + +diplomat_result_ICU4XWeekOf_ICU4XError ICU4XDateTime_week_of_year(const ICU4XDateTime* self, const ICU4XWeekCalculator* calculator); + +uint32_t ICU4XDateTime_ordinal_month(const ICU4XDateTime* self); + +diplomat_result_void_ICU4XError ICU4XDateTime_month_code(const ICU4XDateTime* self, DiplomatWriteable* write); + +int32_t ICU4XDateTime_year_in_era(const ICU4XDateTime* self); + +diplomat_result_void_ICU4XError ICU4XDateTime_era(const ICU4XDateTime* self, DiplomatWriteable* write); + +uint8_t ICU4XDateTime_months_in_year(const ICU4XDateTime* self); + +uint8_t ICU4XDateTime_days_in_month(const ICU4XDateTime* self); + +uint16_t ICU4XDateTime_days_in_year(const ICU4XDateTime* self); + +ICU4XCalendar* ICU4XDateTime_calendar(const ICU4XDateTime* self); +void ICU4XDateTime_destroy(ICU4XDateTime* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XDateTime.hpp b/intl/icu_capi/cpp/include/ICU4XDateTime.hpp new file mode 100644 index 0000000000..baf7ca9565 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XDateTime.hpp @@ -0,0 +1,373 @@ +#ifndef ICU4XDateTime_HPP +#define ICU4XDateTime_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XDateTime.h" + +class ICU4XCalendar; +class ICU4XDateTime; +#include "ICU4XError.hpp" +class ICU4XDate; +class ICU4XTime; +class ICU4XIsoDateTime; +#include "ICU4XIsoWeekday.hpp" +class ICU4XWeekCalculator; +struct ICU4XWeekOf; + +/** + * A destruction policy for using ICU4XDateTime with std::unique_ptr. + */ +struct ICU4XDateTimeDeleter { + void operator()(capi::ICU4XDateTime* l) const noexcept { + capi::ICU4XDateTime_destroy(l); + } +}; + +/** + * An ICU4X DateTime object capable of containing a date and time for any calendar. + * + * See the [Rust documentation for `DateTime`](https://docs.rs/icu/latest/icu/calendar/struct.DateTime.html) for more information. + */ +class ICU4XDateTime { + public: + + /** + * Creates a new [`ICU4XDateTime`] representing the ISO date and time + * given but in a given calendar + * + * See the [Rust documentation for `new_from_iso`](https://docs.rs/icu/latest/icu/struct.DateTime.html#method.new_from_iso) for more information. + */ + static diplomat::result<ICU4XDateTime, ICU4XError> create_from_iso_in_calendar(int32_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second, uint32_t nanosecond, const ICU4XCalendar& calendar); + + /** + * Creates a new [`ICU4XDateTime`] from the given codes, which are interpreted in the given calendar system + * + * See the [Rust documentation for `try_new_from_codes`](https://docs.rs/icu/latest/icu/calendar/struct.DateTime.html#method.try_new_from_codes) for more information. + */ + static diplomat::result<ICU4XDateTime, ICU4XError> create_from_codes_in_calendar(const std::string_view era_code, int32_t year, const std::string_view month_code, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second, uint32_t nanosecond, const ICU4XCalendar& calendar); + + /** + * Creates a new [`ICU4XDateTime`] from an [`ICU4XDate`] and [`ICU4XTime`] object + * + * See the [Rust documentation for `new`](https://docs.rs/icu/latest/icu/calendar/struct.DateTime.html#method.new) for more information. + */ + static ICU4XDateTime create_from_date_and_time(const ICU4XDate& date, const ICU4XTime& time); + + /** + * Gets a copy of the date contained in this object + * + * See the [Rust documentation for `date`](https://docs.rs/icu/latest/icu/calendar/struct.DateTime.html#structfield.date) for more information. + */ + ICU4XDate date() const; + + /** + * Gets the time contained in this object + * + * See the [Rust documentation for `time`](https://docs.rs/icu/latest/icu/calendar/struct.DateTime.html#structfield.time) for more information. + */ + ICU4XTime time() const; + + /** + * Converts this date to ISO + * + * See the [Rust documentation for `to_iso`](https://docs.rs/icu/latest/icu/calendar/struct.DateTime.html#method.to_iso) for more information. + */ + ICU4XIsoDateTime to_iso() const; + + /** + * Convert this datetime to one in a different calendar + * + * See the [Rust documentation for `to_calendar`](https://docs.rs/icu/latest/icu/calendar/struct.DateTime.html#method.to_calendar) for more information. + */ + ICU4XDateTime to_calendar(const ICU4XCalendar& calendar) const; + + /** + * Returns the hour in this time + * + * See the [Rust documentation for `hour`](https://docs.rs/icu/latest/icu/calendar/types/struct.Time.html#structfield.hour) for more information. + */ + uint8_t hour() const; + + /** + * Returns the minute in this time + * + * See the [Rust documentation for `minute`](https://docs.rs/icu/latest/icu/calendar/types/struct.Time.html#structfield.minute) for more information. + */ + uint8_t minute() const; + + /** + * Returns the second in this time + * + * See the [Rust documentation for `second`](https://docs.rs/icu/latest/icu/calendar/types/struct.Time.html#structfield.second) for more information. + */ + uint8_t second() const; + + /** + * Returns the nanosecond in this time + * + * See the [Rust documentation for `nanosecond`](https://docs.rs/icu/latest/icu/calendar/types/struct.Time.html#structfield.nanosecond) for more information. + */ + uint32_t nanosecond() const; + + /** + * Returns the 1-indexed day in the month for this date + * + * See the [Rust documentation for `day_of_month`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.day_of_month) for more information. + */ + uint32_t day_of_month() const; + + /** + * Returns the day in the week for this day + * + * See the [Rust documentation for `day_of_week`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.day_of_week) for more information. + */ + ICU4XIsoWeekday day_of_week() const; + + /** + * Returns the week number in this month, 1-indexed, based on what + * is considered the first day of the week (often a locale preference). + * + * `first_weekday` can be obtained via `first_weekday()` on [`ICU4XWeekCalculator`] + * + * See the [Rust documentation for `week_of_month`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.week_of_month) for more information. + */ + uint32_t week_of_month(ICU4XIsoWeekday first_weekday) const; + + /** + * Returns the week number in this year, using week data + * + * See the [Rust documentation for `week_of_year`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.week_of_year) for more information. + */ + diplomat::result<ICU4XWeekOf, ICU4XError> week_of_year(const ICU4XWeekCalculator& calculator) const; + + /** + * Returns 1-indexed number of the month of this date in its year + * + * Note that for lunar calendars this may not lead to the same month + * having the same ordinal month across years; use month_code if you care + * about month identity. + * + * See the [Rust documentation for `month`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.month) for more information. + */ + uint32_t ordinal_month() const; + + /** + * Returns the month code for this date. Typically something + * like "M01", "M02", but can be more complicated for lunar calendars. + * + * See the [Rust documentation for `month`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.month) for more information. + */ + template<typename W> diplomat::result<std::monostate, ICU4XError> month_code_to_writeable(W& write) const; + + /** + * Returns the month code for this date. Typically something + * like "M01", "M02", but can be more complicated for lunar calendars. + * + * See the [Rust documentation for `month`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.month) for more information. + */ + diplomat::result<std::string, ICU4XError> month_code() const; + + /** + * Returns the year number in the current era for this date + * + * See the [Rust documentation for `year`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.year) for more information. + */ + int32_t year_in_era() const; + + /** + * Returns the era for this date, + * + * See the [Rust documentation for `year`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.year) for more information. + */ + template<typename W> diplomat::result<std::monostate, ICU4XError> era_to_writeable(W& write) const; + + /** + * Returns the era for this date, + * + * See the [Rust documentation for `year`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.year) for more information. + */ + diplomat::result<std::string, ICU4XError> era() const; + + /** + * Returns the number of months in the year represented by this date + * + * See the [Rust documentation for `months_in_year`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.months_in_year) for more information. + */ + uint8_t months_in_year() const; + + /** + * Returns the number of days in the month represented by this date + * + * See the [Rust documentation for `days_in_month`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.days_in_month) for more information. + */ + uint8_t days_in_month() const; + + /** + * Returns the number of days in the year represented by this date + * + * See the [Rust documentation for `days_in_year`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.days_in_year) for more information. + */ + uint16_t days_in_year() const; + + /** + * Returns the [`ICU4XCalendar`] object backing this date + * + * See the [Rust documentation for `calendar`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.calendar) for more information. + */ + ICU4XCalendar calendar() const; + inline const capi::ICU4XDateTime* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XDateTime* AsFFIMut() { return this->inner.get(); } + inline ICU4XDateTime(capi::ICU4XDateTime* i) : inner(i) {} + ICU4XDateTime() = default; + ICU4XDateTime(ICU4XDateTime&&) noexcept = default; + ICU4XDateTime& operator=(ICU4XDateTime&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XDateTime, ICU4XDateTimeDeleter> inner; +}; + +#include "ICU4XCalendar.hpp" +#include "ICU4XDate.hpp" +#include "ICU4XTime.hpp" +#include "ICU4XIsoDateTime.hpp" +#include "ICU4XWeekCalculator.hpp" +#include "ICU4XWeekOf.hpp" + +inline diplomat::result<ICU4XDateTime, ICU4XError> ICU4XDateTime::create_from_iso_in_calendar(int32_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second, uint32_t nanosecond, const ICU4XCalendar& calendar) { + auto diplomat_result_raw_out_value = capi::ICU4XDateTime_create_from_iso_in_calendar(year, month, day, hour, minute, second, nanosecond, calendar.AsFFI()); + diplomat::result<ICU4XDateTime, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XDateTime>(ICU4XDateTime(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XDateTime, ICU4XError> ICU4XDateTime::create_from_codes_in_calendar(const std::string_view era_code, int32_t year, const std::string_view month_code, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second, uint32_t nanosecond, const ICU4XCalendar& calendar) { + auto diplomat_result_raw_out_value = capi::ICU4XDateTime_create_from_codes_in_calendar(era_code.data(), era_code.size(), year, month_code.data(), month_code.size(), day, hour, minute, second, nanosecond, calendar.AsFFI()); + diplomat::result<ICU4XDateTime, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XDateTime>(ICU4XDateTime(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline ICU4XDateTime ICU4XDateTime::create_from_date_and_time(const ICU4XDate& date, const ICU4XTime& time) { + return ICU4XDateTime(capi::ICU4XDateTime_create_from_date_and_time(date.AsFFI(), time.AsFFI())); +} +inline ICU4XDate ICU4XDateTime::date() const { + return ICU4XDate(capi::ICU4XDateTime_date(this->inner.get())); +} +inline ICU4XTime ICU4XDateTime::time() const { + return ICU4XTime(capi::ICU4XDateTime_time(this->inner.get())); +} +inline ICU4XIsoDateTime ICU4XDateTime::to_iso() const { + return ICU4XIsoDateTime(capi::ICU4XDateTime_to_iso(this->inner.get())); +} +inline ICU4XDateTime ICU4XDateTime::to_calendar(const ICU4XCalendar& calendar) const { + return ICU4XDateTime(capi::ICU4XDateTime_to_calendar(this->inner.get(), calendar.AsFFI())); +} +inline uint8_t ICU4XDateTime::hour() const { + return capi::ICU4XDateTime_hour(this->inner.get()); +} +inline uint8_t ICU4XDateTime::minute() const { + return capi::ICU4XDateTime_minute(this->inner.get()); +} +inline uint8_t ICU4XDateTime::second() const { + return capi::ICU4XDateTime_second(this->inner.get()); +} +inline uint32_t ICU4XDateTime::nanosecond() const { + return capi::ICU4XDateTime_nanosecond(this->inner.get()); +} +inline uint32_t ICU4XDateTime::day_of_month() const { + return capi::ICU4XDateTime_day_of_month(this->inner.get()); +} +inline ICU4XIsoWeekday ICU4XDateTime::day_of_week() const { + return static_cast<ICU4XIsoWeekday>(capi::ICU4XDateTime_day_of_week(this->inner.get())); +} +inline uint32_t ICU4XDateTime::week_of_month(ICU4XIsoWeekday first_weekday) const { + return capi::ICU4XDateTime_week_of_month(this->inner.get(), static_cast<capi::ICU4XIsoWeekday>(first_weekday)); +} +inline diplomat::result<ICU4XWeekOf, ICU4XError> ICU4XDateTime::week_of_year(const ICU4XWeekCalculator& calculator) const { + auto diplomat_result_raw_out_value = capi::ICU4XDateTime_week_of_year(this->inner.get(), calculator.AsFFI()); + diplomat::result<ICU4XWeekOf, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + capi::ICU4XWeekOf diplomat_raw_struct_out_value = diplomat_result_raw_out_value.ok; + diplomat_result_out_value = diplomat::Ok<ICU4XWeekOf>(ICU4XWeekOf{ .week = std::move(diplomat_raw_struct_out_value.week), .unit = std::move(static_cast<ICU4XWeekRelativeUnit>(diplomat_raw_struct_out_value.unit)) }); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline uint32_t ICU4XDateTime::ordinal_month() const { + return capi::ICU4XDateTime_ordinal_month(this->inner.get()); +} +template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XDateTime::month_code_to_writeable(W& write) const { + capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write); + auto diplomat_result_raw_out_value = capi::ICU4XDateTime_month_code(this->inner.get(), &write_writer); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<std::string, ICU4XError> ICU4XDateTime::month_code() const { + std::string diplomat_writeable_string; + capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); + auto diplomat_result_raw_out_value = capi::ICU4XDateTime_month_code(this->inner.get(), &diplomat_writeable_out); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string)); +} +inline int32_t ICU4XDateTime::year_in_era() const { + return capi::ICU4XDateTime_year_in_era(this->inner.get()); +} +template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XDateTime::era_to_writeable(W& write) const { + capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write); + auto diplomat_result_raw_out_value = capi::ICU4XDateTime_era(this->inner.get(), &write_writer); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<std::string, ICU4XError> ICU4XDateTime::era() const { + std::string diplomat_writeable_string; + capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); + auto diplomat_result_raw_out_value = capi::ICU4XDateTime_era(this->inner.get(), &diplomat_writeable_out); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string)); +} +inline uint8_t ICU4XDateTime::months_in_year() const { + return capi::ICU4XDateTime_months_in_year(this->inner.get()); +} +inline uint8_t ICU4XDateTime::days_in_month() const { + return capi::ICU4XDateTime_days_in_month(this->inner.get()); +} +inline uint16_t ICU4XDateTime::days_in_year() const { + return capi::ICU4XDateTime_days_in_year(this->inner.get()); +} +inline ICU4XCalendar ICU4XDateTime::calendar() const { + return ICU4XCalendar(capi::ICU4XDateTime_calendar(this->inner.get())); +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XDateTimeFormatter.h b/intl/icu_capi/cpp/include/ICU4XDateTimeFormatter.h new file mode 100644 index 0000000000..5f0af4ddba --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XDateTimeFormatter.h @@ -0,0 +1,41 @@ +#ifndef ICU4XDateTimeFormatter_H +#define ICU4XDateTimeFormatter_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XDateTimeFormatter ICU4XDateTimeFormatter; +#ifdef __cplusplus +} // namespace capi +#endif +#include "ICU4XDataProvider.h" +#include "ICU4XLocale.h" +#include "ICU4XDateLength.h" +#include "ICU4XTimeLength.h" +#include "diplomat_result_box_ICU4XDateTimeFormatter_ICU4XError.h" +#include "ICU4XDateTime.h" +#include "diplomat_result_void_ICU4XError.h" +#include "ICU4XIsoDateTime.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +diplomat_result_box_ICU4XDateTimeFormatter_ICU4XError ICU4XDateTimeFormatter_create_with_lengths(const ICU4XDataProvider* provider, const ICU4XLocale* locale, ICU4XDateLength date_length, ICU4XTimeLength time_length); + +diplomat_result_void_ICU4XError ICU4XDateTimeFormatter_format_datetime(const ICU4XDateTimeFormatter* self, const ICU4XDateTime* value, DiplomatWriteable* write); + +diplomat_result_void_ICU4XError ICU4XDateTimeFormatter_format_iso_datetime(const ICU4XDateTimeFormatter* self, const ICU4XIsoDateTime* value, DiplomatWriteable* write); +void ICU4XDateTimeFormatter_destroy(ICU4XDateTimeFormatter* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XDateTimeFormatter.hpp b/intl/icu_capi/cpp/include/ICU4XDateTimeFormatter.hpp new file mode 100644 index 0000000000..2a556eedc8 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XDateTimeFormatter.hpp @@ -0,0 +1,150 @@ +#ifndef ICU4XDateTimeFormatter_HPP +#define ICU4XDateTimeFormatter_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XDateTimeFormatter.h" + +class ICU4XDataProvider; +class ICU4XLocale; +#include "ICU4XDateLength.hpp" +#include "ICU4XTimeLength.hpp" +class ICU4XDateTimeFormatter; +#include "ICU4XError.hpp" +class ICU4XDateTime; +class ICU4XIsoDateTime; + +/** + * A destruction policy for using ICU4XDateTimeFormatter with std::unique_ptr. + */ +struct ICU4XDateTimeFormatterDeleter { + void operator()(capi::ICU4XDateTimeFormatter* l) const noexcept { + capi::ICU4XDateTimeFormatter_destroy(l); + } +}; + +/** + * An ICU4X DateFormatter object capable of formatting a [`ICU4XDateTime`] as a string, + * using some calendar specified at runtime in the locale. + * + * See the [Rust documentation for `DateTimeFormatter`](https://docs.rs/icu/latest/icu/datetime/struct.DateTimeFormatter.html) for more information. + */ +class ICU4XDateTimeFormatter { + public: + + /** + * Creates a new [`ICU4XDateTimeFormatter`] from locale data. + * + * See the [Rust documentation for `try_new`](https://docs.rs/icu/latest/icu/datetime/struct.DateTimeFormatter.html#method.try_new) for more information. + */ + static diplomat::result<ICU4XDateTimeFormatter, ICU4XError> create_with_lengths(const ICU4XDataProvider& provider, const ICU4XLocale& locale, ICU4XDateLength date_length, ICU4XTimeLength time_length); + + /** + * Formats a [`ICU4XDateTime`] to a string. + * + * See the [Rust documentation for `format`](https://docs.rs/icu/latest/icu/datetime/struct.DateTimeFormatter.html#method.format) for more information. + */ + template<typename W> diplomat::result<std::monostate, ICU4XError> format_datetime_to_writeable(const ICU4XDateTime& value, W& write) const; + + /** + * Formats a [`ICU4XDateTime`] to a string. + * + * See the [Rust documentation for `format`](https://docs.rs/icu/latest/icu/datetime/struct.DateTimeFormatter.html#method.format) for more information. + */ + diplomat::result<std::string, ICU4XError> format_datetime(const ICU4XDateTime& value) const; + + /** + * Formats a [`ICU4XIsoDateTime`] to a string. + * + * Will convert to this formatter's calendar first + * + * See the [Rust documentation for `format`](https://docs.rs/icu/latest/icu/datetime/struct.DateTimeFormatter.html#method.format) for more information. + */ + template<typename W> diplomat::result<std::monostate, ICU4XError> format_iso_datetime_to_writeable(const ICU4XIsoDateTime& value, W& write) const; + + /** + * Formats a [`ICU4XIsoDateTime`] to a string. + * + * Will convert to this formatter's calendar first + * + * See the [Rust documentation for `format`](https://docs.rs/icu/latest/icu/datetime/struct.DateTimeFormatter.html#method.format) for more information. + */ + diplomat::result<std::string, ICU4XError> format_iso_datetime(const ICU4XIsoDateTime& value) const; + inline const capi::ICU4XDateTimeFormatter* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XDateTimeFormatter* AsFFIMut() { return this->inner.get(); } + inline ICU4XDateTimeFormatter(capi::ICU4XDateTimeFormatter* i) : inner(i) {} + ICU4XDateTimeFormatter() = default; + ICU4XDateTimeFormatter(ICU4XDateTimeFormatter&&) noexcept = default; + ICU4XDateTimeFormatter& operator=(ICU4XDateTimeFormatter&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XDateTimeFormatter, ICU4XDateTimeFormatterDeleter> inner; +}; + +#include "ICU4XDataProvider.hpp" +#include "ICU4XLocale.hpp" +#include "ICU4XDateTime.hpp" +#include "ICU4XIsoDateTime.hpp" + +inline diplomat::result<ICU4XDateTimeFormatter, ICU4XError> ICU4XDateTimeFormatter::create_with_lengths(const ICU4XDataProvider& provider, const ICU4XLocale& locale, ICU4XDateLength date_length, ICU4XTimeLength time_length) { + auto diplomat_result_raw_out_value = capi::ICU4XDateTimeFormatter_create_with_lengths(provider.AsFFI(), locale.AsFFI(), static_cast<capi::ICU4XDateLength>(date_length), static_cast<capi::ICU4XTimeLength>(time_length)); + diplomat::result<ICU4XDateTimeFormatter, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XDateTimeFormatter>(ICU4XDateTimeFormatter(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XDateTimeFormatter::format_datetime_to_writeable(const ICU4XDateTime& value, W& write) const { + capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write); + auto diplomat_result_raw_out_value = capi::ICU4XDateTimeFormatter_format_datetime(this->inner.get(), value.AsFFI(), &write_writer); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<std::string, ICU4XError> ICU4XDateTimeFormatter::format_datetime(const ICU4XDateTime& value) const { + std::string diplomat_writeable_string; + capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); + auto diplomat_result_raw_out_value = capi::ICU4XDateTimeFormatter_format_datetime(this->inner.get(), value.AsFFI(), &diplomat_writeable_out); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string)); +} +template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XDateTimeFormatter::format_iso_datetime_to_writeable(const ICU4XIsoDateTime& value, W& write) const { + capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write); + auto diplomat_result_raw_out_value = capi::ICU4XDateTimeFormatter_format_iso_datetime(this->inner.get(), value.AsFFI(), &write_writer); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<std::string, ICU4XError> ICU4XDateTimeFormatter::format_iso_datetime(const ICU4XIsoDateTime& value) const { + std::string diplomat_writeable_string; + capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); + auto diplomat_result_raw_out_value = capi::ICU4XDateTimeFormatter_format_iso_datetime(this->inner.get(), value.AsFFI(), &diplomat_writeable_out); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string)); +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XDecomposed.h b/intl/icu_capi/cpp/include/ICU4XDecomposed.h new file mode 100644 index 0000000000..3f287e8192 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XDecomposed.h @@ -0,0 +1,31 @@ +#ifndef ICU4XDecomposed_H +#define ICU4XDecomposed_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XDecomposed { + char32_t first; + char32_t second; +} ICU4XDecomposed; +#ifdef __cplusplus +} // namespace capi +#endif +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +void ICU4XDecomposed_destroy(ICU4XDecomposed* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XDecomposed.hpp b/intl/icu_capi/cpp/include/ICU4XDecomposed.hpp new file mode 100644 index 0000000000..5628ae2be9 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XDecomposed.hpp @@ -0,0 +1,30 @@ +#ifndef ICU4XDecomposed_HPP +#define ICU4XDecomposed_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XDecomposed.h" + + + +/** + * The outcome of non-recursive canonical decomposition of a character. + * `second` will be NUL when the decomposition expands to a single character + * (which may or may not be the original one) + * + * See the [Rust documentation for `Decomposed`](https://docs.rs/icu/latest/icu/normalizer/properties/enum.Decomposed.html) for more information. + */ +struct ICU4XDecomposed { + public: + char32_t first; + char32_t second; +}; + + +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XDecomposingNormalizer.h b/intl/icu_capi/cpp/include/ICU4XDecomposingNormalizer.h new file mode 100644 index 0000000000..f542f7a730 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XDecomposingNormalizer.h @@ -0,0 +1,38 @@ +#ifndef ICU4XDecomposingNormalizer_H +#define ICU4XDecomposingNormalizer_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XDecomposingNormalizer ICU4XDecomposingNormalizer; +#ifdef __cplusplus +} // namespace capi +#endif +#include "ICU4XDataProvider.h" +#include "diplomat_result_box_ICU4XDecomposingNormalizer_ICU4XError.h" +#include "diplomat_result_void_ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +diplomat_result_box_ICU4XDecomposingNormalizer_ICU4XError ICU4XDecomposingNormalizer_create_nfd(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XDecomposingNormalizer_ICU4XError ICU4XDecomposingNormalizer_create_nfkd(const ICU4XDataProvider* provider); + +diplomat_result_void_ICU4XError ICU4XDecomposingNormalizer_normalize(const ICU4XDecomposingNormalizer* self, const char* s_data, size_t s_len, DiplomatWriteable* write); + +bool ICU4XDecomposingNormalizer_is_normalized(const ICU4XDecomposingNormalizer* self, const char* s_data, size_t s_len); +void ICU4XDecomposingNormalizer_destroy(ICU4XDecomposingNormalizer* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XDecomposingNormalizer.hpp b/intl/icu_capi/cpp/include/ICU4XDecomposingNormalizer.hpp new file mode 100644 index 0000000000..501513f7c2 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XDecomposingNormalizer.hpp @@ -0,0 +1,131 @@ +#ifndef ICU4XDecomposingNormalizer_HPP +#define ICU4XDecomposingNormalizer_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XDecomposingNormalizer.h" + +class ICU4XDataProvider; +class ICU4XDecomposingNormalizer; +#include "ICU4XError.hpp" + +/** + * A destruction policy for using ICU4XDecomposingNormalizer with std::unique_ptr. + */ +struct ICU4XDecomposingNormalizerDeleter { + void operator()(capi::ICU4XDecomposingNormalizer* l) const noexcept { + capi::ICU4XDecomposingNormalizer_destroy(l); + } +}; + +/** + * See the [Rust documentation for `DecomposingNormalizer`](https://docs.rs/icu/latest/icu/normalizer/struct.DecomposingNormalizer.html) for more information. + */ +class ICU4XDecomposingNormalizer { + public: + + /** + * Construct a new ICU4XDecomposingNormalizer instance for NFC + * + * See the [Rust documentation for `new_nfd`](https://docs.rs/icu/latest/icu/normalizer/struct.DecomposingNormalizer.html#method.new_nfd) for more information. + */ + static diplomat::result<ICU4XDecomposingNormalizer, ICU4XError> create_nfd(const ICU4XDataProvider& provider); + + /** + * Construct a new ICU4XDecomposingNormalizer instance for NFKC + * + * See the [Rust documentation for `new_nfkd`](https://docs.rs/icu/latest/icu/normalizer/struct.DecomposingNormalizer.html#method.new_nfkd) for more information. + */ + static diplomat::result<ICU4XDecomposingNormalizer, ICU4XError> create_nfkd(const ICU4XDataProvider& provider); + + /** + * Normalize a (potentially ill-formed) UTF8 string + * + * Errors are mapped to REPLACEMENT CHARACTER + * + * See the [Rust documentation for `normalize_utf8`](https://docs.rs/icu/latest/icu/normalizer/struct.DecomposingNormalizer.html#method.normalize_utf8) for more information. + */ + template<typename W> diplomat::result<std::monostate, ICU4XError> normalize_to_writeable(const std::string_view s, W& write) const; + + /** + * Normalize a (potentially ill-formed) UTF8 string + * + * Errors are mapped to REPLACEMENT CHARACTER + * + * See the [Rust documentation for `normalize_utf8`](https://docs.rs/icu/latest/icu/normalizer/struct.DecomposingNormalizer.html#method.normalize_utf8) for more information. + */ + diplomat::result<std::string, ICU4XError> normalize(const std::string_view s) const; + + /** + * Check if a (potentially ill-formed) UTF8 string is normalized + * + * Errors are mapped to REPLACEMENT CHARACTER + * + * See the [Rust documentation for `is_normalized_utf8`](https://docs.rs/icu/latest/icu/normalizer/struct.DecomposingNormalizer.html#method.is_normalized_utf8) for more information. + */ + bool is_normalized(const std::string_view s) const; + inline const capi::ICU4XDecomposingNormalizer* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XDecomposingNormalizer* AsFFIMut() { return this->inner.get(); } + inline ICU4XDecomposingNormalizer(capi::ICU4XDecomposingNormalizer* i) : inner(i) {} + ICU4XDecomposingNormalizer() = default; + ICU4XDecomposingNormalizer(ICU4XDecomposingNormalizer&&) noexcept = default; + ICU4XDecomposingNormalizer& operator=(ICU4XDecomposingNormalizer&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XDecomposingNormalizer, ICU4XDecomposingNormalizerDeleter> inner; +}; + +#include "ICU4XDataProvider.hpp" + +inline diplomat::result<ICU4XDecomposingNormalizer, ICU4XError> ICU4XDecomposingNormalizer::create_nfd(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XDecomposingNormalizer_create_nfd(provider.AsFFI()); + diplomat::result<ICU4XDecomposingNormalizer, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XDecomposingNormalizer>(ICU4XDecomposingNormalizer(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XDecomposingNormalizer, ICU4XError> ICU4XDecomposingNormalizer::create_nfkd(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XDecomposingNormalizer_create_nfkd(provider.AsFFI()); + diplomat::result<ICU4XDecomposingNormalizer, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XDecomposingNormalizer>(ICU4XDecomposingNormalizer(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XDecomposingNormalizer::normalize_to_writeable(const std::string_view s, W& write) const { + capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write); + auto diplomat_result_raw_out_value = capi::ICU4XDecomposingNormalizer_normalize(this->inner.get(), s.data(), s.size(), &write_writer); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<std::string, ICU4XError> ICU4XDecomposingNormalizer::normalize(const std::string_view s) const { + std::string diplomat_writeable_string; + capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); + auto diplomat_result_raw_out_value = capi::ICU4XDecomposingNormalizer_normalize(this->inner.get(), s.data(), s.size(), &diplomat_writeable_out); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string)); +} +inline bool ICU4XDecomposingNormalizer::is_normalized(const std::string_view s) const { + return capi::ICU4XDecomposingNormalizer_is_normalized(this->inner.get(), s.data(), s.size()); +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XDisplayNamesFallback.h b/intl/icu_capi/cpp/include/ICU4XDisplayNamesFallback.h new file mode 100644 index 0000000000..085fc8de5d --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XDisplayNamesFallback.h @@ -0,0 +1,31 @@ +#ifndef ICU4XDisplayNamesFallback_H +#define ICU4XDisplayNamesFallback_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef enum ICU4XDisplayNamesFallback { + ICU4XDisplayNamesFallback_Code = 0, + ICU4XDisplayNamesFallback_None = 1, +} ICU4XDisplayNamesFallback; +#ifdef __cplusplus +} // namespace capi +#endif +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +void ICU4XDisplayNamesFallback_destroy(ICU4XDisplayNamesFallback* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XDisplayNamesFallback.hpp b/intl/icu_capi/cpp/include/ICU4XDisplayNamesFallback.hpp new file mode 100644 index 0000000000..230539852b --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XDisplayNamesFallback.hpp @@ -0,0 +1,24 @@ +#ifndef ICU4XDisplayNamesFallback_HPP +#define ICU4XDisplayNamesFallback_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XDisplayNamesFallback.h" + + + +/** + * See the [Rust documentation for `Fallback`](https://docs.rs/icu/latest/icu/displaynames/options/enum.Fallback.html) for more information. + */ +enum struct ICU4XDisplayNamesFallback { + Code = 0, + None = 1, +}; + +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XDisplayNamesOptionsV1.h b/intl/icu_capi/cpp/include/ICU4XDisplayNamesOptionsV1.h new file mode 100644 index 0000000000..e998cde0e7 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XDisplayNamesOptionsV1.h @@ -0,0 +1,38 @@ +#ifndef ICU4XDisplayNamesOptionsV1_H +#define ICU4XDisplayNamesOptionsV1_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#include "ICU4XDisplayNamesStyle.h" +#include "ICU4XDisplayNamesFallback.h" +#include "ICU4XLanguageDisplay.h" +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XDisplayNamesOptionsV1 { + ICU4XDisplayNamesStyle style; + ICU4XDisplayNamesFallback fallback; + ICU4XLanguageDisplay language_display; +} ICU4XDisplayNamesOptionsV1; +#ifdef __cplusplus +} // namespace capi +#endif +#include "ICU4XDisplayNamesStyle.h" +#include "ICU4XDisplayNamesFallback.h" +#include "ICU4XLanguageDisplay.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +void ICU4XDisplayNamesOptionsV1_destroy(ICU4XDisplayNamesOptionsV1* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XDisplayNamesOptionsV1.hpp b/intl/icu_capi/cpp/include/ICU4XDisplayNamesOptionsV1.hpp new file mode 100644 index 0000000000..52b66efa7e --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XDisplayNamesOptionsV1.hpp @@ -0,0 +1,43 @@ +#ifndef ICU4XDisplayNamesOptionsV1_HPP +#define ICU4XDisplayNamesOptionsV1_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XDisplayNamesOptionsV1.h" + +#include "ICU4XDisplayNamesStyle.hpp" +#include "ICU4XDisplayNamesFallback.hpp" +#include "ICU4XLanguageDisplay.hpp" + + +/** + * See the [Rust documentation for `DisplayNamesOptions`](https://docs.rs/icu/latest/icu/displaynames/options/struct.DisplayNamesOptions.html) for more information. + */ +struct ICU4XDisplayNamesOptionsV1 { + public: + + /** + * The optional formatting style to use for display name. + */ + ICU4XDisplayNamesStyle style; + + /** + * The fallback return when the system does not have the + * requested display name, defaults to "code". + */ + ICU4XDisplayNamesFallback fallback; + + /** + * The language display kind, defaults to "dialect". + */ + ICU4XLanguageDisplay language_display; +}; + + +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XDisplayNamesStyle.h b/intl/icu_capi/cpp/include/ICU4XDisplayNamesStyle.h new file mode 100644 index 0000000000..048da455da --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XDisplayNamesStyle.h @@ -0,0 +1,34 @@ +#ifndef ICU4XDisplayNamesStyle_H +#define ICU4XDisplayNamesStyle_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef enum ICU4XDisplayNamesStyle { + ICU4XDisplayNamesStyle_Auto = 0, + ICU4XDisplayNamesStyle_Narrow = 1, + ICU4XDisplayNamesStyle_Short = 2, + ICU4XDisplayNamesStyle_Long = 3, + ICU4XDisplayNamesStyle_Menu = 4, +} ICU4XDisplayNamesStyle; +#ifdef __cplusplus +} // namespace capi +#endif +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +void ICU4XDisplayNamesStyle_destroy(ICU4XDisplayNamesStyle* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XDisplayNamesStyle.hpp b/intl/icu_capi/cpp/include/ICU4XDisplayNamesStyle.hpp new file mode 100644 index 0000000000..0199bdc80d --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XDisplayNamesStyle.hpp @@ -0,0 +1,27 @@ +#ifndef ICU4XDisplayNamesStyle_HPP +#define ICU4XDisplayNamesStyle_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XDisplayNamesStyle.h" + + + +/** + * See the [Rust documentation for `Style`](https://docs.rs/icu/latest/icu/displaynames/options/enum.Style.html) for more information. + */ +enum struct ICU4XDisplayNamesStyle { + Auto = 0, + Narrow = 1, + Short = 2, + Long = 3, + Menu = 4, +}; + +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XError.h b/intl/icu_capi/cpp/include/ICU4XError.h new file mode 100644 index 0000000000..8836275ac5 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XError.h @@ -0,0 +1,84 @@ +#ifndef ICU4XError_H +#define ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef enum ICU4XError { + ICU4XError_UnknownError = 0, + ICU4XError_WriteableError = 1, + ICU4XError_OutOfBoundsError = 2, + ICU4XError_DataMissingDataKeyError = 256, + ICU4XError_DataMissingVariantError = 257, + ICU4XError_DataMissingLocaleError = 258, + ICU4XError_DataNeedsVariantError = 259, + ICU4XError_DataNeedsLocaleError = 260, + ICU4XError_DataExtraneousLocaleError = 261, + ICU4XError_DataFilteredResourceError = 262, + ICU4XError_DataMismatchedTypeError = 263, + ICU4XError_DataMissingPayloadError = 264, + ICU4XError_DataInvalidStateError = 265, + ICU4XError_DataCustomError = 266, + ICU4XError_DataIoError = 267, + ICU4XError_DataUnavailableBufferFormatError = 268, + ICU4XError_DataMismatchedAnyBufferError = 269, + ICU4XError_LocaleUndefinedSubtagError = 512, + ICU4XError_LocaleParserLanguageError = 513, + ICU4XError_LocaleParserSubtagError = 514, + ICU4XError_LocaleParserExtensionError = 515, + ICU4XError_DataStructValidityError = 768, + ICU4XError_PropertyUnknownScriptIdError = 1024, + ICU4XError_PropertyUnknownGeneralCategoryGroupError = 1025, + ICU4XError_PropertyUnexpectedPropertyNameError = 1026, + ICU4XError_FixedDecimalLimitError = 1280, + ICU4XError_FixedDecimalSyntaxError = 1281, + ICU4XError_PluralsParserError = 1536, + ICU4XError_CalendarParseError = 1792, + ICU4XError_CalendarOverflowError = 1793, + ICU4XError_CalendarUnderflowError = 1794, + ICU4XError_CalendarOutOfRangeError = 1795, + ICU4XError_CalendarUnknownEraError = 1796, + ICU4XError_CalendarUnknownMonthCodeError = 1797, + ICU4XError_CalendarMissingInputError = 1798, + ICU4XError_CalendarUnknownKindError = 1799, + ICU4XError_CalendarMissingError = 1800, + ICU4XError_DateTimePatternError = 2048, + ICU4XError_DateTimeMissingInputFieldError = 2049, + ICU4XError_DateTimeSkeletonError = 2050, + ICU4XError_DateTimeUnsupportedFieldError = 2051, + ICU4XError_DateTimeUnsupportedOptionsError = 2052, + ICU4XError_DateTimeMissingWeekdaySymbolError = 2053, + ICU4XError_DateTimeMissingMonthSymbolError = 2054, + ICU4XError_DateTimeFixedDecimalError = 2055, + ICU4XError_DateTimeMismatchedCalendarError = 2056, + ICU4XError_TinyStrTooLargeError = 2304, + ICU4XError_TinyStrContainsNullError = 2305, + ICU4XError_TinyStrNonAsciiError = 2306, + ICU4XError_TimeZoneOffsetOutOfBoundsError = 2560, + ICU4XError_TimeZoneInvalidOffsetError = 2561, + ICU4XError_TimeZoneMissingInputError = 2562, + ICU4XError_TimeZoneInvalidIdError = 2563, + ICU4XError_NormalizerFutureExtensionError = 2816, + ICU4XError_NormalizerValidationError = 2817, +} ICU4XError; +#ifdef __cplusplus +} // namespace capi +#endif +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +void ICU4XError_destroy(ICU4XError* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XError.hpp b/intl/icu_capi/cpp/include/ICU4XError.hpp new file mode 100644 index 0000000000..1a306ca2b5 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XError.hpp @@ -0,0 +1,104 @@ +#ifndef ICU4XError_HPP +#define ICU4XError_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XError.h" + + + +/** + * A common enum for errors that ICU4X may return, organized by API + * + * The error names are stable and can be checked against as strings in the JS API + * + * Additional information: [1](https://docs.rs/fixed_decimal/latest/fixed_decimal/enum.FixedDecimalError.html), [2](https://docs.rs/icu/latest/icu/calendar/enum.CalendarError.html), [3](https://docs.rs/icu/latest/icu/collator/enum.CollatorError.html), [4](https://docs.rs/icu/latest/icu/datetime/enum.DateTimeError.html), [5](https://docs.rs/icu/latest/icu/decimal/enum.DecimalError.html), [6](https://docs.rs/icu/latest/icu/list/enum.ListError.html), [7](https://docs.rs/icu/latest/icu/locid/enum.ParserError.html), [8](https://docs.rs/icu/latest/icu/locid_transform/enum.LocaleTransformError.html), [9](https://docs.rs/icu/latest/icu/normalizer/enum.NormalizerError.html), [10](https://docs.rs/icu/latest/icu/plurals/enum.PluralsError.html), [11](https://docs.rs/icu/latest/icu/properties/enum.PropertiesError.html), [12](https://docs.rs/icu/latest/icu/provider/struct.DataError.html), [13](https://docs.rs/icu/latest/icu/provider/enum.DataErrorKind.html), [14](https://docs.rs/icu/latest/icu/segmenter/enum.SegmenterError.html), [15](https://docs.rs/icu/latest/icu/timezone/enum.TimeZoneError.html) + */ +enum struct ICU4XError { + + /** + * The error is not currently categorized as ICU4XError. + * Please file a bug + */ + UnknownError = 0, + + /** + * An error arising from writing to a string + * Typically found when not enough space is allocated + * Most APIs that return a string may return this error + */ + WriteableError = 1, + OutOfBoundsError = 2, + DataMissingDataKeyError = 256, + DataMissingVariantError = 257, + DataMissingLocaleError = 258, + DataNeedsVariantError = 259, + DataNeedsLocaleError = 260, + DataExtraneousLocaleError = 261, + DataFilteredResourceError = 262, + DataMismatchedTypeError = 263, + DataMissingPayloadError = 264, + DataInvalidStateError = 265, + DataCustomError = 266, + DataIoError = 267, + DataUnavailableBufferFormatError = 268, + DataMismatchedAnyBufferError = 269, + + /** + * The subtag being requested was not set + */ + LocaleUndefinedSubtagError = 512, + + /** + * The locale or subtag string failed to parse + */ + LocaleParserLanguageError = 513, + LocaleParserSubtagError = 514, + LocaleParserExtensionError = 515, + + /** + * Attempted to construct an invalid data struct + */ + DataStructValidityError = 768, + PropertyUnknownScriptIdError = 1024, + PropertyUnknownGeneralCategoryGroupError = 1025, + PropertyUnexpectedPropertyNameError = 1026, + FixedDecimalLimitError = 1280, + FixedDecimalSyntaxError = 1281, + PluralsParserError = 1536, + CalendarParseError = 1792, + CalendarOverflowError = 1793, + CalendarUnderflowError = 1794, + CalendarOutOfRangeError = 1795, + CalendarUnknownEraError = 1796, + CalendarUnknownMonthCodeError = 1797, + CalendarMissingInputError = 1798, + CalendarUnknownKindError = 1799, + CalendarMissingError = 1800, + DateTimePatternError = 2048, + DateTimeMissingInputFieldError = 2049, + DateTimeSkeletonError = 2050, + DateTimeUnsupportedFieldError = 2051, + DateTimeUnsupportedOptionsError = 2052, + DateTimeMissingWeekdaySymbolError = 2053, + DateTimeMissingMonthSymbolError = 2054, + DateTimeFixedDecimalError = 2055, + DateTimeMismatchedCalendarError = 2056, + TinyStrTooLargeError = 2304, + TinyStrContainsNullError = 2305, + TinyStrNonAsciiError = 2306, + TimeZoneOffsetOutOfBoundsError = 2560, + TimeZoneInvalidOffsetError = 2561, + TimeZoneMissingInputError = 2562, + TimeZoneInvalidIdError = 2563, + NormalizerFutureExtensionError = 2816, + NormalizerValidationError = 2817, +}; + +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XFixedDecimal.h b/intl/icu_capi/cpp/include/ICU4XFixedDecimal.h new file mode 100644 index 0000000000..361294b687 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XFixedDecimal.h @@ -0,0 +1,101 @@ +#ifndef ICU4XFixedDecimal_H +#define ICU4XFixedDecimal_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XFixedDecimal ICU4XFixedDecimal; +#ifdef __cplusplus +} // namespace capi +#endif +#include "diplomat_result_box_ICU4XFixedDecimal_ICU4XError.h" +#include "ICU4XFixedDecimalSign.h" +#include "ICU4XFixedDecimalSignDisplay.h" +#include "diplomat_result_void_void.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +ICU4XFixedDecimal* ICU4XFixedDecimal_create_from_i32(int32_t v); + +ICU4XFixedDecimal* ICU4XFixedDecimal_create_from_u32(uint32_t v); + +ICU4XFixedDecimal* ICU4XFixedDecimal_create_from_i64(int64_t v); + +ICU4XFixedDecimal* ICU4XFixedDecimal_create_from_u64(uint64_t v); + +diplomat_result_box_ICU4XFixedDecimal_ICU4XError ICU4XFixedDecimal_create_from_f64_with_integer_precision(double f); + +diplomat_result_box_ICU4XFixedDecimal_ICU4XError ICU4XFixedDecimal_create_from_f64_with_lower_magnitude(double f, int16_t magnitude); + +diplomat_result_box_ICU4XFixedDecimal_ICU4XError ICU4XFixedDecimal_create_from_f64_with_significant_digits(double f, uint8_t digits); + +diplomat_result_box_ICU4XFixedDecimal_ICU4XError ICU4XFixedDecimal_create_from_f64_with_floating_precision(double f); + +diplomat_result_box_ICU4XFixedDecimal_ICU4XError ICU4XFixedDecimal_create_from_string(const char* v_data, size_t v_len); + +uint8_t ICU4XFixedDecimal_digit_at(const ICU4XFixedDecimal* self, int16_t magnitude); + +int16_t ICU4XFixedDecimal_magnitude_start(const ICU4XFixedDecimal* self); + +int16_t ICU4XFixedDecimal_magnitude_end(const ICU4XFixedDecimal* self); + +int16_t ICU4XFixedDecimal_nonzero_magnitude_start(const ICU4XFixedDecimal* self); + +int16_t ICU4XFixedDecimal_nonzero_magnitude_end(const ICU4XFixedDecimal* self); + +bool ICU4XFixedDecimal_is_zero(const ICU4XFixedDecimal* self); + +void ICU4XFixedDecimal_multiply_pow10(ICU4XFixedDecimal* self, int16_t power); + +ICU4XFixedDecimalSign ICU4XFixedDecimal_sign(const ICU4XFixedDecimal* self); + +void ICU4XFixedDecimal_set_sign(ICU4XFixedDecimal* self, ICU4XFixedDecimalSign sign); + +void ICU4XFixedDecimal_apply_sign_display(ICU4XFixedDecimal* self, ICU4XFixedDecimalSignDisplay sign_display); + +void ICU4XFixedDecimal_trim_start(ICU4XFixedDecimal* self); + +void ICU4XFixedDecimal_trim_end(ICU4XFixedDecimal* self); + +void ICU4XFixedDecimal_pad_start(ICU4XFixedDecimal* self, int16_t position); + +void ICU4XFixedDecimal_pad_end(ICU4XFixedDecimal* self, int16_t position); + +void ICU4XFixedDecimal_set_max_position(ICU4XFixedDecimal* self, int16_t position); + +void ICU4XFixedDecimal_trunc(ICU4XFixedDecimal* self, int16_t position); + +void ICU4XFixedDecimal_half_trunc(ICU4XFixedDecimal* self, int16_t position); + +void ICU4XFixedDecimal_expand(ICU4XFixedDecimal* self, int16_t position); + +void ICU4XFixedDecimal_half_expand(ICU4XFixedDecimal* self, int16_t position); + +void ICU4XFixedDecimal_ceil(ICU4XFixedDecimal* self, int16_t position); + +void ICU4XFixedDecimal_half_ceil(ICU4XFixedDecimal* self, int16_t position); + +void ICU4XFixedDecimal_floor(ICU4XFixedDecimal* self, int16_t position); + +void ICU4XFixedDecimal_half_floor(ICU4XFixedDecimal* self, int16_t position); + +void ICU4XFixedDecimal_half_even(ICU4XFixedDecimal* self, int16_t position); + +diplomat_result_void_void ICU4XFixedDecimal_concatenate_end(ICU4XFixedDecimal* self, ICU4XFixedDecimal* other); + +void ICU4XFixedDecimal_to_string(const ICU4XFixedDecimal* self, DiplomatWriteable* to); +void ICU4XFixedDecimal_destroy(ICU4XFixedDecimal* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XFixedDecimal.hpp b/intl/icu_capi/cpp/include/ICU4XFixedDecimal.hpp new file mode 100644 index 0000000000..fed2ac629a --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XFixedDecimal.hpp @@ -0,0 +1,426 @@ +#ifndef ICU4XFixedDecimal_HPP +#define ICU4XFixedDecimal_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XFixedDecimal.h" + +class ICU4XFixedDecimal; +#include "ICU4XError.hpp" +#include "ICU4XFixedDecimalSign.hpp" +#include "ICU4XFixedDecimalSignDisplay.hpp" + +/** + * A destruction policy for using ICU4XFixedDecimal with std::unique_ptr. + */ +struct ICU4XFixedDecimalDeleter { + void operator()(capi::ICU4XFixedDecimal* l) const noexcept { + capi::ICU4XFixedDecimal_destroy(l); + } +}; + +/** + * See the [Rust documentation for `FixedDecimal`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html) for more information. + */ +class ICU4XFixedDecimal { + public: + + /** + * Construct an [`ICU4XFixedDecimal`] from an integer. + * + * See the [Rust documentation for `FixedDecimal`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html) for more information. + */ + static ICU4XFixedDecimal create_from_i32(int32_t v); + + /** + * Construct an [`ICU4XFixedDecimal`] from an integer. + * + * See the [Rust documentation for `FixedDecimal`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html) for more information. + */ + static ICU4XFixedDecimal create_from_u32(uint32_t v); + + /** + * Construct an [`ICU4XFixedDecimal`] from an integer. + * + * See the [Rust documentation for `FixedDecimal`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html) for more information. + */ + static ICU4XFixedDecimal create_from_i64(int64_t v); + + /** + * Construct an [`ICU4XFixedDecimal`] from an integer. + * + * See the [Rust documentation for `FixedDecimal`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html) for more information. + */ + static ICU4XFixedDecimal create_from_u64(uint64_t v); + + /** + * Construct an [`ICU4XFixedDecimal`] from an integer-valued float + * + * See the [Rust documentation for `try_from_f64`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.try_from_f64) for more information. + * + * See the [Rust documentation for `FloatPrecision`](https://docs.rs/fixed_decimal/latest/fixed_decimal/enum.FloatPrecision.html) for more information. + */ + static diplomat::result<ICU4XFixedDecimal, ICU4XError> create_from_f64_with_integer_precision(double f); + + /** + * Construct an [`ICU4XFixedDecimal`] from an float, with a given power of 10 for the lower magnitude + * + * See the [Rust documentation for `try_from_f64`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.try_from_f64) for more information. + * + * See the [Rust documentation for `FloatPrecision`](https://docs.rs/fixed_decimal/latest/fixed_decimal/enum.FloatPrecision.html) for more information. + */ + static diplomat::result<ICU4XFixedDecimal, ICU4XError> create_from_f64_with_lower_magnitude(double f, int16_t magnitude); + + /** + * Construct an [`ICU4XFixedDecimal`] from an float, for a given number of significant digits + * + * See the [Rust documentation for `try_from_f64`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.try_from_f64) for more information. + * + * See the [Rust documentation for `FloatPrecision`](https://docs.rs/fixed_decimal/latest/fixed_decimal/enum.FloatPrecision.html) for more information. + */ + static diplomat::result<ICU4XFixedDecimal, ICU4XError> create_from_f64_with_significant_digits(double f, uint8_t digits); + + /** + * Construct an [`ICU4XFixedDecimal`] from an float, with enough digits to recover + * the original floating point in IEEE 754 without needing trailing zeros + * + * See the [Rust documentation for `try_from_f64`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.try_from_f64) for more information. + * + * See the [Rust documentation for `FloatPrecision`](https://docs.rs/fixed_decimal/latest/fixed_decimal/enum.FloatPrecision.html) for more information. + */ + static diplomat::result<ICU4XFixedDecimal, ICU4XError> create_from_f64_with_floating_precision(double f); + + /** + * Construct an [`ICU4XFixedDecimal`] from a string. + * + * See the [Rust documentation for `from_str`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.from_str) for more information. + */ + static diplomat::result<ICU4XFixedDecimal, ICU4XError> create_from_string(const std::string_view v); + + /** + * See the [Rust documentation for `digit_at`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.digit_at) for more information. + */ + uint8_t digit_at(int16_t magnitude) const; + + /** + * See the [Rust documentation for `magnitude_range`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.magnitude_range) for more information. + */ + int16_t magnitude_start() const; + + /** + * See the [Rust documentation for `magnitude_range`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.magnitude_range) for more information. + */ + int16_t magnitude_end() const; + + /** + * See the [Rust documentation for `nonzero_magnitude_start`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.nonzero_magnitude_start) for more information. + */ + int16_t nonzero_magnitude_start() const; + + /** + * See the [Rust documentation for `nonzero_magnitude_end`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.nonzero_magnitude_end) for more information. + */ + int16_t nonzero_magnitude_end() const; + + /** + * See the [Rust documentation for `is_zero`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.is_zero) for more information. + */ + bool is_zero() const; + + /** + * Multiply the [`ICU4XFixedDecimal`] by a given power of ten. + * + * See the [Rust documentation for `multiply_pow10`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.multiply_pow10) for more information. + */ + void multiply_pow10(int16_t power); + + /** + * See the [Rust documentation for `sign`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.sign) for more information. + */ + ICU4XFixedDecimalSign sign() const; + + /** + * Set the sign of the [`ICU4XFixedDecimal`]. + * + * See the [Rust documentation for `set_sign`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.set_sign) for more information. + */ + void set_sign(ICU4XFixedDecimalSign sign); + + /** + * See the [Rust documentation for `apply_sign_display`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.apply_sign_display) for more information. + */ + void apply_sign_display(ICU4XFixedDecimalSignDisplay sign_display); + + /** + * See the [Rust documentation for `trim_start`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.trim_start) for more information. + */ + void trim_start(); + + /** + * See the [Rust documentation for `trim_end`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.trim_end) for more information. + */ + void trim_end(); + + /** + * Zero-pad the [`ICU4XFixedDecimal`] on the left to a particular position + * + * See the [Rust documentation for `pad_start`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.pad_start) for more information. + */ + void pad_start(int16_t position); + + /** + * Zero-pad the [`ICU4XFixedDecimal`] on the right to a particular position + * + * See the [Rust documentation for `pad_end`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.pad_end) for more information. + */ + void pad_end(int16_t position); + + /** + * Truncate the [`ICU4XFixedDecimal`] on the left to a particular position, deleting digits if necessary. This is useful for, e.g. abbreviating years + * ("2022" -> "22") + * + * See the [Rust documentation for `set_max_position`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.set_max_position) for more information. + */ + void set_max_position(int16_t position); + + /** + * See the [Rust documentation for `trunc`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.trunc) for more information. + */ + void trunc(int16_t position); + + /** + * See the [Rust documentation for `half_trunc`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.half_trunc) for more information. + */ + void half_trunc(int16_t position); + + /** + * See the [Rust documentation for `expand`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.expand) for more information. + */ + void expand(int16_t position); + + /** + * See the [Rust documentation for `half_expand`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.half_expand) for more information. + */ + void half_expand(int16_t position); + + /** + * See the [Rust documentation for `ceil`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.ceil) for more information. + */ + void ceil(int16_t position); + + /** + * See the [Rust documentation for `half_ceil`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.half_ceil) for more information. + */ + void half_ceil(int16_t position); + + /** + * See the [Rust documentation for `floor`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.floor) for more information. + */ + void floor(int16_t position); + + /** + * See the [Rust documentation for `half_floor`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.half_floor) for more information. + */ + void half_floor(int16_t position); + + /** + * See the [Rust documentation for `half_even`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.half_even) for more information. + */ + void half_even(int16_t position); + + /** + * Concatenates `other` to the end of `self`. + * + * If successful, `other` will be set to 0 and a successful status is returned. + * + * If not successful, `other` will be unchanged and an error is returned. + * + * See the [Rust documentation for `concatenate_end`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.concatenate_end) for more information. + */ + diplomat::result<std::monostate, std::monostate> concatenate_end(ICU4XFixedDecimal& other); + + /** + * Format the [`ICU4XFixedDecimal`] as a string. + * + * See the [Rust documentation for `write_to`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.write_to) for more information. + */ + template<typename W> void to_string_to_writeable(W& to) const; + + /** + * Format the [`ICU4XFixedDecimal`] as a string. + * + * See the [Rust documentation for `write_to`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.write_to) for more information. + */ + std::string to_string() const; + inline const capi::ICU4XFixedDecimal* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XFixedDecimal* AsFFIMut() { return this->inner.get(); } + inline ICU4XFixedDecimal(capi::ICU4XFixedDecimal* i) : inner(i) {} + ICU4XFixedDecimal() = default; + ICU4XFixedDecimal(ICU4XFixedDecimal&&) noexcept = default; + ICU4XFixedDecimal& operator=(ICU4XFixedDecimal&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XFixedDecimal, ICU4XFixedDecimalDeleter> inner; +}; + + +inline ICU4XFixedDecimal ICU4XFixedDecimal::create_from_i32(int32_t v) { + return ICU4XFixedDecimal(capi::ICU4XFixedDecimal_create_from_i32(v)); +} +inline ICU4XFixedDecimal ICU4XFixedDecimal::create_from_u32(uint32_t v) { + return ICU4XFixedDecimal(capi::ICU4XFixedDecimal_create_from_u32(v)); +} +inline ICU4XFixedDecimal ICU4XFixedDecimal::create_from_i64(int64_t v) { + return ICU4XFixedDecimal(capi::ICU4XFixedDecimal_create_from_i64(v)); +} +inline ICU4XFixedDecimal ICU4XFixedDecimal::create_from_u64(uint64_t v) { + return ICU4XFixedDecimal(capi::ICU4XFixedDecimal_create_from_u64(v)); +} +inline diplomat::result<ICU4XFixedDecimal, ICU4XError> ICU4XFixedDecimal::create_from_f64_with_integer_precision(double f) { + auto diplomat_result_raw_out_value = capi::ICU4XFixedDecimal_create_from_f64_with_integer_precision(f); + diplomat::result<ICU4XFixedDecimal, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XFixedDecimal>(ICU4XFixedDecimal(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XFixedDecimal, ICU4XError> ICU4XFixedDecimal::create_from_f64_with_lower_magnitude(double f, int16_t magnitude) { + auto diplomat_result_raw_out_value = capi::ICU4XFixedDecimal_create_from_f64_with_lower_magnitude(f, magnitude); + diplomat::result<ICU4XFixedDecimal, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XFixedDecimal>(ICU4XFixedDecimal(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XFixedDecimal, ICU4XError> ICU4XFixedDecimal::create_from_f64_with_significant_digits(double f, uint8_t digits) { + auto diplomat_result_raw_out_value = capi::ICU4XFixedDecimal_create_from_f64_with_significant_digits(f, digits); + diplomat::result<ICU4XFixedDecimal, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XFixedDecimal>(ICU4XFixedDecimal(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XFixedDecimal, ICU4XError> ICU4XFixedDecimal::create_from_f64_with_floating_precision(double f) { + auto diplomat_result_raw_out_value = capi::ICU4XFixedDecimal_create_from_f64_with_floating_precision(f); + diplomat::result<ICU4XFixedDecimal, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XFixedDecimal>(ICU4XFixedDecimal(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XFixedDecimal, ICU4XError> ICU4XFixedDecimal::create_from_string(const std::string_view v) { + auto diplomat_result_raw_out_value = capi::ICU4XFixedDecimal_create_from_string(v.data(), v.size()); + diplomat::result<ICU4XFixedDecimal, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XFixedDecimal>(ICU4XFixedDecimal(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline uint8_t ICU4XFixedDecimal::digit_at(int16_t magnitude) const { + return capi::ICU4XFixedDecimal_digit_at(this->inner.get(), magnitude); +} +inline int16_t ICU4XFixedDecimal::magnitude_start() const { + return capi::ICU4XFixedDecimal_magnitude_start(this->inner.get()); +} +inline int16_t ICU4XFixedDecimal::magnitude_end() const { + return capi::ICU4XFixedDecimal_magnitude_end(this->inner.get()); +} +inline int16_t ICU4XFixedDecimal::nonzero_magnitude_start() const { + return capi::ICU4XFixedDecimal_nonzero_magnitude_start(this->inner.get()); +} +inline int16_t ICU4XFixedDecimal::nonzero_magnitude_end() const { + return capi::ICU4XFixedDecimal_nonzero_magnitude_end(this->inner.get()); +} +inline bool ICU4XFixedDecimal::is_zero() const { + return capi::ICU4XFixedDecimal_is_zero(this->inner.get()); +} +inline void ICU4XFixedDecimal::multiply_pow10(int16_t power) { + capi::ICU4XFixedDecimal_multiply_pow10(this->inner.get(), power); +} +inline ICU4XFixedDecimalSign ICU4XFixedDecimal::sign() const { + return static_cast<ICU4XFixedDecimalSign>(capi::ICU4XFixedDecimal_sign(this->inner.get())); +} +inline void ICU4XFixedDecimal::set_sign(ICU4XFixedDecimalSign sign) { + capi::ICU4XFixedDecimal_set_sign(this->inner.get(), static_cast<capi::ICU4XFixedDecimalSign>(sign)); +} +inline void ICU4XFixedDecimal::apply_sign_display(ICU4XFixedDecimalSignDisplay sign_display) { + capi::ICU4XFixedDecimal_apply_sign_display(this->inner.get(), static_cast<capi::ICU4XFixedDecimalSignDisplay>(sign_display)); +} +inline void ICU4XFixedDecimal::trim_start() { + capi::ICU4XFixedDecimal_trim_start(this->inner.get()); +} +inline void ICU4XFixedDecimal::trim_end() { + capi::ICU4XFixedDecimal_trim_end(this->inner.get()); +} +inline void ICU4XFixedDecimal::pad_start(int16_t position) { + capi::ICU4XFixedDecimal_pad_start(this->inner.get(), position); +} +inline void ICU4XFixedDecimal::pad_end(int16_t position) { + capi::ICU4XFixedDecimal_pad_end(this->inner.get(), position); +} +inline void ICU4XFixedDecimal::set_max_position(int16_t position) { + capi::ICU4XFixedDecimal_set_max_position(this->inner.get(), position); +} +inline void ICU4XFixedDecimal::trunc(int16_t position) { + capi::ICU4XFixedDecimal_trunc(this->inner.get(), position); +} +inline void ICU4XFixedDecimal::half_trunc(int16_t position) { + capi::ICU4XFixedDecimal_half_trunc(this->inner.get(), position); +} +inline void ICU4XFixedDecimal::expand(int16_t position) { + capi::ICU4XFixedDecimal_expand(this->inner.get(), position); +} +inline void ICU4XFixedDecimal::half_expand(int16_t position) { + capi::ICU4XFixedDecimal_half_expand(this->inner.get(), position); +} +inline void ICU4XFixedDecimal::ceil(int16_t position) { + capi::ICU4XFixedDecimal_ceil(this->inner.get(), position); +} +inline void ICU4XFixedDecimal::half_ceil(int16_t position) { + capi::ICU4XFixedDecimal_half_ceil(this->inner.get(), position); +} +inline void ICU4XFixedDecimal::floor(int16_t position) { + capi::ICU4XFixedDecimal_floor(this->inner.get(), position); +} +inline void ICU4XFixedDecimal::half_floor(int16_t position) { + capi::ICU4XFixedDecimal_half_floor(this->inner.get(), position); +} +inline void ICU4XFixedDecimal::half_even(int16_t position) { + capi::ICU4XFixedDecimal_half_even(this->inner.get(), position); +} +inline diplomat::result<std::monostate, std::monostate> ICU4XFixedDecimal::concatenate_end(ICU4XFixedDecimal& other) { + auto diplomat_result_raw_out_value = capi::ICU4XFixedDecimal_concatenate_end(this->inner.get(), other.AsFFIMut()); + diplomat::result<std::monostate, std::monostate> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err(std::monostate()); + } + return diplomat_result_out_value; +} +template<typename W> inline void ICU4XFixedDecimal::to_string_to_writeable(W& to) const { + capi::DiplomatWriteable to_writer = diplomat::WriteableTrait<W>::Construct(to); + capi::ICU4XFixedDecimal_to_string(this->inner.get(), &to_writer); +} +inline std::string ICU4XFixedDecimal::to_string() const { + std::string diplomat_writeable_string; + capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); + capi::ICU4XFixedDecimal_to_string(this->inner.get(), &diplomat_writeable_out); + return diplomat_writeable_string; +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XFixedDecimalFormatter.h b/intl/icu_capi/cpp/include/ICU4XFixedDecimalFormatter.h new file mode 100644 index 0000000000..aa1cfd6a48 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XFixedDecimalFormatter.h @@ -0,0 +1,40 @@ +#ifndef ICU4XFixedDecimalFormatter_H +#define ICU4XFixedDecimalFormatter_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XFixedDecimalFormatter ICU4XFixedDecimalFormatter; +#ifdef __cplusplus +} // namespace capi +#endif +#include "ICU4XDataProvider.h" +#include "ICU4XLocale.h" +#include "ICU4XFixedDecimalGroupingStrategy.h" +#include "diplomat_result_box_ICU4XFixedDecimalFormatter_ICU4XError.h" +#include "ICU4XDataStruct.h" +#include "ICU4XFixedDecimal.h" +#include "diplomat_result_void_ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +diplomat_result_box_ICU4XFixedDecimalFormatter_ICU4XError ICU4XFixedDecimalFormatter_create_with_grouping_strategy(const ICU4XDataProvider* provider, const ICU4XLocale* locale, ICU4XFixedDecimalGroupingStrategy grouping_strategy); + +diplomat_result_box_ICU4XFixedDecimalFormatter_ICU4XError ICU4XFixedDecimalFormatter_create_with_decimal_symbols_v1(const ICU4XDataStruct* data_struct, ICU4XFixedDecimalGroupingStrategy grouping_strategy); + +diplomat_result_void_ICU4XError ICU4XFixedDecimalFormatter_format(const ICU4XFixedDecimalFormatter* self, const ICU4XFixedDecimal* value, DiplomatWriteable* write); +void ICU4XFixedDecimalFormatter_destroy(ICU4XFixedDecimalFormatter* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XFixedDecimalFormatter.hpp b/intl/icu_capi/cpp/include/ICU4XFixedDecimalFormatter.hpp new file mode 100644 index 0000000000..9ba29490e7 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XFixedDecimalFormatter.hpp @@ -0,0 +1,126 @@ +#ifndef ICU4XFixedDecimalFormatter_HPP +#define ICU4XFixedDecimalFormatter_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XFixedDecimalFormatter.h" + +class ICU4XDataProvider; +class ICU4XLocale; +#include "ICU4XFixedDecimalGroupingStrategy.hpp" +class ICU4XFixedDecimalFormatter; +#include "ICU4XError.hpp" +class ICU4XDataStruct; +class ICU4XFixedDecimal; + +/** + * A destruction policy for using ICU4XFixedDecimalFormatter with std::unique_ptr. + */ +struct ICU4XFixedDecimalFormatterDeleter { + void operator()(capi::ICU4XFixedDecimalFormatter* l) const noexcept { + capi::ICU4XFixedDecimalFormatter_destroy(l); + } +}; + +/** + * An ICU4X Fixed Decimal Format object, capable of formatting a [`ICU4XFixedDecimal`] as a string. + * + * See the [Rust documentation for `FixedDecimalFormatter`](https://docs.rs/icu/latest/icu/decimal/struct.FixedDecimalFormatter.html) for more information. + */ +class ICU4XFixedDecimalFormatter { + public: + + /** + * Creates a new [`ICU4XFixedDecimalFormatter`] from locale data. + * + * See the [Rust documentation for `try_new`](https://docs.rs/icu/latest/icu/decimal/struct.FixedDecimalFormatter.html#method.try_new) for more information. + */ + static diplomat::result<ICU4XFixedDecimalFormatter, ICU4XError> create_with_grouping_strategy(const ICU4XDataProvider& provider, const ICU4XLocale& locale, ICU4XFixedDecimalGroupingStrategy grouping_strategy); + + /** + * Creates a new [`ICU4XFixedDecimalFormatter`] from preconstructed locale data in the form of an [`ICU4XDataStruct`] + * constructed from `ICU4XDataStruct::create_decimal_symbols()`. + * + * The contents of the data struct will be consumed: if you wish to use the struct again it will have to be reconstructed. + * Passing a consumed struct to this method will return an error. + */ + static diplomat::result<ICU4XFixedDecimalFormatter, ICU4XError> create_with_decimal_symbols_v1(const ICU4XDataStruct& data_struct, ICU4XFixedDecimalGroupingStrategy grouping_strategy); + + /** + * Formats a [`ICU4XFixedDecimal`] to a string. + * + * See the [Rust documentation for `format`](https://docs.rs/icu/latest/icu/decimal/struct.FixedDecimalFormatter.html#method.format) for more information. + */ + template<typename W> diplomat::result<std::monostate, ICU4XError> format_to_writeable(const ICU4XFixedDecimal& value, W& write) const; + + /** + * Formats a [`ICU4XFixedDecimal`] to a string. + * + * See the [Rust documentation for `format`](https://docs.rs/icu/latest/icu/decimal/struct.FixedDecimalFormatter.html#method.format) for more information. + */ + diplomat::result<std::string, ICU4XError> format(const ICU4XFixedDecimal& value) const; + inline const capi::ICU4XFixedDecimalFormatter* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XFixedDecimalFormatter* AsFFIMut() { return this->inner.get(); } + inline ICU4XFixedDecimalFormatter(capi::ICU4XFixedDecimalFormatter* i) : inner(i) {} + ICU4XFixedDecimalFormatter() = default; + ICU4XFixedDecimalFormatter(ICU4XFixedDecimalFormatter&&) noexcept = default; + ICU4XFixedDecimalFormatter& operator=(ICU4XFixedDecimalFormatter&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XFixedDecimalFormatter, ICU4XFixedDecimalFormatterDeleter> inner; +}; + +#include "ICU4XDataProvider.hpp" +#include "ICU4XLocale.hpp" +#include "ICU4XDataStruct.hpp" +#include "ICU4XFixedDecimal.hpp" + +inline diplomat::result<ICU4XFixedDecimalFormatter, ICU4XError> ICU4XFixedDecimalFormatter::create_with_grouping_strategy(const ICU4XDataProvider& provider, const ICU4XLocale& locale, ICU4XFixedDecimalGroupingStrategy grouping_strategy) { + auto diplomat_result_raw_out_value = capi::ICU4XFixedDecimalFormatter_create_with_grouping_strategy(provider.AsFFI(), locale.AsFFI(), static_cast<capi::ICU4XFixedDecimalGroupingStrategy>(grouping_strategy)); + diplomat::result<ICU4XFixedDecimalFormatter, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XFixedDecimalFormatter>(ICU4XFixedDecimalFormatter(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XFixedDecimalFormatter, ICU4XError> ICU4XFixedDecimalFormatter::create_with_decimal_symbols_v1(const ICU4XDataStruct& data_struct, ICU4XFixedDecimalGroupingStrategy grouping_strategy) { + auto diplomat_result_raw_out_value = capi::ICU4XFixedDecimalFormatter_create_with_decimal_symbols_v1(data_struct.AsFFI(), static_cast<capi::ICU4XFixedDecimalGroupingStrategy>(grouping_strategy)); + diplomat::result<ICU4XFixedDecimalFormatter, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XFixedDecimalFormatter>(ICU4XFixedDecimalFormatter(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XFixedDecimalFormatter::format_to_writeable(const ICU4XFixedDecimal& value, W& write) const { + capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write); + auto diplomat_result_raw_out_value = capi::ICU4XFixedDecimalFormatter_format(this->inner.get(), value.AsFFI(), &write_writer); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<std::string, ICU4XError> ICU4XFixedDecimalFormatter::format(const ICU4XFixedDecimal& value) const { + std::string diplomat_writeable_string; + capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); + auto diplomat_result_raw_out_value = capi::ICU4XFixedDecimalFormatter_format(this->inner.get(), value.AsFFI(), &diplomat_writeable_out); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string)); +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XFixedDecimalGroupingStrategy.h b/intl/icu_capi/cpp/include/ICU4XFixedDecimalGroupingStrategy.h new file mode 100644 index 0000000000..7648892cc5 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XFixedDecimalGroupingStrategy.h @@ -0,0 +1,33 @@ +#ifndef ICU4XFixedDecimalGroupingStrategy_H +#define ICU4XFixedDecimalGroupingStrategy_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef enum ICU4XFixedDecimalGroupingStrategy { + ICU4XFixedDecimalGroupingStrategy_Auto = 0, + ICU4XFixedDecimalGroupingStrategy_Never = 1, + ICU4XFixedDecimalGroupingStrategy_Always = 2, + ICU4XFixedDecimalGroupingStrategy_Min2 = 3, +} ICU4XFixedDecimalGroupingStrategy; +#ifdef __cplusplus +} // namespace capi +#endif +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +void ICU4XFixedDecimalGroupingStrategy_destroy(ICU4XFixedDecimalGroupingStrategy* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XFixedDecimalGroupingStrategy.hpp b/intl/icu_capi/cpp/include/ICU4XFixedDecimalGroupingStrategy.hpp new file mode 100644 index 0000000000..85effe2fc5 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XFixedDecimalGroupingStrategy.hpp @@ -0,0 +1,26 @@ +#ifndef ICU4XFixedDecimalGroupingStrategy_HPP +#define ICU4XFixedDecimalGroupingStrategy_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XFixedDecimalGroupingStrategy.h" + + + +/** + * See the [Rust documentation for `GroupingStrategy`](https://docs.rs/icu/latest/icu/decimal/options/enum.GroupingStrategy.html) for more information. + */ +enum struct ICU4XFixedDecimalGroupingStrategy { + Auto = 0, + Never = 1, + Always = 2, + Min2 = 3, +}; + +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XFixedDecimalSign.h b/intl/icu_capi/cpp/include/ICU4XFixedDecimalSign.h new file mode 100644 index 0000000000..12fff3cf1c --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XFixedDecimalSign.h @@ -0,0 +1,32 @@ +#ifndef ICU4XFixedDecimalSign_H +#define ICU4XFixedDecimalSign_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef enum ICU4XFixedDecimalSign { + ICU4XFixedDecimalSign_None = 0, + ICU4XFixedDecimalSign_Negative = 1, + ICU4XFixedDecimalSign_Positive = 2, +} ICU4XFixedDecimalSign; +#ifdef __cplusplus +} // namespace capi +#endif +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +void ICU4XFixedDecimalSign_destroy(ICU4XFixedDecimalSign* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XFixedDecimalSign.hpp b/intl/icu_capi/cpp/include/ICU4XFixedDecimalSign.hpp new file mode 100644 index 0000000000..b56cdfc4b6 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XFixedDecimalSign.hpp @@ -0,0 +1,39 @@ +#ifndef ICU4XFixedDecimalSign_HPP +#define ICU4XFixedDecimalSign_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XFixedDecimalSign.h" + + + +/** + * The sign of a FixedDecimal, as shown in formatting. + * + * See the [Rust documentation for `Sign`](https://docs.rs/fixed_decimal/latest/fixed_decimal/enum.Sign.html) for more information. + */ +enum struct ICU4XFixedDecimalSign { + + /** + * No sign (implicitly positive, e.g., 1729). + */ + None = 0, + + /** + * A negative sign, e.g., -1729. + */ + Negative = 1, + + /** + * An explicit positive sign, e.g., +1729. + */ + Positive = 2, +}; + +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XFixedDecimalSignDisplay.h b/intl/icu_capi/cpp/include/ICU4XFixedDecimalSignDisplay.h new file mode 100644 index 0000000000..8c2612e516 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XFixedDecimalSignDisplay.h @@ -0,0 +1,34 @@ +#ifndef ICU4XFixedDecimalSignDisplay_H +#define ICU4XFixedDecimalSignDisplay_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef enum ICU4XFixedDecimalSignDisplay { + ICU4XFixedDecimalSignDisplay_Auto = 0, + ICU4XFixedDecimalSignDisplay_Never = 1, + ICU4XFixedDecimalSignDisplay_Always = 2, + ICU4XFixedDecimalSignDisplay_ExceptZero = 3, + ICU4XFixedDecimalSignDisplay_Negative = 4, +} ICU4XFixedDecimalSignDisplay; +#ifdef __cplusplus +} // namespace capi +#endif +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +void ICU4XFixedDecimalSignDisplay_destroy(ICU4XFixedDecimalSignDisplay* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XFixedDecimalSignDisplay.hpp b/intl/icu_capi/cpp/include/ICU4XFixedDecimalSignDisplay.hpp new file mode 100644 index 0000000000..6261edacea --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XFixedDecimalSignDisplay.hpp @@ -0,0 +1,29 @@ +#ifndef ICU4XFixedDecimalSignDisplay_HPP +#define ICU4XFixedDecimalSignDisplay_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XFixedDecimalSignDisplay.h" + + + +/** + * ECMA-402 compatible sign display preference. + * + * See the [Rust documentation for `SignDisplay`](https://docs.rs/fixed_decimal/latest/fixed_decimal/enum.SignDisplay.html) for more information. + */ +enum struct ICU4XFixedDecimalSignDisplay { + Auto = 0, + Never = 1, + Always = 2, + ExceptZero = 3, + Negative = 4, +}; + +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XGeneralCategoryNameToMaskMapper.h b/intl/icu_capi/cpp/include/ICU4XGeneralCategoryNameToMaskMapper.h new file mode 100644 index 0000000000..3a4e2d4d13 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XGeneralCategoryNameToMaskMapper.h @@ -0,0 +1,35 @@ +#ifndef ICU4XGeneralCategoryNameToMaskMapper_H +#define ICU4XGeneralCategoryNameToMaskMapper_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XGeneralCategoryNameToMaskMapper ICU4XGeneralCategoryNameToMaskMapper; +#ifdef __cplusplus +} // namespace capi +#endif +#include "ICU4XDataProvider.h" +#include "diplomat_result_box_ICU4XGeneralCategoryNameToMaskMapper_ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +uint32_t ICU4XGeneralCategoryNameToMaskMapper_get_strict(const ICU4XGeneralCategoryNameToMaskMapper* self, const char* name_data, size_t name_len); + +uint32_t ICU4XGeneralCategoryNameToMaskMapper_get_loose(const ICU4XGeneralCategoryNameToMaskMapper* self, const char* name_data, size_t name_len); + +diplomat_result_box_ICU4XGeneralCategoryNameToMaskMapper_ICU4XError ICU4XGeneralCategoryNameToMaskMapper_load(const ICU4XDataProvider* provider); +void ICU4XGeneralCategoryNameToMaskMapper_destroy(ICU4XGeneralCategoryNameToMaskMapper* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XGeneralCategoryNameToMaskMapper.hpp b/intl/icu_capi/cpp/include/ICU4XGeneralCategoryNameToMaskMapper.hpp new file mode 100644 index 0000000000..0a7fe54be0 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XGeneralCategoryNameToMaskMapper.hpp @@ -0,0 +1,83 @@ +#ifndef ICU4XGeneralCategoryNameToMaskMapper_HPP +#define ICU4XGeneralCategoryNameToMaskMapper_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XGeneralCategoryNameToMaskMapper.h" + +class ICU4XDataProvider; +class ICU4XGeneralCategoryNameToMaskMapper; +#include "ICU4XError.hpp" + +/** + * A destruction policy for using ICU4XGeneralCategoryNameToMaskMapper with std::unique_ptr. + */ +struct ICU4XGeneralCategoryNameToMaskMapperDeleter { + void operator()(capi::ICU4XGeneralCategoryNameToMaskMapper* l) const noexcept { + capi::ICU4XGeneralCategoryNameToMaskMapper_destroy(l); + } +}; + +/** + * A type capable of looking up General Category mask values from a string name. + * + * See the [Rust documentation for `get_name_to_enum_mapper`](https://docs.rs/icu/latest/icu/properties/struct.GeneralCategoryGroup.html#method.get_name_to_enum_mapper) for more information. + * + * See the [Rust documentation for `PropertyValueNameToEnumMapper`](https://docs.rs/icu/latest/icu/properties/names/struct.PropertyValueNameToEnumMapper.html) for more information. + */ +class ICU4XGeneralCategoryNameToMaskMapper { + public: + + /** + * Get the mask value matching the given name, using strict matching + * + * Returns 0 if the name is unknown for this property + */ + uint32_t get_strict(const std::string_view name) const; + + /** + * Get the mask value matching the given name, using loose matching + * + * Returns 0 if the name is unknown for this property + */ + uint32_t get_loose(const std::string_view name) const; + + /** + * See the [Rust documentation for `get_name_to_enum_mapper`](https://docs.rs/icu/latest/icu/properties/struct.GeneralCategoryGroup.html#method.get_name_to_enum_mapper) for more information. + */ + static diplomat::result<ICU4XGeneralCategoryNameToMaskMapper, ICU4XError> load(const ICU4XDataProvider& provider); + inline const capi::ICU4XGeneralCategoryNameToMaskMapper* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XGeneralCategoryNameToMaskMapper* AsFFIMut() { return this->inner.get(); } + inline ICU4XGeneralCategoryNameToMaskMapper(capi::ICU4XGeneralCategoryNameToMaskMapper* i) : inner(i) {} + ICU4XGeneralCategoryNameToMaskMapper() = default; + ICU4XGeneralCategoryNameToMaskMapper(ICU4XGeneralCategoryNameToMaskMapper&&) noexcept = default; + ICU4XGeneralCategoryNameToMaskMapper& operator=(ICU4XGeneralCategoryNameToMaskMapper&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XGeneralCategoryNameToMaskMapper, ICU4XGeneralCategoryNameToMaskMapperDeleter> inner; +}; + +#include "ICU4XDataProvider.hpp" + +inline uint32_t ICU4XGeneralCategoryNameToMaskMapper::get_strict(const std::string_view name) const { + return capi::ICU4XGeneralCategoryNameToMaskMapper_get_strict(this->inner.get(), name.data(), name.size()); +} +inline uint32_t ICU4XGeneralCategoryNameToMaskMapper::get_loose(const std::string_view name) const { + return capi::ICU4XGeneralCategoryNameToMaskMapper_get_loose(this->inner.get(), name.data(), name.size()); +} +inline diplomat::result<ICU4XGeneralCategoryNameToMaskMapper, ICU4XError> ICU4XGeneralCategoryNameToMaskMapper::load(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XGeneralCategoryNameToMaskMapper_load(provider.AsFFI()); + diplomat::result<ICU4XGeneralCategoryNameToMaskMapper, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XGeneralCategoryNameToMaskMapper>(ICU4XGeneralCategoryNameToMaskMapper(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XGraphemeClusterBreakIteratorLatin1.h b/intl/icu_capi/cpp/include/ICU4XGraphemeClusterBreakIteratorLatin1.h new file mode 100644 index 0000000000..9e23489fd3 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XGraphemeClusterBreakIteratorLatin1.h @@ -0,0 +1,29 @@ +#ifndef ICU4XGraphemeClusterBreakIteratorLatin1_H +#define ICU4XGraphemeClusterBreakIteratorLatin1_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XGraphemeClusterBreakIteratorLatin1 ICU4XGraphemeClusterBreakIteratorLatin1; +#ifdef __cplusplus +} // namespace capi +#endif +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +int32_t ICU4XGraphemeClusterBreakIteratorLatin1_next(ICU4XGraphemeClusterBreakIteratorLatin1* self); +void ICU4XGraphemeClusterBreakIteratorLatin1_destroy(ICU4XGraphemeClusterBreakIteratorLatin1* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XGraphemeClusterBreakIteratorLatin1.hpp b/intl/icu_capi/cpp/include/ICU4XGraphemeClusterBreakIteratorLatin1.hpp new file mode 100644 index 0000000000..3948a6e00b --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XGraphemeClusterBreakIteratorLatin1.hpp @@ -0,0 +1,51 @@ +#ifndef ICU4XGraphemeClusterBreakIteratorLatin1_HPP +#define ICU4XGraphemeClusterBreakIteratorLatin1_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XGraphemeClusterBreakIteratorLatin1.h" + + +/** + * A destruction policy for using ICU4XGraphemeClusterBreakIteratorLatin1 with std::unique_ptr. + */ +struct ICU4XGraphemeClusterBreakIteratorLatin1Deleter { + void operator()(capi::ICU4XGraphemeClusterBreakIteratorLatin1* l) const noexcept { + capi::ICU4XGraphemeClusterBreakIteratorLatin1_destroy(l); + } +}; + +/** + * See the [Rust documentation for `GraphemeClusterBreakIterator`](https://docs.rs/icu/latest/icu/segmenter/struct.GraphemeClusterBreakIterator.html) for more information. + */ +class ICU4XGraphemeClusterBreakIteratorLatin1 { + public: + + /** + * Finds the next breakpoint. Returns -1 if at the end of the string or if the index is + * out of range of a 32-bit signed integer. + * + * See the [Rust documentation for `next`](https://docs.rs/icu/latest/icu/segmenter/struct.GraphemeClusterBreakIterator.html#method.next) for more information. + */ + int32_t next(); + inline const capi::ICU4XGraphemeClusterBreakIteratorLatin1* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XGraphemeClusterBreakIteratorLatin1* AsFFIMut() { return this->inner.get(); } + inline ICU4XGraphemeClusterBreakIteratorLatin1(capi::ICU4XGraphemeClusterBreakIteratorLatin1* i) : inner(i) {} + ICU4XGraphemeClusterBreakIteratorLatin1() = default; + ICU4XGraphemeClusterBreakIteratorLatin1(ICU4XGraphemeClusterBreakIteratorLatin1&&) noexcept = default; + ICU4XGraphemeClusterBreakIteratorLatin1& operator=(ICU4XGraphemeClusterBreakIteratorLatin1&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XGraphemeClusterBreakIteratorLatin1, ICU4XGraphemeClusterBreakIteratorLatin1Deleter> inner; +}; + + +inline int32_t ICU4XGraphemeClusterBreakIteratorLatin1::next() { + return capi::ICU4XGraphemeClusterBreakIteratorLatin1_next(this->inner.get()); +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XGraphemeClusterBreakIteratorUtf16.h b/intl/icu_capi/cpp/include/ICU4XGraphemeClusterBreakIteratorUtf16.h new file mode 100644 index 0000000000..f0de4c0214 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XGraphemeClusterBreakIteratorUtf16.h @@ -0,0 +1,29 @@ +#ifndef ICU4XGraphemeClusterBreakIteratorUtf16_H +#define ICU4XGraphemeClusterBreakIteratorUtf16_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XGraphemeClusterBreakIteratorUtf16 ICU4XGraphemeClusterBreakIteratorUtf16; +#ifdef __cplusplus +} // namespace capi +#endif +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +int32_t ICU4XGraphemeClusterBreakIteratorUtf16_next(ICU4XGraphemeClusterBreakIteratorUtf16* self); +void ICU4XGraphemeClusterBreakIteratorUtf16_destroy(ICU4XGraphemeClusterBreakIteratorUtf16* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XGraphemeClusterBreakIteratorUtf16.hpp b/intl/icu_capi/cpp/include/ICU4XGraphemeClusterBreakIteratorUtf16.hpp new file mode 100644 index 0000000000..3c16a0c53c --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XGraphemeClusterBreakIteratorUtf16.hpp @@ -0,0 +1,51 @@ +#ifndef ICU4XGraphemeClusterBreakIteratorUtf16_HPP +#define ICU4XGraphemeClusterBreakIteratorUtf16_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XGraphemeClusterBreakIteratorUtf16.h" + + +/** + * A destruction policy for using ICU4XGraphemeClusterBreakIteratorUtf16 with std::unique_ptr. + */ +struct ICU4XGraphemeClusterBreakIteratorUtf16Deleter { + void operator()(capi::ICU4XGraphemeClusterBreakIteratorUtf16* l) const noexcept { + capi::ICU4XGraphemeClusterBreakIteratorUtf16_destroy(l); + } +}; + +/** + * See the [Rust documentation for `GraphemeClusterBreakIterator`](https://docs.rs/icu/latest/icu/segmenter/struct.GraphemeClusterBreakIterator.html) for more information. + */ +class ICU4XGraphemeClusterBreakIteratorUtf16 { + public: + + /** + * Finds the next breakpoint. Returns -1 if at the end of the string or if the index is + * out of range of a 32-bit signed integer. + * + * See the [Rust documentation for `next`](https://docs.rs/icu/latest/icu/segmenter/struct.GraphemeClusterBreakIterator.html#method.next) for more information. + */ + int32_t next(); + inline const capi::ICU4XGraphemeClusterBreakIteratorUtf16* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XGraphemeClusterBreakIteratorUtf16* AsFFIMut() { return this->inner.get(); } + inline ICU4XGraphemeClusterBreakIteratorUtf16(capi::ICU4XGraphemeClusterBreakIteratorUtf16* i) : inner(i) {} + ICU4XGraphemeClusterBreakIteratorUtf16() = default; + ICU4XGraphemeClusterBreakIteratorUtf16(ICU4XGraphemeClusterBreakIteratorUtf16&&) noexcept = default; + ICU4XGraphemeClusterBreakIteratorUtf16& operator=(ICU4XGraphemeClusterBreakIteratorUtf16&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XGraphemeClusterBreakIteratorUtf16, ICU4XGraphemeClusterBreakIteratorUtf16Deleter> inner; +}; + + +inline int32_t ICU4XGraphemeClusterBreakIteratorUtf16::next() { + return capi::ICU4XGraphemeClusterBreakIteratorUtf16_next(this->inner.get()); +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XGraphemeClusterBreakIteratorUtf8.h b/intl/icu_capi/cpp/include/ICU4XGraphemeClusterBreakIteratorUtf8.h new file mode 100644 index 0000000000..331b17eac7 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XGraphemeClusterBreakIteratorUtf8.h @@ -0,0 +1,29 @@ +#ifndef ICU4XGraphemeClusterBreakIteratorUtf8_H +#define ICU4XGraphemeClusterBreakIteratorUtf8_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XGraphemeClusterBreakIteratorUtf8 ICU4XGraphemeClusterBreakIteratorUtf8; +#ifdef __cplusplus +} // namespace capi +#endif +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +int32_t ICU4XGraphemeClusterBreakIteratorUtf8_next(ICU4XGraphemeClusterBreakIteratorUtf8* self); +void ICU4XGraphemeClusterBreakIteratorUtf8_destroy(ICU4XGraphemeClusterBreakIteratorUtf8* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XGraphemeClusterBreakIteratorUtf8.hpp b/intl/icu_capi/cpp/include/ICU4XGraphemeClusterBreakIteratorUtf8.hpp new file mode 100644 index 0000000000..6e7bdcc0bd --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XGraphemeClusterBreakIteratorUtf8.hpp @@ -0,0 +1,51 @@ +#ifndef ICU4XGraphemeClusterBreakIteratorUtf8_HPP +#define ICU4XGraphemeClusterBreakIteratorUtf8_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XGraphemeClusterBreakIteratorUtf8.h" + + +/** + * A destruction policy for using ICU4XGraphemeClusterBreakIteratorUtf8 with std::unique_ptr. + */ +struct ICU4XGraphemeClusterBreakIteratorUtf8Deleter { + void operator()(capi::ICU4XGraphemeClusterBreakIteratorUtf8* l) const noexcept { + capi::ICU4XGraphemeClusterBreakIteratorUtf8_destroy(l); + } +}; + +/** + * See the [Rust documentation for `GraphemeClusterBreakIterator`](https://docs.rs/icu/latest/icu/segmenter/struct.GraphemeClusterBreakIterator.html) for more information. + */ +class ICU4XGraphemeClusterBreakIteratorUtf8 { + public: + + /** + * Finds the next breakpoint. Returns -1 if at the end of the string or if the index is + * out of range of a 32-bit signed integer. + * + * See the [Rust documentation for `next`](https://docs.rs/icu/latest/icu/segmenter/struct.GraphemeClusterBreakIterator.html#method.next) for more information. + */ + int32_t next(); + inline const capi::ICU4XGraphemeClusterBreakIteratorUtf8* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XGraphemeClusterBreakIteratorUtf8* AsFFIMut() { return this->inner.get(); } + inline ICU4XGraphemeClusterBreakIteratorUtf8(capi::ICU4XGraphemeClusterBreakIteratorUtf8* i) : inner(i) {} + ICU4XGraphemeClusterBreakIteratorUtf8() = default; + ICU4XGraphemeClusterBreakIteratorUtf8(ICU4XGraphemeClusterBreakIteratorUtf8&&) noexcept = default; + ICU4XGraphemeClusterBreakIteratorUtf8& operator=(ICU4XGraphemeClusterBreakIteratorUtf8&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XGraphemeClusterBreakIteratorUtf8, ICU4XGraphemeClusterBreakIteratorUtf8Deleter> inner; +}; + + +inline int32_t ICU4XGraphemeClusterBreakIteratorUtf8::next() { + return capi::ICU4XGraphemeClusterBreakIteratorUtf8_next(this->inner.get()); +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XGraphemeClusterSegmenter.h b/intl/icu_capi/cpp/include/ICU4XGraphemeClusterSegmenter.h new file mode 100644 index 0000000000..1805090bfb --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XGraphemeClusterSegmenter.h @@ -0,0 +1,40 @@ +#ifndef ICU4XGraphemeClusterSegmenter_H +#define ICU4XGraphemeClusterSegmenter_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XGraphemeClusterSegmenter ICU4XGraphemeClusterSegmenter; +#ifdef __cplusplus +} // namespace capi +#endif +#include "ICU4XDataProvider.h" +#include "diplomat_result_box_ICU4XGraphemeClusterSegmenter_ICU4XError.h" +#include "ICU4XGraphemeClusterBreakIteratorUtf8.h" +#include "ICU4XGraphemeClusterBreakIteratorUtf16.h" +#include "ICU4XGraphemeClusterBreakIteratorLatin1.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +diplomat_result_box_ICU4XGraphemeClusterSegmenter_ICU4XError ICU4XGraphemeClusterSegmenter_create(const ICU4XDataProvider* provider); + +ICU4XGraphemeClusterBreakIteratorUtf8* ICU4XGraphemeClusterSegmenter_segment_utf8(const ICU4XGraphemeClusterSegmenter* self, const char* input_data, size_t input_len); + +ICU4XGraphemeClusterBreakIteratorUtf16* ICU4XGraphemeClusterSegmenter_segment_utf16(const ICU4XGraphemeClusterSegmenter* self, const uint16_t* input_data, size_t input_len); + +ICU4XGraphemeClusterBreakIteratorLatin1* ICU4XGraphemeClusterSegmenter_segment_latin1(const ICU4XGraphemeClusterSegmenter* self, const uint8_t* input_data, size_t input_len); +void ICU4XGraphemeClusterSegmenter_destroy(ICU4XGraphemeClusterSegmenter* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XGraphemeClusterSegmenter.hpp b/intl/icu_capi/cpp/include/ICU4XGraphemeClusterSegmenter.hpp new file mode 100644 index 0000000000..76941847e1 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XGraphemeClusterSegmenter.hpp @@ -0,0 +1,106 @@ +#ifndef ICU4XGraphemeClusterSegmenter_HPP +#define ICU4XGraphemeClusterSegmenter_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XGraphemeClusterSegmenter.h" + +class ICU4XDataProvider; +class ICU4XGraphemeClusterSegmenter; +#include "ICU4XError.hpp" +class ICU4XGraphemeClusterBreakIteratorUtf8; +class ICU4XGraphemeClusterBreakIteratorUtf16; +class ICU4XGraphemeClusterBreakIteratorLatin1; + +/** + * A destruction policy for using ICU4XGraphemeClusterSegmenter with std::unique_ptr. + */ +struct ICU4XGraphemeClusterSegmenterDeleter { + void operator()(capi::ICU4XGraphemeClusterSegmenter* l) const noexcept { + capi::ICU4XGraphemeClusterSegmenter_destroy(l); + } +}; + +/** + * An ICU4X grapheme-cluster-break segmenter, capable of finding grapheme cluster breakpoints + * in strings. + * + * See the [Rust documentation for `GraphemeClusterSegmenter`](https://docs.rs/icu/latest/icu/segmenter/struct.GraphemeClusterSegmenter.html) for more information. + */ +class ICU4XGraphemeClusterSegmenter { + public: + + /** + * Construct an [`ICU4XGraphemeClusterSegmenter`]. + * + * See the [Rust documentation for `new`](https://docs.rs/icu/latest/icu/segmenter/struct.GraphemeClusterSegmenter.html#method.new) for more information. + */ + static diplomat::result<ICU4XGraphemeClusterSegmenter, ICU4XError> create(const ICU4XDataProvider& provider); + + /** + * Segments a (potentially ill-formed) UTF-8 string. + * + * See the [Rust documentation for `segment_utf8`](https://docs.rs/icu/latest/icu/segmenter/struct.GraphemeClusterSegmenter.html#method.segment_utf8) for more information. + * + * Lifetimes: `this`, `input` must live at least as long as the output. + */ + ICU4XGraphemeClusterBreakIteratorUtf8 segment_utf8(const std::string_view input) const; + + /** + * Segments a UTF-16 string. + * + * See the [Rust documentation for `segment_utf16`](https://docs.rs/icu/latest/icu/segmenter/struct.GraphemeClusterSegmenter.html#method.segment_utf16) for more information. + * + * Lifetimes: `this`, `input` must live at least as long as the output. + */ + ICU4XGraphemeClusterBreakIteratorUtf16 segment_utf16(const diplomat::span<const uint16_t> input) const; + + /** + * Segments a Latin-1 string. + * + * See the [Rust documentation for `segment_latin1`](https://docs.rs/icu/latest/icu/segmenter/struct.GraphemeClusterSegmenter.html#method.segment_latin1) for more information. + * + * Lifetimes: `this`, `input` must live at least as long as the output. + */ + ICU4XGraphemeClusterBreakIteratorLatin1 segment_latin1(const diplomat::span<const uint8_t> input) const; + inline const capi::ICU4XGraphemeClusterSegmenter* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XGraphemeClusterSegmenter* AsFFIMut() { return this->inner.get(); } + inline ICU4XGraphemeClusterSegmenter(capi::ICU4XGraphemeClusterSegmenter* i) : inner(i) {} + ICU4XGraphemeClusterSegmenter() = default; + ICU4XGraphemeClusterSegmenter(ICU4XGraphemeClusterSegmenter&&) noexcept = default; + ICU4XGraphemeClusterSegmenter& operator=(ICU4XGraphemeClusterSegmenter&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XGraphemeClusterSegmenter, ICU4XGraphemeClusterSegmenterDeleter> inner; +}; + +#include "ICU4XDataProvider.hpp" +#include "ICU4XGraphemeClusterBreakIteratorUtf8.hpp" +#include "ICU4XGraphemeClusterBreakIteratorUtf16.hpp" +#include "ICU4XGraphemeClusterBreakIteratorLatin1.hpp" + +inline diplomat::result<ICU4XGraphemeClusterSegmenter, ICU4XError> ICU4XGraphemeClusterSegmenter::create(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XGraphemeClusterSegmenter_create(provider.AsFFI()); + diplomat::result<ICU4XGraphemeClusterSegmenter, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XGraphemeClusterSegmenter>(ICU4XGraphemeClusterSegmenter(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline ICU4XGraphemeClusterBreakIteratorUtf8 ICU4XGraphemeClusterSegmenter::segment_utf8(const std::string_view input) const { + return ICU4XGraphemeClusterBreakIteratorUtf8(capi::ICU4XGraphemeClusterSegmenter_segment_utf8(this->inner.get(), input.data(), input.size())); +} +inline ICU4XGraphemeClusterBreakIteratorUtf16 ICU4XGraphemeClusterSegmenter::segment_utf16(const diplomat::span<const uint16_t> input) const { + return ICU4XGraphemeClusterBreakIteratorUtf16(capi::ICU4XGraphemeClusterSegmenter_segment_utf16(this->inner.get(), input.data(), input.size())); +} +inline ICU4XGraphemeClusterBreakIteratorLatin1 ICU4XGraphemeClusterSegmenter::segment_latin1(const diplomat::span<const uint8_t> input) const { + return ICU4XGraphemeClusterBreakIteratorLatin1(capi::ICU4XGraphemeClusterSegmenter_segment_latin1(this->inner.get(), input.data(), input.size())); +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XGregorianDateFormatter.h b/intl/icu_capi/cpp/include/ICU4XGregorianDateFormatter.h new file mode 100644 index 0000000000..cf3ad9e9f4 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XGregorianDateFormatter.h @@ -0,0 +1,40 @@ +#ifndef ICU4XGregorianDateFormatter_H +#define ICU4XGregorianDateFormatter_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XGregorianDateFormatter ICU4XGregorianDateFormatter; +#ifdef __cplusplus +} // namespace capi +#endif +#include "ICU4XDataProvider.h" +#include "ICU4XLocale.h" +#include "ICU4XDateLength.h" +#include "diplomat_result_box_ICU4XGregorianDateFormatter_ICU4XError.h" +#include "ICU4XIsoDate.h" +#include "diplomat_result_void_ICU4XError.h" +#include "ICU4XIsoDateTime.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +diplomat_result_box_ICU4XGregorianDateFormatter_ICU4XError ICU4XGregorianDateFormatter_create_with_length(const ICU4XDataProvider* provider, const ICU4XLocale* locale, ICU4XDateLength length); + +diplomat_result_void_ICU4XError ICU4XGregorianDateFormatter_format_iso_date(const ICU4XGregorianDateFormatter* self, const ICU4XIsoDate* value, DiplomatWriteable* write); + +diplomat_result_void_ICU4XError ICU4XGregorianDateFormatter_format_iso_datetime(const ICU4XGregorianDateFormatter* self, const ICU4XIsoDateTime* value, DiplomatWriteable* write); +void ICU4XGregorianDateFormatter_destroy(ICU4XGregorianDateFormatter* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XGregorianDateFormatter.hpp b/intl/icu_capi/cpp/include/ICU4XGregorianDateFormatter.hpp new file mode 100644 index 0000000000..01b8c95015 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XGregorianDateFormatter.hpp @@ -0,0 +1,145 @@ +#ifndef ICU4XGregorianDateFormatter_HPP +#define ICU4XGregorianDateFormatter_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XGregorianDateFormatter.h" + +class ICU4XDataProvider; +class ICU4XLocale; +#include "ICU4XDateLength.hpp" +class ICU4XGregorianDateFormatter; +#include "ICU4XError.hpp" +class ICU4XIsoDate; +class ICU4XIsoDateTime; + +/** + * A destruction policy for using ICU4XGregorianDateFormatter with std::unique_ptr. + */ +struct ICU4XGregorianDateFormatterDeleter { + void operator()(capi::ICU4XGregorianDateFormatter* l) const noexcept { + capi::ICU4XGregorianDateFormatter_destroy(l); + } +}; + +/** + * An ICU4X TypedDateFormatter object capable of formatting a [`ICU4XIsoDateTime`] as a string, + * using the Gregorian Calendar. + * + * See the [Rust documentation for `TypedDateFormatter`](https://docs.rs/icu/latest/icu/datetime/struct.TypedDateFormatter.html) for more information. + */ +class ICU4XGregorianDateFormatter { + public: + + /** + * Creates a new [`ICU4XGregorianDateFormatter`] from locale data. + * + * See the [Rust documentation for `try_new_with_length`](https://docs.rs/icu/latest/icu/datetime/struct.TypedDateFormatter.html#method.try_new_with_length) for more information. + */ + static diplomat::result<ICU4XGregorianDateFormatter, ICU4XError> create_with_length(const ICU4XDataProvider& provider, const ICU4XLocale& locale, ICU4XDateLength length); + + /** + * Formats a [`ICU4XIsoDate`] to a string. + * + * See the [Rust documentation for `format`](https://docs.rs/icu/latest/icu/datetime/struct.TypedDateFormatter.html#method.format) for more information. + */ + template<typename W> diplomat::result<std::monostate, ICU4XError> format_iso_date_to_writeable(const ICU4XIsoDate& value, W& write) const; + + /** + * Formats a [`ICU4XIsoDate`] to a string. + * + * See the [Rust documentation for `format`](https://docs.rs/icu/latest/icu/datetime/struct.TypedDateFormatter.html#method.format) for more information. + */ + diplomat::result<std::string, ICU4XError> format_iso_date(const ICU4XIsoDate& value) const; + + /** + * Formats a [`ICU4XIsoDateTime`] to a string. + * + * See the [Rust documentation for `format`](https://docs.rs/icu/latest/icu/datetime/struct.TypedDateFormatter.html#method.format) for more information. + */ + template<typename W> diplomat::result<std::monostate, ICU4XError> format_iso_datetime_to_writeable(const ICU4XIsoDateTime& value, W& write) const; + + /** + * Formats a [`ICU4XIsoDateTime`] to a string. + * + * See the [Rust documentation for `format`](https://docs.rs/icu/latest/icu/datetime/struct.TypedDateFormatter.html#method.format) for more information. + */ + diplomat::result<std::string, ICU4XError> format_iso_datetime(const ICU4XIsoDateTime& value) const; + inline const capi::ICU4XGregorianDateFormatter* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XGregorianDateFormatter* AsFFIMut() { return this->inner.get(); } + inline ICU4XGregorianDateFormatter(capi::ICU4XGregorianDateFormatter* i) : inner(i) {} + ICU4XGregorianDateFormatter() = default; + ICU4XGregorianDateFormatter(ICU4XGregorianDateFormatter&&) noexcept = default; + ICU4XGregorianDateFormatter& operator=(ICU4XGregorianDateFormatter&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XGregorianDateFormatter, ICU4XGregorianDateFormatterDeleter> inner; +}; + +#include "ICU4XDataProvider.hpp" +#include "ICU4XLocale.hpp" +#include "ICU4XIsoDate.hpp" +#include "ICU4XIsoDateTime.hpp" + +inline diplomat::result<ICU4XGregorianDateFormatter, ICU4XError> ICU4XGregorianDateFormatter::create_with_length(const ICU4XDataProvider& provider, const ICU4XLocale& locale, ICU4XDateLength length) { + auto diplomat_result_raw_out_value = capi::ICU4XGregorianDateFormatter_create_with_length(provider.AsFFI(), locale.AsFFI(), static_cast<capi::ICU4XDateLength>(length)); + diplomat::result<ICU4XGregorianDateFormatter, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XGregorianDateFormatter>(ICU4XGregorianDateFormatter(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XGregorianDateFormatter::format_iso_date_to_writeable(const ICU4XIsoDate& value, W& write) const { + capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write); + auto diplomat_result_raw_out_value = capi::ICU4XGregorianDateFormatter_format_iso_date(this->inner.get(), value.AsFFI(), &write_writer); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<std::string, ICU4XError> ICU4XGregorianDateFormatter::format_iso_date(const ICU4XIsoDate& value) const { + std::string diplomat_writeable_string; + capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); + auto diplomat_result_raw_out_value = capi::ICU4XGregorianDateFormatter_format_iso_date(this->inner.get(), value.AsFFI(), &diplomat_writeable_out); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string)); +} +template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XGregorianDateFormatter::format_iso_datetime_to_writeable(const ICU4XIsoDateTime& value, W& write) const { + capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write); + auto diplomat_result_raw_out_value = capi::ICU4XGregorianDateFormatter_format_iso_datetime(this->inner.get(), value.AsFFI(), &write_writer); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<std::string, ICU4XError> ICU4XGregorianDateFormatter::format_iso_datetime(const ICU4XIsoDateTime& value) const { + std::string diplomat_writeable_string; + capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); + auto diplomat_result_raw_out_value = capi::ICU4XGregorianDateFormatter_format_iso_datetime(this->inner.get(), value.AsFFI(), &diplomat_writeable_out); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string)); +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XGregorianDateTimeFormatter.h b/intl/icu_capi/cpp/include/ICU4XGregorianDateTimeFormatter.h new file mode 100644 index 0000000000..0b56ddc393 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XGregorianDateTimeFormatter.h @@ -0,0 +1,38 @@ +#ifndef ICU4XGregorianDateTimeFormatter_H +#define ICU4XGregorianDateTimeFormatter_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XGregorianDateTimeFormatter ICU4XGregorianDateTimeFormatter; +#ifdef __cplusplus +} // namespace capi +#endif +#include "ICU4XDataProvider.h" +#include "ICU4XLocale.h" +#include "ICU4XDateLength.h" +#include "ICU4XTimeLength.h" +#include "diplomat_result_box_ICU4XGregorianDateTimeFormatter_ICU4XError.h" +#include "ICU4XIsoDateTime.h" +#include "diplomat_result_void_ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +diplomat_result_box_ICU4XGregorianDateTimeFormatter_ICU4XError ICU4XGregorianDateTimeFormatter_create_with_lengths(const ICU4XDataProvider* provider, const ICU4XLocale* locale, ICU4XDateLength date_length, ICU4XTimeLength time_length); + +diplomat_result_void_ICU4XError ICU4XGregorianDateTimeFormatter_format_iso_datetime(const ICU4XGregorianDateTimeFormatter* self, const ICU4XIsoDateTime* value, DiplomatWriteable* write); +void ICU4XGregorianDateTimeFormatter_destroy(ICU4XGregorianDateTimeFormatter* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XGregorianDateTimeFormatter.hpp b/intl/icu_capi/cpp/include/ICU4XGregorianDateTimeFormatter.hpp new file mode 100644 index 0000000000..ce0fbc6704 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XGregorianDateTimeFormatter.hpp @@ -0,0 +1,107 @@ +#ifndef ICU4XGregorianDateTimeFormatter_HPP +#define ICU4XGregorianDateTimeFormatter_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XGregorianDateTimeFormatter.h" + +class ICU4XDataProvider; +class ICU4XLocale; +#include "ICU4XDateLength.hpp" +#include "ICU4XTimeLength.hpp" +class ICU4XGregorianDateTimeFormatter; +#include "ICU4XError.hpp" +class ICU4XIsoDateTime; + +/** + * A destruction policy for using ICU4XGregorianDateTimeFormatter with std::unique_ptr. + */ +struct ICU4XGregorianDateTimeFormatterDeleter { + void operator()(capi::ICU4XGregorianDateTimeFormatter* l) const noexcept { + capi::ICU4XGregorianDateTimeFormatter_destroy(l); + } +}; + +/** + * An ICU4X TypedDateTimeFormatter object capable of formatting a [`ICU4XIsoDateTime`] as a string, + * using the Gregorian Calendar. + * + * See the [Rust documentation for `TypedDateTimeFormatter`](https://docs.rs/icu/latest/icu/datetime/struct.TypedDateTimeFormatter.html) for more information. + */ +class ICU4XGregorianDateTimeFormatter { + public: + + /** + * Creates a new [`ICU4XGregorianDateFormatter`] from locale data. + * + * See the [Rust documentation for `try_new`](https://docs.rs/icu/latest/icu/datetime/struct.TypedDateTimeFormatter.html#method.try_new) for more information. + */ + static diplomat::result<ICU4XGregorianDateTimeFormatter, ICU4XError> create_with_lengths(const ICU4XDataProvider& provider, const ICU4XLocale& locale, ICU4XDateLength date_length, ICU4XTimeLength time_length); + + /** + * Formats a [`ICU4XIsoDateTime`] to a string. + * + * See the [Rust documentation for `format`](https://docs.rs/icu/latest/icu/datetime/struct.TypedDateTimeFormatter.html#method.format) for more information. + */ + template<typename W> diplomat::result<std::monostate, ICU4XError> format_iso_datetime_to_writeable(const ICU4XIsoDateTime& value, W& write) const; + + /** + * Formats a [`ICU4XIsoDateTime`] to a string. + * + * See the [Rust documentation for `format`](https://docs.rs/icu/latest/icu/datetime/struct.TypedDateTimeFormatter.html#method.format) for more information. + */ + diplomat::result<std::string, ICU4XError> format_iso_datetime(const ICU4XIsoDateTime& value) const; + inline const capi::ICU4XGregorianDateTimeFormatter* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XGregorianDateTimeFormatter* AsFFIMut() { return this->inner.get(); } + inline ICU4XGregorianDateTimeFormatter(capi::ICU4XGregorianDateTimeFormatter* i) : inner(i) {} + ICU4XGregorianDateTimeFormatter() = default; + ICU4XGregorianDateTimeFormatter(ICU4XGregorianDateTimeFormatter&&) noexcept = default; + ICU4XGregorianDateTimeFormatter& operator=(ICU4XGregorianDateTimeFormatter&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XGregorianDateTimeFormatter, ICU4XGregorianDateTimeFormatterDeleter> inner; +}; + +#include "ICU4XDataProvider.hpp" +#include "ICU4XLocale.hpp" +#include "ICU4XIsoDateTime.hpp" + +inline diplomat::result<ICU4XGregorianDateTimeFormatter, ICU4XError> ICU4XGregorianDateTimeFormatter::create_with_lengths(const ICU4XDataProvider& provider, const ICU4XLocale& locale, ICU4XDateLength date_length, ICU4XTimeLength time_length) { + auto diplomat_result_raw_out_value = capi::ICU4XGregorianDateTimeFormatter_create_with_lengths(provider.AsFFI(), locale.AsFFI(), static_cast<capi::ICU4XDateLength>(date_length), static_cast<capi::ICU4XTimeLength>(time_length)); + diplomat::result<ICU4XGregorianDateTimeFormatter, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XGregorianDateTimeFormatter>(ICU4XGregorianDateTimeFormatter(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XGregorianDateTimeFormatter::format_iso_datetime_to_writeable(const ICU4XIsoDateTime& value, W& write) const { + capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write); + auto diplomat_result_raw_out_value = capi::ICU4XGregorianDateTimeFormatter_format_iso_datetime(this->inner.get(), value.AsFFI(), &write_writer); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<std::string, ICU4XError> ICU4XGregorianDateTimeFormatter::format_iso_datetime(const ICU4XIsoDateTime& value) const { + std::string diplomat_writeable_string; + capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); + auto diplomat_result_raw_out_value = capi::ICU4XGregorianDateTimeFormatter_format_iso_datetime(this->inner.get(), value.AsFFI(), &diplomat_writeable_out); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string)); +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XGregorianZonedDateTimeFormatter.h b/intl/icu_capi/cpp/include/ICU4XGregorianZonedDateTimeFormatter.h new file mode 100644 index 0000000000..4be60c2b0b --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XGregorianZonedDateTimeFormatter.h @@ -0,0 +1,42 @@ +#ifndef ICU4XGregorianZonedDateTimeFormatter_H +#define ICU4XGregorianZonedDateTimeFormatter_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XGregorianZonedDateTimeFormatter ICU4XGregorianZonedDateTimeFormatter; +#ifdef __cplusplus +} // namespace capi +#endif +#include "ICU4XDataProvider.h" +#include "ICU4XLocale.h" +#include "ICU4XDateLength.h" +#include "ICU4XTimeLength.h" +#include "diplomat_result_box_ICU4XGregorianZonedDateTimeFormatter_ICU4XError.h" +#include "ICU4XIsoTimeZoneOptions.h" +#include "ICU4XIsoDateTime.h" +#include "ICU4XCustomTimeZone.h" +#include "diplomat_result_void_ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +diplomat_result_box_ICU4XGregorianZonedDateTimeFormatter_ICU4XError ICU4XGregorianZonedDateTimeFormatter_create_with_lengths(const ICU4XDataProvider* provider, const ICU4XLocale* locale, ICU4XDateLength date_length, ICU4XTimeLength time_length); + +diplomat_result_box_ICU4XGregorianZonedDateTimeFormatter_ICU4XError ICU4XGregorianZonedDateTimeFormatter_create_with_lengths_and_iso_8601_time_zone_fallback(const ICU4XDataProvider* provider, const ICU4XLocale* locale, ICU4XDateLength date_length, ICU4XTimeLength time_length, ICU4XIsoTimeZoneOptions zone_options); + +diplomat_result_void_ICU4XError ICU4XGregorianZonedDateTimeFormatter_format_iso_datetime_with_custom_time_zone(const ICU4XGregorianZonedDateTimeFormatter* self, const ICU4XIsoDateTime* datetime, const ICU4XCustomTimeZone* time_zone, DiplomatWriteable* write); +void ICU4XGregorianZonedDateTimeFormatter_destroy(ICU4XGregorianZonedDateTimeFormatter* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XGregorianZonedDateTimeFormatter.hpp b/intl/icu_capi/cpp/include/ICU4XGregorianZonedDateTimeFormatter.hpp new file mode 100644 index 0000000000..9f86f4bfda --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XGregorianZonedDateTimeFormatter.hpp @@ -0,0 +1,134 @@ +#ifndef ICU4XGregorianZonedDateTimeFormatter_HPP +#define ICU4XGregorianZonedDateTimeFormatter_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XGregorianZonedDateTimeFormatter.h" + +class ICU4XDataProvider; +class ICU4XLocale; +#include "ICU4XDateLength.hpp" +#include "ICU4XTimeLength.hpp" +class ICU4XGregorianZonedDateTimeFormatter; +#include "ICU4XError.hpp" +struct ICU4XIsoTimeZoneOptions; +class ICU4XIsoDateTime; +class ICU4XCustomTimeZone; + +/** + * A destruction policy for using ICU4XGregorianZonedDateTimeFormatter with std::unique_ptr. + */ +struct ICU4XGregorianZonedDateTimeFormatterDeleter { + void operator()(capi::ICU4XGregorianZonedDateTimeFormatter* l) const noexcept { + capi::ICU4XGregorianZonedDateTimeFormatter_destroy(l); + } +}; + +/** + * An object capable of formatting a date time with time zone to a string. + * + * See the [Rust documentation for `TypedZonedDateTimeFormatter`](https://docs.rs/icu/latest/icu/datetime/struct.TypedZonedDateTimeFormatter.html) for more information. + */ +class ICU4XGregorianZonedDateTimeFormatter { + public: + + /** + * Creates a new [`ICU4XGregorianZonedDateTimeFormatter`] from locale data. + * + * This function has `date_length` and `time_length` arguments and uses default options + * for the time zone. + * + * See the [Rust documentation for `try_new`](https://docs.rs/icu/latest/icu/datetime/struct.TypedZonedDateTimeFormatter.html#method.try_new) for more information. + */ + static diplomat::result<ICU4XGregorianZonedDateTimeFormatter, ICU4XError> create_with_lengths(const ICU4XDataProvider& provider, const ICU4XLocale& locale, ICU4XDateLength date_length, ICU4XTimeLength time_length); + + /** + * Creates a new [`ICU4XGregorianZonedDateTimeFormatter`] from locale data. + * + * This function has `date_length` and `time_length` arguments and uses an ISO-8601 style + * fallback for the time zone with the given configurations. + * + * See the [Rust documentation for `try_new`](https://docs.rs/icu/latest/icu/datetime/struct.TypedZonedDateTimeFormatter.html#method.try_new) for more information. + */ + static diplomat::result<ICU4XGregorianZonedDateTimeFormatter, ICU4XError> create_with_lengths_and_iso_8601_time_zone_fallback(const ICU4XDataProvider& provider, const ICU4XLocale& locale, ICU4XDateLength date_length, ICU4XTimeLength time_length, ICU4XIsoTimeZoneOptions zone_options); + + /** + * Formats a [`ICU4XIsoDateTime`] and [`ICU4XCustomTimeZone`] to a string. + * + * See the [Rust documentation for `format`](https://docs.rs/icu/latest/icu/datetime/struct.TypedZonedDateTimeFormatter.html#method.format) for more information. + */ + template<typename W> diplomat::result<std::monostate, ICU4XError> format_iso_datetime_with_custom_time_zone_to_writeable(const ICU4XIsoDateTime& datetime, const ICU4XCustomTimeZone& time_zone, W& write) const; + + /** + * Formats a [`ICU4XIsoDateTime`] and [`ICU4XCustomTimeZone`] to a string. + * + * See the [Rust documentation for `format`](https://docs.rs/icu/latest/icu/datetime/struct.TypedZonedDateTimeFormatter.html#method.format) for more information. + */ + diplomat::result<std::string, ICU4XError> format_iso_datetime_with_custom_time_zone(const ICU4XIsoDateTime& datetime, const ICU4XCustomTimeZone& time_zone) const; + inline const capi::ICU4XGregorianZonedDateTimeFormatter* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XGregorianZonedDateTimeFormatter* AsFFIMut() { return this->inner.get(); } + inline ICU4XGregorianZonedDateTimeFormatter(capi::ICU4XGregorianZonedDateTimeFormatter* i) : inner(i) {} + ICU4XGregorianZonedDateTimeFormatter() = default; + ICU4XGregorianZonedDateTimeFormatter(ICU4XGregorianZonedDateTimeFormatter&&) noexcept = default; + ICU4XGregorianZonedDateTimeFormatter& operator=(ICU4XGregorianZonedDateTimeFormatter&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XGregorianZonedDateTimeFormatter, ICU4XGregorianZonedDateTimeFormatterDeleter> inner; +}; + +#include "ICU4XDataProvider.hpp" +#include "ICU4XLocale.hpp" +#include "ICU4XIsoTimeZoneOptions.hpp" +#include "ICU4XIsoDateTime.hpp" +#include "ICU4XCustomTimeZone.hpp" + +inline diplomat::result<ICU4XGregorianZonedDateTimeFormatter, ICU4XError> ICU4XGregorianZonedDateTimeFormatter::create_with_lengths(const ICU4XDataProvider& provider, const ICU4XLocale& locale, ICU4XDateLength date_length, ICU4XTimeLength time_length) { + auto diplomat_result_raw_out_value = capi::ICU4XGregorianZonedDateTimeFormatter_create_with_lengths(provider.AsFFI(), locale.AsFFI(), static_cast<capi::ICU4XDateLength>(date_length), static_cast<capi::ICU4XTimeLength>(time_length)); + diplomat::result<ICU4XGregorianZonedDateTimeFormatter, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XGregorianZonedDateTimeFormatter>(ICU4XGregorianZonedDateTimeFormatter(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XGregorianZonedDateTimeFormatter, ICU4XError> ICU4XGregorianZonedDateTimeFormatter::create_with_lengths_and_iso_8601_time_zone_fallback(const ICU4XDataProvider& provider, const ICU4XLocale& locale, ICU4XDateLength date_length, ICU4XTimeLength time_length, ICU4XIsoTimeZoneOptions zone_options) { + ICU4XIsoTimeZoneOptions diplomat_wrapped_struct_zone_options = zone_options; + auto diplomat_result_raw_out_value = capi::ICU4XGregorianZonedDateTimeFormatter_create_with_lengths_and_iso_8601_time_zone_fallback(provider.AsFFI(), locale.AsFFI(), static_cast<capi::ICU4XDateLength>(date_length), static_cast<capi::ICU4XTimeLength>(time_length), capi::ICU4XIsoTimeZoneOptions{ .format = static_cast<capi::ICU4XIsoTimeZoneFormat>(diplomat_wrapped_struct_zone_options.format), .minutes = static_cast<capi::ICU4XIsoTimeZoneMinuteDisplay>(diplomat_wrapped_struct_zone_options.minutes), .seconds = static_cast<capi::ICU4XIsoTimeZoneSecondDisplay>(diplomat_wrapped_struct_zone_options.seconds) }); + diplomat::result<ICU4XGregorianZonedDateTimeFormatter, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XGregorianZonedDateTimeFormatter>(ICU4XGregorianZonedDateTimeFormatter(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XGregorianZonedDateTimeFormatter::format_iso_datetime_with_custom_time_zone_to_writeable(const ICU4XIsoDateTime& datetime, const ICU4XCustomTimeZone& time_zone, W& write) const { + capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write); + auto diplomat_result_raw_out_value = capi::ICU4XGregorianZonedDateTimeFormatter_format_iso_datetime_with_custom_time_zone(this->inner.get(), datetime.AsFFI(), time_zone.AsFFI(), &write_writer); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<std::string, ICU4XError> ICU4XGregorianZonedDateTimeFormatter::format_iso_datetime_with_custom_time_zone(const ICU4XIsoDateTime& datetime, const ICU4XCustomTimeZone& time_zone) const { + std::string diplomat_writeable_string; + capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); + auto diplomat_result_raw_out_value = capi::ICU4XGregorianZonedDateTimeFormatter_format_iso_datetime_with_custom_time_zone(this->inner.get(), datetime.AsFFI(), time_zone.AsFFI(), &diplomat_writeable_out); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string)); +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XIanaToBcp47Mapper.h b/intl/icu_capi/cpp/include/ICU4XIanaToBcp47Mapper.h new file mode 100644 index 0000000000..e06433b6d0 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XIanaToBcp47Mapper.h @@ -0,0 +1,31 @@ +#ifndef ICU4XIanaToBcp47Mapper_H +#define ICU4XIanaToBcp47Mapper_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XIanaToBcp47Mapper ICU4XIanaToBcp47Mapper; +#ifdef __cplusplus +} // namespace capi +#endif +#include "ICU4XDataProvider.h" +#include "diplomat_result_box_ICU4XIanaToBcp47Mapper_ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +diplomat_result_box_ICU4XIanaToBcp47Mapper_ICU4XError ICU4XIanaToBcp47Mapper_create(const ICU4XDataProvider* provider); +void ICU4XIanaToBcp47Mapper_destroy(ICU4XIanaToBcp47Mapper* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XIanaToBcp47Mapper.hpp b/intl/icu_capi/cpp/include/ICU4XIanaToBcp47Mapper.hpp new file mode 100644 index 0000000000..69b4d691fd --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XIanaToBcp47Mapper.hpp @@ -0,0 +1,65 @@ +#ifndef ICU4XIanaToBcp47Mapper_HPP +#define ICU4XIanaToBcp47Mapper_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XIanaToBcp47Mapper.h" + +class ICU4XDataProvider; +class ICU4XIanaToBcp47Mapper; +#include "ICU4XError.hpp" + +/** + * A destruction policy for using ICU4XIanaToBcp47Mapper with std::unique_ptr. + */ +struct ICU4XIanaToBcp47MapperDeleter { + void operator()(capi::ICU4XIanaToBcp47Mapper* l) const noexcept { + capi::ICU4XIanaToBcp47Mapper_destroy(l); + } +}; + +/** + * An object capable of mapping from an IANA time zone ID to a BCP-47 ID. + * + * This can be used via `try_set_iana_time_zone_id()` on [`ICU4XCustomTimeZone`]. + * + * [`ICU4XCustomTimeZone`]: crate::timezone::ffi::ICU4XCustomTimeZone + * + * See the [Rust documentation for `IanaToBcp47Mapper`](https://docs.rs/icu/latest/icu/timezone/struct.IanaToBcp47Mapper.html) for more information. + */ +class ICU4XIanaToBcp47Mapper { + public: + + /** + * See the [Rust documentation for `new`](https://docs.rs/icu/latest/icu/timezone/struct.IanaToBcp47Mapper.html#method.new) for more information. + */ + static diplomat::result<ICU4XIanaToBcp47Mapper, ICU4XError> create(const ICU4XDataProvider& provider); + inline const capi::ICU4XIanaToBcp47Mapper* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XIanaToBcp47Mapper* AsFFIMut() { return this->inner.get(); } + inline ICU4XIanaToBcp47Mapper(capi::ICU4XIanaToBcp47Mapper* i) : inner(i) {} + ICU4XIanaToBcp47Mapper() = default; + ICU4XIanaToBcp47Mapper(ICU4XIanaToBcp47Mapper&&) noexcept = default; + ICU4XIanaToBcp47Mapper& operator=(ICU4XIanaToBcp47Mapper&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XIanaToBcp47Mapper, ICU4XIanaToBcp47MapperDeleter> inner; +}; + +#include "ICU4XDataProvider.hpp" + +inline diplomat::result<ICU4XIanaToBcp47Mapper, ICU4XError> ICU4XIanaToBcp47Mapper::create(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XIanaToBcp47Mapper_create(provider.AsFFI()); + diplomat::result<ICU4XIanaToBcp47Mapper, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XIanaToBcp47Mapper>(ICU4XIanaToBcp47Mapper(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XIsoDate.h b/intl/icu_capi/cpp/include/ICU4XIsoDate.h new file mode 100644 index 0000000000..d7a018244a --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XIsoDate.h @@ -0,0 +1,61 @@ +#ifndef ICU4XIsoDate_H +#define ICU4XIsoDate_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XIsoDate ICU4XIsoDate; +#ifdef __cplusplus +} // namespace capi +#endif +#include "diplomat_result_box_ICU4XIsoDate_ICU4XError.h" +#include "ICU4XCalendar.h" +#include "ICU4XDate.h" +#include "ICU4XIsoWeekday.h" +#include "ICU4XWeekCalculator.h" +#include "diplomat_result_ICU4XWeekOf_ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +diplomat_result_box_ICU4XIsoDate_ICU4XError ICU4XIsoDate_create(int32_t year, uint8_t month, uint8_t day); + +ICU4XIsoDate* ICU4XIsoDate_create_for_unix_epoch(); + +ICU4XDate* ICU4XIsoDate_to_calendar(const ICU4XIsoDate* self, const ICU4XCalendar* calendar); + +ICU4XDate* ICU4XIsoDate_to_any(const ICU4XIsoDate* self); + +uint32_t ICU4XIsoDate_day_of_month(const ICU4XIsoDate* self); + +ICU4XIsoWeekday ICU4XIsoDate_day_of_week(const ICU4XIsoDate* self); + +uint32_t ICU4XIsoDate_week_of_month(const ICU4XIsoDate* self, ICU4XIsoWeekday first_weekday); + +diplomat_result_ICU4XWeekOf_ICU4XError ICU4XIsoDate_week_of_year(const ICU4XIsoDate* self, const ICU4XWeekCalculator* calculator); + +uint32_t ICU4XIsoDate_month(const ICU4XIsoDate* self); + +int32_t ICU4XIsoDate_year(const ICU4XIsoDate* self); + +bool ICU4XIsoDate_is_in_leap_year(const ICU4XIsoDate* self); + +uint8_t ICU4XIsoDate_months_in_year(const ICU4XIsoDate* self); + +uint8_t ICU4XIsoDate_days_in_month(const ICU4XIsoDate* self); + +uint16_t ICU4XIsoDate_days_in_year(const ICU4XIsoDate* self); +void ICU4XIsoDate_destroy(ICU4XIsoDate* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XIsoDate.hpp b/intl/icu_capi/cpp/include/ICU4XIsoDate.hpp new file mode 100644 index 0000000000..ba91918f6d --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XIsoDate.hpp @@ -0,0 +1,209 @@ +#ifndef ICU4XIsoDate_HPP +#define ICU4XIsoDate_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XIsoDate.h" + +class ICU4XIsoDate; +#include "ICU4XError.hpp" +class ICU4XCalendar; +class ICU4XDate; +#include "ICU4XIsoWeekday.hpp" +class ICU4XWeekCalculator; +struct ICU4XWeekOf; + +/** + * A destruction policy for using ICU4XIsoDate with std::unique_ptr. + */ +struct ICU4XIsoDateDeleter { + void operator()(capi::ICU4XIsoDate* l) const noexcept { + capi::ICU4XIsoDate_destroy(l); + } +}; + +/** + * An ICU4X Date object capable of containing a ISO-8601 date + * + * See the [Rust documentation for `Date`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html) for more information. + */ +class ICU4XIsoDate { + public: + + /** + * Creates a new [`ICU4XIsoDate`] from the specified date and time. + * + * See the [Rust documentation for `try_new_iso_date`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.try_new_iso_date) for more information. + */ + static diplomat::result<ICU4XIsoDate, ICU4XError> create(int32_t year, uint8_t month, uint8_t day); + + /** + * Creates a new [`ICU4XIsoDate`] representing January 1, 1970. + * + * See the [Rust documentation for `unix_epoch`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.unix_epoch) for more information. + */ + static ICU4XIsoDate create_for_unix_epoch(); + + /** + * Convert this date to one in a different calendar + * + * See the [Rust documentation for `to_calendar`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.to_calendar) for more information. + */ + ICU4XDate to_calendar(const ICU4XCalendar& calendar) const; + + /** + * See the [Rust documentation for `to_any`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.to_any) for more information. + */ + ICU4XDate to_any() const; + + /** + * Returns the 1-indexed day in the month for this date + * + * See the [Rust documentation for `day_of_month`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.day_of_month) for more information. + */ + uint32_t day_of_month() const; + + /** + * Returns the day in the week for this day + * + * See the [Rust documentation for `day_of_week`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.day_of_week) for more information. + */ + ICU4XIsoWeekday day_of_week() const; + + /** + * Returns the week number in this month, 1-indexed, based on what + * is considered the first day of the week (often a locale preference). + * + * `first_weekday` can be obtained via `first_weekday()` on [`ICU4XWeekCalculator`] + * + * See the [Rust documentation for `week_of_month`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.week_of_month) for more information. + */ + uint32_t week_of_month(ICU4XIsoWeekday first_weekday) const; + + /** + * Returns the week number in this year, using week data + * + * See the [Rust documentation for `week_of_year`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.week_of_year) for more information. + */ + diplomat::result<ICU4XWeekOf, ICU4XError> week_of_year(const ICU4XWeekCalculator& calculator) const; + + /** + * Returns 1-indexed number of the month of this date in its year + * + * See the [Rust documentation for `month`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.month) for more information. + */ + uint32_t month() const; + + /** + * Returns the year number for this date + * + * See the [Rust documentation for `year`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.year) for more information. + */ + int32_t year() const; + + /** + * Returns if the year is a leap year for this date + * + * See the [Rust documentation for `is_in_leap_year`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.is_in_leap_year) for more information. + */ + bool is_in_leap_year() const; + + /** + * Returns the number of months in the year represented by this date + * + * See the [Rust documentation for `months_in_year`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.months_in_year) for more information. + */ + uint8_t months_in_year() const; + + /** + * Returns the number of days in the month represented by this date + * + * See the [Rust documentation for `days_in_month`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.days_in_month) for more information. + */ + uint8_t days_in_month() const; + + /** + * Returns the number of days in the year represented by this date + * + * See the [Rust documentation for `days_in_year`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.days_in_year) for more information. + */ + uint16_t days_in_year() const; + inline const capi::ICU4XIsoDate* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XIsoDate* AsFFIMut() { return this->inner.get(); } + inline ICU4XIsoDate(capi::ICU4XIsoDate* i) : inner(i) {} + ICU4XIsoDate() = default; + ICU4XIsoDate(ICU4XIsoDate&&) noexcept = default; + ICU4XIsoDate& operator=(ICU4XIsoDate&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XIsoDate, ICU4XIsoDateDeleter> inner; +}; + +#include "ICU4XCalendar.hpp" +#include "ICU4XDate.hpp" +#include "ICU4XWeekCalculator.hpp" +#include "ICU4XWeekOf.hpp" + +inline diplomat::result<ICU4XIsoDate, ICU4XError> ICU4XIsoDate::create(int32_t year, uint8_t month, uint8_t day) { + auto diplomat_result_raw_out_value = capi::ICU4XIsoDate_create(year, month, day); + diplomat::result<ICU4XIsoDate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XIsoDate>(ICU4XIsoDate(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline ICU4XIsoDate ICU4XIsoDate::create_for_unix_epoch() { + return ICU4XIsoDate(capi::ICU4XIsoDate_create_for_unix_epoch()); +} +inline ICU4XDate ICU4XIsoDate::to_calendar(const ICU4XCalendar& calendar) const { + return ICU4XDate(capi::ICU4XIsoDate_to_calendar(this->inner.get(), calendar.AsFFI())); +} +inline ICU4XDate ICU4XIsoDate::to_any() const { + return ICU4XDate(capi::ICU4XIsoDate_to_any(this->inner.get())); +} +inline uint32_t ICU4XIsoDate::day_of_month() const { + return capi::ICU4XIsoDate_day_of_month(this->inner.get()); +} +inline ICU4XIsoWeekday ICU4XIsoDate::day_of_week() const { + return static_cast<ICU4XIsoWeekday>(capi::ICU4XIsoDate_day_of_week(this->inner.get())); +} +inline uint32_t ICU4XIsoDate::week_of_month(ICU4XIsoWeekday first_weekday) const { + return capi::ICU4XIsoDate_week_of_month(this->inner.get(), static_cast<capi::ICU4XIsoWeekday>(first_weekday)); +} +inline diplomat::result<ICU4XWeekOf, ICU4XError> ICU4XIsoDate::week_of_year(const ICU4XWeekCalculator& calculator) const { + auto diplomat_result_raw_out_value = capi::ICU4XIsoDate_week_of_year(this->inner.get(), calculator.AsFFI()); + diplomat::result<ICU4XWeekOf, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + capi::ICU4XWeekOf diplomat_raw_struct_out_value = diplomat_result_raw_out_value.ok; + diplomat_result_out_value = diplomat::Ok<ICU4XWeekOf>(ICU4XWeekOf{ .week = std::move(diplomat_raw_struct_out_value.week), .unit = std::move(static_cast<ICU4XWeekRelativeUnit>(diplomat_raw_struct_out_value.unit)) }); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline uint32_t ICU4XIsoDate::month() const { + return capi::ICU4XIsoDate_month(this->inner.get()); +} +inline int32_t ICU4XIsoDate::year() const { + return capi::ICU4XIsoDate_year(this->inner.get()); +} +inline bool ICU4XIsoDate::is_in_leap_year() const { + return capi::ICU4XIsoDate_is_in_leap_year(this->inner.get()); +} +inline uint8_t ICU4XIsoDate::months_in_year() const { + return capi::ICU4XIsoDate_months_in_year(this->inner.get()); +} +inline uint8_t ICU4XIsoDate::days_in_month() const { + return capi::ICU4XIsoDate_days_in_month(this->inner.get()); +} +inline uint16_t ICU4XIsoDate::days_in_year() const { + return capi::ICU4XIsoDate_days_in_year(this->inner.get()); +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XIsoDateTime.h b/intl/icu_capi/cpp/include/ICU4XIsoDateTime.h new file mode 100644 index 0000000000..404cbfedc8 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XIsoDateTime.h @@ -0,0 +1,79 @@ +#ifndef ICU4XIsoDateTime_H +#define ICU4XIsoDateTime_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XIsoDateTime ICU4XIsoDateTime; +#ifdef __cplusplus +} // namespace capi +#endif +#include "diplomat_result_box_ICU4XIsoDateTime_ICU4XError.h" +#include "ICU4XIsoDate.h" +#include "ICU4XTime.h" +#include "ICU4XDateTime.h" +#include "ICU4XCalendar.h" +#include "ICU4XIsoWeekday.h" +#include "ICU4XWeekCalculator.h" +#include "diplomat_result_ICU4XWeekOf_ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +diplomat_result_box_ICU4XIsoDateTime_ICU4XError ICU4XIsoDateTime_create(int32_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second, uint32_t nanosecond); + +ICU4XIsoDateTime* ICU4XIsoDateTime_crate_from_date_and_time(const ICU4XIsoDate* date, const ICU4XTime* time); + +ICU4XIsoDateTime* ICU4XIsoDateTime_create_from_minutes_since_local_unix_epoch(int32_t minutes); + +ICU4XIsoDate* ICU4XIsoDateTime_date(const ICU4XIsoDateTime* self); + +ICU4XTime* ICU4XIsoDateTime_time(const ICU4XIsoDateTime* self); + +ICU4XDateTime* ICU4XIsoDateTime_to_any(const ICU4XIsoDateTime* self); + +int32_t ICU4XIsoDateTime_minutes_since_local_unix_epoch(const ICU4XIsoDateTime* self); + +ICU4XDateTime* ICU4XIsoDateTime_to_calendar(const ICU4XIsoDateTime* self, const ICU4XCalendar* calendar); + +uint8_t ICU4XIsoDateTime_hour(const ICU4XIsoDateTime* self); + +uint8_t ICU4XIsoDateTime_minute(const ICU4XIsoDateTime* self); + +uint8_t ICU4XIsoDateTime_second(const ICU4XIsoDateTime* self); + +uint32_t ICU4XIsoDateTime_nanosecond(const ICU4XIsoDateTime* self); + +uint32_t ICU4XIsoDateTime_day_of_month(const ICU4XIsoDateTime* self); + +ICU4XIsoWeekday ICU4XIsoDateTime_day_of_week(const ICU4XIsoDateTime* self); + +uint32_t ICU4XIsoDateTime_week_of_month(const ICU4XIsoDateTime* self, ICU4XIsoWeekday first_weekday); + +diplomat_result_ICU4XWeekOf_ICU4XError ICU4XIsoDateTime_week_of_year(const ICU4XIsoDateTime* self, const ICU4XWeekCalculator* calculator); + +uint32_t ICU4XIsoDateTime_month(const ICU4XIsoDateTime* self); + +int32_t ICU4XIsoDateTime_year(const ICU4XIsoDateTime* self); + +bool ICU4XIsoDateTime_is_in_leap_year(const ICU4XIsoDateTime* self); + +uint8_t ICU4XIsoDateTime_months_in_year(const ICU4XIsoDateTime* self); + +uint8_t ICU4XIsoDateTime_days_in_month(const ICU4XIsoDateTime* self); + +uint16_t ICU4XIsoDateTime_days_in_year(const ICU4XIsoDateTime* self); +void ICU4XIsoDateTime_destroy(ICU4XIsoDateTime* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XIsoDateTime.hpp b/intl/icu_capi/cpp/include/ICU4XIsoDateTime.hpp new file mode 100644 index 0000000000..62d45a8747 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XIsoDateTime.hpp @@ -0,0 +1,296 @@ +#ifndef ICU4XIsoDateTime_HPP +#define ICU4XIsoDateTime_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XIsoDateTime.h" + +class ICU4XIsoDateTime; +#include "ICU4XError.hpp" +class ICU4XIsoDate; +class ICU4XTime; +class ICU4XDateTime; +class ICU4XCalendar; +#include "ICU4XIsoWeekday.hpp" +class ICU4XWeekCalculator; +struct ICU4XWeekOf; + +/** + * A destruction policy for using ICU4XIsoDateTime with std::unique_ptr. + */ +struct ICU4XIsoDateTimeDeleter { + void operator()(capi::ICU4XIsoDateTime* l) const noexcept { + capi::ICU4XIsoDateTime_destroy(l); + } +}; + +/** + * An ICU4X DateTime object capable of containing a ISO-8601 date and time. + * + * See the [Rust documentation for `DateTime`](https://docs.rs/icu/latest/icu/calendar/struct.DateTime.html) for more information. + */ +class ICU4XIsoDateTime { + public: + + /** + * Creates a new [`ICU4XIsoDateTime`] from the specified date and time. + * + * See the [Rust documentation for `try_new_iso_datetime`](https://docs.rs/icu/latest/icu/calendar/struct.DateTime.html#method.try_new_iso_datetime) for more information. + */ + static diplomat::result<ICU4XIsoDateTime, ICU4XError> create(int32_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second, uint32_t nanosecond); + + /** + * Creates a new [`ICU4XIsoDateTime`] from an [`ICU4XIsoDate`] and [`ICU4XTime`] object + * + * See the [Rust documentation for `new`](https://docs.rs/icu/latest/icu/calendar/struct.DateTime.html#method.new) for more information. + */ + static ICU4XIsoDateTime crate_from_date_and_time(const ICU4XIsoDate& date, const ICU4XTime& time); + + /** + * Construct from the minutes since the local unix epoch for this date (Jan 1 1970, 00:00) + * + * See the [Rust documentation for `from_minutes_since_local_unix_epoch`](https://docs.rs/icu/latest/icu/calendar/struct.DateTime.html#method.from_minutes_since_local_unix_epoch) for more information. + */ + static ICU4XIsoDateTime create_from_minutes_since_local_unix_epoch(int32_t minutes); + + /** + * Gets the date contained in this object + * + * See the [Rust documentation for `date`](https://docs.rs/icu/latest/icu/calendar/struct.DateTime.html#structfield.date) for more information. + */ + ICU4XIsoDate date() const; + + /** + * Gets the time contained in this object + * + * See the [Rust documentation for `time`](https://docs.rs/icu/latest/icu/calendar/struct.DateTime.html#structfield.time) for more information. + */ + ICU4XTime time() const; + + /** + * Converts this to an [`ICU4XDateTime`] capable of being mixed with dates of + * other calendars + * + * See the [Rust documentation for `to_any`](https://docs.rs/icu/latest/icu/calendar/struct.DateTime.html#method.to_any) for more information. + */ + ICU4XDateTime to_any() const; + + /** + * Gets the minutes since the local unix epoch for this date (Jan 1 1970, 00:00) + * + * See the [Rust documentation for `minutes_since_local_unix_epoch`](https://docs.rs/icu/latest/icu/calendar/struct.DateTime.html#method.minutes_since_local_unix_epoch) for more information. + */ + int32_t minutes_since_local_unix_epoch() const; + + /** + * Convert this datetime to one in a different calendar + * + * See the [Rust documentation for `to_calendar`](https://docs.rs/icu/latest/icu/calendar/struct.DateTime.html#method.to_calendar) for more information. + */ + ICU4XDateTime to_calendar(const ICU4XCalendar& calendar) const; + + /** + * Returns the hour in this time + * + * See the [Rust documentation for `hour`](https://docs.rs/icu/latest/icu/calendar/types/struct.Time.html#structfield.hour) for more information. + */ + uint8_t hour() const; + + /** + * Returns the minute in this time + * + * See the [Rust documentation for `minute`](https://docs.rs/icu/latest/icu/calendar/types/struct.Time.html#structfield.minute) for more information. + */ + uint8_t minute() const; + + /** + * Returns the second in this time + * + * See the [Rust documentation for `second`](https://docs.rs/icu/latest/icu/calendar/types/struct.Time.html#structfield.second) for more information. + */ + uint8_t second() const; + + /** + * Returns the nanosecond in this time + * + * See the [Rust documentation for `nanosecond`](https://docs.rs/icu/latest/icu/calendar/types/struct.Time.html#structfield.nanosecond) for more information. + */ + uint32_t nanosecond() const; + + /** + * Returns the 1-indexed day in the month for this date + * + * See the [Rust documentation for `day_of_month`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.day_of_month) for more information. + */ + uint32_t day_of_month() const; + + /** + * Returns the day in the week for this day + * + * See the [Rust documentation for `day_of_week`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.day_of_week) for more information. + */ + ICU4XIsoWeekday day_of_week() const; + + /** + * Returns the week number in this month, 1-indexed, based on what + * is considered the first day of the week (often a locale preference). + * + * `first_weekday` can be obtained via `first_weekday()` on [`ICU4XWeekCalculator`] + * + * See the [Rust documentation for `week_of_month`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.week_of_month) for more information. + */ + uint32_t week_of_month(ICU4XIsoWeekday first_weekday) const; + + /** + * Returns the week number in this year, using week data + * + * See the [Rust documentation for `week_of_year`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.week_of_year) for more information. + */ + diplomat::result<ICU4XWeekOf, ICU4XError> week_of_year(const ICU4XWeekCalculator& calculator) const; + + /** + * Returns 1-indexed number of the month of this date in its year + * + * See the [Rust documentation for `month`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.month) for more information. + */ + uint32_t month() const; + + /** + * Returns the year number for this date + * + * See the [Rust documentation for `year`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.year) for more information. + */ + int32_t year() const; + + /** + * Returns whether this date is in a leap year + * + * See the [Rust documentation for `is_in_leap_year`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.is_in_leap_year) for more information. + */ + bool is_in_leap_year() const; + + /** + * Returns the number of months in the year represented by this date + * + * See the [Rust documentation for `months_in_year`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.months_in_year) for more information. + */ + uint8_t months_in_year() const; + + /** + * Returns the number of days in the month represented by this date + * + * See the [Rust documentation for `days_in_month`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.days_in_month) for more information. + */ + uint8_t days_in_month() const; + + /** + * Returns the number of days in the year represented by this date + * + * See the [Rust documentation for `days_in_year`](https://docs.rs/icu/latest/icu/calendar/struct.Date.html#method.days_in_year) for more information. + */ + uint16_t days_in_year() const; + inline const capi::ICU4XIsoDateTime* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XIsoDateTime* AsFFIMut() { return this->inner.get(); } + inline ICU4XIsoDateTime(capi::ICU4XIsoDateTime* i) : inner(i) {} + ICU4XIsoDateTime() = default; + ICU4XIsoDateTime(ICU4XIsoDateTime&&) noexcept = default; + ICU4XIsoDateTime& operator=(ICU4XIsoDateTime&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XIsoDateTime, ICU4XIsoDateTimeDeleter> inner; +}; + +#include "ICU4XIsoDate.hpp" +#include "ICU4XTime.hpp" +#include "ICU4XDateTime.hpp" +#include "ICU4XCalendar.hpp" +#include "ICU4XWeekCalculator.hpp" +#include "ICU4XWeekOf.hpp" + +inline diplomat::result<ICU4XIsoDateTime, ICU4XError> ICU4XIsoDateTime::create(int32_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second, uint32_t nanosecond) { + auto diplomat_result_raw_out_value = capi::ICU4XIsoDateTime_create(year, month, day, hour, minute, second, nanosecond); + diplomat::result<ICU4XIsoDateTime, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XIsoDateTime>(ICU4XIsoDateTime(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline ICU4XIsoDateTime ICU4XIsoDateTime::crate_from_date_and_time(const ICU4XIsoDate& date, const ICU4XTime& time) { + return ICU4XIsoDateTime(capi::ICU4XIsoDateTime_crate_from_date_and_time(date.AsFFI(), time.AsFFI())); +} +inline ICU4XIsoDateTime ICU4XIsoDateTime::create_from_minutes_since_local_unix_epoch(int32_t minutes) { + return ICU4XIsoDateTime(capi::ICU4XIsoDateTime_create_from_minutes_since_local_unix_epoch(minutes)); +} +inline ICU4XIsoDate ICU4XIsoDateTime::date() const { + return ICU4XIsoDate(capi::ICU4XIsoDateTime_date(this->inner.get())); +} +inline ICU4XTime ICU4XIsoDateTime::time() const { + return ICU4XTime(capi::ICU4XIsoDateTime_time(this->inner.get())); +} +inline ICU4XDateTime ICU4XIsoDateTime::to_any() const { + return ICU4XDateTime(capi::ICU4XIsoDateTime_to_any(this->inner.get())); +} +inline int32_t ICU4XIsoDateTime::minutes_since_local_unix_epoch() const { + return capi::ICU4XIsoDateTime_minutes_since_local_unix_epoch(this->inner.get()); +} +inline ICU4XDateTime ICU4XIsoDateTime::to_calendar(const ICU4XCalendar& calendar) const { + return ICU4XDateTime(capi::ICU4XIsoDateTime_to_calendar(this->inner.get(), calendar.AsFFI())); +} +inline uint8_t ICU4XIsoDateTime::hour() const { + return capi::ICU4XIsoDateTime_hour(this->inner.get()); +} +inline uint8_t ICU4XIsoDateTime::minute() const { + return capi::ICU4XIsoDateTime_minute(this->inner.get()); +} +inline uint8_t ICU4XIsoDateTime::second() const { + return capi::ICU4XIsoDateTime_second(this->inner.get()); +} +inline uint32_t ICU4XIsoDateTime::nanosecond() const { + return capi::ICU4XIsoDateTime_nanosecond(this->inner.get()); +} +inline uint32_t ICU4XIsoDateTime::day_of_month() const { + return capi::ICU4XIsoDateTime_day_of_month(this->inner.get()); +} +inline ICU4XIsoWeekday ICU4XIsoDateTime::day_of_week() const { + return static_cast<ICU4XIsoWeekday>(capi::ICU4XIsoDateTime_day_of_week(this->inner.get())); +} +inline uint32_t ICU4XIsoDateTime::week_of_month(ICU4XIsoWeekday first_weekday) const { + return capi::ICU4XIsoDateTime_week_of_month(this->inner.get(), static_cast<capi::ICU4XIsoWeekday>(first_weekday)); +} +inline diplomat::result<ICU4XWeekOf, ICU4XError> ICU4XIsoDateTime::week_of_year(const ICU4XWeekCalculator& calculator) const { + auto diplomat_result_raw_out_value = capi::ICU4XIsoDateTime_week_of_year(this->inner.get(), calculator.AsFFI()); + diplomat::result<ICU4XWeekOf, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + capi::ICU4XWeekOf diplomat_raw_struct_out_value = diplomat_result_raw_out_value.ok; + diplomat_result_out_value = diplomat::Ok<ICU4XWeekOf>(ICU4XWeekOf{ .week = std::move(diplomat_raw_struct_out_value.week), .unit = std::move(static_cast<ICU4XWeekRelativeUnit>(diplomat_raw_struct_out_value.unit)) }); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline uint32_t ICU4XIsoDateTime::month() const { + return capi::ICU4XIsoDateTime_month(this->inner.get()); +} +inline int32_t ICU4XIsoDateTime::year() const { + return capi::ICU4XIsoDateTime_year(this->inner.get()); +} +inline bool ICU4XIsoDateTime::is_in_leap_year() const { + return capi::ICU4XIsoDateTime_is_in_leap_year(this->inner.get()); +} +inline uint8_t ICU4XIsoDateTime::months_in_year() const { + return capi::ICU4XIsoDateTime_months_in_year(this->inner.get()); +} +inline uint8_t ICU4XIsoDateTime::days_in_month() const { + return capi::ICU4XIsoDateTime_days_in_month(this->inner.get()); +} +inline uint16_t ICU4XIsoDateTime::days_in_year() const { + return capi::ICU4XIsoDateTime_days_in_year(this->inner.get()); +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XIsoTimeZoneFormat.h b/intl/icu_capi/cpp/include/ICU4XIsoTimeZoneFormat.h new file mode 100644 index 0000000000..e48a1142f2 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XIsoTimeZoneFormat.h @@ -0,0 +1,33 @@ +#ifndef ICU4XIsoTimeZoneFormat_H +#define ICU4XIsoTimeZoneFormat_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef enum ICU4XIsoTimeZoneFormat { + ICU4XIsoTimeZoneFormat_Basic = 0, + ICU4XIsoTimeZoneFormat_Extended = 1, + ICU4XIsoTimeZoneFormat_UtcBasic = 2, + ICU4XIsoTimeZoneFormat_UtcExtended = 3, +} ICU4XIsoTimeZoneFormat; +#ifdef __cplusplus +} // namespace capi +#endif +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +void ICU4XIsoTimeZoneFormat_destroy(ICU4XIsoTimeZoneFormat* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XIsoTimeZoneFormat.hpp b/intl/icu_capi/cpp/include/ICU4XIsoTimeZoneFormat.hpp new file mode 100644 index 0000000000..7ede2d2ca8 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XIsoTimeZoneFormat.hpp @@ -0,0 +1,26 @@ +#ifndef ICU4XIsoTimeZoneFormat_HPP +#define ICU4XIsoTimeZoneFormat_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XIsoTimeZoneFormat.h" + + + +/** + * See the [Rust documentation for `IsoFormat`](https://docs.rs/icu/latest/icu/datetime/time_zone/enum.IsoFormat.html) for more information. + */ +enum struct ICU4XIsoTimeZoneFormat { + Basic = 0, + Extended = 1, + UtcBasic = 2, + UtcExtended = 3, +}; + +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XIsoTimeZoneMinuteDisplay.h b/intl/icu_capi/cpp/include/ICU4XIsoTimeZoneMinuteDisplay.h new file mode 100644 index 0000000000..edeee97019 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XIsoTimeZoneMinuteDisplay.h @@ -0,0 +1,31 @@ +#ifndef ICU4XIsoTimeZoneMinuteDisplay_H +#define ICU4XIsoTimeZoneMinuteDisplay_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef enum ICU4XIsoTimeZoneMinuteDisplay { + ICU4XIsoTimeZoneMinuteDisplay_Required = 0, + ICU4XIsoTimeZoneMinuteDisplay_Optional = 1, +} ICU4XIsoTimeZoneMinuteDisplay; +#ifdef __cplusplus +} // namespace capi +#endif +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +void ICU4XIsoTimeZoneMinuteDisplay_destroy(ICU4XIsoTimeZoneMinuteDisplay* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XIsoTimeZoneMinuteDisplay.hpp b/intl/icu_capi/cpp/include/ICU4XIsoTimeZoneMinuteDisplay.hpp new file mode 100644 index 0000000000..6b3e653b1d --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XIsoTimeZoneMinuteDisplay.hpp @@ -0,0 +1,24 @@ +#ifndef ICU4XIsoTimeZoneMinuteDisplay_HPP +#define ICU4XIsoTimeZoneMinuteDisplay_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XIsoTimeZoneMinuteDisplay.h" + + + +/** + * See the [Rust documentation for `IsoMinutes`](https://docs.rs/icu/latest/icu/datetime/time_zone/enum.IsoMinutes.html) for more information. + */ +enum struct ICU4XIsoTimeZoneMinuteDisplay { + Required = 0, + Optional = 1, +}; + +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XIsoTimeZoneOptions.h b/intl/icu_capi/cpp/include/ICU4XIsoTimeZoneOptions.h new file mode 100644 index 0000000000..7ba051c3e6 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XIsoTimeZoneOptions.h @@ -0,0 +1,38 @@ +#ifndef ICU4XIsoTimeZoneOptions_H +#define ICU4XIsoTimeZoneOptions_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#include "ICU4XIsoTimeZoneFormat.h" +#include "ICU4XIsoTimeZoneMinuteDisplay.h" +#include "ICU4XIsoTimeZoneSecondDisplay.h" +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XIsoTimeZoneOptions { + ICU4XIsoTimeZoneFormat format; + ICU4XIsoTimeZoneMinuteDisplay minutes; + ICU4XIsoTimeZoneSecondDisplay seconds; +} ICU4XIsoTimeZoneOptions; +#ifdef __cplusplus +} // namespace capi +#endif +#include "ICU4XIsoTimeZoneFormat.h" +#include "ICU4XIsoTimeZoneMinuteDisplay.h" +#include "ICU4XIsoTimeZoneSecondDisplay.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +void ICU4XIsoTimeZoneOptions_destroy(ICU4XIsoTimeZoneOptions* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XIsoTimeZoneOptions.hpp b/intl/icu_capi/cpp/include/ICU4XIsoTimeZoneOptions.hpp new file mode 100644 index 0000000000..5082683329 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XIsoTimeZoneOptions.hpp @@ -0,0 +1,26 @@ +#ifndef ICU4XIsoTimeZoneOptions_HPP +#define ICU4XIsoTimeZoneOptions_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XIsoTimeZoneOptions.h" + +#include "ICU4XIsoTimeZoneFormat.hpp" +#include "ICU4XIsoTimeZoneMinuteDisplay.hpp" +#include "ICU4XIsoTimeZoneSecondDisplay.hpp" + +struct ICU4XIsoTimeZoneOptions { + public: + ICU4XIsoTimeZoneFormat format; + ICU4XIsoTimeZoneMinuteDisplay minutes; + ICU4XIsoTimeZoneSecondDisplay seconds; +}; + + +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XIsoTimeZoneSecondDisplay.h b/intl/icu_capi/cpp/include/ICU4XIsoTimeZoneSecondDisplay.h new file mode 100644 index 0000000000..487a248f95 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XIsoTimeZoneSecondDisplay.h @@ -0,0 +1,31 @@ +#ifndef ICU4XIsoTimeZoneSecondDisplay_H +#define ICU4XIsoTimeZoneSecondDisplay_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef enum ICU4XIsoTimeZoneSecondDisplay { + ICU4XIsoTimeZoneSecondDisplay_Optional = 0, + ICU4XIsoTimeZoneSecondDisplay_Never = 1, +} ICU4XIsoTimeZoneSecondDisplay; +#ifdef __cplusplus +} // namespace capi +#endif +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +void ICU4XIsoTimeZoneSecondDisplay_destroy(ICU4XIsoTimeZoneSecondDisplay* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XIsoTimeZoneSecondDisplay.hpp b/intl/icu_capi/cpp/include/ICU4XIsoTimeZoneSecondDisplay.hpp new file mode 100644 index 0000000000..23a0a3a85e --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XIsoTimeZoneSecondDisplay.hpp @@ -0,0 +1,24 @@ +#ifndef ICU4XIsoTimeZoneSecondDisplay_HPP +#define ICU4XIsoTimeZoneSecondDisplay_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XIsoTimeZoneSecondDisplay.h" + + + +/** + * See the [Rust documentation for `IsoSeconds`](https://docs.rs/icu/latest/icu/datetime/time_zone/enum.IsoSeconds.html) for more information. + */ +enum struct ICU4XIsoTimeZoneSecondDisplay { + Optional = 0, + Never = 1, +}; + +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XIsoWeekday.h b/intl/icu_capi/cpp/include/ICU4XIsoWeekday.h new file mode 100644 index 0000000000..a23d0a3b9e --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XIsoWeekday.h @@ -0,0 +1,36 @@ +#ifndef ICU4XIsoWeekday_H +#define ICU4XIsoWeekday_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef enum ICU4XIsoWeekday { + ICU4XIsoWeekday_Monday = 1, + ICU4XIsoWeekday_Tuesday = 2, + ICU4XIsoWeekday_Wednesday = 3, + ICU4XIsoWeekday_Thursday = 4, + ICU4XIsoWeekday_Friday = 5, + ICU4XIsoWeekday_Saturday = 6, + ICU4XIsoWeekday_Sunday = 7, +} ICU4XIsoWeekday; +#ifdef __cplusplus +} // namespace capi +#endif +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +void ICU4XIsoWeekday_destroy(ICU4XIsoWeekday* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XIsoWeekday.hpp b/intl/icu_capi/cpp/include/ICU4XIsoWeekday.hpp new file mode 100644 index 0000000000..ec33e4a80e --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XIsoWeekday.hpp @@ -0,0 +1,25 @@ +#ifndef ICU4XIsoWeekday_HPP +#define ICU4XIsoWeekday_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XIsoWeekday.h" + + +enum struct ICU4XIsoWeekday { + Monday = 1, + Tuesday = 2, + Wednesday = 3, + Thursday = 4, + Friday = 5, + Saturday = 6, + Sunday = 7, +}; + +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XLanguageDisplay.h b/intl/icu_capi/cpp/include/ICU4XLanguageDisplay.h new file mode 100644 index 0000000000..0b921351fe --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XLanguageDisplay.h @@ -0,0 +1,31 @@ +#ifndef ICU4XLanguageDisplay_H +#define ICU4XLanguageDisplay_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef enum ICU4XLanguageDisplay { + ICU4XLanguageDisplay_Dialect = 0, + ICU4XLanguageDisplay_Standard = 1, +} ICU4XLanguageDisplay; +#ifdef __cplusplus +} // namespace capi +#endif +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +void ICU4XLanguageDisplay_destroy(ICU4XLanguageDisplay* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XLanguageDisplay.hpp b/intl/icu_capi/cpp/include/ICU4XLanguageDisplay.hpp new file mode 100644 index 0000000000..6914e4671e --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XLanguageDisplay.hpp @@ -0,0 +1,24 @@ +#ifndef ICU4XLanguageDisplay_HPP +#define ICU4XLanguageDisplay_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XLanguageDisplay.h" + + + +/** + * See the [Rust documentation for `LanguageDisplay`](https://docs.rs/icu/latest/icu/displaynames/options/enum.LanguageDisplay.html) for more information. + */ +enum struct ICU4XLanguageDisplay { + Dialect = 0, + Standard = 1, +}; + +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XLeadingAdjustment.h b/intl/icu_capi/cpp/include/ICU4XLeadingAdjustment.h new file mode 100644 index 0000000000..91647188ed --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XLeadingAdjustment.h @@ -0,0 +1,32 @@ +#ifndef ICU4XLeadingAdjustment_H +#define ICU4XLeadingAdjustment_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef enum ICU4XLeadingAdjustment { + ICU4XLeadingAdjustment_Auto = 0, + ICU4XLeadingAdjustment_None = 1, + ICU4XLeadingAdjustment_ToCased = 2, +} ICU4XLeadingAdjustment; +#ifdef __cplusplus +} // namespace capi +#endif +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +void ICU4XLeadingAdjustment_destroy(ICU4XLeadingAdjustment* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XLeadingAdjustment.hpp b/intl/icu_capi/cpp/include/ICU4XLeadingAdjustment.hpp new file mode 100644 index 0000000000..17ba8dc33a --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XLeadingAdjustment.hpp @@ -0,0 +1,25 @@ +#ifndef ICU4XLeadingAdjustment_HPP +#define ICU4XLeadingAdjustment_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XLeadingAdjustment.h" + + + +/** + * See the [Rust documentation for `LeadingAdjustment`](https://docs.rs/icu/latest/icu/casemap/titlecase/enum.LeadingAdjustment.html) for more information. + */ +enum struct ICU4XLeadingAdjustment { + Auto = 0, + None = 1, + ToCased = 2, +}; + +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XLineBreakIteratorLatin1.h b/intl/icu_capi/cpp/include/ICU4XLineBreakIteratorLatin1.h new file mode 100644 index 0000000000..c1a4c39131 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XLineBreakIteratorLatin1.h @@ -0,0 +1,29 @@ +#ifndef ICU4XLineBreakIteratorLatin1_H +#define ICU4XLineBreakIteratorLatin1_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XLineBreakIteratorLatin1 ICU4XLineBreakIteratorLatin1; +#ifdef __cplusplus +} // namespace capi +#endif +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +int32_t ICU4XLineBreakIteratorLatin1_next(ICU4XLineBreakIteratorLatin1* self); +void ICU4XLineBreakIteratorLatin1_destroy(ICU4XLineBreakIteratorLatin1* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XLineBreakIteratorLatin1.hpp b/intl/icu_capi/cpp/include/ICU4XLineBreakIteratorLatin1.hpp new file mode 100644 index 0000000000..566ed7f49b --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XLineBreakIteratorLatin1.hpp @@ -0,0 +1,53 @@ +#ifndef ICU4XLineBreakIteratorLatin1_HPP +#define ICU4XLineBreakIteratorLatin1_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XLineBreakIteratorLatin1.h" + + +/** + * A destruction policy for using ICU4XLineBreakIteratorLatin1 with std::unique_ptr. + */ +struct ICU4XLineBreakIteratorLatin1Deleter { + void operator()(capi::ICU4XLineBreakIteratorLatin1* l) const noexcept { + capi::ICU4XLineBreakIteratorLatin1_destroy(l); + } +}; + +/** + * See the [Rust documentation for `LineBreakIterator`](https://docs.rs/icu/latest/icu/segmenter/struct.LineBreakIterator.html) for more information. + * + * Additional information: [1](https://docs.rs/icu/latest/icu/segmenter/type.LineBreakIteratorLatin1.html) + */ +class ICU4XLineBreakIteratorLatin1 { + public: + + /** + * Finds the next breakpoint. Returns -1 if at the end of the string or if the index is + * out of range of a 32-bit signed integer. + * + * See the [Rust documentation for `next`](https://docs.rs/icu/latest/icu/segmenter/struct.LineBreakIterator.html#method.next) for more information. + */ + int32_t next(); + inline const capi::ICU4XLineBreakIteratorLatin1* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XLineBreakIteratorLatin1* AsFFIMut() { return this->inner.get(); } + inline explicit ICU4XLineBreakIteratorLatin1(capi::ICU4XLineBreakIteratorLatin1* i) : inner(i) {} + ICU4XLineBreakIteratorLatin1() = default; + ICU4XLineBreakIteratorLatin1(ICU4XLineBreakIteratorLatin1&&) noexcept = default; + ICU4XLineBreakIteratorLatin1& operator=(ICU4XLineBreakIteratorLatin1&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XLineBreakIteratorLatin1, ICU4XLineBreakIteratorLatin1Deleter> inner; +}; + + +inline int32_t ICU4XLineBreakIteratorLatin1::next() { + return capi::ICU4XLineBreakIteratorLatin1_next(this->inner.get()); +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XLineBreakIteratorUtf16.h b/intl/icu_capi/cpp/include/ICU4XLineBreakIteratorUtf16.h new file mode 100644 index 0000000000..78ae12c7e4 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XLineBreakIteratorUtf16.h @@ -0,0 +1,29 @@ +#ifndef ICU4XLineBreakIteratorUtf16_H +#define ICU4XLineBreakIteratorUtf16_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XLineBreakIteratorUtf16 ICU4XLineBreakIteratorUtf16; +#ifdef __cplusplus +} // namespace capi +#endif +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +int32_t ICU4XLineBreakIteratorUtf16_next(ICU4XLineBreakIteratorUtf16* self); +void ICU4XLineBreakIteratorUtf16_destroy(ICU4XLineBreakIteratorUtf16* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XLineBreakIteratorUtf16.hpp b/intl/icu_capi/cpp/include/ICU4XLineBreakIteratorUtf16.hpp new file mode 100644 index 0000000000..656b806bee --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XLineBreakIteratorUtf16.hpp @@ -0,0 +1,53 @@ +#ifndef ICU4XLineBreakIteratorUtf16_HPP +#define ICU4XLineBreakIteratorUtf16_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XLineBreakIteratorUtf16.h" + + +/** + * A destruction policy for using ICU4XLineBreakIteratorUtf16 with std::unique_ptr. + */ +struct ICU4XLineBreakIteratorUtf16Deleter { + void operator()(capi::ICU4XLineBreakIteratorUtf16* l) const noexcept { + capi::ICU4XLineBreakIteratorUtf16_destroy(l); + } +}; + +/** + * See the [Rust documentation for `LineBreakIterator`](https://docs.rs/icu/latest/icu/segmenter/struct.LineBreakIterator.html) for more information. + * + * Additional information: [1](https://docs.rs/icu/latest/icu/segmenter/type.LineBreakIteratorUtf16.html) + */ +class ICU4XLineBreakIteratorUtf16 { + public: + + /** + * Finds the next breakpoint. Returns -1 if at the end of the string or if the index is + * out of range of a 32-bit signed integer. + * + * See the [Rust documentation for `next`](https://docs.rs/icu/latest/icu/segmenter/struct.LineBreakIterator.html#method.next) for more information. + */ + int32_t next(); + inline const capi::ICU4XLineBreakIteratorUtf16* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XLineBreakIteratorUtf16* AsFFIMut() { return this->inner.get(); } + inline explicit ICU4XLineBreakIteratorUtf16(capi::ICU4XLineBreakIteratorUtf16* i) : inner(i) {} + ICU4XLineBreakIteratorUtf16() = default; + ICU4XLineBreakIteratorUtf16(ICU4XLineBreakIteratorUtf16&&) noexcept = default; + ICU4XLineBreakIteratorUtf16& operator=(ICU4XLineBreakIteratorUtf16&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XLineBreakIteratorUtf16, ICU4XLineBreakIteratorUtf16Deleter> inner; +}; + + +inline int32_t ICU4XLineBreakIteratorUtf16::next() { + return capi::ICU4XLineBreakIteratorUtf16_next(this->inner.get()); +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XLineBreakIteratorUtf8.h b/intl/icu_capi/cpp/include/ICU4XLineBreakIteratorUtf8.h new file mode 100644 index 0000000000..3a08c5ad23 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XLineBreakIteratorUtf8.h @@ -0,0 +1,29 @@ +#ifndef ICU4XLineBreakIteratorUtf8_H +#define ICU4XLineBreakIteratorUtf8_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XLineBreakIteratorUtf8 ICU4XLineBreakIteratorUtf8; +#ifdef __cplusplus +} // namespace capi +#endif +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +int32_t ICU4XLineBreakIteratorUtf8_next(ICU4XLineBreakIteratorUtf8* self); +void ICU4XLineBreakIteratorUtf8_destroy(ICU4XLineBreakIteratorUtf8* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XLineBreakIteratorUtf8.hpp b/intl/icu_capi/cpp/include/ICU4XLineBreakIteratorUtf8.hpp new file mode 100644 index 0000000000..e24e4a706a --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XLineBreakIteratorUtf8.hpp @@ -0,0 +1,53 @@ +#ifndef ICU4XLineBreakIteratorUtf8_HPP +#define ICU4XLineBreakIteratorUtf8_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XLineBreakIteratorUtf8.h" + + +/** + * A destruction policy for using ICU4XLineBreakIteratorUtf8 with std::unique_ptr. + */ +struct ICU4XLineBreakIteratorUtf8Deleter { + void operator()(capi::ICU4XLineBreakIteratorUtf8* l) const noexcept { + capi::ICU4XLineBreakIteratorUtf8_destroy(l); + } +}; + +/** + * See the [Rust documentation for `LineBreakIterator`](https://docs.rs/icu/latest/icu/segmenter/struct.LineBreakIterator.html) for more information. + * + * Additional information: [1](https://docs.rs/icu/latest/icu/segmenter/type.LineBreakIteratorPotentiallyIllFormedUtf8.html) + */ +class ICU4XLineBreakIteratorUtf8 { + public: + + /** + * Finds the next breakpoint. Returns -1 if at the end of the string or if the index is + * out of range of a 32-bit signed integer. + * + * See the [Rust documentation for `next`](https://docs.rs/icu/latest/icu/segmenter/struct.LineBreakIterator.html#method.next) for more information. + */ + int32_t next(); + inline const capi::ICU4XLineBreakIteratorUtf8* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XLineBreakIteratorUtf8* AsFFIMut() { return this->inner.get(); } + inline ICU4XLineBreakIteratorUtf8(capi::ICU4XLineBreakIteratorUtf8* i) : inner(i) {} + ICU4XLineBreakIteratorUtf8() = default; + ICU4XLineBreakIteratorUtf8(ICU4XLineBreakIteratorUtf8&&) noexcept = default; + ICU4XLineBreakIteratorUtf8& operator=(ICU4XLineBreakIteratorUtf8&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XLineBreakIteratorUtf8, ICU4XLineBreakIteratorUtf8Deleter> inner; +}; + + +inline int32_t ICU4XLineBreakIteratorUtf8::next() { + return capi::ICU4XLineBreakIteratorUtf8_next(this->inner.get()); +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XLineBreakOptionsV1.h b/intl/icu_capi/cpp/include/ICU4XLineBreakOptionsV1.h new file mode 100644 index 0000000000..5fbf4b5814 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XLineBreakOptionsV1.h @@ -0,0 +1,36 @@ +#ifndef ICU4XLineBreakOptionsV1_H +#define ICU4XLineBreakOptionsV1_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#include "ICU4XLineBreakStrictness.h" +#include "ICU4XLineBreakWordOption.h" +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XLineBreakOptionsV1 { + ICU4XLineBreakStrictness strictness; + ICU4XLineBreakWordOption word_option; + bool ja_zh; +} ICU4XLineBreakOptionsV1; +#ifdef __cplusplus +} // namespace capi +#endif +#include "ICU4XLineBreakStrictness.h" +#include "ICU4XLineBreakWordOption.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +void ICU4XLineBreakOptionsV1_destroy(ICU4XLineBreakOptionsV1* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XLineBreakOptionsV1.hpp b/intl/icu_capi/cpp/include/ICU4XLineBreakOptionsV1.hpp new file mode 100644 index 0000000000..1a60164db4 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XLineBreakOptionsV1.hpp @@ -0,0 +1,29 @@ +#ifndef ICU4XLineBreakOptionsV1_HPP +#define ICU4XLineBreakOptionsV1_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XLineBreakOptionsV1.h" + +#include "ICU4XLineBreakStrictness.hpp" +#include "ICU4XLineBreakWordOption.hpp" + + +/** + * See the [Rust documentation for `LineBreakOptions`](https://docs.rs/icu/latest/icu/segmenter/struct.LineBreakOptions.html) for more information. + */ +struct ICU4XLineBreakOptionsV1 { + public: + ICU4XLineBreakStrictness strictness; + ICU4XLineBreakWordOption word_option; + bool ja_zh; +}; + + +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XLineBreakStrictness.h b/intl/icu_capi/cpp/include/ICU4XLineBreakStrictness.h new file mode 100644 index 0000000000..e3534b7ec7 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XLineBreakStrictness.h @@ -0,0 +1,33 @@ +#ifndef ICU4XLineBreakStrictness_H +#define ICU4XLineBreakStrictness_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef enum ICU4XLineBreakStrictness { + ICU4XLineBreakStrictness_Loose = 0, + ICU4XLineBreakStrictness_Normal = 1, + ICU4XLineBreakStrictness_Strict = 2, + ICU4XLineBreakStrictness_Anywhere = 3, +} ICU4XLineBreakStrictness; +#ifdef __cplusplus +} // namespace capi +#endif +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +void ICU4XLineBreakStrictness_destroy(ICU4XLineBreakStrictness* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XLineBreakStrictness.hpp b/intl/icu_capi/cpp/include/ICU4XLineBreakStrictness.hpp new file mode 100644 index 0000000000..d4eac0f43e --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XLineBreakStrictness.hpp @@ -0,0 +1,26 @@ +#ifndef ICU4XLineBreakStrictness_HPP +#define ICU4XLineBreakStrictness_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XLineBreakStrictness.h" + + + +/** + * See the [Rust documentation for `LineBreakStrictness`](https://docs.rs/icu/latest/icu/segmenter/enum.LineBreakStrictness.html) for more information. + */ +enum struct ICU4XLineBreakStrictness { + Loose = 0, + Normal = 1, + Strict = 2, + Anywhere = 3, +}; + +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XLineBreakWordOption.h b/intl/icu_capi/cpp/include/ICU4XLineBreakWordOption.h new file mode 100644 index 0000000000..02a6ca6f2d --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XLineBreakWordOption.h @@ -0,0 +1,32 @@ +#ifndef ICU4XLineBreakWordOption_H +#define ICU4XLineBreakWordOption_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef enum ICU4XLineBreakWordOption { + ICU4XLineBreakWordOption_Normal = 0, + ICU4XLineBreakWordOption_BreakAll = 1, + ICU4XLineBreakWordOption_KeepAll = 2, +} ICU4XLineBreakWordOption; +#ifdef __cplusplus +} // namespace capi +#endif +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +void ICU4XLineBreakWordOption_destroy(ICU4XLineBreakWordOption* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XLineBreakWordOption.hpp b/intl/icu_capi/cpp/include/ICU4XLineBreakWordOption.hpp new file mode 100644 index 0000000000..094a938d11 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XLineBreakWordOption.hpp @@ -0,0 +1,25 @@ +#ifndef ICU4XLineBreakWordOption_HPP +#define ICU4XLineBreakWordOption_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XLineBreakWordOption.h" + + + +/** + * See the [Rust documentation for `LineBreakWordOption`](https://docs.rs/icu/latest/icu/segmenter/enum.LineBreakWordOption.html) for more information. + */ +enum struct ICU4XLineBreakWordOption { + Normal = 0, + BreakAll = 1, + KeepAll = 2, +}; + +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XLineSegmenter.h b/intl/icu_capi/cpp/include/ICU4XLineSegmenter.h new file mode 100644 index 0000000000..f734ec78f8 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XLineSegmenter.h @@ -0,0 +1,51 @@ +#ifndef ICU4XLineSegmenter_H +#define ICU4XLineSegmenter_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XLineSegmenter ICU4XLineSegmenter; +#ifdef __cplusplus +} // namespace capi +#endif +#include "ICU4XDataProvider.h" +#include "diplomat_result_box_ICU4XLineSegmenter_ICU4XError.h" +#include "ICU4XLineBreakOptionsV1.h" +#include "ICU4XLineBreakIteratorUtf8.h" +#include "ICU4XLineBreakIteratorUtf16.h" +#include "ICU4XLineBreakIteratorLatin1.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +diplomat_result_box_ICU4XLineSegmenter_ICU4XError ICU4XLineSegmenter_create_auto(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XLineSegmenter_ICU4XError ICU4XLineSegmenter_create_lstm(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XLineSegmenter_ICU4XError ICU4XLineSegmenter_create_dictionary(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XLineSegmenter_ICU4XError ICU4XLineSegmenter_create_auto_with_options_v1(const ICU4XDataProvider* provider, ICU4XLineBreakOptionsV1 options); + +diplomat_result_box_ICU4XLineSegmenter_ICU4XError ICU4XLineSegmenter_create_lstm_with_options_v1(const ICU4XDataProvider* provider, ICU4XLineBreakOptionsV1 options); + +diplomat_result_box_ICU4XLineSegmenter_ICU4XError ICU4XLineSegmenter_create_dictionary_with_options_v1(const ICU4XDataProvider* provider, ICU4XLineBreakOptionsV1 options); + +ICU4XLineBreakIteratorUtf8* ICU4XLineSegmenter_segment_utf8(const ICU4XLineSegmenter* self, const char* input_data, size_t input_len); + +ICU4XLineBreakIteratorUtf16* ICU4XLineSegmenter_segment_utf16(const ICU4XLineSegmenter* self, const uint16_t* input_data, size_t input_len); + +ICU4XLineBreakIteratorLatin1* ICU4XLineSegmenter_segment_latin1(const ICU4XLineSegmenter* self, const uint8_t* input_data, size_t input_len); +void ICU4XLineSegmenter_destroy(ICU4XLineSegmenter* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XLineSegmenter.hpp b/intl/icu_capi/cpp/include/ICU4XLineSegmenter.hpp new file mode 100644 index 0000000000..7d94f79e8d --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XLineSegmenter.hpp @@ -0,0 +1,201 @@ +#ifndef ICU4XLineSegmenter_HPP +#define ICU4XLineSegmenter_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XLineSegmenter.h" + +class ICU4XDataProvider; +class ICU4XLineSegmenter; +#include "ICU4XError.hpp" +struct ICU4XLineBreakOptionsV1; +class ICU4XLineBreakIteratorUtf8; +class ICU4XLineBreakIteratorUtf16; +class ICU4XLineBreakIteratorLatin1; + +/** + * A destruction policy for using ICU4XLineSegmenter with std::unique_ptr. + */ +struct ICU4XLineSegmenterDeleter { + void operator()(capi::ICU4XLineSegmenter* l) const noexcept { + capi::ICU4XLineSegmenter_destroy(l); + } +}; + +/** + * An ICU4X line-break segmenter, capable of finding breakpoints in strings. + * + * See the [Rust documentation for `LineSegmenter`](https://docs.rs/icu/latest/icu/segmenter/struct.LineSegmenter.html) for more information. + */ +class ICU4XLineSegmenter { + public: + + /** + * Construct a [`ICU4XLineSegmenter`] with default options. It automatically loads the best + * available payload data for Burmese, Khmer, Lao, and Thai. + * + * See the [Rust documentation for `new_auto`](https://docs.rs/icu/latest/icu/segmenter/struct.LineSegmenter.html#method.new_auto) for more information. + */ + static diplomat::result<ICU4XLineSegmenter, ICU4XError> create_auto(const ICU4XDataProvider& provider); + + /** + * Construct a [`ICU4XLineSegmenter`] with default options and LSTM payload data for + * Burmese, Khmer, Lao, and Thai. + * + * See the [Rust documentation for `new_lstm`](https://docs.rs/icu/latest/icu/segmenter/struct.LineSegmenter.html#method.new_lstm) for more information. + */ + static diplomat::result<ICU4XLineSegmenter, ICU4XError> create_lstm(const ICU4XDataProvider& provider); + + /** + * Construct a [`ICU4XLineSegmenter`] with default options and dictionary payload data for + * Burmese, Khmer, Lao, and Thai.. + * + * See the [Rust documentation for `new_dictionary`](https://docs.rs/icu/latest/icu/segmenter/struct.LineSegmenter.html#method.new_dictionary) for more information. + */ + static diplomat::result<ICU4XLineSegmenter, ICU4XError> create_dictionary(const ICU4XDataProvider& provider); + + /** + * Construct a [`ICU4XLineSegmenter`] with custom options. It automatically loads the best + * available payload data for Burmese, Khmer, Lao, and Thai. + * + * See the [Rust documentation for `new_auto_with_options`](https://docs.rs/icu/latest/icu/segmenter/struct.LineSegmenter.html#method.new_auto_with_options) for more information. + */ + static diplomat::result<ICU4XLineSegmenter, ICU4XError> create_auto_with_options_v1(const ICU4XDataProvider& provider, ICU4XLineBreakOptionsV1 options); + + /** + * Construct a [`ICU4XLineSegmenter`] with custom options and LSTM payload data for + * Burmese, Khmer, Lao, and Thai. + * + * See the [Rust documentation for `new_lstm_with_options`](https://docs.rs/icu/latest/icu/segmenter/struct.LineSegmenter.html#method.new_lstm_with_options) for more information. + */ + static diplomat::result<ICU4XLineSegmenter, ICU4XError> create_lstm_with_options_v1(const ICU4XDataProvider& provider, ICU4XLineBreakOptionsV1 options); + + /** + * Construct a [`ICU4XLineSegmenter`] with custom options and dictionary payload data for + * Burmese, Khmer, Lao, and Thai. + * + * See the [Rust documentation for `new_dictionary_with_options`](https://docs.rs/icu/latest/icu/segmenter/struct.LineSegmenter.html#method.new_dictionary_with_options) for more information. + */ + static diplomat::result<ICU4XLineSegmenter, ICU4XError> create_dictionary_with_options_v1(const ICU4XDataProvider& provider, ICU4XLineBreakOptionsV1 options); + + /** + * Segments a (potentially ill-formed) UTF-8 string. + * + * See the [Rust documentation for `segment_utf8`](https://docs.rs/icu/latest/icu/segmenter/struct.LineSegmenter.html#method.segment_utf8) for more information. + * + * Lifetimes: `this`, `input` must live at least as long as the output. + */ + ICU4XLineBreakIteratorUtf8 segment_utf8(const std::string_view input) const; + + /** + * Segments a UTF-16 string. + * + * See the [Rust documentation for `segment_utf16`](https://docs.rs/icu/latest/icu/segmenter/struct.LineSegmenter.html#method.segment_utf16) for more information. + * + * Lifetimes: `this`, `input` must live at least as long as the output. + */ + ICU4XLineBreakIteratorUtf16 segment_utf16(const diplomat::span<const uint16_t> input) const; + + /** + * Segments a Latin-1 string. + * + * See the [Rust documentation for `segment_latin1`](https://docs.rs/icu/latest/icu/segmenter/struct.LineSegmenter.html#method.segment_latin1) for more information. + * + * Lifetimes: `this`, `input` must live at least as long as the output. + */ + ICU4XLineBreakIteratorLatin1 segment_latin1(const diplomat::span<const uint8_t> input) const; + inline const capi::ICU4XLineSegmenter* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XLineSegmenter* AsFFIMut() { return this->inner.get(); } + inline ICU4XLineSegmenter(capi::ICU4XLineSegmenter* i) : inner(i) {} + ICU4XLineSegmenter() = default; + ICU4XLineSegmenter(ICU4XLineSegmenter&&) noexcept = default; + ICU4XLineSegmenter& operator=(ICU4XLineSegmenter&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XLineSegmenter, ICU4XLineSegmenterDeleter> inner; +}; + +#include "ICU4XDataProvider.hpp" +#include "ICU4XLineBreakOptionsV1.hpp" +#include "ICU4XLineBreakIteratorUtf8.hpp" +#include "ICU4XLineBreakIteratorUtf16.hpp" +#include "ICU4XLineBreakIteratorLatin1.hpp" + +inline diplomat::result<ICU4XLineSegmenter, ICU4XError> ICU4XLineSegmenter::create_auto(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XLineSegmenter_create_auto(provider.AsFFI()); + diplomat::result<ICU4XLineSegmenter, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XLineSegmenter>(ICU4XLineSegmenter(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XLineSegmenter, ICU4XError> ICU4XLineSegmenter::create_lstm(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XLineSegmenter_create_lstm(provider.AsFFI()); + diplomat::result<ICU4XLineSegmenter, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XLineSegmenter>(ICU4XLineSegmenter(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XLineSegmenter, ICU4XError> ICU4XLineSegmenter::create_dictionary(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XLineSegmenter_create_dictionary(provider.AsFFI()); + diplomat::result<ICU4XLineSegmenter, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XLineSegmenter>(ICU4XLineSegmenter(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XLineSegmenter, ICU4XError> ICU4XLineSegmenter::create_auto_with_options_v1(const ICU4XDataProvider& provider, ICU4XLineBreakOptionsV1 options) { + ICU4XLineBreakOptionsV1 diplomat_wrapped_struct_options = options; + auto diplomat_result_raw_out_value = capi::ICU4XLineSegmenter_create_auto_with_options_v1(provider.AsFFI(), capi::ICU4XLineBreakOptionsV1{ .strictness = static_cast<capi::ICU4XLineBreakStrictness>(diplomat_wrapped_struct_options.strictness), .word_option = static_cast<capi::ICU4XLineBreakWordOption>(diplomat_wrapped_struct_options.word_option), .ja_zh = diplomat_wrapped_struct_options.ja_zh }); + diplomat::result<ICU4XLineSegmenter, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XLineSegmenter>(ICU4XLineSegmenter(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XLineSegmenter, ICU4XError> ICU4XLineSegmenter::create_lstm_with_options_v1(const ICU4XDataProvider& provider, ICU4XLineBreakOptionsV1 options) { + ICU4XLineBreakOptionsV1 diplomat_wrapped_struct_options = options; + auto diplomat_result_raw_out_value = capi::ICU4XLineSegmenter_create_lstm_with_options_v1(provider.AsFFI(), capi::ICU4XLineBreakOptionsV1{ .strictness = static_cast<capi::ICU4XLineBreakStrictness>(diplomat_wrapped_struct_options.strictness), .word_option = static_cast<capi::ICU4XLineBreakWordOption>(diplomat_wrapped_struct_options.word_option), .ja_zh = diplomat_wrapped_struct_options.ja_zh }); + diplomat::result<ICU4XLineSegmenter, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XLineSegmenter>(ICU4XLineSegmenter(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XLineSegmenter, ICU4XError> ICU4XLineSegmenter::create_dictionary_with_options_v1(const ICU4XDataProvider& provider, ICU4XLineBreakOptionsV1 options) { + ICU4XLineBreakOptionsV1 diplomat_wrapped_struct_options = options; + auto diplomat_result_raw_out_value = capi::ICU4XLineSegmenter_create_dictionary_with_options_v1(provider.AsFFI(), capi::ICU4XLineBreakOptionsV1{ .strictness = static_cast<capi::ICU4XLineBreakStrictness>(diplomat_wrapped_struct_options.strictness), .word_option = static_cast<capi::ICU4XLineBreakWordOption>(diplomat_wrapped_struct_options.word_option), .ja_zh = diplomat_wrapped_struct_options.ja_zh }); + diplomat::result<ICU4XLineSegmenter, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XLineSegmenter>(ICU4XLineSegmenter(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline ICU4XLineBreakIteratorUtf8 ICU4XLineSegmenter::segment_utf8(const std::string_view input) const { + return ICU4XLineBreakIteratorUtf8(capi::ICU4XLineSegmenter_segment_utf8(this->inner.get(), input.data(), input.size())); +} +inline ICU4XLineBreakIteratorUtf16 ICU4XLineSegmenter::segment_utf16(const diplomat::span<const uint16_t> input) const { + return ICU4XLineBreakIteratorUtf16(capi::ICU4XLineSegmenter_segment_utf16(this->inner.get(), input.data(), input.size())); +} +inline ICU4XLineBreakIteratorLatin1 ICU4XLineSegmenter::segment_latin1(const diplomat::span<const uint8_t> input) const { + return ICU4XLineBreakIteratorLatin1(capi::ICU4XLineSegmenter_segment_latin1(this->inner.get(), input.data(), input.size())); +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XList.h b/intl/icu_capi/cpp/include/ICU4XList.h new file mode 100644 index 0000000000..6549561c37 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XList.h @@ -0,0 +1,35 @@ +#ifndef ICU4XList_H +#define ICU4XList_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XList ICU4XList; +#ifdef __cplusplus +} // namespace capi +#endif +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +ICU4XList* ICU4XList_create(); + +ICU4XList* ICU4XList_create_with_capacity(size_t capacity); + +void ICU4XList_push(ICU4XList* self, const char* val_data, size_t val_len); + +size_t ICU4XList_len(const ICU4XList* self); +void ICU4XList_destroy(ICU4XList* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XList.hpp b/intl/icu_capi/cpp/include/ICU4XList.hpp new file mode 100644 index 0000000000..e2212c021a --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XList.hpp @@ -0,0 +1,77 @@ +#ifndef ICU4XList_HPP +#define ICU4XList_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XList.h" + +class ICU4XList; + +/** + * A destruction policy for using ICU4XList with std::unique_ptr. + */ +struct ICU4XListDeleter { + void operator()(capi::ICU4XList* l) const noexcept { + capi::ICU4XList_destroy(l); + } +}; + +/** + * A list of strings + */ +class ICU4XList { + public: + + /** + * Create a new list of strings + */ + static ICU4XList create(); + + /** + * Create a new list of strings with preallocated space to hold + * at least `capacity` elements + */ + static ICU4XList create_with_capacity(size_t capacity); + + /** + * Push a string to the list + * + * For C++ users, potentially invalid UTF8 will be handled via + * REPLACEMENT CHARACTERs + */ + void push(const std::string_view val); + + /** + * The number of elements in this list + */ + size_t len() const; + inline const capi::ICU4XList* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XList* AsFFIMut() { return this->inner.get(); } + inline ICU4XList(capi::ICU4XList* i) : inner(i) {} + ICU4XList() = default; + ICU4XList(ICU4XList&&) noexcept = default; + ICU4XList& operator=(ICU4XList&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XList, ICU4XListDeleter> inner; +}; + + +inline ICU4XList ICU4XList::create() { + return ICU4XList(capi::ICU4XList_create()); +} +inline ICU4XList ICU4XList::create_with_capacity(size_t capacity) { + return ICU4XList(capi::ICU4XList_create_with_capacity(capacity)); +} +inline void ICU4XList::push(const std::string_view val) { + capi::ICU4XList_push(this->inner.get(), val.data(), val.size()); +} +inline size_t ICU4XList::len() const { + return capi::ICU4XList_len(this->inner.get()); +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XListFormatter.h b/intl/icu_capi/cpp/include/ICU4XListFormatter.h new file mode 100644 index 0000000000..ee358dc254 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XListFormatter.h @@ -0,0 +1,41 @@ +#ifndef ICU4XListFormatter_H +#define ICU4XListFormatter_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XListFormatter ICU4XListFormatter; +#ifdef __cplusplus +} // namespace capi +#endif +#include "ICU4XDataProvider.h" +#include "ICU4XLocale.h" +#include "ICU4XListLength.h" +#include "diplomat_result_box_ICU4XListFormatter_ICU4XError.h" +#include "ICU4XList.h" +#include "diplomat_result_void_ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +diplomat_result_box_ICU4XListFormatter_ICU4XError ICU4XListFormatter_create_and_with_length(const ICU4XDataProvider* provider, const ICU4XLocale* locale, ICU4XListLength length); + +diplomat_result_box_ICU4XListFormatter_ICU4XError ICU4XListFormatter_create_or_with_length(const ICU4XDataProvider* provider, const ICU4XLocale* locale, ICU4XListLength length); + +diplomat_result_box_ICU4XListFormatter_ICU4XError ICU4XListFormatter_create_unit_with_length(const ICU4XDataProvider* provider, const ICU4XLocale* locale, ICU4XListLength length); + +diplomat_result_void_ICU4XError ICU4XListFormatter_format(const ICU4XListFormatter* self, const ICU4XList* list, DiplomatWriteable* write); +void ICU4XListFormatter_destroy(ICU4XListFormatter* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XListFormatter.hpp b/intl/icu_capi/cpp/include/ICU4XListFormatter.hpp new file mode 100644 index 0000000000..73be39bcf7 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XListFormatter.hpp @@ -0,0 +1,133 @@ +#ifndef ICU4XListFormatter_HPP +#define ICU4XListFormatter_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XListFormatter.h" + +class ICU4XDataProvider; +class ICU4XLocale; +#include "ICU4XListLength.hpp" +class ICU4XListFormatter; +#include "ICU4XError.hpp" +class ICU4XList; + +/** + * A destruction policy for using ICU4XListFormatter with std::unique_ptr. + */ +struct ICU4XListFormatterDeleter { + void operator()(capi::ICU4XListFormatter* l) const noexcept { + capi::ICU4XListFormatter_destroy(l); + } +}; + +/** + * See the [Rust documentation for `ListFormatter`](https://docs.rs/icu/latest/icu/list/struct.ListFormatter.html) for more information. + */ +class ICU4XListFormatter { + public: + + /** + * Construct a new ICU4XListFormatter instance for And patterns + * + * See the [Rust documentation for `try_new_and_with_length`](https://docs.rs/icu/latest/icu/list/struct.ListFormatter.html#method.try_new_and_with_length) for more information. + */ + static diplomat::result<ICU4XListFormatter, ICU4XError> create_and_with_length(const ICU4XDataProvider& provider, const ICU4XLocale& locale, ICU4XListLength length); + + /** + * Construct a new ICU4XListFormatter instance for And patterns + * + * See the [Rust documentation for `try_new_or_with_length`](https://docs.rs/icu/latest/icu/list/struct.ListFormatter.html#method.try_new_or_with_length) for more information. + */ + static diplomat::result<ICU4XListFormatter, ICU4XError> create_or_with_length(const ICU4XDataProvider& provider, const ICU4XLocale& locale, ICU4XListLength length); + + /** + * Construct a new ICU4XListFormatter instance for And patterns + * + * See the [Rust documentation for `try_new_unit_with_length`](https://docs.rs/icu/latest/icu/list/struct.ListFormatter.html#method.try_new_unit_with_length) for more information. + */ + static diplomat::result<ICU4XListFormatter, ICU4XError> create_unit_with_length(const ICU4XDataProvider& provider, const ICU4XLocale& locale, ICU4XListLength length); + + /** + * See the [Rust documentation for `format`](https://docs.rs/icu/latest/icu/list/struct.ListFormatter.html#method.format) for more information. + */ + template<typename W> diplomat::result<std::monostate, ICU4XError> format_to_writeable(const ICU4XList& list, W& write) const; + + /** + * See the [Rust documentation for `format`](https://docs.rs/icu/latest/icu/list/struct.ListFormatter.html#method.format) for more information. + */ + diplomat::result<std::string, ICU4XError> format(const ICU4XList& list) const; + inline const capi::ICU4XListFormatter* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XListFormatter* AsFFIMut() { return this->inner.get(); } + inline ICU4XListFormatter(capi::ICU4XListFormatter* i) : inner(i) {} + ICU4XListFormatter() = default; + ICU4XListFormatter(ICU4XListFormatter&&) noexcept = default; + ICU4XListFormatter& operator=(ICU4XListFormatter&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XListFormatter, ICU4XListFormatterDeleter> inner; +}; + +#include "ICU4XDataProvider.hpp" +#include "ICU4XLocale.hpp" +#include "ICU4XList.hpp" + +inline diplomat::result<ICU4XListFormatter, ICU4XError> ICU4XListFormatter::create_and_with_length(const ICU4XDataProvider& provider, const ICU4XLocale& locale, ICU4XListLength length) { + auto diplomat_result_raw_out_value = capi::ICU4XListFormatter_create_and_with_length(provider.AsFFI(), locale.AsFFI(), static_cast<capi::ICU4XListLength>(length)); + diplomat::result<ICU4XListFormatter, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XListFormatter>(ICU4XListFormatter(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XListFormatter, ICU4XError> ICU4XListFormatter::create_or_with_length(const ICU4XDataProvider& provider, const ICU4XLocale& locale, ICU4XListLength length) { + auto diplomat_result_raw_out_value = capi::ICU4XListFormatter_create_or_with_length(provider.AsFFI(), locale.AsFFI(), static_cast<capi::ICU4XListLength>(length)); + diplomat::result<ICU4XListFormatter, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XListFormatter>(ICU4XListFormatter(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XListFormatter, ICU4XError> ICU4XListFormatter::create_unit_with_length(const ICU4XDataProvider& provider, const ICU4XLocale& locale, ICU4XListLength length) { + auto diplomat_result_raw_out_value = capi::ICU4XListFormatter_create_unit_with_length(provider.AsFFI(), locale.AsFFI(), static_cast<capi::ICU4XListLength>(length)); + diplomat::result<ICU4XListFormatter, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XListFormatter>(ICU4XListFormatter(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XListFormatter::format_to_writeable(const ICU4XList& list, W& write) const { + capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write); + auto diplomat_result_raw_out_value = capi::ICU4XListFormatter_format(this->inner.get(), list.AsFFI(), &write_writer); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<std::string, ICU4XError> ICU4XListFormatter::format(const ICU4XList& list) const { + std::string diplomat_writeable_string; + capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); + auto diplomat_result_raw_out_value = capi::ICU4XListFormatter_format(this->inner.get(), list.AsFFI(), &diplomat_writeable_out); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string)); +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XListLength.h b/intl/icu_capi/cpp/include/ICU4XListLength.h new file mode 100644 index 0000000000..7092f6d9df --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XListLength.h @@ -0,0 +1,32 @@ +#ifndef ICU4XListLength_H +#define ICU4XListLength_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef enum ICU4XListLength { + ICU4XListLength_Wide = 0, + ICU4XListLength_Short = 1, + ICU4XListLength_Narrow = 2, +} ICU4XListLength; +#ifdef __cplusplus +} // namespace capi +#endif +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +void ICU4XListLength_destroy(ICU4XListLength* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XListLength.hpp b/intl/icu_capi/cpp/include/ICU4XListLength.hpp new file mode 100644 index 0000000000..a9bd4372d0 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XListLength.hpp @@ -0,0 +1,25 @@ +#ifndef ICU4XListLength_HPP +#define ICU4XListLength_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XListLength.h" + + + +/** + * See the [Rust documentation for `ListLength`](https://docs.rs/icu/latest/icu/list/enum.ListLength.html) for more information. + */ +enum struct ICU4XListLength { + Wide = 0, + Short = 1, + Narrow = 2, +}; + +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XLocale.h b/intl/icu_capi/cpp/include/ICU4XLocale.h new file mode 100644 index 0000000000..dea8d196b5 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XLocale.h @@ -0,0 +1,64 @@ +#ifndef ICU4XLocale_H +#define ICU4XLocale_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XLocale ICU4XLocale; +#ifdef __cplusplus +} // namespace capi +#endif +#include "diplomat_result_box_ICU4XLocale_ICU4XError.h" +#include "diplomat_result_void_ICU4XError.h" +#include "ICU4XOrdering.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +diplomat_result_box_ICU4XLocale_ICU4XError ICU4XLocale_create_from_string(const char* name_data, size_t name_len); + +ICU4XLocale* ICU4XLocale_create_und(); + +ICU4XLocale* ICU4XLocale_clone(const ICU4XLocale* self); + +diplomat_result_void_ICU4XError ICU4XLocale_basename(const ICU4XLocale* self, DiplomatWriteable* write); + +diplomat_result_void_ICU4XError ICU4XLocale_get_unicode_extension(const ICU4XLocale* self, const char* bytes_data, size_t bytes_len, DiplomatWriteable* write); + +diplomat_result_void_ICU4XError ICU4XLocale_language(const ICU4XLocale* self, DiplomatWriteable* write); + +diplomat_result_void_ICU4XError ICU4XLocale_set_language(ICU4XLocale* self, const char* bytes_data, size_t bytes_len); + +diplomat_result_void_ICU4XError ICU4XLocale_region(const ICU4XLocale* self, DiplomatWriteable* write); + +diplomat_result_void_ICU4XError ICU4XLocale_set_region(ICU4XLocale* self, const char* bytes_data, size_t bytes_len); + +diplomat_result_void_ICU4XError ICU4XLocale_script(const ICU4XLocale* self, DiplomatWriteable* write); + +diplomat_result_void_ICU4XError ICU4XLocale_set_script(ICU4XLocale* self, const char* bytes_data, size_t bytes_len); + +diplomat_result_void_ICU4XError ICU4XLocale_canonicalize(const char* bytes_data, size_t bytes_len, DiplomatWriteable* write); + +diplomat_result_void_ICU4XError ICU4XLocale_to_string(const ICU4XLocale* self, DiplomatWriteable* write); + +bool ICU4XLocale_normalizing_eq(const ICU4XLocale* self, const char* other_data, size_t other_len); + +ICU4XOrdering ICU4XLocale_strict_cmp(const ICU4XLocale* self, const char* other_data, size_t other_len); + +ICU4XLocale* ICU4XLocale_create_en(); + +ICU4XLocale* ICU4XLocale_create_bn(); +void ICU4XLocale_destroy(ICU4XLocale* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XLocale.hpp b/intl/icu_capi/cpp/include/ICU4XLocale.hpp new file mode 100644 index 0000000000..578f6e1df3 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XLocale.hpp @@ -0,0 +1,438 @@ +#ifndef ICU4XLocale_HPP +#define ICU4XLocale_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XLocale.h" + +class ICU4XLocale; +#include "ICU4XError.hpp" +#include "ICU4XOrdering.hpp" + +/** + * A destruction policy for using ICU4XLocale with std::unique_ptr. + */ +struct ICU4XLocaleDeleter { + void operator()(capi::ICU4XLocale* l) const noexcept { + capi::ICU4XLocale_destroy(l); + } +}; + +/** + * An ICU4X Locale, capable of representing strings like `"en-US"`. + * + * See the [Rust documentation for `Locale`](https://docs.rs/icu/latest/icu/locid/struct.Locale.html) for more information. + */ +class ICU4XLocale { + public: + + /** + * Construct an [`ICU4XLocale`] from an locale identifier. + * + * This will run the complete locale parsing algorithm. If code size and + * performance are critical and the locale is of a known shape (such as + * `aa-BB`) use `create_und`, `set_language`, `set_script`, and `set_region`. + * + * See the [Rust documentation for `try_from_bytes`](https://docs.rs/icu/latest/icu/locid/struct.Locale.html#method.try_from_bytes) for more information. + */ + static diplomat::result<ICU4XLocale, ICU4XError> create_from_string(const std::string_view name); + + /** + * Construct a default undefined [`ICU4XLocale`] "und". + * + * See the [Rust documentation for `UND`](https://docs.rs/icu/latest/icu/locid/struct.Locale.html#associatedconstant.UND) for more information. + */ + static ICU4XLocale create_und(); + + /** + * Clones the [`ICU4XLocale`]. + * + * See the [Rust documentation for `Locale`](https://docs.rs/icu/latest/icu/locid/struct.Locale.html) for more information. + */ + ICU4XLocale clone() const; + + /** + * Write a string representation of the `LanguageIdentifier` part of + * [`ICU4XLocale`] to `write`. + * + * See the [Rust documentation for `id`](https://docs.rs/icu/latest/icu/locid/struct.Locale.html#structfield.id) for more information. + */ + template<typename W> diplomat::result<std::monostate, ICU4XError> basename_to_writeable(W& write) const; + + /** + * Write a string representation of the `LanguageIdentifier` part of + * [`ICU4XLocale`] to `write`. + * + * See the [Rust documentation for `id`](https://docs.rs/icu/latest/icu/locid/struct.Locale.html#structfield.id) for more information. + */ + diplomat::result<std::string, ICU4XError> basename() const; + + /** + * Write a string representation of the unicode extension to `write` + * + * See the [Rust documentation for `extensions`](https://docs.rs/icu/latest/icu/locid/struct.Locale.html#structfield.extensions) for more information. + */ + template<typename W> diplomat::result<std::monostate, ICU4XError> get_unicode_extension_to_writeable(const std::string_view bytes, W& write) const; + + /** + * Write a string representation of the unicode extension to `write` + * + * See the [Rust documentation for `extensions`](https://docs.rs/icu/latest/icu/locid/struct.Locale.html#structfield.extensions) for more information. + */ + diplomat::result<std::string, ICU4XError> get_unicode_extension(const std::string_view bytes) const; + + /** + * Write a string representation of [`ICU4XLocale`] language to `write` + * + * See the [Rust documentation for `id`](https://docs.rs/icu/latest/icu/locid/struct.Locale.html#structfield.id) for more information. + */ + template<typename W> diplomat::result<std::monostate, ICU4XError> language_to_writeable(W& write) const; + + /** + * Write a string representation of [`ICU4XLocale`] language to `write` + * + * See the [Rust documentation for `id`](https://docs.rs/icu/latest/icu/locid/struct.Locale.html#structfield.id) for more information. + */ + diplomat::result<std::string, ICU4XError> language() const; + + /** + * Set the language part of the [`ICU4XLocale`]. + * + * See the [Rust documentation for `try_from_bytes`](https://docs.rs/icu/latest/icu/locid/struct.Locale.html#method.try_from_bytes) for more information. + */ + diplomat::result<std::monostate, ICU4XError> set_language(const std::string_view bytes); + + /** + * Write a string representation of [`ICU4XLocale`] region to `write` + * + * See the [Rust documentation for `id`](https://docs.rs/icu/latest/icu/locid/struct.Locale.html#structfield.id) for more information. + */ + template<typename W> diplomat::result<std::monostate, ICU4XError> region_to_writeable(W& write) const; + + /** + * Write a string representation of [`ICU4XLocale`] region to `write` + * + * See the [Rust documentation for `id`](https://docs.rs/icu/latest/icu/locid/struct.Locale.html#structfield.id) for more information. + */ + diplomat::result<std::string, ICU4XError> region() const; + + /** + * Set the region part of the [`ICU4XLocale`]. + * + * See the [Rust documentation for `try_from_bytes`](https://docs.rs/icu/latest/icu/locid/struct.Locale.html#method.try_from_bytes) for more information. + */ + diplomat::result<std::monostate, ICU4XError> set_region(const std::string_view bytes); + + /** + * Write a string representation of [`ICU4XLocale`] script to `write` + * + * See the [Rust documentation for `id`](https://docs.rs/icu/latest/icu/locid/struct.Locale.html#structfield.id) for more information. + */ + template<typename W> diplomat::result<std::monostate, ICU4XError> script_to_writeable(W& write) const; + + /** + * Write a string representation of [`ICU4XLocale`] script to `write` + * + * See the [Rust documentation for `id`](https://docs.rs/icu/latest/icu/locid/struct.Locale.html#structfield.id) for more information. + */ + diplomat::result<std::string, ICU4XError> script() const; + + /** + * Set the script part of the [`ICU4XLocale`]. Pass an empty string to remove the script. + * + * See the [Rust documentation for `try_from_bytes`](https://docs.rs/icu/latest/icu/locid/struct.Locale.html#method.try_from_bytes) for more information. + */ + diplomat::result<std::monostate, ICU4XError> set_script(const std::string_view bytes); + + /** + * Best effort locale canonicalizer that doesn't need any data + * + * Use ICU4XLocaleCanonicalizer for better control and functionality + * + * See the [Rust documentation for `canonicalize`](https://docs.rs/icu/latest/icu/locid/struct.Locale.html#method.canonicalize) for more information. + */ + template<typename W> static diplomat::result<std::monostate, ICU4XError> canonicalize_to_writeable(const std::string_view bytes, W& write); + + /** + * Best effort locale canonicalizer that doesn't need any data + * + * Use ICU4XLocaleCanonicalizer for better control and functionality + * + * See the [Rust documentation for `canonicalize`](https://docs.rs/icu/latest/icu/locid/struct.Locale.html#method.canonicalize) for more information. + */ + static diplomat::result<std::string, ICU4XError> canonicalize(const std::string_view bytes); + + /** + * Write a string representation of [`ICU4XLocale`] to `write` + * + * See the [Rust documentation for `write_to`](https://docs.rs/icu/latest/icu/locid/struct.Locale.html#method.write_to) for more information. + */ + template<typename W> diplomat::result<std::monostate, ICU4XError> to_string_to_writeable(W& write) const; + + /** + * Write a string representation of [`ICU4XLocale`] to `write` + * + * See the [Rust documentation for `write_to`](https://docs.rs/icu/latest/icu/locid/struct.Locale.html#method.write_to) for more information. + */ + diplomat::result<std::string, ICU4XError> to_string() const; + + /** + * See the [Rust documentation for `normalizing_eq`](https://docs.rs/icu/latest/icu/locid/struct.Locale.html#method.normalizing_eq) for more information. + */ + bool normalizing_eq(const std::string_view other) const; + + /** + * See the [Rust documentation for `strict_cmp`](https://docs.rs/icu/latest/icu/locid/struct.Locale.html#method.strict_cmp) for more information. + */ + ICU4XOrdering strict_cmp(const std::string_view other) const; + + /** + * Deprecated + * + * Use `create_from_string("en"). + */ + static ICU4XLocale create_en(); + + /** + * Deprecated + * + * Use `create_from_string("bn"). + */ + static ICU4XLocale create_bn(); + inline const capi::ICU4XLocale* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XLocale* AsFFIMut() { return this->inner.get(); } + inline explicit ICU4XLocale(capi::ICU4XLocale* i) : inner(i) {} + ICU4XLocale() = default; + ICU4XLocale(ICU4XLocale&&) noexcept = default; + ICU4XLocale& operator=(ICU4XLocale&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XLocale, ICU4XLocaleDeleter> inner; +}; + + +inline diplomat::result<ICU4XLocale, ICU4XError> ICU4XLocale::create_from_string(const std::string_view name) { + auto diplomat_result_raw_out_value = capi::ICU4XLocale_create_from_string(name.data(), name.size()); + diplomat::result<ICU4XLocale, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XLocale>(ICU4XLocale(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline ICU4XLocale ICU4XLocale::create_und() { + return ICU4XLocale(capi::ICU4XLocale_create_und()); +} +inline ICU4XLocale ICU4XLocale::clone() const { + return ICU4XLocale(capi::ICU4XLocale_clone(this->inner.get())); +} +template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XLocale::basename_to_writeable(W& write) const { + capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write); + auto diplomat_result_raw_out_value = capi::ICU4XLocale_basename(this->inner.get(), &write_writer); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<std::string, ICU4XError> ICU4XLocale::basename() const { + std::string diplomat_writeable_string; + capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); + auto diplomat_result_raw_out_value = capi::ICU4XLocale_basename(this->inner.get(), &diplomat_writeable_out); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string)); +} +template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XLocale::get_unicode_extension_to_writeable(const std::string_view bytes, W& write) const { + capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write); + auto diplomat_result_raw_out_value = capi::ICU4XLocale_get_unicode_extension(this->inner.get(), bytes.data(), bytes.size(), &write_writer); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<std::string, ICU4XError> ICU4XLocale::get_unicode_extension(const std::string_view bytes) const { + std::string diplomat_writeable_string; + capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); + auto diplomat_result_raw_out_value = capi::ICU4XLocale_get_unicode_extension(this->inner.get(), bytes.data(), bytes.size(), &diplomat_writeable_out); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string)); +} +template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XLocale::language_to_writeable(W& write) const { + capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write); + auto diplomat_result_raw_out_value = capi::ICU4XLocale_language(this->inner.get(), &write_writer); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<std::string, ICU4XError> ICU4XLocale::language() const { + std::string diplomat_writeable_string; + capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); + auto diplomat_result_raw_out_value = capi::ICU4XLocale_language(this->inner.get(), &diplomat_writeable_out); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string)); +} +inline diplomat::result<std::monostate, ICU4XError> ICU4XLocale::set_language(const std::string_view bytes) { + auto diplomat_result_raw_out_value = capi::ICU4XLocale_set_language(this->inner.get(), bytes.data(), bytes.size()); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XLocale::region_to_writeable(W& write) const { + capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write); + auto diplomat_result_raw_out_value = capi::ICU4XLocale_region(this->inner.get(), &write_writer); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<std::string, ICU4XError> ICU4XLocale::region() const { + std::string diplomat_writeable_string; + capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); + auto diplomat_result_raw_out_value = capi::ICU4XLocale_region(this->inner.get(), &diplomat_writeable_out); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string)); +} +inline diplomat::result<std::monostate, ICU4XError> ICU4XLocale::set_region(const std::string_view bytes) { + auto diplomat_result_raw_out_value = capi::ICU4XLocale_set_region(this->inner.get(), bytes.data(), bytes.size()); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XLocale::script_to_writeable(W& write) const { + capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write); + auto diplomat_result_raw_out_value = capi::ICU4XLocale_script(this->inner.get(), &write_writer); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<std::string, ICU4XError> ICU4XLocale::script() const { + std::string diplomat_writeable_string; + capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); + auto diplomat_result_raw_out_value = capi::ICU4XLocale_script(this->inner.get(), &diplomat_writeable_out); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string)); +} +inline diplomat::result<std::monostate, ICU4XError> ICU4XLocale::set_script(const std::string_view bytes) { + auto diplomat_result_raw_out_value = capi::ICU4XLocale_set_script(this->inner.get(), bytes.data(), bytes.size()); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XLocale::canonicalize_to_writeable(const std::string_view bytes, W& write) { + capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write); + auto diplomat_result_raw_out_value = capi::ICU4XLocale_canonicalize(bytes.data(), bytes.size(), &write_writer); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<std::string, ICU4XError> ICU4XLocale::canonicalize(const std::string_view bytes) { + std::string diplomat_writeable_string; + capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); + auto diplomat_result_raw_out_value = capi::ICU4XLocale_canonicalize(bytes.data(), bytes.size(), &diplomat_writeable_out); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string)); +} +template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XLocale::to_string_to_writeable(W& write) const { + capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write); + auto diplomat_result_raw_out_value = capi::ICU4XLocale_to_string(this->inner.get(), &write_writer); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<std::string, ICU4XError> ICU4XLocale::to_string() const { + std::string diplomat_writeable_string; + capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); + auto diplomat_result_raw_out_value = capi::ICU4XLocale_to_string(this->inner.get(), &diplomat_writeable_out); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string)); +} +inline bool ICU4XLocale::normalizing_eq(const std::string_view other) const { + return capi::ICU4XLocale_normalizing_eq(this->inner.get(), other.data(), other.size()); +} +inline ICU4XOrdering ICU4XLocale::strict_cmp(const std::string_view other) const { + return static_cast<ICU4XOrdering>(capi::ICU4XLocale_strict_cmp(this->inner.get(), other.data(), other.size())); +} +inline ICU4XLocale ICU4XLocale::create_en() { + return ICU4XLocale(capi::ICU4XLocale_create_en()); +} +inline ICU4XLocale ICU4XLocale::create_bn() { + return ICU4XLocale(capi::ICU4XLocale_create_bn()); +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XLocaleCanonicalizer.h b/intl/icu_capi/cpp/include/ICU4XLocaleCanonicalizer.h new file mode 100644 index 0000000000..8b48ad8bb6 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XLocaleCanonicalizer.h @@ -0,0 +1,37 @@ +#ifndef ICU4XLocaleCanonicalizer_H +#define ICU4XLocaleCanonicalizer_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XLocaleCanonicalizer ICU4XLocaleCanonicalizer; +#ifdef __cplusplus +} // namespace capi +#endif +#include "ICU4XDataProvider.h" +#include "diplomat_result_box_ICU4XLocaleCanonicalizer_ICU4XError.h" +#include "ICU4XLocale.h" +#include "ICU4XTransformResult.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +diplomat_result_box_ICU4XLocaleCanonicalizer_ICU4XError ICU4XLocaleCanonicalizer_create(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XLocaleCanonicalizer_ICU4XError ICU4XLocaleCanonicalizer_create_extended(const ICU4XDataProvider* provider); + +ICU4XTransformResult ICU4XLocaleCanonicalizer_canonicalize(const ICU4XLocaleCanonicalizer* self, ICU4XLocale* locale); +void ICU4XLocaleCanonicalizer_destroy(ICU4XLocaleCanonicalizer* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XLocaleCanonicalizer.hpp b/intl/icu_capi/cpp/include/ICU4XLocaleCanonicalizer.hpp new file mode 100644 index 0000000000..76116cbf50 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XLocaleCanonicalizer.hpp @@ -0,0 +1,93 @@ +#ifndef ICU4XLocaleCanonicalizer_HPP +#define ICU4XLocaleCanonicalizer_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XLocaleCanonicalizer.h" + +class ICU4XDataProvider; +class ICU4XLocaleCanonicalizer; +#include "ICU4XError.hpp" +class ICU4XLocale; +#include "ICU4XTransformResult.hpp" + +/** + * A destruction policy for using ICU4XLocaleCanonicalizer with std::unique_ptr. + */ +struct ICU4XLocaleCanonicalizerDeleter { + void operator()(capi::ICU4XLocaleCanonicalizer* l) const noexcept { + capi::ICU4XLocaleCanonicalizer_destroy(l); + } +}; + +/** + * A locale canonicalizer. + * + * See the [Rust documentation for `LocaleCanonicalizer`](https://docs.rs/icu/latest/icu/locid_transform/struct.LocaleCanonicalizer.html) for more information. + */ +class ICU4XLocaleCanonicalizer { + public: + + /** + * Create a new [`ICU4XLocaleCanonicalizer`]. + * + * See the [Rust documentation for `new`](https://docs.rs/icu/latest/icu/locid_transform/struct.LocaleCanonicalizer.html#method.new) for more information. + */ + static diplomat::result<ICU4XLocaleCanonicalizer, ICU4XError> create(const ICU4XDataProvider& provider); + + /** + * Create a new [`ICU4XLocaleCanonicalizer`] with extended data. + * + * See the [Rust documentation for `new_with_expander`](https://docs.rs/icu/latest/icu/locid_transform/struct.LocaleCanonicalizer.html#method.new_with_expander) for more information. + */ + static diplomat::result<ICU4XLocaleCanonicalizer, ICU4XError> create_extended(const ICU4XDataProvider& provider); + + /** + * FFI version of `LocaleCanonicalizer::canonicalize()`. + * + * See the [Rust documentation for `canonicalize`](https://docs.rs/icu/latest/icu/locid_transform/struct.LocaleCanonicalizer.html#method.canonicalize) for more information. + */ + ICU4XTransformResult canonicalize(ICU4XLocale& locale) const; + inline const capi::ICU4XLocaleCanonicalizer* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XLocaleCanonicalizer* AsFFIMut() { return this->inner.get(); } + inline ICU4XLocaleCanonicalizer(capi::ICU4XLocaleCanonicalizer* i) : inner(i) {} + ICU4XLocaleCanonicalizer() = default; + ICU4XLocaleCanonicalizer(ICU4XLocaleCanonicalizer&&) noexcept = default; + ICU4XLocaleCanonicalizer& operator=(ICU4XLocaleCanonicalizer&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XLocaleCanonicalizer, ICU4XLocaleCanonicalizerDeleter> inner; +}; + +#include "ICU4XDataProvider.hpp" +#include "ICU4XLocale.hpp" + +inline diplomat::result<ICU4XLocaleCanonicalizer, ICU4XError> ICU4XLocaleCanonicalizer::create(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XLocaleCanonicalizer_create(provider.AsFFI()); + diplomat::result<ICU4XLocaleCanonicalizer, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XLocaleCanonicalizer>(ICU4XLocaleCanonicalizer(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XLocaleCanonicalizer, ICU4XError> ICU4XLocaleCanonicalizer::create_extended(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XLocaleCanonicalizer_create_extended(provider.AsFFI()); + diplomat::result<ICU4XLocaleCanonicalizer, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XLocaleCanonicalizer>(ICU4XLocaleCanonicalizer(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline ICU4XTransformResult ICU4XLocaleCanonicalizer::canonicalize(ICU4XLocale& locale) const { + return static_cast<ICU4XTransformResult>(capi::ICU4XLocaleCanonicalizer_canonicalize(this->inner.get(), locale.AsFFIMut())); +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XLocaleDirection.h b/intl/icu_capi/cpp/include/ICU4XLocaleDirection.h new file mode 100644 index 0000000000..688f04c98c --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XLocaleDirection.h @@ -0,0 +1,32 @@ +#ifndef ICU4XLocaleDirection_H +#define ICU4XLocaleDirection_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef enum ICU4XLocaleDirection { + ICU4XLocaleDirection_LeftToRight = 0, + ICU4XLocaleDirection_RightToLeft = 1, + ICU4XLocaleDirection_Unknown = 2, +} ICU4XLocaleDirection; +#ifdef __cplusplus +} // namespace capi +#endif +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +void ICU4XLocaleDirection_destroy(ICU4XLocaleDirection* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XLocaleDirection.hpp b/intl/icu_capi/cpp/include/ICU4XLocaleDirection.hpp new file mode 100644 index 0000000000..25c04e5ff8 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XLocaleDirection.hpp @@ -0,0 +1,25 @@ +#ifndef ICU4XLocaleDirection_HPP +#define ICU4XLocaleDirection_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XLocaleDirection.h" + + + +/** + * See the [Rust documentation for `Direction`](https://docs.rs/icu/latest/icu/locid_transform/enum.Direction.html) for more information. + */ +enum struct ICU4XLocaleDirection { + LeftToRight = 0, + RightToLeft = 1, + Unknown = 2, +}; + +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XLocaleDirectionality.h b/intl/icu_capi/cpp/include/ICU4XLocaleDirectionality.h new file mode 100644 index 0000000000..9271b078c7 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XLocaleDirectionality.h @@ -0,0 +1,42 @@ +#ifndef ICU4XLocaleDirectionality_H +#define ICU4XLocaleDirectionality_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XLocaleDirectionality ICU4XLocaleDirectionality; +#ifdef __cplusplus +} // namespace capi +#endif +#include "ICU4XDataProvider.h" +#include "diplomat_result_box_ICU4XLocaleDirectionality_ICU4XError.h" +#include "ICU4XLocaleExpander.h" +#include "ICU4XLocale.h" +#include "ICU4XLocaleDirection.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +diplomat_result_box_ICU4XLocaleDirectionality_ICU4XError ICU4XLocaleDirectionality_create(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XLocaleDirectionality_ICU4XError ICU4XLocaleDirectionality_create_with_expander(const ICU4XDataProvider* provider, const ICU4XLocaleExpander* expander); + +ICU4XLocaleDirection ICU4XLocaleDirectionality_get(const ICU4XLocaleDirectionality* self, const ICU4XLocale* locale); + +bool ICU4XLocaleDirectionality_is_left_to_right(const ICU4XLocaleDirectionality* self, const ICU4XLocale* locale); + +bool ICU4XLocaleDirectionality_is_right_to_left(const ICU4XLocaleDirectionality* self, const ICU4XLocale* locale); +void ICU4XLocaleDirectionality_destroy(ICU4XLocaleDirectionality* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XLocaleDirectionality.hpp b/intl/icu_capi/cpp/include/ICU4XLocaleDirectionality.hpp new file mode 100644 index 0000000000..5bc295d172 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XLocaleDirectionality.hpp @@ -0,0 +1,107 @@ +#ifndef ICU4XLocaleDirectionality_HPP +#define ICU4XLocaleDirectionality_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XLocaleDirectionality.h" + +class ICU4XDataProvider; +class ICU4XLocaleDirectionality; +#include "ICU4XError.hpp" +class ICU4XLocaleExpander; +class ICU4XLocale; +#include "ICU4XLocaleDirection.hpp" + +/** + * A destruction policy for using ICU4XLocaleDirectionality with std::unique_ptr. + */ +struct ICU4XLocaleDirectionalityDeleter { + void operator()(capi::ICU4XLocaleDirectionality* l) const noexcept { + capi::ICU4XLocaleDirectionality_destroy(l); + } +}; + +/** + * See the [Rust documentation for `LocaleDirectionality`](https://docs.rs/icu/latest/icu/locid_transform/struct.LocaleDirectionality.html) for more information. + */ +class ICU4XLocaleDirectionality { + public: + + /** + * Construct a new ICU4XLocaleDirectionality instance + * + * See the [Rust documentation for `new`](https://docs.rs/icu/latest/icu/locid_transform/struct.LocaleDirectionality.html#method.new) for more information. + */ + static diplomat::result<ICU4XLocaleDirectionality, ICU4XError> create(const ICU4XDataProvider& provider); + + /** + * Construct a new ICU4XLocaleDirectionality instance with a custom expander + * + * See the [Rust documentation for `new_with_expander`](https://docs.rs/icu/latest/icu/locid_transform/struct.LocaleDirectionality.html#method.new_with_expander) for more information. + */ + static diplomat::result<ICU4XLocaleDirectionality, ICU4XError> create_with_expander(const ICU4XDataProvider& provider, const ICU4XLocaleExpander& expander); + + /** + * See the [Rust documentation for `get`](https://docs.rs/icu/latest/icu/locid_transform/struct.LocaleDirectionality.html#method.get) for more information. + */ + ICU4XLocaleDirection get(const ICU4XLocale& locale) const; + + /** + * See the [Rust documentation for `is_left_to_right`](https://docs.rs/icu/latest/icu/locid_transform/struct.LocaleDirectionality.html#method.is_left_to_right) for more information. + */ + bool is_left_to_right(const ICU4XLocale& locale) const; + + /** + * See the [Rust documentation for `is_right_to_left`](https://docs.rs/icu/latest/icu/locid_transform/struct.LocaleDirectionality.html#method.is_right_to_left) for more information. + */ + bool is_right_to_left(const ICU4XLocale& locale) const; + inline const capi::ICU4XLocaleDirectionality* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XLocaleDirectionality* AsFFIMut() { return this->inner.get(); } + inline ICU4XLocaleDirectionality(capi::ICU4XLocaleDirectionality* i) : inner(i) {} + ICU4XLocaleDirectionality() = default; + ICU4XLocaleDirectionality(ICU4XLocaleDirectionality&&) noexcept = default; + ICU4XLocaleDirectionality& operator=(ICU4XLocaleDirectionality&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XLocaleDirectionality, ICU4XLocaleDirectionalityDeleter> inner; +}; + +#include "ICU4XDataProvider.hpp" +#include "ICU4XLocaleExpander.hpp" +#include "ICU4XLocale.hpp" + +inline diplomat::result<ICU4XLocaleDirectionality, ICU4XError> ICU4XLocaleDirectionality::create(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XLocaleDirectionality_create(provider.AsFFI()); + diplomat::result<ICU4XLocaleDirectionality, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XLocaleDirectionality>(ICU4XLocaleDirectionality(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XLocaleDirectionality, ICU4XError> ICU4XLocaleDirectionality::create_with_expander(const ICU4XDataProvider& provider, const ICU4XLocaleExpander& expander) { + auto diplomat_result_raw_out_value = capi::ICU4XLocaleDirectionality_create_with_expander(provider.AsFFI(), expander.AsFFI()); + diplomat::result<ICU4XLocaleDirectionality, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XLocaleDirectionality>(ICU4XLocaleDirectionality(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline ICU4XLocaleDirection ICU4XLocaleDirectionality::get(const ICU4XLocale& locale) const { + return static_cast<ICU4XLocaleDirection>(capi::ICU4XLocaleDirectionality_get(this->inner.get(), locale.AsFFI())); +} +inline bool ICU4XLocaleDirectionality::is_left_to_right(const ICU4XLocale& locale) const { + return capi::ICU4XLocaleDirectionality_is_left_to_right(this->inner.get(), locale.AsFFI()); +} +inline bool ICU4XLocaleDirectionality::is_right_to_left(const ICU4XLocale& locale) const { + return capi::ICU4XLocaleDirectionality_is_right_to_left(this->inner.get(), locale.AsFFI()); +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XLocaleDisplayNamesFormatter.h b/intl/icu_capi/cpp/include/ICU4XLocaleDisplayNamesFormatter.h new file mode 100644 index 0000000000..bfed8ec411 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XLocaleDisplayNamesFormatter.h @@ -0,0 +1,36 @@ +#ifndef ICU4XLocaleDisplayNamesFormatter_H +#define ICU4XLocaleDisplayNamesFormatter_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XLocaleDisplayNamesFormatter ICU4XLocaleDisplayNamesFormatter; +#ifdef __cplusplus +} // namespace capi +#endif +#include "ICU4XDataProvider.h" +#include "ICU4XLocale.h" +#include "ICU4XDisplayNamesOptionsV1.h" +#include "diplomat_result_box_ICU4XLocaleDisplayNamesFormatter_ICU4XError.h" +#include "diplomat_result_void_ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +diplomat_result_box_ICU4XLocaleDisplayNamesFormatter_ICU4XError ICU4XLocaleDisplayNamesFormatter_create(const ICU4XDataProvider* provider, const ICU4XLocale* locale, ICU4XDisplayNamesOptionsV1 options); + +diplomat_result_void_ICU4XError ICU4XLocaleDisplayNamesFormatter_of(const ICU4XLocaleDisplayNamesFormatter* self, const ICU4XLocale* locale, DiplomatWriteable* write); +void ICU4XLocaleDisplayNamesFormatter_destroy(ICU4XLocaleDisplayNamesFormatter* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XLocaleDisplayNamesFormatter.hpp b/intl/icu_capi/cpp/include/ICU4XLocaleDisplayNamesFormatter.hpp new file mode 100644 index 0000000000..06eac9a3ab --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XLocaleDisplayNamesFormatter.hpp @@ -0,0 +1,103 @@ +#ifndef ICU4XLocaleDisplayNamesFormatter_HPP +#define ICU4XLocaleDisplayNamesFormatter_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XLocaleDisplayNamesFormatter.h" + +class ICU4XDataProvider; +class ICU4XLocale; +struct ICU4XDisplayNamesOptionsV1; +class ICU4XLocaleDisplayNamesFormatter; +#include "ICU4XError.hpp" + +/** + * A destruction policy for using ICU4XLocaleDisplayNamesFormatter with std::unique_ptr. + */ +struct ICU4XLocaleDisplayNamesFormatterDeleter { + void operator()(capi::ICU4XLocaleDisplayNamesFormatter* l) const noexcept { + capi::ICU4XLocaleDisplayNamesFormatter_destroy(l); + } +}; + +/** + * See the [Rust documentation for `LocaleDisplayNamesFormatter`](https://docs.rs/icu/latest/icu/displaynames/struct.LocaleDisplayNamesFormatter.html) for more information. + */ +class ICU4XLocaleDisplayNamesFormatter { + public: + + /** + * Creates a new `LocaleDisplayNamesFormatter` from locale data and an options bag. + * + * See the [Rust documentation for `try_new`](https://docs.rs/icu/latest/icu/displaynames/struct.LocaleDisplayNamesFormatter.html#method.try_new) for more information. + */ + static diplomat::result<ICU4XLocaleDisplayNamesFormatter, ICU4XError> create(const ICU4XDataProvider& provider, const ICU4XLocale& locale, ICU4XDisplayNamesOptionsV1 options); + + /** + * Returns the locale-specific display name of a locale. + * + * See the [Rust documentation for `of`](https://docs.rs/icu/latest/icu/displaynames/struct.LocaleDisplayNamesFormatter.html#method.of) for more information. + */ + template<typename W> diplomat::result<std::monostate, ICU4XError> of_to_writeable(const ICU4XLocale& locale, W& write) const; + + /** + * Returns the locale-specific display name of a locale. + * + * See the [Rust documentation for `of`](https://docs.rs/icu/latest/icu/displaynames/struct.LocaleDisplayNamesFormatter.html#method.of) for more information. + */ + diplomat::result<std::string, ICU4XError> of(const ICU4XLocale& locale) const; + inline const capi::ICU4XLocaleDisplayNamesFormatter* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XLocaleDisplayNamesFormatter* AsFFIMut() { return this->inner.get(); } + inline ICU4XLocaleDisplayNamesFormatter(capi::ICU4XLocaleDisplayNamesFormatter* i) : inner(i) {} + ICU4XLocaleDisplayNamesFormatter() = default; + ICU4XLocaleDisplayNamesFormatter(ICU4XLocaleDisplayNamesFormatter&&) noexcept = default; + ICU4XLocaleDisplayNamesFormatter& operator=(ICU4XLocaleDisplayNamesFormatter&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XLocaleDisplayNamesFormatter, ICU4XLocaleDisplayNamesFormatterDeleter> inner; +}; + +#include "ICU4XDataProvider.hpp" +#include "ICU4XLocale.hpp" +#include "ICU4XDisplayNamesOptionsV1.hpp" + +inline diplomat::result<ICU4XLocaleDisplayNamesFormatter, ICU4XError> ICU4XLocaleDisplayNamesFormatter::create(const ICU4XDataProvider& provider, const ICU4XLocale& locale, ICU4XDisplayNamesOptionsV1 options) { + ICU4XDisplayNamesOptionsV1 diplomat_wrapped_struct_options = options; + auto diplomat_result_raw_out_value = capi::ICU4XLocaleDisplayNamesFormatter_create(provider.AsFFI(), locale.AsFFI(), capi::ICU4XDisplayNamesOptionsV1{ .style = static_cast<capi::ICU4XDisplayNamesStyle>(diplomat_wrapped_struct_options.style), .fallback = static_cast<capi::ICU4XDisplayNamesFallback>(diplomat_wrapped_struct_options.fallback), .language_display = static_cast<capi::ICU4XLanguageDisplay>(diplomat_wrapped_struct_options.language_display) }); + diplomat::result<ICU4XLocaleDisplayNamesFormatter, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XLocaleDisplayNamesFormatter>(ICU4XLocaleDisplayNamesFormatter(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XLocaleDisplayNamesFormatter::of_to_writeable(const ICU4XLocale& locale, W& write) const { + capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write); + auto diplomat_result_raw_out_value = capi::ICU4XLocaleDisplayNamesFormatter_of(this->inner.get(), locale.AsFFI(), &write_writer); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<std::string, ICU4XError> ICU4XLocaleDisplayNamesFormatter::of(const ICU4XLocale& locale) const { + std::string diplomat_writeable_string; + capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); + auto diplomat_result_raw_out_value = capi::ICU4XLocaleDisplayNamesFormatter_of(this->inner.get(), locale.AsFFI(), &diplomat_writeable_out); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string)); +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XLocaleExpander.h b/intl/icu_capi/cpp/include/ICU4XLocaleExpander.h new file mode 100644 index 0000000000..a7de7be16b --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XLocaleExpander.h @@ -0,0 +1,39 @@ +#ifndef ICU4XLocaleExpander_H +#define ICU4XLocaleExpander_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XLocaleExpander ICU4XLocaleExpander; +#ifdef __cplusplus +} // namespace capi +#endif +#include "ICU4XDataProvider.h" +#include "diplomat_result_box_ICU4XLocaleExpander_ICU4XError.h" +#include "ICU4XLocale.h" +#include "ICU4XTransformResult.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +diplomat_result_box_ICU4XLocaleExpander_ICU4XError ICU4XLocaleExpander_create(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XLocaleExpander_ICU4XError ICU4XLocaleExpander_create_extended(const ICU4XDataProvider* provider); + +ICU4XTransformResult ICU4XLocaleExpander_maximize(const ICU4XLocaleExpander* self, ICU4XLocale* locale); + +ICU4XTransformResult ICU4XLocaleExpander_minimize(const ICU4XLocaleExpander* self, ICU4XLocale* locale); +void ICU4XLocaleExpander_destroy(ICU4XLocaleExpander* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XLocaleExpander.hpp b/intl/icu_capi/cpp/include/ICU4XLocaleExpander.hpp new file mode 100644 index 0000000000..d63cf92b82 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XLocaleExpander.hpp @@ -0,0 +1,103 @@ +#ifndef ICU4XLocaleExpander_HPP +#define ICU4XLocaleExpander_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XLocaleExpander.h" + +class ICU4XDataProvider; +class ICU4XLocaleExpander; +#include "ICU4XError.hpp" +class ICU4XLocale; +#include "ICU4XTransformResult.hpp" + +/** + * A destruction policy for using ICU4XLocaleExpander with std::unique_ptr. + */ +struct ICU4XLocaleExpanderDeleter { + void operator()(capi::ICU4XLocaleExpander* l) const noexcept { + capi::ICU4XLocaleExpander_destroy(l); + } +}; + +/** + * A locale expander. + * + * See the [Rust documentation for `LocaleExpander`](https://docs.rs/icu/latest/icu/locid_transform/struct.LocaleExpander.html) for more information. + */ +class ICU4XLocaleExpander { + public: + + /** + * Create a new [`ICU4XLocaleExpander`]. + * + * See the [Rust documentation for `new`](https://docs.rs/icu/latest/icu/locid_transform/struct.LocaleExpander.html#method.new) for more information. + */ + static diplomat::result<ICU4XLocaleExpander, ICU4XError> create(const ICU4XDataProvider& provider); + + /** + * Create a new [`ICU4XLocaleExpander`] with extended data. + * + * See the [Rust documentation for `new_extended`](https://docs.rs/icu/latest/icu/locid_transform/struct.LocaleExpander.html#method.new_extended) for more information. + */ + static diplomat::result<ICU4XLocaleExpander, ICU4XError> create_extended(const ICU4XDataProvider& provider); + + /** + * FFI version of `LocaleExpander::maximize()`. + * + * See the [Rust documentation for `maximize`](https://docs.rs/icu/latest/icu/locid_transform/struct.LocaleExpander.html#method.maximize) for more information. + */ + ICU4XTransformResult maximize(ICU4XLocale& locale) const; + + /** + * FFI version of `LocaleExpander::minimize()`. + * + * See the [Rust documentation for `minimize`](https://docs.rs/icu/latest/icu/locid_transform/struct.LocaleExpander.html#method.minimize) for more information. + */ + ICU4XTransformResult minimize(ICU4XLocale& locale) const; + inline const capi::ICU4XLocaleExpander* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XLocaleExpander* AsFFIMut() { return this->inner.get(); } + inline ICU4XLocaleExpander(capi::ICU4XLocaleExpander* i) : inner(i) {} + ICU4XLocaleExpander() = default; + ICU4XLocaleExpander(ICU4XLocaleExpander&&) noexcept = default; + ICU4XLocaleExpander& operator=(ICU4XLocaleExpander&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XLocaleExpander, ICU4XLocaleExpanderDeleter> inner; +}; + +#include "ICU4XDataProvider.hpp" +#include "ICU4XLocale.hpp" + +inline diplomat::result<ICU4XLocaleExpander, ICU4XError> ICU4XLocaleExpander::create(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XLocaleExpander_create(provider.AsFFI()); + diplomat::result<ICU4XLocaleExpander, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XLocaleExpander>(ICU4XLocaleExpander(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XLocaleExpander, ICU4XError> ICU4XLocaleExpander::create_extended(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XLocaleExpander_create_extended(provider.AsFFI()); + diplomat::result<ICU4XLocaleExpander, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XLocaleExpander>(ICU4XLocaleExpander(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline ICU4XTransformResult ICU4XLocaleExpander::maximize(ICU4XLocale& locale) const { + return static_cast<ICU4XTransformResult>(capi::ICU4XLocaleExpander_maximize(this->inner.get(), locale.AsFFIMut())); +} +inline ICU4XTransformResult ICU4XLocaleExpander::minimize(ICU4XLocale& locale) const { + return static_cast<ICU4XTransformResult>(capi::ICU4XLocaleExpander_minimize(this->inner.get(), locale.AsFFIMut())); +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XLocaleFallbackConfig.h b/intl/icu_capi/cpp/include/ICU4XLocaleFallbackConfig.h new file mode 100644 index 0000000000..b40d115418 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XLocaleFallbackConfig.h @@ -0,0 +1,36 @@ +#ifndef ICU4XLocaleFallbackConfig_H +#define ICU4XLocaleFallbackConfig_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#include "ICU4XLocaleFallbackPriority.h" +#include "ICU4XLocaleFallbackSupplement.h" +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XLocaleFallbackConfig { + ICU4XLocaleFallbackPriority priority; + DiplomatStringView extension_key; + ICU4XLocaleFallbackSupplement fallback_supplement; +} ICU4XLocaleFallbackConfig; +#ifdef __cplusplus +} // namespace capi +#endif +#include "ICU4XLocaleFallbackPriority.h" +#include "ICU4XLocaleFallbackSupplement.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +void ICU4XLocaleFallbackConfig_destroy(ICU4XLocaleFallbackConfig* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XLocaleFallbackConfig.hpp b/intl/icu_capi/cpp/include/ICU4XLocaleFallbackConfig.hpp new file mode 100644 index 0000000000..8c177d718a --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XLocaleFallbackConfig.hpp @@ -0,0 +1,43 @@ +#ifndef ICU4XLocaleFallbackConfig_HPP +#define ICU4XLocaleFallbackConfig_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XLocaleFallbackConfig.h" + +#include "ICU4XLocaleFallbackPriority.hpp" +#include "ICU4XLocaleFallbackSupplement.hpp" + + +/** + * Collection of configurations for the ICU4X fallback algorithm. + * + * See the [Rust documentation for `LocaleFallbackConfig`](https://docs.rs/icu/latest/icu/locid_transform/fallback/struct.LocaleFallbackConfig.html) for more information. + */ +struct ICU4XLocaleFallbackConfig { + public: + + /** + * Choice of priority mode. + */ + ICU4XLocaleFallbackPriority priority; + + /** + * An empty string is considered `None`. + */ + std::string_view extension_key; + + /** + * Fallback supplement data key to customize fallback rules. + */ + ICU4XLocaleFallbackSupplement fallback_supplement; +}; + + +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XLocaleFallbackIterator.h b/intl/icu_capi/cpp/include/ICU4XLocaleFallbackIterator.h new file mode 100644 index 0000000000..e2dd7a1a3b --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XLocaleFallbackIterator.h @@ -0,0 +1,32 @@ +#ifndef ICU4XLocaleFallbackIterator_H +#define ICU4XLocaleFallbackIterator_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XLocaleFallbackIterator ICU4XLocaleFallbackIterator; +#ifdef __cplusplus +} // namespace capi +#endif +#include "ICU4XLocale.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +ICU4XLocale* ICU4XLocaleFallbackIterator_get(const ICU4XLocaleFallbackIterator* self); + +void ICU4XLocaleFallbackIterator_step(ICU4XLocaleFallbackIterator* self); +void ICU4XLocaleFallbackIterator_destroy(ICU4XLocaleFallbackIterator* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XLocaleFallbackIterator.hpp b/intl/icu_capi/cpp/include/ICU4XLocaleFallbackIterator.hpp new file mode 100644 index 0000000000..93c47eb01e --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XLocaleFallbackIterator.hpp @@ -0,0 +1,64 @@ +#ifndef ICU4XLocaleFallbackIterator_HPP +#define ICU4XLocaleFallbackIterator_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XLocaleFallbackIterator.h" + +class ICU4XLocale; + +/** + * A destruction policy for using ICU4XLocaleFallbackIterator with std::unique_ptr. + */ +struct ICU4XLocaleFallbackIteratorDeleter { + void operator()(capi::ICU4XLocaleFallbackIterator* l) const noexcept { + capi::ICU4XLocaleFallbackIterator_destroy(l); + } +}; + +/** + * An iterator over the locale under fallback. + * + * See the [Rust documentation for `LocaleFallbackIterator`](https://docs.rs/icu/latest/icu/locid_transform/fallback/struct.LocaleFallbackIterator.html) for more information. + */ +class ICU4XLocaleFallbackIterator { + public: + + /** + * Gets a snapshot of the current state of the locale. + * + * See the [Rust documentation for `get`](https://docs.rs/icu/latest/icu/locid_transform/fallback/struct.LocaleFallbackIterator.html#method.get) for more information. + */ + ICU4XLocale get() const; + + /** + * Performs one step of the fallback algorithm, mutating the locale. + * + * See the [Rust documentation for `step`](https://docs.rs/icu/latest/icu/locid_transform/fallback/struct.LocaleFallbackIterator.html#method.step) for more information. + */ + void step(); + inline const capi::ICU4XLocaleFallbackIterator* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XLocaleFallbackIterator* AsFFIMut() { return this->inner.get(); } + inline explicit ICU4XLocaleFallbackIterator(capi::ICU4XLocaleFallbackIterator* i) : inner(i) {} + ICU4XLocaleFallbackIterator() = default; + ICU4XLocaleFallbackIterator(ICU4XLocaleFallbackIterator&&) noexcept = default; + ICU4XLocaleFallbackIterator& operator=(ICU4XLocaleFallbackIterator&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XLocaleFallbackIterator, ICU4XLocaleFallbackIteratorDeleter> inner; +}; + +#include "ICU4XLocale.hpp" + +inline ICU4XLocale ICU4XLocaleFallbackIterator::get() const { + return ICU4XLocale(capi::ICU4XLocaleFallbackIterator_get(this->inner.get())); +} +inline void ICU4XLocaleFallbackIterator::step() { + capi::ICU4XLocaleFallbackIterator_step(this->inner.get()); +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XLocaleFallbackPriority.h b/intl/icu_capi/cpp/include/ICU4XLocaleFallbackPriority.h new file mode 100644 index 0000000000..e4ab748065 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XLocaleFallbackPriority.h @@ -0,0 +1,32 @@ +#ifndef ICU4XLocaleFallbackPriority_H +#define ICU4XLocaleFallbackPriority_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef enum ICU4XLocaleFallbackPriority { + ICU4XLocaleFallbackPriority_Language = 0, + ICU4XLocaleFallbackPriority_Region = 1, + ICU4XLocaleFallbackPriority_Collation = 2, +} ICU4XLocaleFallbackPriority; +#ifdef __cplusplus +} // namespace capi +#endif +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +void ICU4XLocaleFallbackPriority_destroy(ICU4XLocaleFallbackPriority* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XLocaleFallbackPriority.hpp b/intl/icu_capi/cpp/include/ICU4XLocaleFallbackPriority.hpp new file mode 100644 index 0000000000..19d52ae7a3 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XLocaleFallbackPriority.hpp @@ -0,0 +1,27 @@ +#ifndef ICU4XLocaleFallbackPriority_HPP +#define ICU4XLocaleFallbackPriority_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XLocaleFallbackPriority.h" + + + +/** + * Priority mode for the ICU4X fallback algorithm. + * + * See the [Rust documentation for `LocaleFallbackPriority`](https://docs.rs/icu/latest/icu/locid_transform/fallback/enum.LocaleFallbackPriority.html) for more information. + */ +enum struct ICU4XLocaleFallbackPriority { + Language = 0, + Region = 1, + Collation = 2, +}; + +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XLocaleFallbackSupplement.h b/intl/icu_capi/cpp/include/ICU4XLocaleFallbackSupplement.h new file mode 100644 index 0000000000..952483c724 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XLocaleFallbackSupplement.h @@ -0,0 +1,31 @@ +#ifndef ICU4XLocaleFallbackSupplement_H +#define ICU4XLocaleFallbackSupplement_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef enum ICU4XLocaleFallbackSupplement { + ICU4XLocaleFallbackSupplement_None = 0, + ICU4XLocaleFallbackSupplement_Collation = 1, +} ICU4XLocaleFallbackSupplement; +#ifdef __cplusplus +} // namespace capi +#endif +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +void ICU4XLocaleFallbackSupplement_destroy(ICU4XLocaleFallbackSupplement* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XLocaleFallbackSupplement.hpp b/intl/icu_capi/cpp/include/ICU4XLocaleFallbackSupplement.hpp new file mode 100644 index 0000000000..a357bb4929 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XLocaleFallbackSupplement.hpp @@ -0,0 +1,26 @@ +#ifndef ICU4XLocaleFallbackSupplement_HPP +#define ICU4XLocaleFallbackSupplement_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XLocaleFallbackSupplement.h" + + + +/** + * What additional data is required to load when performing fallback. + * + * See the [Rust documentation for `LocaleFallbackSupplement`](https://docs.rs/icu/latest/icu/locid_transform/fallback/enum.LocaleFallbackSupplement.html) for more information. + */ +enum struct ICU4XLocaleFallbackSupplement { + None = 0, + Collation = 1, +}; + +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XLocaleFallbacker.h b/intl/icu_capi/cpp/include/ICU4XLocaleFallbacker.h new file mode 100644 index 0000000000..24efb0602f --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XLocaleFallbacker.h @@ -0,0 +1,37 @@ +#ifndef ICU4XLocaleFallbacker_H +#define ICU4XLocaleFallbacker_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XLocaleFallbacker ICU4XLocaleFallbacker; +#ifdef __cplusplus +} // namespace capi +#endif +#include "ICU4XDataProvider.h" +#include "diplomat_result_box_ICU4XLocaleFallbacker_ICU4XError.h" +#include "ICU4XLocaleFallbackConfig.h" +#include "diplomat_result_box_ICU4XLocaleFallbackerWithConfig_ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +diplomat_result_box_ICU4XLocaleFallbacker_ICU4XError ICU4XLocaleFallbacker_create(const ICU4XDataProvider* provider); + +ICU4XLocaleFallbacker* ICU4XLocaleFallbacker_create_without_data(); + +diplomat_result_box_ICU4XLocaleFallbackerWithConfig_ICU4XError ICU4XLocaleFallbacker_for_config(const ICU4XLocaleFallbacker* self, ICU4XLocaleFallbackConfig config); +void ICU4XLocaleFallbacker_destroy(ICU4XLocaleFallbacker* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XLocaleFallbacker.hpp b/intl/icu_capi/cpp/include/ICU4XLocaleFallbacker.hpp new file mode 100644 index 0000000000..707ddce386 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XLocaleFallbacker.hpp @@ -0,0 +1,97 @@ +#ifndef ICU4XLocaleFallbacker_HPP +#define ICU4XLocaleFallbacker_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XLocaleFallbacker.h" + +class ICU4XDataProvider; +class ICU4XLocaleFallbacker; +#include "ICU4XError.hpp" +struct ICU4XLocaleFallbackConfig; +class ICU4XLocaleFallbackerWithConfig; + +/** + * A destruction policy for using ICU4XLocaleFallbacker with std::unique_ptr. + */ +struct ICU4XLocaleFallbackerDeleter { + void operator()(capi::ICU4XLocaleFallbacker* l) const noexcept { + capi::ICU4XLocaleFallbacker_destroy(l); + } +}; + +/** + * An object that runs the ICU4X locale fallback algorithm. + * + * See the [Rust documentation for `LocaleFallbacker`](https://docs.rs/icu/latest/icu/locid_transform/fallback/struct.LocaleFallbacker.html) for more information. + */ +class ICU4XLocaleFallbacker { + public: + + /** + * Creates a new `ICU4XLocaleFallbacker` from a data provider. + * + * See the [Rust documentation for `new`](https://docs.rs/icu/latest/icu/locid_transform/fallback/struct.LocaleFallbacker.html#method.new) for more information. + */ + static diplomat::result<ICU4XLocaleFallbacker, ICU4XError> create(const ICU4XDataProvider& provider); + + /** + * Creates a new `ICU4XLocaleFallbacker` without data for limited functionality. + * + * See the [Rust documentation for `new_without_data`](https://docs.rs/icu/latest/icu/locid_transform/fallback/struct.LocaleFallbacker.html#method.new_without_data) for more information. + */ + static ICU4XLocaleFallbacker create_without_data(); + + /** + * Associates this `ICU4XLocaleFallbacker` with configuration options. + * + * See the [Rust documentation for `for_config`](https://docs.rs/icu/latest/icu/locid_transform/fallback/struct.LocaleFallbacker.html#method.for_config) for more information. + * + * Lifetimes: `this` must live at least as long as the output. + */ + diplomat::result<ICU4XLocaleFallbackerWithConfig, ICU4XError> for_config(ICU4XLocaleFallbackConfig config) const; + inline const capi::ICU4XLocaleFallbacker* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XLocaleFallbacker* AsFFIMut() { return this->inner.get(); } + inline explicit ICU4XLocaleFallbacker(capi::ICU4XLocaleFallbacker* i) : inner(i) {} + ICU4XLocaleFallbacker() = default; + ICU4XLocaleFallbacker(ICU4XLocaleFallbacker&&) noexcept = default; + ICU4XLocaleFallbacker& operator=(ICU4XLocaleFallbacker&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XLocaleFallbacker, ICU4XLocaleFallbackerDeleter> inner; +}; + +#include "ICU4XDataProvider.hpp" +#include "ICU4XLocaleFallbackConfig.hpp" +#include "ICU4XLocaleFallbackerWithConfig.hpp" + +inline diplomat::result<ICU4XLocaleFallbacker, ICU4XError> ICU4XLocaleFallbacker::create(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XLocaleFallbacker_create(provider.AsFFI()); + diplomat::result<ICU4XLocaleFallbacker, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XLocaleFallbacker>(ICU4XLocaleFallbacker(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline ICU4XLocaleFallbacker ICU4XLocaleFallbacker::create_without_data() { + return ICU4XLocaleFallbacker(capi::ICU4XLocaleFallbacker_create_without_data()); +} +inline diplomat::result<ICU4XLocaleFallbackerWithConfig, ICU4XError> ICU4XLocaleFallbacker::for_config(ICU4XLocaleFallbackConfig config) const { + ICU4XLocaleFallbackConfig diplomat_wrapped_struct_config = config; + auto diplomat_result_raw_out_value = capi::ICU4XLocaleFallbacker_for_config(this->inner.get(), capi::ICU4XLocaleFallbackConfig{ .priority = static_cast<capi::ICU4XLocaleFallbackPriority>(diplomat_wrapped_struct_config.priority), .extension_key = { diplomat_wrapped_struct_config.extension_key.data(), diplomat_wrapped_struct_config.extension_key.size() }, .fallback_supplement = static_cast<capi::ICU4XLocaleFallbackSupplement>(diplomat_wrapped_struct_config.fallback_supplement) }); + diplomat::result<ICU4XLocaleFallbackerWithConfig, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XLocaleFallbackerWithConfig>(ICU4XLocaleFallbackerWithConfig(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XLocaleFallbackerWithConfig.h b/intl/icu_capi/cpp/include/ICU4XLocaleFallbackerWithConfig.h new file mode 100644 index 0000000000..e8baa9563e --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XLocaleFallbackerWithConfig.h @@ -0,0 +1,31 @@ +#ifndef ICU4XLocaleFallbackerWithConfig_H +#define ICU4XLocaleFallbackerWithConfig_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XLocaleFallbackerWithConfig ICU4XLocaleFallbackerWithConfig; +#ifdef __cplusplus +} // namespace capi +#endif +#include "ICU4XLocale.h" +#include "ICU4XLocaleFallbackIterator.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +ICU4XLocaleFallbackIterator* ICU4XLocaleFallbackerWithConfig_fallback_for_locale(const ICU4XLocaleFallbackerWithConfig* self, const ICU4XLocale* locale); +void ICU4XLocaleFallbackerWithConfig_destroy(ICU4XLocaleFallbackerWithConfig* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XLocaleFallbackerWithConfig.hpp b/intl/icu_capi/cpp/include/ICU4XLocaleFallbackerWithConfig.hpp new file mode 100644 index 0000000000..41f23cd0b0 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XLocaleFallbackerWithConfig.hpp @@ -0,0 +1,60 @@ +#ifndef ICU4XLocaleFallbackerWithConfig_HPP +#define ICU4XLocaleFallbackerWithConfig_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XLocaleFallbackerWithConfig.h" + +class ICU4XLocale; +class ICU4XLocaleFallbackIterator; + +/** + * A destruction policy for using ICU4XLocaleFallbackerWithConfig with std::unique_ptr. + */ +struct ICU4XLocaleFallbackerWithConfigDeleter { + void operator()(capi::ICU4XLocaleFallbackerWithConfig* l) const noexcept { + capi::ICU4XLocaleFallbackerWithConfig_destroy(l); + } +}; + +/** + * An object that runs the ICU4X locale fallback algorithm with specific configurations. + * + * See the [Rust documentation for `LocaleFallbacker`](https://docs.rs/icu/latest/icu/locid_transform/fallback/struct.LocaleFallbacker.html) for more information. + * + * See the [Rust documentation for `LocaleFallbackerWithConfig`](https://docs.rs/icu/latest/icu/locid_transform/fallback/struct.LocaleFallbackerWithConfig.html) for more information. + */ +class ICU4XLocaleFallbackerWithConfig { + public: + + /** + * Creates an iterator from a locale with each step of fallback. + * + * See the [Rust documentation for `fallback_for`](https://docs.rs/icu/latest/icu/locid_transform/fallback/struct.LocaleFallbacker.html#method.fallback_for) for more information. + * + * Lifetimes: `this` must live at least as long as the output. + */ + ICU4XLocaleFallbackIterator fallback_for_locale(const ICU4XLocale& locale) const; + inline const capi::ICU4XLocaleFallbackerWithConfig* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XLocaleFallbackerWithConfig* AsFFIMut() { return this->inner.get(); } + inline explicit ICU4XLocaleFallbackerWithConfig(capi::ICU4XLocaleFallbackerWithConfig* i) : inner(i) {} + ICU4XLocaleFallbackerWithConfig() = default; + ICU4XLocaleFallbackerWithConfig(ICU4XLocaleFallbackerWithConfig&&) noexcept = default; + ICU4XLocaleFallbackerWithConfig& operator=(ICU4XLocaleFallbackerWithConfig&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XLocaleFallbackerWithConfig, ICU4XLocaleFallbackerWithConfigDeleter> inner; +}; + +#include "ICU4XLocale.hpp" +#include "ICU4XLocaleFallbackIterator.hpp" + +inline ICU4XLocaleFallbackIterator ICU4XLocaleFallbackerWithConfig::fallback_for_locale(const ICU4XLocale& locale) const { + return ICU4XLocaleFallbackIterator(capi::ICU4XLocaleFallbackerWithConfig_fallback_for_locale(this->inner.get(), locale.AsFFI())); +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XLogger.h b/intl/icu_capi/cpp/include/ICU4XLogger.h new file mode 100644 index 0000000000..0aa1d0b1f9 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XLogger.h @@ -0,0 +1,31 @@ +#ifndef ICU4XLogger_H +#define ICU4XLogger_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XLogger ICU4XLogger; +#ifdef __cplusplus +} // namespace capi +#endif +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +bool ICU4XLogger_init_simple_logger(); + +bool ICU4XLogger_init_console_logger(); +void ICU4XLogger_destroy(ICU4XLogger* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XLogger.hpp b/intl/icu_capi/cpp/include/ICU4XLogger.hpp new file mode 100644 index 0000000000..4a15424673 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XLogger.hpp @@ -0,0 +1,60 @@ +#ifndef ICU4XLogger_HPP +#define ICU4XLogger_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XLogger.h" + + +/** + * A destruction policy for using ICU4XLogger with std::unique_ptr. + */ +struct ICU4XLoggerDeleter { + void operator()(capi::ICU4XLogger* l) const noexcept { + capi::ICU4XLogger_destroy(l); + } +}; + +/** + * An object allowing control over the logging used + */ +class ICU4XLogger { + public: + + /** + * Initialize the logger using `simple_logger` + * + * Requires the `simple_logger` Cargo feature. + * + * Returns `false` if there was already a logger set. + */ + static bool init_simple_logger(); + + /** + * Deprecated: since ICU4X 1.4, this now happens automatically if the `log` feature is enabled. + */ + static bool init_console_logger(); + inline const capi::ICU4XLogger* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XLogger* AsFFIMut() { return this->inner.get(); } + inline ICU4XLogger(capi::ICU4XLogger* i) : inner(i) {} + ICU4XLogger() = default; + ICU4XLogger(ICU4XLogger&&) noexcept = default; + ICU4XLogger& operator=(ICU4XLogger&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XLogger, ICU4XLoggerDeleter> inner; +}; + + +inline bool ICU4XLogger::init_simple_logger() { + return capi::ICU4XLogger_init_simple_logger(); +} +inline bool ICU4XLogger::init_console_logger() { + return capi::ICU4XLogger_init_console_logger(); +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XMetazoneCalculator.h b/intl/icu_capi/cpp/include/ICU4XMetazoneCalculator.h new file mode 100644 index 0000000000..9c66754e90 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XMetazoneCalculator.h @@ -0,0 +1,31 @@ +#ifndef ICU4XMetazoneCalculator_H +#define ICU4XMetazoneCalculator_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XMetazoneCalculator ICU4XMetazoneCalculator; +#ifdef __cplusplus +} // namespace capi +#endif +#include "ICU4XDataProvider.h" +#include "diplomat_result_box_ICU4XMetazoneCalculator_ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +diplomat_result_box_ICU4XMetazoneCalculator_ICU4XError ICU4XMetazoneCalculator_create(const ICU4XDataProvider* provider); +void ICU4XMetazoneCalculator_destroy(ICU4XMetazoneCalculator* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XMetazoneCalculator.hpp b/intl/icu_capi/cpp/include/ICU4XMetazoneCalculator.hpp new file mode 100644 index 0000000000..263219d07f --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XMetazoneCalculator.hpp @@ -0,0 +1,65 @@ +#ifndef ICU4XMetazoneCalculator_HPP +#define ICU4XMetazoneCalculator_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XMetazoneCalculator.h" + +class ICU4XDataProvider; +class ICU4XMetazoneCalculator; +#include "ICU4XError.hpp" + +/** + * A destruction policy for using ICU4XMetazoneCalculator with std::unique_ptr. + */ +struct ICU4XMetazoneCalculatorDeleter { + void operator()(capi::ICU4XMetazoneCalculator* l) const noexcept { + capi::ICU4XMetazoneCalculator_destroy(l); + } +}; + +/** + * An object capable of computing the metazone from a timezone. + * + * This can be used via `maybe_calculate_metazone()` on [`ICU4XCustomTimeZone`]. + * + * [`ICU4XCustomTimeZone`]: crate::timezone::ffi::ICU4XCustomTimeZone + * + * See the [Rust documentation for `MetazoneCalculator`](https://docs.rs/icu/latest/icu/timezone/struct.MetazoneCalculator.html) for more information. + */ +class ICU4XMetazoneCalculator { + public: + + /** + * See the [Rust documentation for `new`](https://docs.rs/icu/latest/icu/timezone/struct.MetazoneCalculator.html#method.new) for more information. + */ + static diplomat::result<ICU4XMetazoneCalculator, ICU4XError> create(const ICU4XDataProvider& provider); + inline const capi::ICU4XMetazoneCalculator* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XMetazoneCalculator* AsFFIMut() { return this->inner.get(); } + inline ICU4XMetazoneCalculator(capi::ICU4XMetazoneCalculator* i) : inner(i) {} + ICU4XMetazoneCalculator() = default; + ICU4XMetazoneCalculator(ICU4XMetazoneCalculator&&) noexcept = default; + ICU4XMetazoneCalculator& operator=(ICU4XMetazoneCalculator&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XMetazoneCalculator, ICU4XMetazoneCalculatorDeleter> inner; +}; + +#include "ICU4XDataProvider.hpp" + +inline diplomat::result<ICU4XMetazoneCalculator, ICU4XError> ICU4XMetazoneCalculator::create(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XMetazoneCalculator_create(provider.AsFFI()); + diplomat::result<ICU4XMetazoneCalculator, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XMetazoneCalculator>(ICU4XMetazoneCalculator(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XOrdering.h b/intl/icu_capi/cpp/include/ICU4XOrdering.h new file mode 100644 index 0000000000..2c1885f43e --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XOrdering.h @@ -0,0 +1,32 @@ +#ifndef ICU4XOrdering_H +#define ICU4XOrdering_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef enum ICU4XOrdering { + ICU4XOrdering_Less = -1, + ICU4XOrdering_Equal = 0, + ICU4XOrdering_Greater = 1, +} ICU4XOrdering; +#ifdef __cplusplus +} // namespace capi +#endif +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +void ICU4XOrdering_destroy(ICU4XOrdering* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XOrdering.hpp b/intl/icu_capi/cpp/include/ICU4XOrdering.hpp new file mode 100644 index 0000000000..77421325d0 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XOrdering.hpp @@ -0,0 +1,25 @@ +#ifndef ICU4XOrdering_HPP +#define ICU4XOrdering_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XOrdering.h" + + + +/** + * See the [Rust documentation for `Ordering`](https://docs.rs/core/latest/core/cmp/enum.Ordering.html) for more information. + */ +enum struct ICU4XOrdering { + Less = -1, + Equal = 0, + Greater = 1, +}; + +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XPluralCategories.h b/intl/icu_capi/cpp/include/ICU4XPluralCategories.h new file mode 100644 index 0000000000..931ea2daa7 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XPluralCategories.h @@ -0,0 +1,35 @@ +#ifndef ICU4XPluralCategories_H +#define ICU4XPluralCategories_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XPluralCategories { + bool zero; + bool one; + bool two; + bool few; + bool many; + bool other; +} ICU4XPluralCategories; +#ifdef __cplusplus +} // namespace capi +#endif +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +void ICU4XPluralCategories_destroy(ICU4XPluralCategories* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XPluralCategories.hpp b/intl/icu_capi/cpp/include/ICU4XPluralCategories.hpp new file mode 100644 index 0000000000..c8b4a767a4 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XPluralCategories.hpp @@ -0,0 +1,30 @@ +#ifndef ICU4XPluralCategories_HPP +#define ICU4XPluralCategories_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XPluralCategories.h" + + + +/** + * FFI version of `PluralRules::categories()` data. + */ +struct ICU4XPluralCategories { + public: + bool zero; + bool one; + bool two; + bool few; + bool many; + bool other; +}; + + +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XPluralCategory.h b/intl/icu_capi/cpp/include/ICU4XPluralCategory.h new file mode 100644 index 0000000000..543681c746 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XPluralCategory.h @@ -0,0 +1,37 @@ +#ifndef ICU4XPluralCategory_H +#define ICU4XPluralCategory_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef enum ICU4XPluralCategory { + ICU4XPluralCategory_Zero = 0, + ICU4XPluralCategory_One = 1, + ICU4XPluralCategory_Two = 2, + ICU4XPluralCategory_Few = 3, + ICU4XPluralCategory_Many = 4, + ICU4XPluralCategory_Other = 5, +} ICU4XPluralCategory; +#ifdef __cplusplus +} // namespace capi +#endif +#include "diplomat_result_ICU4XPluralCategory_void.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +diplomat_result_ICU4XPluralCategory_void ICU4XPluralCategory_get_for_cldr_string(const char* s_data, size_t s_len); +void ICU4XPluralCategory_destroy(ICU4XPluralCategory* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XPluralCategory.hpp b/intl/icu_capi/cpp/include/ICU4XPluralCategory.hpp new file mode 100644 index 0000000000..24db42ec21 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XPluralCategory.hpp @@ -0,0 +1,30 @@ +#ifndef ICU4XPluralCategory_HPP +#define ICU4XPluralCategory_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XPluralCategory.h" + + + +/** + * FFI version of `PluralCategory`. + * + * See the [Rust documentation for `PluralCategory`](https://docs.rs/icu/latest/icu/plurals/enum.PluralCategory.html) for more information. + */ +enum struct ICU4XPluralCategory { + Zero = 0, + One = 1, + Two = 2, + Few = 3, + Many = 4, + Other = 5, +}; + +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XPluralOperands.h b/intl/icu_capi/cpp/include/ICU4XPluralOperands.h new file mode 100644 index 0000000000..14d997555f --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XPluralOperands.h @@ -0,0 +1,30 @@ +#ifndef ICU4XPluralOperands_H +#define ICU4XPluralOperands_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XPluralOperands ICU4XPluralOperands; +#ifdef __cplusplus +} // namespace capi +#endif +#include "diplomat_result_box_ICU4XPluralOperands_ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +diplomat_result_box_ICU4XPluralOperands_ICU4XError ICU4XPluralOperands_create_from_string(const char* s_data, size_t s_len); +void ICU4XPluralOperands_destroy(ICU4XPluralOperands* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XPluralOperands.hpp b/intl/icu_capi/cpp/include/ICU4XPluralOperands.hpp new file mode 100644 index 0000000000..635011f14f --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XPluralOperands.hpp @@ -0,0 +1,61 @@ +#ifndef ICU4XPluralOperands_HPP +#define ICU4XPluralOperands_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XPluralOperands.h" + +class ICU4XPluralOperands; +#include "ICU4XError.hpp" + +/** + * A destruction policy for using ICU4XPluralOperands with std::unique_ptr. + */ +struct ICU4XPluralOperandsDeleter { + void operator()(capi::ICU4XPluralOperands* l) const noexcept { + capi::ICU4XPluralOperands_destroy(l); + } +}; + +/** + * FFI version of `PluralOperands`. + * + * See the [Rust documentation for `PluralOperands`](https://docs.rs/icu/latest/icu/plurals/struct.PluralOperands.html) for more information. + */ +class ICU4XPluralOperands { + public: + + /** + * Construct for a given string representing a number + * + * See the [Rust documentation for `from_str`](https://docs.rs/icu/latest/icu/plurals/struct.PluralOperands.html#method.from_str) for more information. + */ + static diplomat::result<ICU4XPluralOperands, ICU4XError> create_from_string(const std::string_view s); + inline const capi::ICU4XPluralOperands* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XPluralOperands* AsFFIMut() { return this->inner.get(); } + inline ICU4XPluralOperands(capi::ICU4XPluralOperands* i) : inner(i) {} + ICU4XPluralOperands() = default; + ICU4XPluralOperands(ICU4XPluralOperands&&) noexcept = default; + ICU4XPluralOperands& operator=(ICU4XPluralOperands&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XPluralOperands, ICU4XPluralOperandsDeleter> inner; +}; + + +inline diplomat::result<ICU4XPluralOperands, ICU4XError> ICU4XPluralOperands::create_from_string(const std::string_view s) { + auto diplomat_result_raw_out_value = capi::ICU4XPluralOperands_create_from_string(s.data(), s.size()); + diplomat::result<ICU4XPluralOperands, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XPluralOperands>(ICU4XPluralOperands(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XPluralRules.h b/intl/icu_capi/cpp/include/ICU4XPluralRules.h new file mode 100644 index 0000000000..0794a7ac8e --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XPluralRules.h @@ -0,0 +1,41 @@ +#ifndef ICU4XPluralRules_H +#define ICU4XPluralRules_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XPluralRules ICU4XPluralRules; +#ifdef __cplusplus +} // namespace capi +#endif +#include "ICU4XDataProvider.h" +#include "ICU4XLocale.h" +#include "diplomat_result_box_ICU4XPluralRules_ICU4XError.h" +#include "ICU4XPluralOperands.h" +#include "ICU4XPluralCategory.h" +#include "ICU4XPluralCategories.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +diplomat_result_box_ICU4XPluralRules_ICU4XError ICU4XPluralRules_create_cardinal(const ICU4XDataProvider* provider, const ICU4XLocale* locale); + +diplomat_result_box_ICU4XPluralRules_ICU4XError ICU4XPluralRules_create_ordinal(const ICU4XDataProvider* provider, const ICU4XLocale* locale); + +ICU4XPluralCategory ICU4XPluralRules_category_for(const ICU4XPluralRules* self, const ICU4XPluralOperands* op); + +ICU4XPluralCategories ICU4XPluralRules_categories(const ICU4XPluralRules* self); +void ICU4XPluralRules_destroy(ICU4XPluralRules* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XPluralRules.hpp b/intl/icu_capi/cpp/include/ICU4XPluralRules.hpp new file mode 100644 index 0000000000..adab9ba4a1 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XPluralRules.hpp @@ -0,0 +1,108 @@ +#ifndef ICU4XPluralRules_HPP +#define ICU4XPluralRules_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XPluralRules.h" + +class ICU4XDataProvider; +class ICU4XLocale; +class ICU4XPluralRules; +#include "ICU4XError.hpp" +class ICU4XPluralOperands; +#include "ICU4XPluralCategory.hpp" +struct ICU4XPluralCategories; + +/** + * A destruction policy for using ICU4XPluralRules with std::unique_ptr. + */ +struct ICU4XPluralRulesDeleter { + void operator()(capi::ICU4XPluralRules* l) const noexcept { + capi::ICU4XPluralRules_destroy(l); + } +}; + +/** + * FFI version of `PluralRules`. + * + * See the [Rust documentation for `PluralRules`](https://docs.rs/icu/latest/icu/plurals/struct.PluralRules.html) for more information. + */ +class ICU4XPluralRules { + public: + + /** + * Construct an [`ICU4XPluralRules`] for the given locale, for cardinal numbers + * + * See the [Rust documentation for `try_new_cardinal`](https://docs.rs/icu/latest/icu/plurals/struct.PluralRules.html#method.try_new_cardinal) for more information. + */ + static diplomat::result<ICU4XPluralRules, ICU4XError> create_cardinal(const ICU4XDataProvider& provider, const ICU4XLocale& locale); + + /** + * Construct an [`ICU4XPluralRules`] for the given locale, for ordinal numbers + * + * See the [Rust documentation for `try_new_ordinal`](https://docs.rs/icu/latest/icu/plurals/struct.PluralRules.html#method.try_new_ordinal) for more information. + */ + static diplomat::result<ICU4XPluralRules, ICU4XError> create_ordinal(const ICU4XDataProvider& provider, const ICU4XLocale& locale); + + /** + * Get the category for a given number represented as operands + * + * See the [Rust documentation for `category_for`](https://docs.rs/icu/latest/icu/plurals/struct.PluralRules.html#method.category_for) for more information. + */ + ICU4XPluralCategory category_for(const ICU4XPluralOperands& op) const; + + /** + * Get all of the categories needed in the current locale + * + * See the [Rust documentation for `categories`](https://docs.rs/icu/latest/icu/plurals/struct.PluralRules.html#method.categories) for more information. + */ + ICU4XPluralCategories categories() const; + inline const capi::ICU4XPluralRules* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XPluralRules* AsFFIMut() { return this->inner.get(); } + inline ICU4XPluralRules(capi::ICU4XPluralRules* i) : inner(i) {} + ICU4XPluralRules() = default; + ICU4XPluralRules(ICU4XPluralRules&&) noexcept = default; + ICU4XPluralRules& operator=(ICU4XPluralRules&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XPluralRules, ICU4XPluralRulesDeleter> inner; +}; + +#include "ICU4XDataProvider.hpp" +#include "ICU4XLocale.hpp" +#include "ICU4XPluralOperands.hpp" +#include "ICU4XPluralCategories.hpp" + +inline diplomat::result<ICU4XPluralRules, ICU4XError> ICU4XPluralRules::create_cardinal(const ICU4XDataProvider& provider, const ICU4XLocale& locale) { + auto diplomat_result_raw_out_value = capi::ICU4XPluralRules_create_cardinal(provider.AsFFI(), locale.AsFFI()); + diplomat::result<ICU4XPluralRules, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XPluralRules>(ICU4XPluralRules(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XPluralRules, ICU4XError> ICU4XPluralRules::create_ordinal(const ICU4XDataProvider& provider, const ICU4XLocale& locale) { + auto diplomat_result_raw_out_value = capi::ICU4XPluralRules_create_ordinal(provider.AsFFI(), locale.AsFFI()); + diplomat::result<ICU4XPluralRules, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XPluralRules>(ICU4XPluralRules(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline ICU4XPluralCategory ICU4XPluralRules::category_for(const ICU4XPluralOperands& op) const { + return static_cast<ICU4XPluralCategory>(capi::ICU4XPluralRules_category_for(this->inner.get(), op.AsFFI())); +} +inline ICU4XPluralCategories ICU4XPluralRules::categories() const { + capi::ICU4XPluralCategories diplomat_raw_struct_out_value = capi::ICU4XPluralRules_categories(this->inner.get()); + return ICU4XPluralCategories{ .zero = std::move(diplomat_raw_struct_out_value.zero), .one = std::move(diplomat_raw_struct_out_value.one), .two = std::move(diplomat_raw_struct_out_value.two), .few = std::move(diplomat_raw_struct_out_value.few), .many = std::move(diplomat_raw_struct_out_value.many), .other = std::move(diplomat_raw_struct_out_value.other) }; +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XPropertyValueNameToEnumMapper.h b/intl/icu_capi/cpp/include/ICU4XPropertyValueNameToEnumMapper.h new file mode 100644 index 0000000000..54000ce338 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XPropertyValueNameToEnumMapper.h @@ -0,0 +1,51 @@ +#ifndef ICU4XPropertyValueNameToEnumMapper_H +#define ICU4XPropertyValueNameToEnumMapper_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XPropertyValueNameToEnumMapper ICU4XPropertyValueNameToEnumMapper; +#ifdef __cplusplus +} // namespace capi +#endif +#include "ICU4XDataProvider.h" +#include "diplomat_result_box_ICU4XPropertyValueNameToEnumMapper_ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +int16_t ICU4XPropertyValueNameToEnumMapper_get_strict(const ICU4XPropertyValueNameToEnumMapper* self, const char* name_data, size_t name_len); + +int16_t ICU4XPropertyValueNameToEnumMapper_get_loose(const ICU4XPropertyValueNameToEnumMapper* self, const char* name_data, size_t name_len); + +diplomat_result_box_ICU4XPropertyValueNameToEnumMapper_ICU4XError ICU4XPropertyValueNameToEnumMapper_load_general_category(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XPropertyValueNameToEnumMapper_ICU4XError ICU4XPropertyValueNameToEnumMapper_load_bidi_class(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XPropertyValueNameToEnumMapper_ICU4XError ICU4XPropertyValueNameToEnumMapper_load_east_asian_width(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XPropertyValueNameToEnumMapper_ICU4XError ICU4XPropertyValueNameToEnumMapper_load_indic_syllabic_category(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XPropertyValueNameToEnumMapper_ICU4XError ICU4XPropertyValueNameToEnumMapper_load_line_break(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XPropertyValueNameToEnumMapper_ICU4XError ICU4XPropertyValueNameToEnumMapper_load_grapheme_cluster_break(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XPropertyValueNameToEnumMapper_ICU4XError ICU4XPropertyValueNameToEnumMapper_load_word_break(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XPropertyValueNameToEnumMapper_ICU4XError ICU4XPropertyValueNameToEnumMapper_load_sentence_break(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XPropertyValueNameToEnumMapper_ICU4XError ICU4XPropertyValueNameToEnumMapper_load_script(const ICU4XDataProvider* provider); +void ICU4XPropertyValueNameToEnumMapper_destroy(ICU4XPropertyValueNameToEnumMapper* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XPropertyValueNameToEnumMapper.hpp b/intl/icu_capi/cpp/include/ICU4XPropertyValueNameToEnumMapper.hpp new file mode 100644 index 0000000000..b690dee096 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XPropertyValueNameToEnumMapper.hpp @@ -0,0 +1,207 @@ +#ifndef ICU4XPropertyValueNameToEnumMapper_HPP +#define ICU4XPropertyValueNameToEnumMapper_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XPropertyValueNameToEnumMapper.h" + +class ICU4XDataProvider; +class ICU4XPropertyValueNameToEnumMapper; +#include "ICU4XError.hpp" + +/** + * A destruction policy for using ICU4XPropertyValueNameToEnumMapper with std::unique_ptr. + */ +struct ICU4XPropertyValueNameToEnumMapperDeleter { + void operator()(capi::ICU4XPropertyValueNameToEnumMapper* l) const noexcept { + capi::ICU4XPropertyValueNameToEnumMapper_destroy(l); + } +}; + +/** + * A type capable of looking up a property value from a string name. + * + * See the [Rust documentation for `PropertyValueNameToEnumMapper`](https://docs.rs/icu/latest/icu/properties/names/struct.PropertyValueNameToEnumMapper.html) for more information. + * + * See the [Rust documentation for `PropertyValueNameToEnumMapperBorrowed`](https://docs.rs/icu/latest/icu/properties/names/struct.PropertyValueNameToEnumMapperBorrowed.html) for more information. + */ +class ICU4XPropertyValueNameToEnumMapper { + public: + + /** + * Get the property value matching the given name, using strict matching + * + * Returns -1 if the name is unknown for this property + * + * See the [Rust documentation for `get_strict`](https://docs.rs/icu/latest/icu/properties/names/struct.PropertyValueNameToEnumMapperBorrowed.html#method.get_strict) for more information. + */ + int16_t get_strict(const std::string_view name) const; + + /** + * Get the property value matching the given name, using loose matching + * + * Returns -1 if the name is unknown for this property + * + * See the [Rust documentation for `get_loose`](https://docs.rs/icu/latest/icu/properties/names/struct.PropertyValueNameToEnumMapperBorrowed.html#method.get_loose) for more information. + */ + int16_t get_loose(const std::string_view name) const; + + /** + * See the [Rust documentation for `get_name_to_enum_mapper`](https://docs.rs/icu/latest/icu/properties/struct.GeneralCategory.html#method.get_name_to_enum_mapper) for more information. + */ + static diplomat::result<ICU4XPropertyValueNameToEnumMapper, ICU4XError> load_general_category(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `name_to_enum_mapper`](https://docs.rs/icu/latest/icu/properties/struct.BidiClass.html#method.name_to_enum_mapper) for more information. + */ + static diplomat::result<ICU4XPropertyValueNameToEnumMapper, ICU4XError> load_bidi_class(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `name_to_enum_mapper`](https://docs.rs/icu/latest/icu/properties/struct.EastAsianWidth.html#method.name_to_enum_mapper) for more information. + */ + static diplomat::result<ICU4XPropertyValueNameToEnumMapper, ICU4XError> load_east_asian_width(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `name_to_enum_mapper`](https://docs.rs/icu/latest/icu/properties/struct.IndicSyllabicCategory.html#method.name_to_enum_mapper) for more information. + */ + static diplomat::result<ICU4XPropertyValueNameToEnumMapper, ICU4XError> load_indic_syllabic_category(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `name_to_enum_mapper`](https://docs.rs/icu/latest/icu/properties/struct.LineBreak.html#method.name_to_enum_mapper) for more information. + */ + static diplomat::result<ICU4XPropertyValueNameToEnumMapper, ICU4XError> load_line_break(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `get_name_to_enum_mapper`](https://docs.rs/icu/latest/icu/properties/struct.GraphemeClusterBreak.html#method.get_name_to_enum_mapper) for more information. + */ + static diplomat::result<ICU4XPropertyValueNameToEnumMapper, ICU4XError> load_grapheme_cluster_break(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `name_to_enum_mapper`](https://docs.rs/icu/latest/icu/properties/struct.WordBreak.html#method.name_to_enum_mapper) for more information. + */ + static diplomat::result<ICU4XPropertyValueNameToEnumMapper, ICU4XError> load_word_break(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `name_to_enum_mapper`](https://docs.rs/icu/latest/icu/properties/struct.SentenceBreak.html#method.name_to_enum_mapper) for more information. + */ + static diplomat::result<ICU4XPropertyValueNameToEnumMapper, ICU4XError> load_sentence_break(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `name_to_enum_mapper`](https://docs.rs/icu/latest/icu/properties/struct.Script.html#method.name_to_enum_mapper) for more information. + */ + static diplomat::result<ICU4XPropertyValueNameToEnumMapper, ICU4XError> load_script(const ICU4XDataProvider& provider); + inline const capi::ICU4XPropertyValueNameToEnumMapper* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XPropertyValueNameToEnumMapper* AsFFIMut() { return this->inner.get(); } + inline ICU4XPropertyValueNameToEnumMapper(capi::ICU4XPropertyValueNameToEnumMapper* i) : inner(i) {} + ICU4XPropertyValueNameToEnumMapper() = default; + ICU4XPropertyValueNameToEnumMapper(ICU4XPropertyValueNameToEnumMapper&&) noexcept = default; + ICU4XPropertyValueNameToEnumMapper& operator=(ICU4XPropertyValueNameToEnumMapper&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XPropertyValueNameToEnumMapper, ICU4XPropertyValueNameToEnumMapperDeleter> inner; +}; + +#include "ICU4XDataProvider.hpp" + +inline int16_t ICU4XPropertyValueNameToEnumMapper::get_strict(const std::string_view name) const { + return capi::ICU4XPropertyValueNameToEnumMapper_get_strict(this->inner.get(), name.data(), name.size()); +} +inline int16_t ICU4XPropertyValueNameToEnumMapper::get_loose(const std::string_view name) const { + return capi::ICU4XPropertyValueNameToEnumMapper_get_loose(this->inner.get(), name.data(), name.size()); +} +inline diplomat::result<ICU4XPropertyValueNameToEnumMapper, ICU4XError> ICU4XPropertyValueNameToEnumMapper::load_general_category(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XPropertyValueNameToEnumMapper_load_general_category(provider.AsFFI()); + diplomat::result<ICU4XPropertyValueNameToEnumMapper, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XPropertyValueNameToEnumMapper>(ICU4XPropertyValueNameToEnumMapper(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XPropertyValueNameToEnumMapper, ICU4XError> ICU4XPropertyValueNameToEnumMapper::load_bidi_class(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XPropertyValueNameToEnumMapper_load_bidi_class(provider.AsFFI()); + diplomat::result<ICU4XPropertyValueNameToEnumMapper, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XPropertyValueNameToEnumMapper>(ICU4XPropertyValueNameToEnumMapper(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XPropertyValueNameToEnumMapper, ICU4XError> ICU4XPropertyValueNameToEnumMapper::load_east_asian_width(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XPropertyValueNameToEnumMapper_load_east_asian_width(provider.AsFFI()); + diplomat::result<ICU4XPropertyValueNameToEnumMapper, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XPropertyValueNameToEnumMapper>(ICU4XPropertyValueNameToEnumMapper(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XPropertyValueNameToEnumMapper, ICU4XError> ICU4XPropertyValueNameToEnumMapper::load_indic_syllabic_category(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XPropertyValueNameToEnumMapper_load_indic_syllabic_category(provider.AsFFI()); + diplomat::result<ICU4XPropertyValueNameToEnumMapper, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XPropertyValueNameToEnumMapper>(ICU4XPropertyValueNameToEnumMapper(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XPropertyValueNameToEnumMapper, ICU4XError> ICU4XPropertyValueNameToEnumMapper::load_line_break(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XPropertyValueNameToEnumMapper_load_line_break(provider.AsFFI()); + diplomat::result<ICU4XPropertyValueNameToEnumMapper, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XPropertyValueNameToEnumMapper>(ICU4XPropertyValueNameToEnumMapper(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XPropertyValueNameToEnumMapper, ICU4XError> ICU4XPropertyValueNameToEnumMapper::load_grapheme_cluster_break(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XPropertyValueNameToEnumMapper_load_grapheme_cluster_break(provider.AsFFI()); + diplomat::result<ICU4XPropertyValueNameToEnumMapper, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XPropertyValueNameToEnumMapper>(ICU4XPropertyValueNameToEnumMapper(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XPropertyValueNameToEnumMapper, ICU4XError> ICU4XPropertyValueNameToEnumMapper::load_word_break(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XPropertyValueNameToEnumMapper_load_word_break(provider.AsFFI()); + diplomat::result<ICU4XPropertyValueNameToEnumMapper, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XPropertyValueNameToEnumMapper>(ICU4XPropertyValueNameToEnumMapper(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XPropertyValueNameToEnumMapper, ICU4XError> ICU4XPropertyValueNameToEnumMapper::load_sentence_break(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XPropertyValueNameToEnumMapper_load_sentence_break(provider.AsFFI()); + diplomat::result<ICU4XPropertyValueNameToEnumMapper, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XPropertyValueNameToEnumMapper>(ICU4XPropertyValueNameToEnumMapper(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XPropertyValueNameToEnumMapper, ICU4XError> ICU4XPropertyValueNameToEnumMapper::load_script(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XPropertyValueNameToEnumMapper_load_script(provider.AsFFI()); + diplomat::result<ICU4XPropertyValueNameToEnumMapper, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XPropertyValueNameToEnumMapper>(ICU4XPropertyValueNameToEnumMapper(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XRegionDisplayNames.h b/intl/icu_capi/cpp/include/ICU4XRegionDisplayNames.h new file mode 100644 index 0000000000..a78ec64865 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XRegionDisplayNames.h @@ -0,0 +1,35 @@ +#ifndef ICU4XRegionDisplayNames_H +#define ICU4XRegionDisplayNames_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XRegionDisplayNames ICU4XRegionDisplayNames; +#ifdef __cplusplus +} // namespace capi +#endif +#include "ICU4XDataProvider.h" +#include "ICU4XLocale.h" +#include "diplomat_result_box_ICU4XRegionDisplayNames_ICU4XError.h" +#include "diplomat_result_void_ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +diplomat_result_box_ICU4XRegionDisplayNames_ICU4XError ICU4XRegionDisplayNames_create(const ICU4XDataProvider* provider, const ICU4XLocale* locale); + +diplomat_result_void_ICU4XError ICU4XRegionDisplayNames_of(const ICU4XRegionDisplayNames* self, const char* region_data, size_t region_len, DiplomatWriteable* write); +void ICU4XRegionDisplayNames_destroy(ICU4XRegionDisplayNames* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XRegionDisplayNames.hpp b/intl/icu_capi/cpp/include/ICU4XRegionDisplayNames.hpp new file mode 100644 index 0000000000..b8ab50e0c1 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XRegionDisplayNames.hpp @@ -0,0 +1,104 @@ +#ifndef ICU4XRegionDisplayNames_HPP +#define ICU4XRegionDisplayNames_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XRegionDisplayNames.h" + +class ICU4XDataProvider; +class ICU4XLocale; +class ICU4XRegionDisplayNames; +#include "ICU4XError.hpp" + +/** + * A destruction policy for using ICU4XRegionDisplayNames with std::unique_ptr. + */ +struct ICU4XRegionDisplayNamesDeleter { + void operator()(capi::ICU4XRegionDisplayNames* l) const noexcept { + capi::ICU4XRegionDisplayNames_destroy(l); + } +}; + +/** + * See the [Rust documentation for `RegionDisplayNames`](https://docs.rs/icu/latest/icu/displaynames/struct.RegionDisplayNames.html) for more information. + */ +class ICU4XRegionDisplayNames { + public: + + /** + * Creates a new `RegionDisplayNames` from locale data and an options bag. + * + * See the [Rust documentation for `try_new`](https://docs.rs/icu/latest/icu/displaynames/struct.RegionDisplayNames.html#method.try_new) for more information. + */ + static diplomat::result<ICU4XRegionDisplayNames, ICU4XError> create(const ICU4XDataProvider& provider, const ICU4XLocale& locale); + + /** + * Returns the locale specific display name of a region. + * Note that the funtion returns an empty string in case the display name for a given + * region code is not found. + * + * See the [Rust documentation for `of`](https://docs.rs/icu/latest/icu/displaynames/struct.RegionDisplayNames.html#method.of) for more information. + */ + template<typename W> diplomat::result<std::monostate, ICU4XError> of_to_writeable(const std::string_view region, W& write) const; + + /** + * Returns the locale specific display name of a region. + * Note that the funtion returns an empty string in case the display name for a given + * region code is not found. + * + * See the [Rust documentation for `of`](https://docs.rs/icu/latest/icu/displaynames/struct.RegionDisplayNames.html#method.of) for more information. + */ + diplomat::result<std::string, ICU4XError> of(const std::string_view region) const; + inline const capi::ICU4XRegionDisplayNames* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XRegionDisplayNames* AsFFIMut() { return this->inner.get(); } + inline ICU4XRegionDisplayNames(capi::ICU4XRegionDisplayNames* i) : inner(i) {} + ICU4XRegionDisplayNames() = default; + ICU4XRegionDisplayNames(ICU4XRegionDisplayNames&&) noexcept = default; + ICU4XRegionDisplayNames& operator=(ICU4XRegionDisplayNames&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XRegionDisplayNames, ICU4XRegionDisplayNamesDeleter> inner; +}; + +#include "ICU4XDataProvider.hpp" +#include "ICU4XLocale.hpp" + +inline diplomat::result<ICU4XRegionDisplayNames, ICU4XError> ICU4XRegionDisplayNames::create(const ICU4XDataProvider& provider, const ICU4XLocale& locale) { + auto diplomat_result_raw_out_value = capi::ICU4XRegionDisplayNames_create(provider.AsFFI(), locale.AsFFI()); + diplomat::result<ICU4XRegionDisplayNames, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XRegionDisplayNames>(ICU4XRegionDisplayNames(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XRegionDisplayNames::of_to_writeable(const std::string_view region, W& write) const { + capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write); + auto diplomat_result_raw_out_value = capi::ICU4XRegionDisplayNames_of(this->inner.get(), region.data(), region.size(), &write_writer); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<std::string, ICU4XError> ICU4XRegionDisplayNames::of(const std::string_view region) const { + std::string diplomat_writeable_string; + capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); + auto diplomat_result_raw_out_value = capi::ICU4XRegionDisplayNames_of(this->inner.get(), region.data(), region.size(), &diplomat_writeable_out); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string)); +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XReorderedIndexMap.h b/intl/icu_capi/cpp/include/ICU4XReorderedIndexMap.h new file mode 100644 index 0000000000..f5507a7217 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XReorderedIndexMap.h @@ -0,0 +1,33 @@ +#ifndef ICU4XReorderedIndexMap_H +#define ICU4XReorderedIndexMap_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XReorderedIndexMap ICU4XReorderedIndexMap; +#ifdef __cplusplus +} // namespace capi +#endif +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +DiplomatUsizeView ICU4XReorderedIndexMap_as_slice(const ICU4XReorderedIndexMap* self); + +size_t ICU4XReorderedIndexMap_len(const ICU4XReorderedIndexMap* self); + +size_t ICU4XReorderedIndexMap_get(const ICU4XReorderedIndexMap* self, size_t index); +void ICU4XReorderedIndexMap_destroy(ICU4XReorderedIndexMap* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XReorderedIndexMap.hpp b/intl/icu_capi/cpp/include/ICU4XReorderedIndexMap.hpp new file mode 100644 index 0000000000..1fe4270baa --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XReorderedIndexMap.hpp @@ -0,0 +1,74 @@ +#ifndef ICU4XReorderedIndexMap_HPP +#define ICU4XReorderedIndexMap_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XReorderedIndexMap.h" + + +/** + * A destruction policy for using ICU4XReorderedIndexMap with std::unique_ptr. + */ +struct ICU4XReorderedIndexMapDeleter { + void operator()(capi::ICU4XReorderedIndexMap* l) const noexcept { + capi::ICU4XReorderedIndexMap_destroy(l); + } +}; + +/** + * Thin wrapper around a vector that maps visual indices to source indices + * + * `map[visualIndex] = sourceIndex` + * + * Produced by `reorder_visual()` on [`ICU4XBidi`]. + */ +class ICU4XReorderedIndexMap { + public: + + /** + * Get this as a slice/array of indices + * + * Lifetimes: `this` must live at least as long as the output. + */ + const diplomat::span<const size_t> as_slice() const; + + /** + * The length of this map + */ + size_t len() const; + + /** + * Get element at `index`. Returns 0 when out of bounds + * (note that 0 is also a valid in-bounds value, please use `len()` + * to avoid out-of-bounds) + */ + size_t get(size_t index) const; + inline const capi::ICU4XReorderedIndexMap* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XReorderedIndexMap* AsFFIMut() { return this->inner.get(); } + inline ICU4XReorderedIndexMap(capi::ICU4XReorderedIndexMap* i) : inner(i) {} + ICU4XReorderedIndexMap() = default; + ICU4XReorderedIndexMap(ICU4XReorderedIndexMap&&) noexcept = default; + ICU4XReorderedIndexMap& operator=(ICU4XReorderedIndexMap&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XReorderedIndexMap, ICU4XReorderedIndexMapDeleter> inner; +}; + + +inline const diplomat::span<const size_t> ICU4XReorderedIndexMap::as_slice() const { + capi::DiplomatUsizeView diplomat_slice_raw_out_value = capi::ICU4XReorderedIndexMap_as_slice(this->inner.get()); + diplomat::span<const size_t> slice(diplomat_slice_raw_out_value.data, diplomat_slice_raw_out_value.len); + return slice; +} +inline size_t ICU4XReorderedIndexMap::len() const { + return capi::ICU4XReorderedIndexMap_len(this->inner.get()); +} +inline size_t ICU4XReorderedIndexMap::get(size_t index) const { + return capi::ICU4XReorderedIndexMap_get(this->inner.get(), index); +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XRoundingIncrement.h b/intl/icu_capi/cpp/include/ICU4XRoundingIncrement.h new file mode 100644 index 0000000000..c4b0666bef --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XRoundingIncrement.h @@ -0,0 +1,33 @@ +#ifndef ICU4XRoundingIncrement_H +#define ICU4XRoundingIncrement_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef enum ICU4XRoundingIncrement { + ICU4XRoundingIncrement_MultiplesOf1 = 0, + ICU4XRoundingIncrement_MultiplesOf2 = 1, + ICU4XRoundingIncrement_MultiplesOf5 = 2, + ICU4XRoundingIncrement_MultiplesOf25 = 3, +} ICU4XRoundingIncrement; +#ifdef __cplusplus +} // namespace capi +#endif +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +void ICU4XRoundingIncrement_destroy(ICU4XRoundingIncrement* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XRoundingIncrement.hpp b/intl/icu_capi/cpp/include/ICU4XRoundingIncrement.hpp new file mode 100644 index 0000000000..be93aa0401 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XRoundingIncrement.hpp @@ -0,0 +1,28 @@ +#ifndef ICU4XRoundingIncrement_HPP +#define ICU4XRoundingIncrement_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XRoundingIncrement.h" + + + +/** + * Increment used in a rounding operation. + * + * See the [Rust documentation for `RoundingIncrement`](https://docs.rs/fixed_decimal/latest/fixed_decimal/enum.RoundingIncrement.html) for more information. + */ +enum struct ICU4XRoundingIncrement { + MultiplesOf1 = 0, + MultiplesOf2 = 1, + MultiplesOf5 = 2, + MultiplesOf25 = 3, +}; + +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XScriptExtensionsSet.h b/intl/icu_capi/cpp/include/ICU4XScriptExtensionsSet.h new file mode 100644 index 0000000000..b4982dc22c --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XScriptExtensionsSet.h @@ -0,0 +1,34 @@ +#ifndef ICU4XScriptExtensionsSet_H +#define ICU4XScriptExtensionsSet_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XScriptExtensionsSet ICU4XScriptExtensionsSet; +#ifdef __cplusplus +} // namespace capi +#endif +#include "diplomat_result_uint16_t_void.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +bool ICU4XScriptExtensionsSet_contains(const ICU4XScriptExtensionsSet* self, uint16_t script); + +size_t ICU4XScriptExtensionsSet_count(const ICU4XScriptExtensionsSet* self); + +diplomat_result_uint16_t_void ICU4XScriptExtensionsSet_script_at(const ICU4XScriptExtensionsSet* self, size_t index); +void ICU4XScriptExtensionsSet_destroy(ICU4XScriptExtensionsSet* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XScriptExtensionsSet.hpp b/intl/icu_capi/cpp/include/ICU4XScriptExtensionsSet.hpp new file mode 100644 index 0000000000..fb2893634d --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XScriptExtensionsSet.hpp @@ -0,0 +1,79 @@ +#ifndef ICU4XScriptExtensionsSet_HPP +#define ICU4XScriptExtensionsSet_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XScriptExtensionsSet.h" + + +/** + * A destruction policy for using ICU4XScriptExtensionsSet with std::unique_ptr. + */ +struct ICU4XScriptExtensionsSetDeleter { + void operator()(capi::ICU4XScriptExtensionsSet* l) const noexcept { + capi::ICU4XScriptExtensionsSet_destroy(l); + } +}; + +/** + * An object that represents the Script_Extensions property for a single character + * + * See the [Rust documentation for `ScriptExtensionsSet`](https://docs.rs/icu/latest/icu/properties/script/struct.ScriptExtensionsSet.html) for more information. + */ +class ICU4XScriptExtensionsSet { + public: + + /** + * Check if the Script_Extensions property of the given code point covers the given script + * + * See the [Rust documentation for `contains`](https://docs.rs/icu/latest/icu/properties/script/struct.ScriptExtensionsSet.html#method.contains) for more information. + */ + bool contains(uint16_t script) const; + + /** + * Get the number of scripts contained in here + * + * See the [Rust documentation for `iter`](https://docs.rs/icu/latest/icu/properties/script/struct.ScriptExtensionsSet.html#method.iter) for more information. + */ + size_t count() const; + + /** + * Get script at index, returning an error if out of bounds + * + * See the [Rust documentation for `iter`](https://docs.rs/icu/latest/icu/properties/script/struct.ScriptExtensionsSet.html#method.iter) for more information. + */ + diplomat::result<uint16_t, std::monostate> script_at(size_t index) const; + inline const capi::ICU4XScriptExtensionsSet* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XScriptExtensionsSet* AsFFIMut() { return this->inner.get(); } + inline ICU4XScriptExtensionsSet(capi::ICU4XScriptExtensionsSet* i) : inner(i) {} + ICU4XScriptExtensionsSet() = default; + ICU4XScriptExtensionsSet(ICU4XScriptExtensionsSet&&) noexcept = default; + ICU4XScriptExtensionsSet& operator=(ICU4XScriptExtensionsSet&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XScriptExtensionsSet, ICU4XScriptExtensionsSetDeleter> inner; +}; + + +inline bool ICU4XScriptExtensionsSet::contains(uint16_t script) const { + return capi::ICU4XScriptExtensionsSet_contains(this->inner.get(), script); +} +inline size_t ICU4XScriptExtensionsSet::count() const { + return capi::ICU4XScriptExtensionsSet_count(this->inner.get()); +} +inline diplomat::result<uint16_t, std::monostate> ICU4XScriptExtensionsSet::script_at(size_t index) const { + auto diplomat_result_raw_out_value = capi::ICU4XScriptExtensionsSet_script_at(this->inner.get(), index); + diplomat::result<uint16_t, std::monostate> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<uint16_t>(diplomat_result_raw_out_value.ok); + } else { + diplomat_result_out_value = diplomat::Err(std::monostate()); + } + return diplomat_result_out_value; +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XScriptWithExtensions.h b/intl/icu_capi/cpp/include/ICU4XScriptWithExtensions.h new file mode 100644 index 0000000000..df2dd53946 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XScriptWithExtensions.h @@ -0,0 +1,41 @@ +#ifndef ICU4XScriptWithExtensions_H +#define ICU4XScriptWithExtensions_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XScriptWithExtensions ICU4XScriptWithExtensions; +#ifdef __cplusplus +} // namespace capi +#endif +#include "ICU4XDataProvider.h" +#include "diplomat_result_box_ICU4XScriptWithExtensions_ICU4XError.h" +#include "ICU4XScriptWithExtensionsBorrowed.h" +#include "CodePointRangeIterator.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +diplomat_result_box_ICU4XScriptWithExtensions_ICU4XError ICU4XScriptWithExtensions_create(const ICU4XDataProvider* provider); + +uint16_t ICU4XScriptWithExtensions_get_script_val(const ICU4XScriptWithExtensions* self, uint32_t code_point); + +bool ICU4XScriptWithExtensions_has_script(const ICU4XScriptWithExtensions* self, uint32_t code_point, uint16_t script); + +ICU4XScriptWithExtensionsBorrowed* ICU4XScriptWithExtensions_as_borrowed(const ICU4XScriptWithExtensions* self); + +CodePointRangeIterator* ICU4XScriptWithExtensions_iter_ranges_for_script(const ICU4XScriptWithExtensions* self, uint16_t script); +void ICU4XScriptWithExtensions_destroy(ICU4XScriptWithExtensions* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XScriptWithExtensions.hpp b/intl/icu_capi/cpp/include/ICU4XScriptWithExtensions.hpp new file mode 100644 index 0000000000..ffce554c3d --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XScriptWithExtensions.hpp @@ -0,0 +1,109 @@ +#ifndef ICU4XScriptWithExtensions_HPP +#define ICU4XScriptWithExtensions_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XScriptWithExtensions.h" + +class ICU4XDataProvider; +class ICU4XScriptWithExtensions; +#include "ICU4XError.hpp" +class ICU4XScriptWithExtensionsBorrowed; +class CodePointRangeIterator; + +/** + * A destruction policy for using ICU4XScriptWithExtensions with std::unique_ptr. + */ +struct ICU4XScriptWithExtensionsDeleter { + void operator()(capi::ICU4XScriptWithExtensions* l) const noexcept { + capi::ICU4XScriptWithExtensions_destroy(l); + } +}; + +/** + * An ICU4X ScriptWithExtensions map object, capable of holding a map of codepoints to scriptextensions values + * + * See the [Rust documentation for `ScriptWithExtensions`](https://docs.rs/icu/latest/icu/properties/script/struct.ScriptWithExtensions.html) for more information. + */ +class ICU4XScriptWithExtensions { + public: + + /** + * See the [Rust documentation for `script_with_extensions`](https://docs.rs/icu/latest/icu/properties/script/fn.script_with_extensions.html) for more information. + */ + static diplomat::result<ICU4XScriptWithExtensions, ICU4XError> create(const ICU4XDataProvider& provider); + + /** + * Get the Script property value for a code point + * + * 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. + */ + uint16_t get_script_val(uint32_t code_point) const; + + /** + * Check if the Script_Extensions property of the given code point covers the given script + * + * See the [Rust documentation for `has_script`](https://docs.rs/icu/latest/icu/properties/script/struct.ScriptWithExtensionsBorrowed.html#method.has_script) for more information. + */ + bool has_script(uint32_t code_point, uint16_t script) const; + + /** + * Borrow this object for a slightly faster variant with more operations + * + * See the [Rust documentation for `as_borrowed`](https://docs.rs/icu/latest/icu/properties/script/struct.ScriptWithExtensions.html#method.as_borrowed) for more information. + * + * Lifetimes: `this` must live at least as long as the output. + */ + ICU4XScriptWithExtensionsBorrowed as_borrowed() const; + + /** + * Get a list of ranges of code points that contain this script in their Script_Extensions values + * + * 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. + * + * Lifetimes: `this` must live at least as long as the output. + */ + CodePointRangeIterator iter_ranges_for_script(uint16_t script) const; + inline const capi::ICU4XScriptWithExtensions* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XScriptWithExtensions* AsFFIMut() { return this->inner.get(); } + inline ICU4XScriptWithExtensions(capi::ICU4XScriptWithExtensions* i) : inner(i) {} + ICU4XScriptWithExtensions() = default; + ICU4XScriptWithExtensions(ICU4XScriptWithExtensions&&) noexcept = default; + ICU4XScriptWithExtensions& operator=(ICU4XScriptWithExtensions&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XScriptWithExtensions, ICU4XScriptWithExtensionsDeleter> inner; +}; + +#include "ICU4XDataProvider.hpp" +#include "ICU4XScriptWithExtensionsBorrowed.hpp" +#include "CodePointRangeIterator.hpp" + +inline diplomat::result<ICU4XScriptWithExtensions, ICU4XError> ICU4XScriptWithExtensions::create(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XScriptWithExtensions_create(provider.AsFFI()); + diplomat::result<ICU4XScriptWithExtensions, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XScriptWithExtensions>(ICU4XScriptWithExtensions(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline uint16_t ICU4XScriptWithExtensions::get_script_val(uint32_t code_point) const { + return capi::ICU4XScriptWithExtensions_get_script_val(this->inner.get(), code_point); +} +inline bool ICU4XScriptWithExtensions::has_script(uint32_t code_point, uint16_t script) const { + return capi::ICU4XScriptWithExtensions_has_script(this->inner.get(), code_point, script); +} +inline ICU4XScriptWithExtensionsBorrowed ICU4XScriptWithExtensions::as_borrowed() const { + return ICU4XScriptWithExtensionsBorrowed(capi::ICU4XScriptWithExtensions_as_borrowed(this->inner.get())); +} +inline CodePointRangeIterator ICU4XScriptWithExtensions::iter_ranges_for_script(uint16_t script) const { + return CodePointRangeIterator(capi::ICU4XScriptWithExtensions_iter_ranges_for_script(this->inner.get(), script)); +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XScriptWithExtensionsBorrowed.h b/intl/icu_capi/cpp/include/ICU4XScriptWithExtensionsBorrowed.h new file mode 100644 index 0000000000..82faeec178 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XScriptWithExtensionsBorrowed.h @@ -0,0 +1,37 @@ +#ifndef ICU4XScriptWithExtensionsBorrowed_H +#define ICU4XScriptWithExtensionsBorrowed_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XScriptWithExtensionsBorrowed ICU4XScriptWithExtensionsBorrowed; +#ifdef __cplusplus +} // namespace capi +#endif +#include "ICU4XScriptExtensionsSet.h" +#include "ICU4XCodePointSetData.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +uint16_t ICU4XScriptWithExtensionsBorrowed_get_script_val(const ICU4XScriptWithExtensionsBorrowed* self, uint32_t code_point); + +ICU4XScriptExtensionsSet* ICU4XScriptWithExtensionsBorrowed_get_script_extensions_val(const ICU4XScriptWithExtensionsBorrowed* self, uint32_t code_point); + +bool ICU4XScriptWithExtensionsBorrowed_has_script(const ICU4XScriptWithExtensionsBorrowed* self, uint32_t code_point, uint16_t script); + +ICU4XCodePointSetData* ICU4XScriptWithExtensionsBorrowed_get_script_extensions_set(const ICU4XScriptWithExtensionsBorrowed* self, uint16_t script); +void ICU4XScriptWithExtensionsBorrowed_destroy(ICU4XScriptWithExtensionsBorrowed* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XScriptWithExtensionsBorrowed.hpp b/intl/icu_capi/cpp/include/ICU4XScriptWithExtensionsBorrowed.hpp new file mode 100644 index 0000000000..7793146bd2 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XScriptWithExtensionsBorrowed.hpp @@ -0,0 +1,89 @@ +#ifndef ICU4XScriptWithExtensionsBorrowed_HPP +#define ICU4XScriptWithExtensionsBorrowed_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XScriptWithExtensionsBorrowed.h" + +class ICU4XScriptExtensionsSet; +class ICU4XCodePointSetData; + +/** + * A destruction policy for using ICU4XScriptWithExtensionsBorrowed with std::unique_ptr. + */ +struct ICU4XScriptWithExtensionsBorrowedDeleter { + void operator()(capi::ICU4XScriptWithExtensionsBorrowed* l) const noexcept { + capi::ICU4XScriptWithExtensionsBorrowed_destroy(l); + } +}; + +/** + * A slightly faster ICU4XScriptWithExtensions object + * + * See the [Rust documentation for `ScriptWithExtensionsBorrowed`](https://docs.rs/icu/latest/icu/properties/script/struct.ScriptWithExtensionsBorrowed.html) for more information. + */ +class ICU4XScriptWithExtensionsBorrowed { + public: + + /** + * Get the Script property value for a code point + * + * 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. + */ + uint16_t get_script_val(uint32_t code_point) const; + + /** + * Get the Script property value for a code point + * + * See the [Rust documentation for `get_script_extensions_val`](https://docs.rs/icu/latest/icu/properties/script/struct.ScriptWithExtensionsBorrowed.html#method.get_script_extensions_val) for more information. + * + * Lifetimes: `this` must live at least as long as the output. + */ + ICU4XScriptExtensionsSet get_script_extensions_val(uint32_t code_point) const; + + /** + * Check if the Script_Extensions property of the given code point covers the given script + * + * See the [Rust documentation for `has_script`](https://docs.rs/icu/latest/icu/properties/script/struct.ScriptWithExtensionsBorrowed.html#method.has_script) for more information. + */ + bool has_script(uint32_t code_point, uint16_t script) const; + + /** + * Build the CodePointSetData corresponding to a codepoints matching a particular script + * in their Script_Extensions + * + * See the [Rust documentation for `get_script_extensions_set`](https://docs.rs/icu/latest/icu/properties/script/struct.ScriptWithExtensionsBorrowed.html#method.get_script_extensions_set) for more information. + */ + ICU4XCodePointSetData get_script_extensions_set(uint16_t script) const; + inline const capi::ICU4XScriptWithExtensionsBorrowed* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XScriptWithExtensionsBorrowed* AsFFIMut() { return this->inner.get(); } + inline ICU4XScriptWithExtensionsBorrowed(capi::ICU4XScriptWithExtensionsBorrowed* i) : inner(i) {} + ICU4XScriptWithExtensionsBorrowed() = default; + ICU4XScriptWithExtensionsBorrowed(ICU4XScriptWithExtensionsBorrowed&&) noexcept = default; + ICU4XScriptWithExtensionsBorrowed& operator=(ICU4XScriptWithExtensionsBorrowed&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XScriptWithExtensionsBorrowed, ICU4XScriptWithExtensionsBorrowedDeleter> inner; +}; + +#include "ICU4XScriptExtensionsSet.hpp" +#include "ICU4XCodePointSetData.hpp" + +inline uint16_t ICU4XScriptWithExtensionsBorrowed::get_script_val(uint32_t code_point) const { + return capi::ICU4XScriptWithExtensionsBorrowed_get_script_val(this->inner.get(), code_point); +} +inline ICU4XScriptExtensionsSet ICU4XScriptWithExtensionsBorrowed::get_script_extensions_val(uint32_t code_point) const { + return ICU4XScriptExtensionsSet(capi::ICU4XScriptWithExtensionsBorrowed_get_script_extensions_val(this->inner.get(), code_point)); +} +inline bool ICU4XScriptWithExtensionsBorrowed::has_script(uint32_t code_point, uint16_t script) const { + return capi::ICU4XScriptWithExtensionsBorrowed_has_script(this->inner.get(), code_point, script); +} +inline ICU4XCodePointSetData ICU4XScriptWithExtensionsBorrowed::get_script_extensions_set(uint16_t script) const { + return ICU4XCodePointSetData(capi::ICU4XScriptWithExtensionsBorrowed_get_script_extensions_set(this->inner.get(), script)); +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XSegmenterWordType.h b/intl/icu_capi/cpp/include/ICU4XSegmenterWordType.h new file mode 100644 index 0000000000..9f4f81cf10 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XSegmenterWordType.h @@ -0,0 +1,32 @@ +#ifndef ICU4XSegmenterWordType_H +#define ICU4XSegmenterWordType_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef enum ICU4XSegmenterWordType { + ICU4XSegmenterWordType_None = 0, + ICU4XSegmenterWordType_Number = 1, + ICU4XSegmenterWordType_Letter = 2, +} ICU4XSegmenterWordType; +#ifdef __cplusplus +} // namespace capi +#endif +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +void ICU4XSegmenterWordType_destroy(ICU4XSegmenterWordType* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XSegmenterWordType.hpp b/intl/icu_capi/cpp/include/ICU4XSegmenterWordType.hpp new file mode 100644 index 0000000000..8a61504b70 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XSegmenterWordType.hpp @@ -0,0 +1,25 @@ +#ifndef ICU4XSegmenterWordType_HPP +#define ICU4XSegmenterWordType_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XSegmenterWordType.h" + + + +/** + * See the [Rust documentation for `WordType`](https://docs.rs/icu/latest/icu/segmenter/enum.WordType.html) for more information. + */ +enum struct ICU4XSegmenterWordType { + None = 0, + Number = 1, + Letter = 2, +}; + +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XSentenceBreakIteratorLatin1.h b/intl/icu_capi/cpp/include/ICU4XSentenceBreakIteratorLatin1.h new file mode 100644 index 0000000000..6dd7b132dc --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XSentenceBreakIteratorLatin1.h @@ -0,0 +1,29 @@ +#ifndef ICU4XSentenceBreakIteratorLatin1_H +#define ICU4XSentenceBreakIteratorLatin1_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XSentenceBreakIteratorLatin1 ICU4XSentenceBreakIteratorLatin1; +#ifdef __cplusplus +} // namespace capi +#endif +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +int32_t ICU4XSentenceBreakIteratorLatin1_next(ICU4XSentenceBreakIteratorLatin1* self); +void ICU4XSentenceBreakIteratorLatin1_destroy(ICU4XSentenceBreakIteratorLatin1* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XSentenceBreakIteratorLatin1.hpp b/intl/icu_capi/cpp/include/ICU4XSentenceBreakIteratorLatin1.hpp new file mode 100644 index 0000000000..6c2a2a372f --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XSentenceBreakIteratorLatin1.hpp @@ -0,0 +1,51 @@ +#ifndef ICU4XSentenceBreakIteratorLatin1_HPP +#define ICU4XSentenceBreakIteratorLatin1_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XSentenceBreakIteratorLatin1.h" + + +/** + * A destruction policy for using ICU4XSentenceBreakIteratorLatin1 with std::unique_ptr. + */ +struct ICU4XSentenceBreakIteratorLatin1Deleter { + void operator()(capi::ICU4XSentenceBreakIteratorLatin1* l) const noexcept { + capi::ICU4XSentenceBreakIteratorLatin1_destroy(l); + } +}; + +/** + * See the [Rust documentation for `SentenceBreakIterator`](https://docs.rs/icu/latest/icu/segmenter/struct.SentenceBreakIterator.html) for more information. + */ +class ICU4XSentenceBreakIteratorLatin1 { + public: + + /** + * Finds the next breakpoint. Returns -1 if at the end of the string or if the index is + * out of range of a 32-bit signed integer. + * + * See the [Rust documentation for `next`](https://docs.rs/icu/latest/icu/segmenter/struct.SentenceBreakIterator.html#method.next) for more information. + */ + int32_t next(); + inline const capi::ICU4XSentenceBreakIteratorLatin1* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XSentenceBreakIteratorLatin1* AsFFIMut() { return this->inner.get(); } + inline ICU4XSentenceBreakIteratorLatin1(capi::ICU4XSentenceBreakIteratorLatin1* i) : inner(i) {} + ICU4XSentenceBreakIteratorLatin1() = default; + ICU4XSentenceBreakIteratorLatin1(ICU4XSentenceBreakIteratorLatin1&&) noexcept = default; + ICU4XSentenceBreakIteratorLatin1& operator=(ICU4XSentenceBreakIteratorLatin1&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XSentenceBreakIteratorLatin1, ICU4XSentenceBreakIteratorLatin1Deleter> inner; +}; + + +inline int32_t ICU4XSentenceBreakIteratorLatin1::next() { + return capi::ICU4XSentenceBreakIteratorLatin1_next(this->inner.get()); +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XSentenceBreakIteratorUtf16.h b/intl/icu_capi/cpp/include/ICU4XSentenceBreakIteratorUtf16.h new file mode 100644 index 0000000000..3ed0dc18c3 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XSentenceBreakIteratorUtf16.h @@ -0,0 +1,29 @@ +#ifndef ICU4XSentenceBreakIteratorUtf16_H +#define ICU4XSentenceBreakIteratorUtf16_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XSentenceBreakIteratorUtf16 ICU4XSentenceBreakIteratorUtf16; +#ifdef __cplusplus +} // namespace capi +#endif +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +int32_t ICU4XSentenceBreakIteratorUtf16_next(ICU4XSentenceBreakIteratorUtf16* self); +void ICU4XSentenceBreakIteratorUtf16_destroy(ICU4XSentenceBreakIteratorUtf16* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XSentenceBreakIteratorUtf16.hpp b/intl/icu_capi/cpp/include/ICU4XSentenceBreakIteratorUtf16.hpp new file mode 100644 index 0000000000..6b98df79a1 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XSentenceBreakIteratorUtf16.hpp @@ -0,0 +1,51 @@ +#ifndef ICU4XSentenceBreakIteratorUtf16_HPP +#define ICU4XSentenceBreakIteratorUtf16_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XSentenceBreakIteratorUtf16.h" + + +/** + * A destruction policy for using ICU4XSentenceBreakIteratorUtf16 with std::unique_ptr. + */ +struct ICU4XSentenceBreakIteratorUtf16Deleter { + void operator()(capi::ICU4XSentenceBreakIteratorUtf16* l) const noexcept { + capi::ICU4XSentenceBreakIteratorUtf16_destroy(l); + } +}; + +/** + * See the [Rust documentation for `SentenceBreakIterator`](https://docs.rs/icu/latest/icu/segmenter/struct.SentenceBreakIterator.html) for more information. + */ +class ICU4XSentenceBreakIteratorUtf16 { + public: + + /** + * Finds the next breakpoint. Returns -1 if at the end of the string or if the index is + * out of range of a 32-bit signed integer. + * + * See the [Rust documentation for `next`](https://docs.rs/icu/latest/icu/segmenter/struct.SentenceBreakIterator.html#method.next) for more information. + */ + int32_t next(); + inline const capi::ICU4XSentenceBreakIteratorUtf16* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XSentenceBreakIteratorUtf16* AsFFIMut() { return this->inner.get(); } + inline ICU4XSentenceBreakIteratorUtf16(capi::ICU4XSentenceBreakIteratorUtf16* i) : inner(i) {} + ICU4XSentenceBreakIteratorUtf16() = default; + ICU4XSentenceBreakIteratorUtf16(ICU4XSentenceBreakIteratorUtf16&&) noexcept = default; + ICU4XSentenceBreakIteratorUtf16& operator=(ICU4XSentenceBreakIteratorUtf16&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XSentenceBreakIteratorUtf16, ICU4XSentenceBreakIteratorUtf16Deleter> inner; +}; + + +inline int32_t ICU4XSentenceBreakIteratorUtf16::next() { + return capi::ICU4XSentenceBreakIteratorUtf16_next(this->inner.get()); +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XSentenceBreakIteratorUtf8.h b/intl/icu_capi/cpp/include/ICU4XSentenceBreakIteratorUtf8.h new file mode 100644 index 0000000000..655cb67b6c --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XSentenceBreakIteratorUtf8.h @@ -0,0 +1,29 @@ +#ifndef ICU4XSentenceBreakIteratorUtf8_H +#define ICU4XSentenceBreakIteratorUtf8_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XSentenceBreakIteratorUtf8 ICU4XSentenceBreakIteratorUtf8; +#ifdef __cplusplus +} // namespace capi +#endif +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +int32_t ICU4XSentenceBreakIteratorUtf8_next(ICU4XSentenceBreakIteratorUtf8* self); +void ICU4XSentenceBreakIteratorUtf8_destroy(ICU4XSentenceBreakIteratorUtf8* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XSentenceBreakIteratorUtf8.hpp b/intl/icu_capi/cpp/include/ICU4XSentenceBreakIteratorUtf8.hpp new file mode 100644 index 0000000000..6f02a9e40c --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XSentenceBreakIteratorUtf8.hpp @@ -0,0 +1,51 @@ +#ifndef ICU4XSentenceBreakIteratorUtf8_HPP +#define ICU4XSentenceBreakIteratorUtf8_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XSentenceBreakIteratorUtf8.h" + + +/** + * A destruction policy for using ICU4XSentenceBreakIteratorUtf8 with std::unique_ptr. + */ +struct ICU4XSentenceBreakIteratorUtf8Deleter { + void operator()(capi::ICU4XSentenceBreakIteratorUtf8* l) const noexcept { + capi::ICU4XSentenceBreakIteratorUtf8_destroy(l); + } +}; + +/** + * See the [Rust documentation for `SentenceBreakIterator`](https://docs.rs/icu/latest/icu/segmenter/struct.SentenceBreakIterator.html) for more information. + */ +class ICU4XSentenceBreakIteratorUtf8 { + public: + + /** + * Finds the next breakpoint. Returns -1 if at the end of the string or if the index is + * out of range of a 32-bit signed integer. + * + * See the [Rust documentation for `next`](https://docs.rs/icu/latest/icu/segmenter/struct.SentenceBreakIterator.html#method.next) for more information. + */ + int32_t next(); + inline const capi::ICU4XSentenceBreakIteratorUtf8* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XSentenceBreakIteratorUtf8* AsFFIMut() { return this->inner.get(); } + inline ICU4XSentenceBreakIteratorUtf8(capi::ICU4XSentenceBreakIteratorUtf8* i) : inner(i) {} + ICU4XSentenceBreakIteratorUtf8() = default; + ICU4XSentenceBreakIteratorUtf8(ICU4XSentenceBreakIteratorUtf8&&) noexcept = default; + ICU4XSentenceBreakIteratorUtf8& operator=(ICU4XSentenceBreakIteratorUtf8&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XSentenceBreakIteratorUtf8, ICU4XSentenceBreakIteratorUtf8Deleter> inner; +}; + + +inline int32_t ICU4XSentenceBreakIteratorUtf8::next() { + return capi::ICU4XSentenceBreakIteratorUtf8_next(this->inner.get()); +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XSentenceSegmenter.h b/intl/icu_capi/cpp/include/ICU4XSentenceSegmenter.h new file mode 100644 index 0000000000..7701c9f042 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XSentenceSegmenter.h @@ -0,0 +1,40 @@ +#ifndef ICU4XSentenceSegmenter_H +#define ICU4XSentenceSegmenter_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XSentenceSegmenter ICU4XSentenceSegmenter; +#ifdef __cplusplus +} // namespace capi +#endif +#include "ICU4XDataProvider.h" +#include "diplomat_result_box_ICU4XSentenceSegmenter_ICU4XError.h" +#include "ICU4XSentenceBreakIteratorUtf8.h" +#include "ICU4XSentenceBreakIteratorUtf16.h" +#include "ICU4XSentenceBreakIteratorLatin1.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +diplomat_result_box_ICU4XSentenceSegmenter_ICU4XError ICU4XSentenceSegmenter_create(const ICU4XDataProvider* provider); + +ICU4XSentenceBreakIteratorUtf8* ICU4XSentenceSegmenter_segment_utf8(const ICU4XSentenceSegmenter* self, const char* input_data, size_t input_len); + +ICU4XSentenceBreakIteratorUtf16* ICU4XSentenceSegmenter_segment_utf16(const ICU4XSentenceSegmenter* self, const uint16_t* input_data, size_t input_len); + +ICU4XSentenceBreakIteratorLatin1* ICU4XSentenceSegmenter_segment_latin1(const ICU4XSentenceSegmenter* self, const uint8_t* input_data, size_t input_len); +void ICU4XSentenceSegmenter_destroy(ICU4XSentenceSegmenter* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XSentenceSegmenter.hpp b/intl/icu_capi/cpp/include/ICU4XSentenceSegmenter.hpp new file mode 100644 index 0000000000..25790199f3 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XSentenceSegmenter.hpp @@ -0,0 +1,105 @@ +#ifndef ICU4XSentenceSegmenter_HPP +#define ICU4XSentenceSegmenter_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XSentenceSegmenter.h" + +class ICU4XDataProvider; +class ICU4XSentenceSegmenter; +#include "ICU4XError.hpp" +class ICU4XSentenceBreakIteratorUtf8; +class ICU4XSentenceBreakIteratorUtf16; +class ICU4XSentenceBreakIteratorLatin1; + +/** + * A destruction policy for using ICU4XSentenceSegmenter with std::unique_ptr. + */ +struct ICU4XSentenceSegmenterDeleter { + void operator()(capi::ICU4XSentenceSegmenter* l) const noexcept { + capi::ICU4XSentenceSegmenter_destroy(l); + } +}; + +/** + * An ICU4X sentence-break segmenter, capable of finding sentence breakpoints in strings. + * + * See the [Rust documentation for `SentenceSegmenter`](https://docs.rs/icu/latest/icu/segmenter/struct.SentenceSegmenter.html) for more information. + */ +class ICU4XSentenceSegmenter { + public: + + /** + * Construct an [`ICU4XSentenceSegmenter`]. + * + * See the [Rust documentation for `new`](https://docs.rs/icu/latest/icu/segmenter/struct.SentenceSegmenter.html#method.new) for more information. + */ + static diplomat::result<ICU4XSentenceSegmenter, ICU4XError> create(const ICU4XDataProvider& provider); + + /** + * Segments a (potentially ill-formed) UTF-8 string. + * + * See the [Rust documentation for `segment_utf8`](https://docs.rs/icu/latest/icu/segmenter/struct.SentenceSegmenter.html#method.segment_utf8) for more information. + * + * Lifetimes: `this`, `input` must live at least as long as the output. + */ + ICU4XSentenceBreakIteratorUtf8 segment_utf8(const std::string_view input) const; + + /** + * Segments a UTF-16 string. + * + * See the [Rust documentation for `segment_utf16`](https://docs.rs/icu/latest/icu/segmenter/struct.SentenceSegmenter.html#method.segment_utf16) for more information. + * + * Lifetimes: `this`, `input` must live at least as long as the output. + */ + ICU4XSentenceBreakIteratorUtf16 segment_utf16(const diplomat::span<const uint16_t> input) const; + + /** + * Segments a Latin-1 string. + * + * See the [Rust documentation for `segment_latin1`](https://docs.rs/icu/latest/icu/segmenter/struct.SentenceSegmenter.html#method.segment_latin1) for more information. + * + * Lifetimes: `this`, `input` must live at least as long as the output. + */ + ICU4XSentenceBreakIteratorLatin1 segment_latin1(const diplomat::span<const uint8_t> input) const; + inline const capi::ICU4XSentenceSegmenter* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XSentenceSegmenter* AsFFIMut() { return this->inner.get(); } + inline ICU4XSentenceSegmenter(capi::ICU4XSentenceSegmenter* i) : inner(i) {} + ICU4XSentenceSegmenter() = default; + ICU4XSentenceSegmenter(ICU4XSentenceSegmenter&&) noexcept = default; + ICU4XSentenceSegmenter& operator=(ICU4XSentenceSegmenter&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XSentenceSegmenter, ICU4XSentenceSegmenterDeleter> inner; +}; + +#include "ICU4XDataProvider.hpp" +#include "ICU4XSentenceBreakIteratorUtf8.hpp" +#include "ICU4XSentenceBreakIteratorUtf16.hpp" +#include "ICU4XSentenceBreakIteratorLatin1.hpp" + +inline diplomat::result<ICU4XSentenceSegmenter, ICU4XError> ICU4XSentenceSegmenter::create(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XSentenceSegmenter_create(provider.AsFFI()); + diplomat::result<ICU4XSentenceSegmenter, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XSentenceSegmenter>(ICU4XSentenceSegmenter(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline ICU4XSentenceBreakIteratorUtf8 ICU4XSentenceSegmenter::segment_utf8(const std::string_view input) const { + return ICU4XSentenceBreakIteratorUtf8(capi::ICU4XSentenceSegmenter_segment_utf8(this->inner.get(), input.data(), input.size())); +} +inline ICU4XSentenceBreakIteratorUtf16 ICU4XSentenceSegmenter::segment_utf16(const diplomat::span<const uint16_t> input) const { + return ICU4XSentenceBreakIteratorUtf16(capi::ICU4XSentenceSegmenter_segment_utf16(this->inner.get(), input.data(), input.size())); +} +inline ICU4XSentenceBreakIteratorLatin1 ICU4XSentenceSegmenter::segment_latin1(const diplomat::span<const uint8_t> input) const { + return ICU4XSentenceBreakIteratorLatin1(capi::ICU4XSentenceSegmenter_segment_latin1(this->inner.get(), input.data(), input.size())); +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XTime.h b/intl/icu_capi/cpp/include/ICU4XTime.h new file mode 100644 index 0000000000..2f3a9967fa --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XTime.h @@ -0,0 +1,40 @@ +#ifndef ICU4XTime_H +#define ICU4XTime_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XTime ICU4XTime; +#ifdef __cplusplus +} // namespace capi +#endif +#include "diplomat_result_box_ICU4XTime_ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +diplomat_result_box_ICU4XTime_ICU4XError ICU4XTime_create(uint8_t hour, uint8_t minute, uint8_t second, uint32_t nanosecond); + +diplomat_result_box_ICU4XTime_ICU4XError ICU4XTime_create_midnight(); + +uint8_t ICU4XTime_hour(const ICU4XTime* self); + +uint8_t ICU4XTime_minute(const ICU4XTime* self); + +uint8_t ICU4XTime_second(const ICU4XTime* self); + +uint32_t ICU4XTime_nanosecond(const ICU4XTime* self); +void ICU4XTime_destroy(ICU4XTime* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XTime.hpp b/intl/icu_capi/cpp/include/ICU4XTime.hpp new file mode 100644 index 0000000000..facac6ade7 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XTime.hpp @@ -0,0 +1,118 @@ +#ifndef ICU4XTime_HPP +#define ICU4XTime_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XTime.h" + +class ICU4XTime; +#include "ICU4XError.hpp" + +/** + * A destruction policy for using ICU4XTime with std::unique_ptr. + */ +struct ICU4XTimeDeleter { + void operator()(capi::ICU4XTime* l) const noexcept { + capi::ICU4XTime_destroy(l); + } +}; + +/** + * An ICU4X Time object representing a time in terms of hour, minute, second, nanosecond + * + * See the [Rust documentation for `Time`](https://docs.rs/icu/latest/icu/calendar/types/struct.Time.html) for more information. + */ +class ICU4XTime { + public: + + /** + * Creates a new [`ICU4XTime`] given field values + * + * See the [Rust documentation for `Time`](https://docs.rs/icu/latest/icu/calendar/types/struct.Time.html) for more information. + */ + static diplomat::result<ICU4XTime, ICU4XError> create(uint8_t hour, uint8_t minute, uint8_t second, uint32_t nanosecond); + + /** + * Creates a new [`ICU4XTime`] representing midnight (00:00.000). + * + * See the [Rust documentation for `Time`](https://docs.rs/icu/latest/icu/calendar/types/struct.Time.html) for more information. + */ + static diplomat::result<ICU4XTime, ICU4XError> create_midnight(); + + /** + * Returns the hour in this time + * + * See the [Rust documentation for `hour`](https://docs.rs/icu/latest/icu/calendar/types/struct.Time.html#structfield.hour) for more information. + */ + uint8_t hour() const; + + /** + * Returns the minute in this time + * + * See the [Rust documentation for `minute`](https://docs.rs/icu/latest/icu/calendar/types/struct.Time.html#structfield.minute) for more information. + */ + uint8_t minute() const; + + /** + * Returns the second in this time + * + * See the [Rust documentation for `second`](https://docs.rs/icu/latest/icu/calendar/types/struct.Time.html#structfield.second) for more information. + */ + uint8_t second() const; + + /** + * Returns the nanosecond in this time + * + * See the [Rust documentation for `nanosecond`](https://docs.rs/icu/latest/icu/calendar/types/struct.Time.html#structfield.nanosecond) for more information. + */ + uint32_t nanosecond() const; + inline const capi::ICU4XTime* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XTime* AsFFIMut() { return this->inner.get(); } + inline ICU4XTime(capi::ICU4XTime* i) : inner(i) {} + ICU4XTime() = default; + ICU4XTime(ICU4XTime&&) noexcept = default; + ICU4XTime& operator=(ICU4XTime&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XTime, ICU4XTimeDeleter> inner; +}; + + +inline diplomat::result<ICU4XTime, ICU4XError> ICU4XTime::create(uint8_t hour, uint8_t minute, uint8_t second, uint32_t nanosecond) { + auto diplomat_result_raw_out_value = capi::ICU4XTime_create(hour, minute, second, nanosecond); + diplomat::result<ICU4XTime, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XTime>(ICU4XTime(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XTime, ICU4XError> ICU4XTime::create_midnight() { + auto diplomat_result_raw_out_value = capi::ICU4XTime_create_midnight(); + diplomat::result<ICU4XTime, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XTime>(ICU4XTime(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline uint8_t ICU4XTime::hour() const { + return capi::ICU4XTime_hour(this->inner.get()); +} +inline uint8_t ICU4XTime::minute() const { + return capi::ICU4XTime_minute(this->inner.get()); +} +inline uint8_t ICU4XTime::second() const { + return capi::ICU4XTime_second(this->inner.get()); +} +inline uint32_t ICU4XTime::nanosecond() const { + return capi::ICU4XTime_nanosecond(this->inner.get()); +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XTimeFormatter.h b/intl/icu_capi/cpp/include/ICU4XTimeFormatter.h new file mode 100644 index 0000000000..d200881399 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XTimeFormatter.h @@ -0,0 +1,43 @@ +#ifndef ICU4XTimeFormatter_H +#define ICU4XTimeFormatter_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XTimeFormatter ICU4XTimeFormatter; +#ifdef __cplusplus +} // namespace capi +#endif +#include "ICU4XDataProvider.h" +#include "ICU4XLocale.h" +#include "ICU4XTimeLength.h" +#include "diplomat_result_box_ICU4XTimeFormatter_ICU4XError.h" +#include "ICU4XTime.h" +#include "diplomat_result_void_ICU4XError.h" +#include "ICU4XDateTime.h" +#include "ICU4XIsoDateTime.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +diplomat_result_box_ICU4XTimeFormatter_ICU4XError ICU4XTimeFormatter_create_with_length(const ICU4XDataProvider* provider, const ICU4XLocale* locale, ICU4XTimeLength length); + +diplomat_result_void_ICU4XError ICU4XTimeFormatter_format_time(const ICU4XTimeFormatter* self, const ICU4XTime* value, DiplomatWriteable* write); + +diplomat_result_void_ICU4XError ICU4XTimeFormatter_format_datetime(const ICU4XTimeFormatter* self, const ICU4XDateTime* value, DiplomatWriteable* write); + +diplomat_result_void_ICU4XError ICU4XTimeFormatter_format_iso_datetime(const ICU4XTimeFormatter* self, const ICU4XIsoDateTime* value, DiplomatWriteable* write); +void ICU4XTimeFormatter_destroy(ICU4XTimeFormatter* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XTimeFormatter.hpp b/intl/icu_capi/cpp/include/ICU4XTimeFormatter.hpp new file mode 100644 index 0000000000..3800ee5d16 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XTimeFormatter.hpp @@ -0,0 +1,183 @@ +#ifndef ICU4XTimeFormatter_HPP +#define ICU4XTimeFormatter_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XTimeFormatter.h" + +class ICU4XDataProvider; +class ICU4XLocale; +#include "ICU4XTimeLength.hpp" +class ICU4XTimeFormatter; +#include "ICU4XError.hpp" +class ICU4XTime; +class ICU4XDateTime; +class ICU4XIsoDateTime; + +/** + * A destruction policy for using ICU4XTimeFormatter with std::unique_ptr. + */ +struct ICU4XTimeFormatterDeleter { + void operator()(capi::ICU4XTimeFormatter* l) const noexcept { + capi::ICU4XTimeFormatter_destroy(l); + } +}; + +/** + * An ICU4X TimeFormatter object capable of formatting an [`ICU4XTime`] type (and others) as a string + * + * See the [Rust documentation for `TimeFormatter`](https://docs.rs/icu/latest/icu/datetime/struct.TimeFormatter.html) for more information. + */ +class ICU4XTimeFormatter { + public: + + /** + * Creates a new [`ICU4XTimeFormatter`] from locale data. + * + * See the [Rust documentation for `try_new_with_length`](https://docs.rs/icu/latest/icu/datetime/struct.TimeFormatter.html#method.try_new_with_length) for more information. + */ + static diplomat::result<ICU4XTimeFormatter, ICU4XError> create_with_length(const ICU4XDataProvider& provider, const ICU4XLocale& locale, ICU4XTimeLength length); + + /** + * Formats a [`ICU4XTime`] to a string. + * + * See the [Rust documentation for `format`](https://docs.rs/icu/latest/icu/datetime/struct.TimeFormatter.html#method.format) for more information. + */ + template<typename W> diplomat::result<std::monostate, ICU4XError> format_time_to_writeable(const ICU4XTime& value, W& write) const; + + /** + * Formats a [`ICU4XTime`] to a string. + * + * See the [Rust documentation for `format`](https://docs.rs/icu/latest/icu/datetime/struct.TimeFormatter.html#method.format) for more information. + */ + diplomat::result<std::string, ICU4XError> format_time(const ICU4XTime& value) const; + + /** + * Formats a [`ICU4XDateTime`] to a string. + * + * See the [Rust documentation for `format`](https://docs.rs/icu/latest/icu/datetime/struct.TimeFormatter.html#method.format) for more information. + */ + template<typename W> diplomat::result<std::monostate, ICU4XError> format_datetime_to_writeable(const ICU4XDateTime& value, W& write) const; + + /** + * Formats a [`ICU4XDateTime`] to a string. + * + * See the [Rust documentation for `format`](https://docs.rs/icu/latest/icu/datetime/struct.TimeFormatter.html#method.format) for more information. + */ + diplomat::result<std::string, ICU4XError> format_datetime(const ICU4XDateTime& value) const; + + /** + * Formats a [`ICU4XIsoDateTime`] to a string. + * + * See the [Rust documentation for `format`](https://docs.rs/icu/latest/icu/datetime/struct.TimeFormatter.html#method.format) for more information. + */ + template<typename W> diplomat::result<std::monostate, ICU4XError> format_iso_datetime_to_writeable(const ICU4XIsoDateTime& value, W& write) const; + + /** + * Formats a [`ICU4XIsoDateTime`] to a string. + * + * See the [Rust documentation for `format`](https://docs.rs/icu/latest/icu/datetime/struct.TimeFormatter.html#method.format) for more information. + */ + diplomat::result<std::string, ICU4XError> format_iso_datetime(const ICU4XIsoDateTime& value) const; + inline const capi::ICU4XTimeFormatter* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XTimeFormatter* AsFFIMut() { return this->inner.get(); } + inline ICU4XTimeFormatter(capi::ICU4XTimeFormatter* i) : inner(i) {} + ICU4XTimeFormatter() = default; + ICU4XTimeFormatter(ICU4XTimeFormatter&&) noexcept = default; + ICU4XTimeFormatter& operator=(ICU4XTimeFormatter&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XTimeFormatter, ICU4XTimeFormatterDeleter> inner; +}; + +#include "ICU4XDataProvider.hpp" +#include "ICU4XLocale.hpp" +#include "ICU4XTime.hpp" +#include "ICU4XDateTime.hpp" +#include "ICU4XIsoDateTime.hpp" + +inline diplomat::result<ICU4XTimeFormatter, ICU4XError> ICU4XTimeFormatter::create_with_length(const ICU4XDataProvider& provider, const ICU4XLocale& locale, ICU4XTimeLength length) { + auto diplomat_result_raw_out_value = capi::ICU4XTimeFormatter_create_with_length(provider.AsFFI(), locale.AsFFI(), static_cast<capi::ICU4XTimeLength>(length)); + diplomat::result<ICU4XTimeFormatter, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XTimeFormatter>(ICU4XTimeFormatter(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XTimeFormatter::format_time_to_writeable(const ICU4XTime& value, W& write) const { + capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write); + auto diplomat_result_raw_out_value = capi::ICU4XTimeFormatter_format_time(this->inner.get(), value.AsFFI(), &write_writer); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<std::string, ICU4XError> ICU4XTimeFormatter::format_time(const ICU4XTime& value) const { + std::string diplomat_writeable_string; + capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); + auto diplomat_result_raw_out_value = capi::ICU4XTimeFormatter_format_time(this->inner.get(), value.AsFFI(), &diplomat_writeable_out); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string)); +} +template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XTimeFormatter::format_datetime_to_writeable(const ICU4XDateTime& value, W& write) const { + capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write); + auto diplomat_result_raw_out_value = capi::ICU4XTimeFormatter_format_datetime(this->inner.get(), value.AsFFI(), &write_writer); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<std::string, ICU4XError> ICU4XTimeFormatter::format_datetime(const ICU4XDateTime& value) const { + std::string diplomat_writeable_string; + capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); + auto diplomat_result_raw_out_value = capi::ICU4XTimeFormatter_format_datetime(this->inner.get(), value.AsFFI(), &diplomat_writeable_out); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string)); +} +template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XTimeFormatter::format_iso_datetime_to_writeable(const ICU4XIsoDateTime& value, W& write) const { + capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write); + auto diplomat_result_raw_out_value = capi::ICU4XTimeFormatter_format_iso_datetime(this->inner.get(), value.AsFFI(), &write_writer); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<std::string, ICU4XError> ICU4XTimeFormatter::format_iso_datetime(const ICU4XIsoDateTime& value) const { + std::string diplomat_writeable_string; + capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); + auto diplomat_result_raw_out_value = capi::ICU4XTimeFormatter_format_iso_datetime(this->inner.get(), value.AsFFI(), &diplomat_writeable_out); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string)); +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XTimeLength.h b/intl/icu_capi/cpp/include/ICU4XTimeLength.h new file mode 100644 index 0000000000..6d98bc8ccb --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XTimeLength.h @@ -0,0 +1,33 @@ +#ifndef ICU4XTimeLength_H +#define ICU4XTimeLength_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef enum ICU4XTimeLength { + ICU4XTimeLength_Full = 0, + ICU4XTimeLength_Long = 1, + ICU4XTimeLength_Medium = 2, + ICU4XTimeLength_Short = 3, +} ICU4XTimeLength; +#ifdef __cplusplus +} // namespace capi +#endif +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +void ICU4XTimeLength_destroy(ICU4XTimeLength* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XTimeLength.hpp b/intl/icu_capi/cpp/include/ICU4XTimeLength.hpp new file mode 100644 index 0000000000..a7035d0900 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XTimeLength.hpp @@ -0,0 +1,26 @@ +#ifndef ICU4XTimeLength_HPP +#define ICU4XTimeLength_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XTimeLength.h" + + + +/** + * See the [Rust documentation for `Time`](https://docs.rs/icu/latest/icu/datetime/options/length/enum.Time.html) for more information. + */ +enum struct ICU4XTimeLength { + Full = 0, + Long = 1, + Medium = 2, + Short = 3, +}; + +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XTimeZoneFormatter.h b/intl/icu_capi/cpp/include/ICU4XTimeZoneFormatter.h new file mode 100644 index 0000000000..5eb1299543 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XTimeZoneFormatter.h @@ -0,0 +1,53 @@ +#ifndef ICU4XTimeZoneFormatter_H +#define ICU4XTimeZoneFormatter_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XTimeZoneFormatter ICU4XTimeZoneFormatter; +#ifdef __cplusplus +} // namespace capi +#endif +#include "ICU4XDataProvider.h" +#include "ICU4XLocale.h" +#include "diplomat_result_box_ICU4XTimeZoneFormatter_ICU4XError.h" +#include "ICU4XIsoTimeZoneOptions.h" +#include "diplomat_result_void_ICU4XError.h" +#include "ICU4XCustomTimeZone.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +diplomat_result_box_ICU4XTimeZoneFormatter_ICU4XError ICU4XTimeZoneFormatter_create_with_localized_gmt_fallback(const ICU4XDataProvider* provider, const ICU4XLocale* locale); + +diplomat_result_box_ICU4XTimeZoneFormatter_ICU4XError ICU4XTimeZoneFormatter_create_with_iso_8601_fallback(const ICU4XDataProvider* provider, const ICU4XLocale* locale, ICU4XIsoTimeZoneOptions options); + +diplomat_result_void_ICU4XError ICU4XTimeZoneFormatter_load_generic_non_location_long(ICU4XTimeZoneFormatter* self, const ICU4XDataProvider* provider); + +diplomat_result_void_ICU4XError ICU4XTimeZoneFormatter_load_generic_non_location_short(ICU4XTimeZoneFormatter* self, const ICU4XDataProvider* provider); + +diplomat_result_void_ICU4XError ICU4XTimeZoneFormatter_load_specific_non_location_long(ICU4XTimeZoneFormatter* self, const ICU4XDataProvider* provider); + +diplomat_result_void_ICU4XError ICU4XTimeZoneFormatter_load_specific_non_location_short(ICU4XTimeZoneFormatter* self, const ICU4XDataProvider* provider); + +diplomat_result_void_ICU4XError ICU4XTimeZoneFormatter_load_generic_location_format(ICU4XTimeZoneFormatter* self, const ICU4XDataProvider* provider); + +diplomat_result_void_ICU4XError ICU4XTimeZoneFormatter_include_localized_gmt_format(ICU4XTimeZoneFormatter* self); + +diplomat_result_void_ICU4XError ICU4XTimeZoneFormatter_load_iso_8601_format(ICU4XTimeZoneFormatter* self, ICU4XIsoTimeZoneOptions options); + +diplomat_result_void_ICU4XError ICU4XTimeZoneFormatter_format_custom_time_zone(const ICU4XTimeZoneFormatter* self, const ICU4XCustomTimeZone* value, DiplomatWriteable* write); +void ICU4XTimeZoneFormatter_destroy(ICU4XTimeZoneFormatter* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XTimeZoneFormatter.hpp b/intl/icu_capi/cpp/include/ICU4XTimeZoneFormatter.hpp new file mode 100644 index 0000000000..5e461ec916 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XTimeZoneFormatter.hpp @@ -0,0 +1,256 @@ +#ifndef ICU4XTimeZoneFormatter_HPP +#define ICU4XTimeZoneFormatter_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XTimeZoneFormatter.h" + +class ICU4XDataProvider; +class ICU4XLocale; +class ICU4XTimeZoneFormatter; +#include "ICU4XError.hpp" +struct ICU4XIsoTimeZoneOptions; +class ICU4XCustomTimeZone; + +/** + * A destruction policy for using ICU4XTimeZoneFormatter with std::unique_ptr. + */ +struct ICU4XTimeZoneFormatterDeleter { + void operator()(capi::ICU4XTimeZoneFormatter* l) const noexcept { + capi::ICU4XTimeZoneFormatter_destroy(l); + } +}; + +/** + * An ICU4X TimeZoneFormatter object capable of formatting an [`ICU4XCustomTimeZone`] type (and others) as a string + * + * See the [Rust documentation for `TimeZoneFormatter`](https://docs.rs/icu/latest/icu/datetime/time_zone/struct.TimeZoneFormatter.html) for more information. + */ +class ICU4XTimeZoneFormatter { + public: + + /** + * Creates a new [`ICU4XTimeZoneFormatter`] from locale data. + * + * Uses localized GMT as the fallback format. + * + * See the [Rust documentation for `try_new`](https://docs.rs/icu/latest/icu/datetime/time_zone/struct.TimeZoneFormatter.html#method.try_new) for more information. + * + * Additional information: [1](https://docs.rs/icu/latest/icu/datetime/time_zone/enum.FallbackFormat.html) + */ + static diplomat::result<ICU4XTimeZoneFormatter, ICU4XError> create_with_localized_gmt_fallback(const ICU4XDataProvider& provider, const ICU4XLocale& locale); + + /** + * Creates a new [`ICU4XTimeZoneFormatter`] from locale data. + * + * Uses ISO-8601 as the fallback format. + * + * See the [Rust documentation for `try_new`](https://docs.rs/icu/latest/icu/datetime/time_zone/struct.TimeZoneFormatter.html#method.try_new) for more information. + * + * Additional information: [1](https://docs.rs/icu/latest/icu/datetime/time_zone/enum.FallbackFormat.html) + */ + static diplomat::result<ICU4XTimeZoneFormatter, ICU4XError> create_with_iso_8601_fallback(const ICU4XDataProvider& provider, const ICU4XLocale& locale, ICU4XIsoTimeZoneOptions options); + + /** + * Loads generic non-location long format. Example: "Pacific Time" + * + * See the [Rust documentation for `include_generic_non_location_long`](https://docs.rs/icu/latest/icu/datetime/time_zone/struct.TimeZoneFormatter.html#method.include_generic_non_location_long) for more information. + */ + diplomat::result<std::monostate, ICU4XError> load_generic_non_location_long(const ICU4XDataProvider& provider); + + /** + * Loads generic non-location short format. Example: "PT" + * + * See the [Rust documentation for `include_generic_non_location_short`](https://docs.rs/icu/latest/icu/datetime/time_zone/struct.TimeZoneFormatter.html#method.include_generic_non_location_short) for more information. + */ + diplomat::result<std::monostate, ICU4XError> load_generic_non_location_short(const ICU4XDataProvider& provider); + + /** + * Loads specific non-location long format. Example: "Pacific Standard Time" + * + * See the [Rust documentation for `include_specific_non_location_long`](https://docs.rs/icu/latest/icu/datetime/time_zone/struct.TimeZoneFormatter.html#method.include_specific_non_location_long) for more information. + */ + diplomat::result<std::monostate, ICU4XError> load_specific_non_location_long(const ICU4XDataProvider& provider); + + /** + * Loads specific non-location short format. Example: "PST" + * + * See the [Rust documentation for `include_specific_non_location_short`](https://docs.rs/icu/latest/icu/datetime/time_zone/struct.TimeZoneFormatter.html#method.include_specific_non_location_short) for more information. + */ + diplomat::result<std::monostate, ICU4XError> load_specific_non_location_short(const ICU4XDataProvider& provider); + + /** + * Loads generic location format. Example: "Los Angeles Time" + * + * See the [Rust documentation for `include_generic_location_format`](https://docs.rs/icu/latest/icu/datetime/time_zone/struct.TimeZoneFormatter.html#method.include_generic_location_format) for more information. + */ + diplomat::result<std::monostate, ICU4XError> load_generic_location_format(const ICU4XDataProvider& provider); + + /** + * Loads localized GMT format. Example: "GMT-07:00" + * + * See the [Rust documentation for `include_localized_gmt_format`](https://docs.rs/icu/latest/icu/datetime/time_zone/struct.TimeZoneFormatter.html#method.include_localized_gmt_format) for more information. + */ + diplomat::result<std::monostate, ICU4XError> include_localized_gmt_format(); + + /** + * Loads ISO-8601 format. Example: "-07:00" + * + * See the [Rust documentation for `include_iso_8601_format`](https://docs.rs/icu/latest/icu/datetime/time_zone/struct.TimeZoneFormatter.html#method.include_iso_8601_format) for more information. + */ + diplomat::result<std::monostate, ICU4XError> load_iso_8601_format(ICU4XIsoTimeZoneOptions options); + + /** + * Formats a [`ICU4XCustomTimeZone`] to a string. + * + * See the [Rust documentation for `format`](https://docs.rs/icu/latest/icu/datetime/time_zone/struct.TimeZoneFormatter.html#method.format) for more information. + * + * See the [Rust documentation for `format_to_string`](https://docs.rs/icu/latest/icu/datetime/time_zone/struct.TimeZoneFormatter.html#method.format_to_string) for more information. + */ + template<typename W> diplomat::result<std::monostate, ICU4XError> format_custom_time_zone_to_writeable(const ICU4XCustomTimeZone& value, W& write) const; + + /** + * Formats a [`ICU4XCustomTimeZone`] to a string. + * + * See the [Rust documentation for `format`](https://docs.rs/icu/latest/icu/datetime/time_zone/struct.TimeZoneFormatter.html#method.format) for more information. + * + * See the [Rust documentation for `format_to_string`](https://docs.rs/icu/latest/icu/datetime/time_zone/struct.TimeZoneFormatter.html#method.format_to_string) for more information. + */ + diplomat::result<std::string, ICU4XError> format_custom_time_zone(const ICU4XCustomTimeZone& value) const; + inline const capi::ICU4XTimeZoneFormatter* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XTimeZoneFormatter* AsFFIMut() { return this->inner.get(); } + inline ICU4XTimeZoneFormatter(capi::ICU4XTimeZoneFormatter* i) : inner(i) {} + ICU4XTimeZoneFormatter() = default; + ICU4XTimeZoneFormatter(ICU4XTimeZoneFormatter&&) noexcept = default; + ICU4XTimeZoneFormatter& operator=(ICU4XTimeZoneFormatter&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XTimeZoneFormatter, ICU4XTimeZoneFormatterDeleter> inner; +}; + +#include "ICU4XDataProvider.hpp" +#include "ICU4XLocale.hpp" +#include "ICU4XIsoTimeZoneOptions.hpp" +#include "ICU4XCustomTimeZone.hpp" + +inline diplomat::result<ICU4XTimeZoneFormatter, ICU4XError> ICU4XTimeZoneFormatter::create_with_localized_gmt_fallback(const ICU4XDataProvider& provider, const ICU4XLocale& locale) { + auto diplomat_result_raw_out_value = capi::ICU4XTimeZoneFormatter_create_with_localized_gmt_fallback(provider.AsFFI(), locale.AsFFI()); + diplomat::result<ICU4XTimeZoneFormatter, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XTimeZoneFormatter>(ICU4XTimeZoneFormatter(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XTimeZoneFormatter, ICU4XError> ICU4XTimeZoneFormatter::create_with_iso_8601_fallback(const ICU4XDataProvider& provider, const ICU4XLocale& locale, ICU4XIsoTimeZoneOptions options) { + ICU4XIsoTimeZoneOptions diplomat_wrapped_struct_options = options; + auto diplomat_result_raw_out_value = capi::ICU4XTimeZoneFormatter_create_with_iso_8601_fallback(provider.AsFFI(), locale.AsFFI(), capi::ICU4XIsoTimeZoneOptions{ .format = static_cast<capi::ICU4XIsoTimeZoneFormat>(diplomat_wrapped_struct_options.format), .minutes = static_cast<capi::ICU4XIsoTimeZoneMinuteDisplay>(diplomat_wrapped_struct_options.minutes), .seconds = static_cast<capi::ICU4XIsoTimeZoneSecondDisplay>(diplomat_wrapped_struct_options.seconds) }); + diplomat::result<ICU4XTimeZoneFormatter, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XTimeZoneFormatter>(ICU4XTimeZoneFormatter(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<std::monostate, ICU4XError> ICU4XTimeZoneFormatter::load_generic_non_location_long(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XTimeZoneFormatter_load_generic_non_location_long(this->inner.get(), provider.AsFFI()); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<std::monostate, ICU4XError> ICU4XTimeZoneFormatter::load_generic_non_location_short(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XTimeZoneFormatter_load_generic_non_location_short(this->inner.get(), provider.AsFFI()); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<std::monostate, ICU4XError> ICU4XTimeZoneFormatter::load_specific_non_location_long(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XTimeZoneFormatter_load_specific_non_location_long(this->inner.get(), provider.AsFFI()); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<std::monostate, ICU4XError> ICU4XTimeZoneFormatter::load_specific_non_location_short(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XTimeZoneFormatter_load_specific_non_location_short(this->inner.get(), provider.AsFFI()); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<std::monostate, ICU4XError> ICU4XTimeZoneFormatter::load_generic_location_format(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XTimeZoneFormatter_load_generic_location_format(this->inner.get(), provider.AsFFI()); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<std::monostate, ICU4XError> ICU4XTimeZoneFormatter::include_localized_gmt_format() { + auto diplomat_result_raw_out_value = capi::ICU4XTimeZoneFormatter_include_localized_gmt_format(this->inner.get()); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<std::monostate, ICU4XError> ICU4XTimeZoneFormatter::load_iso_8601_format(ICU4XIsoTimeZoneOptions options) { + ICU4XIsoTimeZoneOptions diplomat_wrapped_struct_options = options; + auto diplomat_result_raw_out_value = capi::ICU4XTimeZoneFormatter_load_iso_8601_format(this->inner.get(), capi::ICU4XIsoTimeZoneOptions{ .format = static_cast<capi::ICU4XIsoTimeZoneFormat>(diplomat_wrapped_struct_options.format), .minutes = static_cast<capi::ICU4XIsoTimeZoneMinuteDisplay>(diplomat_wrapped_struct_options.minutes), .seconds = static_cast<capi::ICU4XIsoTimeZoneSecondDisplay>(diplomat_wrapped_struct_options.seconds) }); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XTimeZoneFormatter::format_custom_time_zone_to_writeable(const ICU4XCustomTimeZone& value, W& write) const { + capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write); + auto diplomat_result_raw_out_value = capi::ICU4XTimeZoneFormatter_format_custom_time_zone(this->inner.get(), value.AsFFI(), &write_writer); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<std::string, ICU4XError> ICU4XTimeZoneFormatter::format_custom_time_zone(const ICU4XCustomTimeZone& value) const { + std::string diplomat_writeable_string; + capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); + auto diplomat_result_raw_out_value = capi::ICU4XTimeZoneFormatter_format_custom_time_zone(this->inner.get(), value.AsFFI(), &diplomat_writeable_out); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string)); +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XTitlecaseMapper.h b/intl/icu_capi/cpp/include/ICU4XTitlecaseMapper.h new file mode 100644 index 0000000000..04debefbf9 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XTitlecaseMapper.h @@ -0,0 +1,36 @@ +#ifndef ICU4XTitlecaseMapper_H +#define ICU4XTitlecaseMapper_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XTitlecaseMapper ICU4XTitlecaseMapper; +#ifdef __cplusplus +} // namespace capi +#endif +#include "ICU4XDataProvider.h" +#include "diplomat_result_box_ICU4XTitlecaseMapper_ICU4XError.h" +#include "ICU4XLocale.h" +#include "ICU4XTitlecaseOptionsV1.h" +#include "diplomat_result_void_ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +diplomat_result_box_ICU4XTitlecaseMapper_ICU4XError ICU4XTitlecaseMapper_create(const ICU4XDataProvider* provider); + +diplomat_result_void_ICU4XError ICU4XTitlecaseMapper_titlecase_segment_v1(const ICU4XTitlecaseMapper* self, const char* s_data, size_t s_len, const ICU4XLocale* locale, ICU4XTitlecaseOptionsV1 options, DiplomatWriteable* write); +void ICU4XTitlecaseMapper_destroy(ICU4XTitlecaseMapper* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XTitlecaseMapper.hpp b/intl/icu_capi/cpp/include/ICU4XTitlecaseMapper.hpp new file mode 100644 index 0000000000..c0138d94b8 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XTitlecaseMapper.hpp @@ -0,0 +1,108 @@ +#ifndef ICU4XTitlecaseMapper_HPP +#define ICU4XTitlecaseMapper_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XTitlecaseMapper.h" + +class ICU4XDataProvider; +class ICU4XTitlecaseMapper; +#include "ICU4XError.hpp" +class ICU4XLocale; +struct ICU4XTitlecaseOptionsV1; + +/** + * A destruction policy for using ICU4XTitlecaseMapper with std::unique_ptr. + */ +struct ICU4XTitlecaseMapperDeleter { + void operator()(capi::ICU4XTitlecaseMapper* l) const noexcept { + capi::ICU4XTitlecaseMapper_destroy(l); + } +}; + +/** + * See the [Rust documentation for `TitlecaseMapper`](https://docs.rs/icu/latest/icu/casemap/struct.TitlecaseMapper.html) for more information. + */ +class ICU4XTitlecaseMapper { + public: + + /** + * Construct a new `ICU4XTitlecaseMapper` instance + * + * See the [Rust documentation for `new`](https://docs.rs/icu/latest/icu/casemap/struct.TitlecaseMapper.html#method.new) for more information. + */ + static diplomat::result<ICU4XTitlecaseMapper, ICU4XError> create(const ICU4XDataProvider& provider); + + /** + * Returns the full titlecase mapping of the given string + * + * The `v1` refers to the version of the options struct, which may change as we add more options + * + * See the [Rust documentation for `titlecase_segment`](https://docs.rs/icu/latest/icu/casemap/struct.TitlecaseMapper.html#method.titlecase_segment) for more information. + */ + 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; + + /** + * Returns the full titlecase mapping of the given string + * + * The `v1` refers to the version of the options struct, which may change as we add more options + * + * See the [Rust documentation for `titlecase_segment`](https://docs.rs/icu/latest/icu/casemap/struct.TitlecaseMapper.html#method.titlecase_segment) for more information. + */ + diplomat::result<std::string, ICU4XError> titlecase_segment_v1(const std::string_view s, const ICU4XLocale& locale, ICU4XTitlecaseOptionsV1 options) const; + inline const capi::ICU4XTitlecaseMapper* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XTitlecaseMapper* AsFFIMut() { return this->inner.get(); } + inline ICU4XTitlecaseMapper(capi::ICU4XTitlecaseMapper* i) : inner(i) {} + ICU4XTitlecaseMapper() = default; + ICU4XTitlecaseMapper(ICU4XTitlecaseMapper&&) noexcept = default; + ICU4XTitlecaseMapper& operator=(ICU4XTitlecaseMapper&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XTitlecaseMapper, ICU4XTitlecaseMapperDeleter> inner; +}; + +#include "ICU4XDataProvider.hpp" +#include "ICU4XLocale.hpp" +#include "ICU4XTitlecaseOptionsV1.hpp" + +inline diplomat::result<ICU4XTitlecaseMapper, ICU4XError> ICU4XTitlecaseMapper::create(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XTitlecaseMapper_create(provider.AsFFI()); + diplomat::result<ICU4XTitlecaseMapper, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XTitlecaseMapper>(ICU4XTitlecaseMapper(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +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 { + ICU4XTitlecaseOptionsV1 diplomat_wrapped_struct_options = options; + capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write); + 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); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<std::string, ICU4XError> ICU4XTitlecaseMapper::titlecase_segment_v1(const std::string_view s, const ICU4XLocale& locale, ICU4XTitlecaseOptionsV1 options) const { + ICU4XTitlecaseOptionsV1 diplomat_wrapped_struct_options = options; + std::string diplomat_writeable_string; + capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); + 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); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string)); +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XTitlecaseOptionsV1.h b/intl/icu_capi/cpp/include/ICU4XTitlecaseOptionsV1.h new file mode 100644 index 0000000000..a828188560 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XTitlecaseOptionsV1.h @@ -0,0 +1,36 @@ +#ifndef ICU4XTitlecaseOptionsV1_H +#define ICU4XTitlecaseOptionsV1_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#include "ICU4XLeadingAdjustment.h" +#include "ICU4XTrailingCase.h" +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XTitlecaseOptionsV1 { + ICU4XLeadingAdjustment leading_adjustment; + ICU4XTrailingCase trailing_case; +} ICU4XTitlecaseOptionsV1; +#ifdef __cplusplus +} // namespace capi +#endif +#include "ICU4XLeadingAdjustment.h" +#include "ICU4XTrailingCase.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +ICU4XTitlecaseOptionsV1 ICU4XTitlecaseOptionsV1_default_options(); +void ICU4XTitlecaseOptionsV1_destroy(ICU4XTitlecaseOptionsV1* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XTitlecaseOptionsV1.hpp b/intl/icu_capi/cpp/include/ICU4XTitlecaseOptionsV1.hpp new file mode 100644 index 0000000000..dd8816816b --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XTitlecaseOptionsV1.hpp @@ -0,0 +1,38 @@ +#ifndef ICU4XTitlecaseOptionsV1_HPP +#define ICU4XTitlecaseOptionsV1_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XTitlecaseOptionsV1.h" + +#include "ICU4XLeadingAdjustment.hpp" +#include "ICU4XTrailingCase.hpp" +struct ICU4XTitlecaseOptionsV1; + + +/** + * See the [Rust documentation for `TitlecaseOptions`](https://docs.rs/icu/latest/icu/casemap/titlecase/struct.TitlecaseOptions.html) for more information. + */ +struct ICU4XTitlecaseOptionsV1 { + public: + ICU4XLeadingAdjustment leading_adjustment; + ICU4XTrailingCase trailing_case; + + /** + * See the [Rust documentation for `default`](https://docs.rs/icu/latest/icu/casemap/titlecase/struct.TitlecaseOptions.html#method.default) for more information. + */ + static ICU4XTitlecaseOptionsV1 default_options(); +}; + + +inline ICU4XTitlecaseOptionsV1 ICU4XTitlecaseOptionsV1::default_options() { + capi::ICU4XTitlecaseOptionsV1 diplomat_raw_struct_out_value = capi::ICU4XTitlecaseOptionsV1_default_options(); + return ICU4XTitlecaseOptionsV1{ .leading_adjustment = std::move(static_cast<ICU4XLeadingAdjustment>(diplomat_raw_struct_out_value.leading_adjustment)), .trailing_case = std::move(static_cast<ICU4XTrailingCase>(diplomat_raw_struct_out_value.trailing_case)) }; +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XTrailingCase.h b/intl/icu_capi/cpp/include/ICU4XTrailingCase.h new file mode 100644 index 0000000000..d8957e0088 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XTrailingCase.h @@ -0,0 +1,31 @@ +#ifndef ICU4XTrailingCase_H +#define ICU4XTrailingCase_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef enum ICU4XTrailingCase { + ICU4XTrailingCase_Lower = 0, + ICU4XTrailingCase_Unchanged = 1, +} ICU4XTrailingCase; +#ifdef __cplusplus +} // namespace capi +#endif +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +void ICU4XTrailingCase_destroy(ICU4XTrailingCase* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XTrailingCase.hpp b/intl/icu_capi/cpp/include/ICU4XTrailingCase.hpp new file mode 100644 index 0000000000..7124321156 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XTrailingCase.hpp @@ -0,0 +1,24 @@ +#ifndef ICU4XTrailingCase_HPP +#define ICU4XTrailingCase_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XTrailingCase.h" + + + +/** + * See the [Rust documentation for `TrailingCase`](https://docs.rs/icu/latest/icu/casemap/titlecase/enum.TrailingCase.html) for more information. + */ +enum struct ICU4XTrailingCase { + Lower = 0, + Unchanged = 1, +}; + +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XTransformResult.h b/intl/icu_capi/cpp/include/ICU4XTransformResult.h new file mode 100644 index 0000000000..66b268e266 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XTransformResult.h @@ -0,0 +1,31 @@ +#ifndef ICU4XTransformResult_H +#define ICU4XTransformResult_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef enum ICU4XTransformResult { + ICU4XTransformResult_Modified = 0, + ICU4XTransformResult_Unmodified = 1, +} ICU4XTransformResult; +#ifdef __cplusplus +} // namespace capi +#endif +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +void ICU4XTransformResult_destroy(ICU4XTransformResult* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XTransformResult.hpp b/intl/icu_capi/cpp/include/ICU4XTransformResult.hpp new file mode 100644 index 0000000000..106025313b --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XTransformResult.hpp @@ -0,0 +1,26 @@ +#ifndef ICU4XTransformResult_HPP +#define ICU4XTransformResult_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XTransformResult.h" + + + +/** + * FFI version of `TransformResult`. + * + * See the [Rust documentation for `TransformResult`](https://docs.rs/icu/latest/icu/locid_transform/enum.TransformResult.html) for more information. + */ +enum struct ICU4XTransformResult { + Modified = 0, + Unmodified = 1, +}; + +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XUnicodeSetData.h b/intl/icu_capi/cpp/include/ICU4XUnicodeSetData.h new file mode 100644 index 0000000000..3e10e53097 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XUnicodeSetData.h @@ -0,0 +1,48 @@ +#ifndef ICU4XUnicodeSetData_H +#define ICU4XUnicodeSetData_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XUnicodeSetData ICU4XUnicodeSetData; +#ifdef __cplusplus +} // namespace capi +#endif +#include "ICU4XDataProvider.h" +#include "diplomat_result_box_ICU4XUnicodeSetData_ICU4XError.h" +#include "ICU4XLocale.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +bool ICU4XUnicodeSetData_contains(const ICU4XUnicodeSetData* self, const char* s_data, size_t s_len); + +bool ICU4XUnicodeSetData_contains_char(const ICU4XUnicodeSetData* self, char32_t cp); + +bool ICU4XUnicodeSetData_contains32(const ICU4XUnicodeSetData* self, uint32_t cp); + +diplomat_result_box_ICU4XUnicodeSetData_ICU4XError ICU4XUnicodeSetData_load_basic_emoji(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XUnicodeSetData_ICU4XError ICU4XUnicodeSetData_load_exemplars_main(const ICU4XDataProvider* provider, const ICU4XLocale* locale); + +diplomat_result_box_ICU4XUnicodeSetData_ICU4XError ICU4XUnicodeSetData_load_exemplars_auxiliary(const ICU4XDataProvider* provider, const ICU4XLocale* locale); + +diplomat_result_box_ICU4XUnicodeSetData_ICU4XError ICU4XUnicodeSetData_load_exemplars_punctuation(const ICU4XDataProvider* provider, const ICU4XLocale* locale); + +diplomat_result_box_ICU4XUnicodeSetData_ICU4XError ICU4XUnicodeSetData_load_exemplars_numbers(const ICU4XDataProvider* provider, const ICU4XLocale* locale); + +diplomat_result_box_ICU4XUnicodeSetData_ICU4XError ICU4XUnicodeSetData_load_exemplars_index(const ICU4XDataProvider* provider, const ICU4XLocale* locale); +void ICU4XUnicodeSetData_destroy(ICU4XUnicodeSetData* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XUnicodeSetData.hpp b/intl/icu_capi/cpp/include/ICU4XUnicodeSetData.hpp new file mode 100644 index 0000000000..87bef74eac --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XUnicodeSetData.hpp @@ -0,0 +1,170 @@ +#ifndef ICU4XUnicodeSetData_HPP +#define ICU4XUnicodeSetData_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XUnicodeSetData.h" + +class ICU4XDataProvider; +class ICU4XUnicodeSetData; +#include "ICU4XError.hpp" +class ICU4XLocale; + +/** + * A destruction policy for using ICU4XUnicodeSetData with std::unique_ptr. + */ +struct ICU4XUnicodeSetDataDeleter { + void operator()(capi::ICU4XUnicodeSetData* l) const noexcept { + capi::ICU4XUnicodeSetData_destroy(l); + } +}; + +/** + * An ICU4X Unicode Set Property object, capable of querying whether a code point is contained in a set based on a Unicode property. + * + * See the [Rust documentation for `properties`](https://docs.rs/icu/latest/icu/properties/index.html) for more information. + * + * See the [Rust documentation for `UnicodeSetData`](https://docs.rs/icu/latest/icu/properties/sets/struct.UnicodeSetData.html) for more information. + * + * See the [Rust documentation for `UnicodeSetDataBorrowed`](https://docs.rs/icu/latest/icu/properties/sets/struct.UnicodeSetDataBorrowed.html) for more information. + */ +class ICU4XUnicodeSetData { + public: + + /** + * Checks whether the string is in the set. + * + * See the [Rust documentation for `contains`](https://docs.rs/icu/latest/icu/properties/sets/struct.UnicodeSetDataBorrowed.html#method.contains) for more information. + */ + bool contains(const std::string_view s) const; + + /** + * Checks whether the code point is in the set. + * + * See the [Rust documentation for `contains_char`](https://docs.rs/icu/latest/icu/properties/sets/struct.UnicodeSetDataBorrowed.html#method.contains_char) for more information. + */ + bool contains_char(char32_t cp) const; + + /** + * Checks whether the code point (specified as a 32 bit integer, in UTF-32) is in the set. + */ + bool contains32(uint32_t cp) const; + + /** + * See the [Rust documentation for `basic_emoji`](https://docs.rs/icu/latest/icu/properties/sets/fn.basic_emoji.html) for more information. + */ + static diplomat::result<ICU4XUnicodeSetData, ICU4XError> load_basic_emoji(const ICU4XDataProvider& provider); + + /** + * See the [Rust documentation for `exemplars_main`](https://docs.rs/icu/latest/icu/properties/exemplar_chars/fn.exemplars_main.html) for more information. + */ + static diplomat::result<ICU4XUnicodeSetData, ICU4XError> load_exemplars_main(const ICU4XDataProvider& provider, const ICU4XLocale& locale); + + /** + * See the [Rust documentation for `exemplars_auxiliary`](https://docs.rs/icu/latest/icu/properties/exemplar_chars/fn.exemplars_auxiliary.html) for more information. + */ + static diplomat::result<ICU4XUnicodeSetData, ICU4XError> load_exemplars_auxiliary(const ICU4XDataProvider& provider, const ICU4XLocale& locale); + + /** + * See the [Rust documentation for `exemplars_punctuation`](https://docs.rs/icu/latest/icu/properties/exemplar_chars/fn.exemplars_punctuation.html) for more information. + */ + static diplomat::result<ICU4XUnicodeSetData, ICU4XError> load_exemplars_punctuation(const ICU4XDataProvider& provider, const ICU4XLocale& locale); + + /** + * See the [Rust documentation for `exemplars_numbers`](https://docs.rs/icu/latest/icu/properties/exemplar_chars/fn.exemplars_numbers.html) for more information. + */ + static diplomat::result<ICU4XUnicodeSetData, ICU4XError> load_exemplars_numbers(const ICU4XDataProvider& provider, const ICU4XLocale& locale); + + /** + * See the [Rust documentation for `exemplars_index`](https://docs.rs/icu/latest/icu/properties/exemplar_chars/fn.exemplars_index.html) for more information. + */ + static diplomat::result<ICU4XUnicodeSetData, ICU4XError> load_exemplars_index(const ICU4XDataProvider& provider, const ICU4XLocale& locale); + inline const capi::ICU4XUnicodeSetData* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XUnicodeSetData* AsFFIMut() { return this->inner.get(); } + inline ICU4XUnicodeSetData(capi::ICU4XUnicodeSetData* i) : inner(i) {} + ICU4XUnicodeSetData() = default; + ICU4XUnicodeSetData(ICU4XUnicodeSetData&&) noexcept = default; + ICU4XUnicodeSetData& operator=(ICU4XUnicodeSetData&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XUnicodeSetData, ICU4XUnicodeSetDataDeleter> inner; +}; + +#include "ICU4XDataProvider.hpp" +#include "ICU4XLocale.hpp" + +inline bool ICU4XUnicodeSetData::contains(const std::string_view s) const { + return capi::ICU4XUnicodeSetData_contains(this->inner.get(), s.data(), s.size()); +} +inline bool ICU4XUnicodeSetData::contains_char(char32_t cp) const { + return capi::ICU4XUnicodeSetData_contains_char(this->inner.get(), cp); +} +inline bool ICU4XUnicodeSetData::contains32(uint32_t cp) const { + return capi::ICU4XUnicodeSetData_contains32(this->inner.get(), cp); +} +inline diplomat::result<ICU4XUnicodeSetData, ICU4XError> ICU4XUnicodeSetData::load_basic_emoji(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XUnicodeSetData_load_basic_emoji(provider.AsFFI()); + diplomat::result<ICU4XUnicodeSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XUnicodeSetData>(ICU4XUnicodeSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XUnicodeSetData, ICU4XError> ICU4XUnicodeSetData::load_exemplars_main(const ICU4XDataProvider& provider, const ICU4XLocale& locale) { + auto diplomat_result_raw_out_value = capi::ICU4XUnicodeSetData_load_exemplars_main(provider.AsFFI(), locale.AsFFI()); + diplomat::result<ICU4XUnicodeSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XUnicodeSetData>(ICU4XUnicodeSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XUnicodeSetData, ICU4XError> ICU4XUnicodeSetData::load_exemplars_auxiliary(const ICU4XDataProvider& provider, const ICU4XLocale& locale) { + auto diplomat_result_raw_out_value = capi::ICU4XUnicodeSetData_load_exemplars_auxiliary(provider.AsFFI(), locale.AsFFI()); + diplomat::result<ICU4XUnicodeSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XUnicodeSetData>(ICU4XUnicodeSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XUnicodeSetData, ICU4XError> ICU4XUnicodeSetData::load_exemplars_punctuation(const ICU4XDataProvider& provider, const ICU4XLocale& locale) { + auto diplomat_result_raw_out_value = capi::ICU4XUnicodeSetData_load_exemplars_punctuation(provider.AsFFI(), locale.AsFFI()); + diplomat::result<ICU4XUnicodeSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XUnicodeSetData>(ICU4XUnicodeSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XUnicodeSetData, ICU4XError> ICU4XUnicodeSetData::load_exemplars_numbers(const ICU4XDataProvider& provider, const ICU4XLocale& locale) { + auto diplomat_result_raw_out_value = capi::ICU4XUnicodeSetData_load_exemplars_numbers(provider.AsFFI(), locale.AsFFI()); + diplomat::result<ICU4XUnicodeSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XUnicodeSetData>(ICU4XUnicodeSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XUnicodeSetData, ICU4XError> ICU4XUnicodeSetData::load_exemplars_index(const ICU4XDataProvider& provider, const ICU4XLocale& locale) { + auto diplomat_result_raw_out_value = capi::ICU4XUnicodeSetData_load_exemplars_index(provider.AsFFI(), locale.AsFFI()); + diplomat::result<ICU4XUnicodeSetData, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XUnicodeSetData>(ICU4XUnicodeSetData(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XWeekCalculator.h b/intl/icu_capi/cpp/include/ICU4XWeekCalculator.h new file mode 100644 index 0000000000..02a52c6e87 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XWeekCalculator.h @@ -0,0 +1,39 @@ +#ifndef ICU4XWeekCalculator_H +#define ICU4XWeekCalculator_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XWeekCalculator ICU4XWeekCalculator; +#ifdef __cplusplus +} // namespace capi +#endif +#include "ICU4XDataProvider.h" +#include "ICU4XLocale.h" +#include "diplomat_result_box_ICU4XWeekCalculator_ICU4XError.h" +#include "ICU4XIsoWeekday.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +diplomat_result_box_ICU4XWeekCalculator_ICU4XError ICU4XWeekCalculator_create(const ICU4XDataProvider* provider, const ICU4XLocale* locale); + +ICU4XWeekCalculator* ICU4XWeekCalculator_create_from_first_day_of_week_and_min_week_days(ICU4XIsoWeekday first_weekday, uint8_t min_week_days); + +ICU4XIsoWeekday ICU4XWeekCalculator_first_weekday(const ICU4XWeekCalculator* self); + +uint8_t ICU4XWeekCalculator_min_week_days(const ICU4XWeekCalculator* self); +void ICU4XWeekCalculator_destroy(ICU4XWeekCalculator* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XWeekCalculator.hpp b/intl/icu_capi/cpp/include/ICU4XWeekCalculator.hpp new file mode 100644 index 0000000000..ace3c97c4f --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XWeekCalculator.hpp @@ -0,0 +1,95 @@ +#ifndef ICU4XWeekCalculator_HPP +#define ICU4XWeekCalculator_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XWeekCalculator.h" + +class ICU4XDataProvider; +class ICU4XLocale; +class ICU4XWeekCalculator; +#include "ICU4XError.hpp" +#include "ICU4XIsoWeekday.hpp" + +/** + * A destruction policy for using ICU4XWeekCalculator with std::unique_ptr. + */ +struct ICU4XWeekCalculatorDeleter { + void operator()(capi::ICU4XWeekCalculator* l) const noexcept { + capi::ICU4XWeekCalculator_destroy(l); + } +}; + +/** + * A Week calculator, useful to be passed in to `week_of_year()` on Date and DateTime types + * + * See the [Rust documentation for `WeekCalculator`](https://docs.rs/icu/latest/icu/calendar/week/struct.WeekCalculator.html) for more information. + */ +class ICU4XWeekCalculator { + public: + + /** + * Creates a new [`ICU4XWeekCalculator`] from locale data. + * + * See the [Rust documentation for `try_new`](https://docs.rs/icu/latest/icu/calendar/week/struct.WeekCalculator.html#method.try_new) for more information. + */ + static diplomat::result<ICU4XWeekCalculator, ICU4XError> create(const ICU4XDataProvider& provider, const ICU4XLocale& locale); + + /** + * Additional information: [1](https://docs.rs/icu/latest/icu/calendar/week/struct.WeekCalculator.html#structfield.first_weekday), [2](https://docs.rs/icu/latest/icu/calendar/week/struct.WeekCalculator.html#structfield.min_week_days) + */ + static ICU4XWeekCalculator create_from_first_day_of_week_and_min_week_days(ICU4XIsoWeekday first_weekday, uint8_t min_week_days); + + /** + * Returns the weekday that starts the week for this object's locale + * + * See the [Rust documentation for `first_weekday`](https://docs.rs/icu/latest/icu/calendar/week/struct.WeekCalculator.html#structfield.first_weekday) for more information. + */ + ICU4XIsoWeekday first_weekday() const; + + /** + * The minimum number of days overlapping a year required for a week to be + * considered part of that year + * + * See the [Rust documentation for `min_week_days`](https://docs.rs/icu/latest/icu/calendar/week/struct.WeekCalculator.html#structfield.min_week_days) for more information. + */ + uint8_t min_week_days() const; + inline const capi::ICU4XWeekCalculator* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XWeekCalculator* AsFFIMut() { return this->inner.get(); } + inline ICU4XWeekCalculator(capi::ICU4XWeekCalculator* i) : inner(i) {} + ICU4XWeekCalculator() = default; + ICU4XWeekCalculator(ICU4XWeekCalculator&&) noexcept = default; + ICU4XWeekCalculator& operator=(ICU4XWeekCalculator&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XWeekCalculator, ICU4XWeekCalculatorDeleter> inner; +}; + +#include "ICU4XDataProvider.hpp" +#include "ICU4XLocale.hpp" + +inline diplomat::result<ICU4XWeekCalculator, ICU4XError> ICU4XWeekCalculator::create(const ICU4XDataProvider& provider, const ICU4XLocale& locale) { + auto diplomat_result_raw_out_value = capi::ICU4XWeekCalculator_create(provider.AsFFI(), locale.AsFFI()); + diplomat::result<ICU4XWeekCalculator, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XWeekCalculator>(ICU4XWeekCalculator(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline ICU4XWeekCalculator ICU4XWeekCalculator::create_from_first_day_of_week_and_min_week_days(ICU4XIsoWeekday first_weekday, uint8_t min_week_days) { + return ICU4XWeekCalculator(capi::ICU4XWeekCalculator_create_from_first_day_of_week_and_min_week_days(static_cast<capi::ICU4XIsoWeekday>(first_weekday), min_week_days)); +} +inline ICU4XIsoWeekday ICU4XWeekCalculator::first_weekday() const { + return static_cast<ICU4XIsoWeekday>(capi::ICU4XWeekCalculator_first_weekday(this->inner.get())); +} +inline uint8_t ICU4XWeekCalculator::min_week_days() const { + return capi::ICU4XWeekCalculator_min_week_days(this->inner.get()); +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XWeekOf.h b/intl/icu_capi/cpp/include/ICU4XWeekOf.h new file mode 100644 index 0000000000..5441b943d4 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XWeekOf.h @@ -0,0 +1,33 @@ +#ifndef ICU4XWeekOf_H +#define ICU4XWeekOf_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#include "ICU4XWeekRelativeUnit.h" +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XWeekOf { + uint16_t week; + ICU4XWeekRelativeUnit unit; +} ICU4XWeekOf; +#ifdef __cplusplus +} // namespace capi +#endif +#include "ICU4XWeekRelativeUnit.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +void ICU4XWeekOf_destroy(ICU4XWeekOf* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XWeekOf.hpp b/intl/icu_capi/cpp/include/ICU4XWeekOf.hpp new file mode 100644 index 0000000000..f0badc2bfb --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XWeekOf.hpp @@ -0,0 +1,27 @@ +#ifndef ICU4XWeekOf_HPP +#define ICU4XWeekOf_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XWeekOf.h" + +#include "ICU4XWeekRelativeUnit.hpp" + + +/** + * See the [Rust documentation for `WeekOf`](https://docs.rs/icu/latest/icu/calendar/week/struct.WeekOf.html) for more information. + */ +struct ICU4XWeekOf { + public: + uint16_t week; + ICU4XWeekRelativeUnit unit; +}; + + +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XWeekRelativeUnit.h b/intl/icu_capi/cpp/include/ICU4XWeekRelativeUnit.h new file mode 100644 index 0000000000..ee6802dc3b --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XWeekRelativeUnit.h @@ -0,0 +1,32 @@ +#ifndef ICU4XWeekRelativeUnit_H +#define ICU4XWeekRelativeUnit_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef enum ICU4XWeekRelativeUnit { + ICU4XWeekRelativeUnit_Previous = 0, + ICU4XWeekRelativeUnit_Current = 1, + ICU4XWeekRelativeUnit_Next = 2, +} ICU4XWeekRelativeUnit; +#ifdef __cplusplus +} // namespace capi +#endif +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +void ICU4XWeekRelativeUnit_destroy(ICU4XWeekRelativeUnit* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XWeekRelativeUnit.hpp b/intl/icu_capi/cpp/include/ICU4XWeekRelativeUnit.hpp new file mode 100644 index 0000000000..f0862f0d32 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XWeekRelativeUnit.hpp @@ -0,0 +1,25 @@ +#ifndef ICU4XWeekRelativeUnit_HPP +#define ICU4XWeekRelativeUnit_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XWeekRelativeUnit.h" + + + +/** + * See the [Rust documentation for `RelativeUnit`](https://docs.rs/icu/latest/icu/calendar/week/enum.RelativeUnit.html) for more information. + */ +enum struct ICU4XWeekRelativeUnit { + Previous = 0, + Current = 1, + Next = 2, +}; + +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XWordBreakIteratorLatin1.h b/intl/icu_capi/cpp/include/ICU4XWordBreakIteratorLatin1.h new file mode 100644 index 0000000000..112025bdf5 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XWordBreakIteratorLatin1.h @@ -0,0 +1,34 @@ +#ifndef ICU4XWordBreakIteratorLatin1_H +#define ICU4XWordBreakIteratorLatin1_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XWordBreakIteratorLatin1 ICU4XWordBreakIteratorLatin1; +#ifdef __cplusplus +} // namespace capi +#endif +#include "ICU4XSegmenterWordType.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +int32_t ICU4XWordBreakIteratorLatin1_next(ICU4XWordBreakIteratorLatin1* self); + +ICU4XSegmenterWordType ICU4XWordBreakIteratorLatin1_word_type(const ICU4XWordBreakIteratorLatin1* self); + +bool ICU4XWordBreakIteratorLatin1_is_word_like(const ICU4XWordBreakIteratorLatin1* self); +void ICU4XWordBreakIteratorLatin1_destroy(ICU4XWordBreakIteratorLatin1* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XWordBreakIteratorLatin1.hpp b/intl/icu_capi/cpp/include/ICU4XWordBreakIteratorLatin1.hpp new file mode 100644 index 0000000000..83c8f0ef7e --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XWordBreakIteratorLatin1.hpp @@ -0,0 +1,72 @@ +#ifndef ICU4XWordBreakIteratorLatin1_HPP +#define ICU4XWordBreakIteratorLatin1_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XWordBreakIteratorLatin1.h" + +#include "ICU4XSegmenterWordType.hpp" + +/** + * A destruction policy for using ICU4XWordBreakIteratorLatin1 with std::unique_ptr. + */ +struct ICU4XWordBreakIteratorLatin1Deleter { + void operator()(capi::ICU4XWordBreakIteratorLatin1* l) const noexcept { + capi::ICU4XWordBreakIteratorLatin1_destroy(l); + } +}; + +/** + * See the [Rust documentation for `WordBreakIterator`](https://docs.rs/icu/latest/icu/segmenter/struct.WordBreakIterator.html) for more information. + */ +class ICU4XWordBreakIteratorLatin1 { + public: + + /** + * Finds the next breakpoint. Returns -1 if at the end of the string or if the index is + * out of range of a 32-bit signed integer. + * + * See the [Rust documentation for `next`](https://docs.rs/icu/latest/icu/segmenter/struct.WordBreakIterator.html#method.next) for more information. + */ + int32_t next(); + + /** + * Return the status value of break boundary. + * + * See the [Rust documentation for `word_type`](https://docs.rs/icu/latest/icu/segmenter/struct.WordBreakIterator.html#method.word_type) for more information. + */ + ICU4XSegmenterWordType word_type() const; + + /** + * Return true when break boundary is word-like such as letter/number/CJK + * + * See the [Rust documentation for `is_word_like`](https://docs.rs/icu/latest/icu/segmenter/struct.WordBreakIterator.html#method.is_word_like) for more information. + */ + bool is_word_like() const; + inline const capi::ICU4XWordBreakIteratorLatin1* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XWordBreakIteratorLatin1* AsFFIMut() { return this->inner.get(); } + inline explicit ICU4XWordBreakIteratorLatin1(capi::ICU4XWordBreakIteratorLatin1* i) : inner(i) {} + ICU4XWordBreakIteratorLatin1() = default; + ICU4XWordBreakIteratorLatin1(ICU4XWordBreakIteratorLatin1&&) noexcept = default; + ICU4XWordBreakIteratorLatin1& operator=(ICU4XWordBreakIteratorLatin1&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XWordBreakIteratorLatin1, ICU4XWordBreakIteratorLatin1Deleter> inner; +}; + + +inline int32_t ICU4XWordBreakIteratorLatin1::next() { + return capi::ICU4XWordBreakIteratorLatin1_next(this->inner.get()); +} +inline ICU4XSegmenterWordType ICU4XWordBreakIteratorLatin1::word_type() const { + return static_cast<ICU4XSegmenterWordType>(capi::ICU4XWordBreakIteratorLatin1_word_type(this->inner.get())); +} +inline bool ICU4XWordBreakIteratorLatin1::is_word_like() const { + return capi::ICU4XWordBreakIteratorLatin1_is_word_like(this->inner.get()); +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XWordBreakIteratorUtf16.h b/intl/icu_capi/cpp/include/ICU4XWordBreakIteratorUtf16.h new file mode 100644 index 0000000000..676aea3cff --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XWordBreakIteratorUtf16.h @@ -0,0 +1,34 @@ +#ifndef ICU4XWordBreakIteratorUtf16_H +#define ICU4XWordBreakIteratorUtf16_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XWordBreakIteratorUtf16 ICU4XWordBreakIteratorUtf16; +#ifdef __cplusplus +} // namespace capi +#endif +#include "ICU4XSegmenterWordType.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +int32_t ICU4XWordBreakIteratorUtf16_next(ICU4XWordBreakIteratorUtf16* self); + +ICU4XSegmenterWordType ICU4XWordBreakIteratorUtf16_word_type(const ICU4XWordBreakIteratorUtf16* self); + +bool ICU4XWordBreakIteratorUtf16_is_word_like(const ICU4XWordBreakIteratorUtf16* self); +void ICU4XWordBreakIteratorUtf16_destroy(ICU4XWordBreakIteratorUtf16* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XWordBreakIteratorUtf16.hpp b/intl/icu_capi/cpp/include/ICU4XWordBreakIteratorUtf16.hpp new file mode 100644 index 0000000000..38abe0fe2b --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XWordBreakIteratorUtf16.hpp @@ -0,0 +1,72 @@ +#ifndef ICU4XWordBreakIteratorUtf16_HPP +#define ICU4XWordBreakIteratorUtf16_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XWordBreakIteratorUtf16.h" + +#include "ICU4XSegmenterWordType.hpp" + +/** + * A destruction policy for using ICU4XWordBreakIteratorUtf16 with std::unique_ptr. + */ +struct ICU4XWordBreakIteratorUtf16Deleter { + void operator()(capi::ICU4XWordBreakIteratorUtf16* l) const noexcept { + capi::ICU4XWordBreakIteratorUtf16_destroy(l); + } +}; + +/** + * See the [Rust documentation for `WordBreakIterator`](https://docs.rs/icu/latest/icu/segmenter/struct.WordBreakIterator.html) for more information. + */ +class ICU4XWordBreakIteratorUtf16 { + public: + + /** + * Finds the next breakpoint. Returns -1 if at the end of the string or if the index is + * out of range of a 32-bit signed integer. + * + * See the [Rust documentation for `next`](https://docs.rs/icu/latest/icu/segmenter/struct.WordBreakIterator.html#method.next) for more information. + */ + int32_t next(); + + /** + * Return the status value of break boundary. + * + * See the [Rust documentation for `word_type`](https://docs.rs/icu/latest/icu/segmenter/struct.WordBreakIterator.html#method.word_type) for more information. + */ + ICU4XSegmenterWordType word_type() const; + + /** + * Return true when break boundary is word-like such as letter/number/CJK + * + * See the [Rust documentation for `is_word_like`](https://docs.rs/icu/latest/icu/segmenter/struct.WordBreakIterator.html#method.is_word_like) for more information. + */ + bool is_word_like() const; + inline const capi::ICU4XWordBreakIteratorUtf16* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XWordBreakIteratorUtf16* AsFFIMut() { return this->inner.get(); } + inline explicit ICU4XWordBreakIteratorUtf16(capi::ICU4XWordBreakIteratorUtf16* i) : inner(i) {} + ICU4XWordBreakIteratorUtf16() = default; + ICU4XWordBreakIteratorUtf16(ICU4XWordBreakIteratorUtf16&&) noexcept = default; + ICU4XWordBreakIteratorUtf16& operator=(ICU4XWordBreakIteratorUtf16&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XWordBreakIteratorUtf16, ICU4XWordBreakIteratorUtf16Deleter> inner; +}; + + +inline int32_t ICU4XWordBreakIteratorUtf16::next() { + return capi::ICU4XWordBreakIteratorUtf16_next(this->inner.get()); +} +inline ICU4XSegmenterWordType ICU4XWordBreakIteratorUtf16::word_type() const { + return static_cast<ICU4XSegmenterWordType>(capi::ICU4XWordBreakIteratorUtf16_word_type(this->inner.get())); +} +inline bool ICU4XWordBreakIteratorUtf16::is_word_like() const { + return capi::ICU4XWordBreakIteratorUtf16_is_word_like(this->inner.get()); +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XWordBreakIteratorUtf8.h b/intl/icu_capi/cpp/include/ICU4XWordBreakIteratorUtf8.h new file mode 100644 index 0000000000..d8e98fb9b1 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XWordBreakIteratorUtf8.h @@ -0,0 +1,34 @@ +#ifndef ICU4XWordBreakIteratorUtf8_H +#define ICU4XWordBreakIteratorUtf8_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XWordBreakIteratorUtf8 ICU4XWordBreakIteratorUtf8; +#ifdef __cplusplus +} // namespace capi +#endif +#include "ICU4XSegmenterWordType.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +int32_t ICU4XWordBreakIteratorUtf8_next(ICU4XWordBreakIteratorUtf8* self); + +ICU4XSegmenterWordType ICU4XWordBreakIteratorUtf8_word_type(const ICU4XWordBreakIteratorUtf8* self); + +bool ICU4XWordBreakIteratorUtf8_is_word_like(const ICU4XWordBreakIteratorUtf8* self); +void ICU4XWordBreakIteratorUtf8_destroy(ICU4XWordBreakIteratorUtf8* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XWordBreakIteratorUtf8.hpp b/intl/icu_capi/cpp/include/ICU4XWordBreakIteratorUtf8.hpp new file mode 100644 index 0000000000..be47dd1b0d --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XWordBreakIteratorUtf8.hpp @@ -0,0 +1,72 @@ +#ifndef ICU4XWordBreakIteratorUtf8_HPP +#define ICU4XWordBreakIteratorUtf8_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XWordBreakIteratorUtf8.h" + +#include "ICU4XSegmenterWordType.hpp" + +/** + * A destruction policy for using ICU4XWordBreakIteratorUtf8 with std::unique_ptr. + */ +struct ICU4XWordBreakIteratorUtf8Deleter { + void operator()(capi::ICU4XWordBreakIteratorUtf8* l) const noexcept { + capi::ICU4XWordBreakIteratorUtf8_destroy(l); + } +}; + +/** + * See the [Rust documentation for `WordBreakIterator`](https://docs.rs/icu/latest/icu/segmenter/struct.WordBreakIterator.html) for more information. + */ +class ICU4XWordBreakIteratorUtf8 { + public: + + /** + * Finds the next breakpoint. Returns -1 if at the end of the string or if the index is + * out of range of a 32-bit signed integer. + * + * See the [Rust documentation for `next`](https://docs.rs/icu/latest/icu/segmenter/struct.WordBreakIterator.html#method.next) for more information. + */ + int32_t next(); + + /** + * Return the status value of break boundary. + * + * See the [Rust documentation for `word_type`](https://docs.rs/icu/latest/icu/segmenter/struct.WordBreakIterator.html#method.word_type) for more information. + */ + ICU4XSegmenterWordType word_type() const; + + /** + * Return true when break boundary is word-like such as letter/number/CJK + * + * See the [Rust documentation for `is_word_like`](https://docs.rs/icu/latest/icu/segmenter/struct.WordBreakIterator.html#method.is_word_like) for more information. + */ + bool is_word_like() const; + inline const capi::ICU4XWordBreakIteratorUtf8* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XWordBreakIteratorUtf8* AsFFIMut() { return this->inner.get(); } + inline explicit ICU4XWordBreakIteratorUtf8(capi::ICU4XWordBreakIteratorUtf8* i) : inner(i) {} + ICU4XWordBreakIteratorUtf8() = default; + ICU4XWordBreakIteratorUtf8(ICU4XWordBreakIteratorUtf8&&) noexcept = default; + ICU4XWordBreakIteratorUtf8& operator=(ICU4XWordBreakIteratorUtf8&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XWordBreakIteratorUtf8, ICU4XWordBreakIteratorUtf8Deleter> inner; +}; + + +inline int32_t ICU4XWordBreakIteratorUtf8::next() { + return capi::ICU4XWordBreakIteratorUtf8_next(this->inner.get()); +} +inline ICU4XSegmenterWordType ICU4XWordBreakIteratorUtf8::word_type() const { + return static_cast<ICU4XSegmenterWordType>(capi::ICU4XWordBreakIteratorUtf8_word_type(this->inner.get())); +} +inline bool ICU4XWordBreakIteratorUtf8::is_word_like() const { + return capi::ICU4XWordBreakIteratorUtf8_is_word_like(this->inner.get()); +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XWordSegmenter.h b/intl/icu_capi/cpp/include/ICU4XWordSegmenter.h new file mode 100644 index 0000000000..5bef9437e0 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XWordSegmenter.h @@ -0,0 +1,44 @@ +#ifndef ICU4XWordSegmenter_H +#define ICU4XWordSegmenter_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XWordSegmenter ICU4XWordSegmenter; +#ifdef __cplusplus +} // namespace capi +#endif +#include "ICU4XDataProvider.h" +#include "diplomat_result_box_ICU4XWordSegmenter_ICU4XError.h" +#include "ICU4XWordBreakIteratorUtf8.h" +#include "ICU4XWordBreakIteratorUtf16.h" +#include "ICU4XWordBreakIteratorLatin1.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +diplomat_result_box_ICU4XWordSegmenter_ICU4XError ICU4XWordSegmenter_create_auto(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XWordSegmenter_ICU4XError ICU4XWordSegmenter_create_lstm(const ICU4XDataProvider* provider); + +diplomat_result_box_ICU4XWordSegmenter_ICU4XError ICU4XWordSegmenter_create_dictionary(const ICU4XDataProvider* provider); + +ICU4XWordBreakIteratorUtf8* ICU4XWordSegmenter_segment_utf8(const ICU4XWordSegmenter* self, const char* input_data, size_t input_len); + +ICU4XWordBreakIteratorUtf16* ICU4XWordSegmenter_segment_utf16(const ICU4XWordSegmenter* self, const uint16_t* input_data, size_t input_len); + +ICU4XWordBreakIteratorLatin1* ICU4XWordSegmenter_segment_latin1(const ICU4XWordSegmenter* self, const uint8_t* input_data, size_t input_len); +void ICU4XWordSegmenter_destroy(ICU4XWordSegmenter* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XWordSegmenter.hpp b/intl/icu_capi/cpp/include/ICU4XWordSegmenter.hpp new file mode 100644 index 0000000000..49734b5a4a --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XWordSegmenter.hpp @@ -0,0 +1,148 @@ +#ifndef ICU4XWordSegmenter_HPP +#define ICU4XWordSegmenter_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XWordSegmenter.h" + +class ICU4XDataProvider; +class ICU4XWordSegmenter; +#include "ICU4XError.hpp" +class ICU4XWordBreakIteratorUtf8; +class ICU4XWordBreakIteratorUtf16; +class ICU4XWordBreakIteratorLatin1; + +/** + * A destruction policy for using ICU4XWordSegmenter with std::unique_ptr. + */ +struct ICU4XWordSegmenterDeleter { + void operator()(capi::ICU4XWordSegmenter* l) const noexcept { + capi::ICU4XWordSegmenter_destroy(l); + } +}; + +/** + * An ICU4X word-break segmenter, capable of finding word breakpoints in strings. + * + * See the [Rust documentation for `WordSegmenter`](https://docs.rs/icu/latest/icu/segmenter/struct.WordSegmenter.html) for more information. + */ +class ICU4XWordSegmenter { + public: + + /** + * Construct an [`ICU4XWordSegmenter`] with automatically selecting the best available LSTM + * or dictionary payload data. + * + * Note: currently, it uses dictionary for Chinese and Japanese, and LSTM for Burmese, + * Khmer, Lao, and Thai. + * + * See the [Rust documentation for `new_auto`](https://docs.rs/icu/latest/icu/segmenter/struct.WordSegmenter.html#method.new_auto) for more information. + */ + static diplomat::result<ICU4XWordSegmenter, ICU4XError> create_auto(const ICU4XDataProvider& provider); + + /** + * Construct an [`ICU4XWordSegmenter`] with LSTM payload data for Burmese, Khmer, Lao, and + * Thai. + * + * Warning: [`ICU4XWordSegmenter`] created by this function doesn't handle Chinese or + * Japanese. + * + * See the [Rust documentation for `new_lstm`](https://docs.rs/icu/latest/icu/segmenter/struct.WordSegmenter.html#method.new_lstm) for more information. + */ + static diplomat::result<ICU4XWordSegmenter, ICU4XError> create_lstm(const ICU4XDataProvider& provider); + + /** + * Construct an [`ICU4XWordSegmenter`] with dictionary payload data for Chinese, Japanese, + * Burmese, Khmer, Lao, and Thai. + * + * See the [Rust documentation for `new_dictionary`](https://docs.rs/icu/latest/icu/segmenter/struct.WordSegmenter.html#method.new_dictionary) for more information. + */ + static diplomat::result<ICU4XWordSegmenter, ICU4XError> create_dictionary(const ICU4XDataProvider& provider); + + /** + * Segments a (potentially ill-formed) UTF-8 string. + * + * See the [Rust documentation for `segment_utf8`](https://docs.rs/icu/latest/icu/segmenter/struct.WordSegmenter.html#method.segment_utf8) for more information. + * + * Lifetimes: `this`, `input` must live at least as long as the output. + */ + ICU4XWordBreakIteratorUtf8 segment_utf8(const std::string_view input) const; + + /** + * Segments a UTF-16 string. + * + * See the [Rust documentation for `segment_utf16`](https://docs.rs/icu/latest/icu/segmenter/struct.WordSegmenter.html#method.segment_utf16) for more information. + * + * Lifetimes: `this`, `input` must live at least as long as the output. + */ + ICU4XWordBreakIteratorUtf16 segment_utf16(const diplomat::span<const uint16_t> input) const; + + /** + * Segments a Latin-1 string. + * + * See the [Rust documentation for `segment_latin1`](https://docs.rs/icu/latest/icu/segmenter/struct.WordSegmenter.html#method.segment_latin1) for more information. + * + * Lifetimes: `this`, `input` must live at least as long as the output. + */ + ICU4XWordBreakIteratorLatin1 segment_latin1(const diplomat::span<const uint8_t> input) const; + inline const capi::ICU4XWordSegmenter* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XWordSegmenter* AsFFIMut() { return this->inner.get(); } + inline explicit ICU4XWordSegmenter(capi::ICU4XWordSegmenter* i) : inner(i) {} + ICU4XWordSegmenter() = default; + ICU4XWordSegmenter(ICU4XWordSegmenter&&) noexcept = default; + ICU4XWordSegmenter& operator=(ICU4XWordSegmenter&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XWordSegmenter, ICU4XWordSegmenterDeleter> inner; +}; + +#include "ICU4XDataProvider.hpp" +#include "ICU4XWordBreakIteratorUtf8.hpp" +#include "ICU4XWordBreakIteratorUtf16.hpp" +#include "ICU4XWordBreakIteratorLatin1.hpp" + +inline diplomat::result<ICU4XWordSegmenter, ICU4XError> ICU4XWordSegmenter::create_auto(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XWordSegmenter_create_auto(provider.AsFFI()); + diplomat::result<ICU4XWordSegmenter, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XWordSegmenter>(ICU4XWordSegmenter(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XWordSegmenter, ICU4XError> ICU4XWordSegmenter::create_lstm(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XWordSegmenter_create_lstm(provider.AsFFI()); + diplomat::result<ICU4XWordSegmenter, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XWordSegmenter>(ICU4XWordSegmenter(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XWordSegmenter, ICU4XError> ICU4XWordSegmenter::create_dictionary(const ICU4XDataProvider& provider) { + auto diplomat_result_raw_out_value = capi::ICU4XWordSegmenter_create_dictionary(provider.AsFFI()); + diplomat::result<ICU4XWordSegmenter, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XWordSegmenter>(ICU4XWordSegmenter(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline ICU4XWordBreakIteratorUtf8 ICU4XWordSegmenter::segment_utf8(const std::string_view input) const { + return ICU4XWordBreakIteratorUtf8(capi::ICU4XWordSegmenter_segment_utf8(this->inner.get(), input.data(), input.size())); +} +inline ICU4XWordBreakIteratorUtf16 ICU4XWordSegmenter::segment_utf16(const diplomat::span<const uint16_t> input) const { + return ICU4XWordBreakIteratorUtf16(capi::ICU4XWordSegmenter_segment_utf16(this->inner.get(), input.data(), input.size())); +} +inline ICU4XWordBreakIteratorLatin1 ICU4XWordSegmenter::segment_latin1(const diplomat::span<const uint8_t> input) const { + return ICU4XWordBreakIteratorLatin1(capi::ICU4XWordSegmenter_segment_latin1(this->inner.get(), input.data(), input.size())); +} +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XZonedDateTimeFormatter.h b/intl/icu_capi/cpp/include/ICU4XZonedDateTimeFormatter.h new file mode 100644 index 0000000000..77b228a5a2 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XZonedDateTimeFormatter.h @@ -0,0 +1,45 @@ +#ifndef ICU4XZonedDateTimeFormatter_H +#define ICU4XZonedDateTimeFormatter_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef struct ICU4XZonedDateTimeFormatter ICU4XZonedDateTimeFormatter; +#ifdef __cplusplus +} // namespace capi +#endif +#include "ICU4XDataProvider.h" +#include "ICU4XLocale.h" +#include "ICU4XDateLength.h" +#include "ICU4XTimeLength.h" +#include "diplomat_result_box_ICU4XZonedDateTimeFormatter_ICU4XError.h" +#include "ICU4XIsoTimeZoneOptions.h" +#include "ICU4XDateTime.h" +#include "ICU4XCustomTimeZone.h" +#include "diplomat_result_void_ICU4XError.h" +#include "ICU4XIsoDateTime.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +diplomat_result_box_ICU4XZonedDateTimeFormatter_ICU4XError ICU4XZonedDateTimeFormatter_create_with_lengths(const ICU4XDataProvider* provider, const ICU4XLocale* locale, ICU4XDateLength date_length, ICU4XTimeLength time_length); + +diplomat_result_box_ICU4XZonedDateTimeFormatter_ICU4XError ICU4XZonedDateTimeFormatter_create_with_lengths_and_iso_8601_time_zone_fallback(const ICU4XDataProvider* provider, const ICU4XLocale* locale, ICU4XDateLength date_length, ICU4XTimeLength time_length, ICU4XIsoTimeZoneOptions zone_options); + +diplomat_result_void_ICU4XError ICU4XZonedDateTimeFormatter_format_datetime_with_custom_time_zone(const ICU4XZonedDateTimeFormatter* self, const ICU4XDateTime* datetime, const ICU4XCustomTimeZone* time_zone, DiplomatWriteable* write); + +diplomat_result_void_ICU4XError ICU4XZonedDateTimeFormatter_format_iso_datetime_with_custom_time_zone(const ICU4XZonedDateTimeFormatter* self, const ICU4XIsoDateTime* datetime, const ICU4XCustomTimeZone* time_zone, DiplomatWriteable* write); +void ICU4XZonedDateTimeFormatter_destroy(ICU4XZonedDateTimeFormatter* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/ICU4XZonedDateTimeFormatter.hpp b/intl/icu_capi/cpp/include/ICU4XZonedDateTimeFormatter.hpp new file mode 100644 index 0000000000..ac0dba0b1e --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XZonedDateTimeFormatter.hpp @@ -0,0 +1,173 @@ +#ifndef ICU4XZonedDateTimeFormatter_HPP +#define ICU4XZonedDateTimeFormatter_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XZonedDateTimeFormatter.h" + +class ICU4XDataProvider; +class ICU4XLocale; +#include "ICU4XDateLength.hpp" +#include "ICU4XTimeLength.hpp" +class ICU4XZonedDateTimeFormatter; +#include "ICU4XError.hpp" +struct ICU4XIsoTimeZoneOptions; +class ICU4XDateTime; +class ICU4XCustomTimeZone; +class ICU4XIsoDateTime; + +/** + * A destruction policy for using ICU4XZonedDateTimeFormatter with std::unique_ptr. + */ +struct ICU4XZonedDateTimeFormatterDeleter { + void operator()(capi::ICU4XZonedDateTimeFormatter* l) const noexcept { + capi::ICU4XZonedDateTimeFormatter_destroy(l); + } +}; + +/** + * An object capable of formatting a date time with time zone to a string. + * + * See the [Rust documentation for `ZonedDateTimeFormatter`](https://docs.rs/icu/latest/icu/datetime/struct.ZonedDateTimeFormatter.html) for more information. + */ +class ICU4XZonedDateTimeFormatter { + public: + + /** + * Creates a new [`ICU4XZonedDateTimeFormatter`] from locale data. + * + * This function has `date_length` and `time_length` arguments and uses default options + * for the time zone. + * + * See the [Rust documentation for `try_new`](https://docs.rs/icu/latest/icu/datetime/struct.ZonedDateTimeFormatter.html#method.try_new) for more information. + */ + static diplomat::result<ICU4XZonedDateTimeFormatter, ICU4XError> create_with_lengths(const ICU4XDataProvider& provider, const ICU4XLocale& locale, ICU4XDateLength date_length, ICU4XTimeLength time_length); + + /** + * Creates a new [`ICU4XZonedDateTimeFormatter`] from locale data. + * + * This function has `date_length` and `time_length` arguments and uses an ISO-8601 style + * fallback for the time zone with the given configurations. + * + * See the [Rust documentation for `try_new`](https://docs.rs/icu/latest/icu/datetime/struct.ZonedDateTimeFormatter.html#method.try_new) for more information. + */ + static diplomat::result<ICU4XZonedDateTimeFormatter, ICU4XError> create_with_lengths_and_iso_8601_time_zone_fallback(const ICU4XDataProvider& provider, const ICU4XLocale& locale, ICU4XDateLength date_length, ICU4XTimeLength time_length, ICU4XIsoTimeZoneOptions zone_options); + + /** + * Formats a [`ICU4XDateTime`] and [`ICU4XCustomTimeZone`] to a string. + * + * See the [Rust documentation for `format`](https://docs.rs/icu/latest/icu/datetime/struct.ZonedDateTimeFormatter.html#method.format) for more information. + */ + template<typename W> diplomat::result<std::monostate, ICU4XError> format_datetime_with_custom_time_zone_to_writeable(const ICU4XDateTime& datetime, const ICU4XCustomTimeZone& time_zone, W& write) const; + + /** + * Formats a [`ICU4XDateTime`] and [`ICU4XCustomTimeZone`] to a string. + * + * See the [Rust documentation for `format`](https://docs.rs/icu/latest/icu/datetime/struct.ZonedDateTimeFormatter.html#method.format) for more information. + */ + diplomat::result<std::string, ICU4XError> format_datetime_with_custom_time_zone(const ICU4XDateTime& datetime, const ICU4XCustomTimeZone& time_zone) const; + + /** + * Formats a [`ICU4XIsoDateTime`] and [`ICU4XCustomTimeZone`] to a string. + * + * See the [Rust documentation for `format`](https://docs.rs/icu/latest/icu/datetime/struct.ZonedDateTimeFormatter.html#method.format) for more information. + */ + template<typename W> diplomat::result<std::monostate, ICU4XError> format_iso_datetime_with_custom_time_zone_to_writeable(const ICU4XIsoDateTime& datetime, const ICU4XCustomTimeZone& time_zone, W& write) const; + + /** + * Formats a [`ICU4XIsoDateTime`] and [`ICU4XCustomTimeZone`] to a string. + * + * See the [Rust documentation for `format`](https://docs.rs/icu/latest/icu/datetime/struct.ZonedDateTimeFormatter.html#method.format) for more information. + */ + diplomat::result<std::string, ICU4XError> format_iso_datetime_with_custom_time_zone(const ICU4XIsoDateTime& datetime, const ICU4XCustomTimeZone& time_zone) const; + inline const capi::ICU4XZonedDateTimeFormatter* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XZonedDateTimeFormatter* AsFFIMut() { return this->inner.get(); } + inline ICU4XZonedDateTimeFormatter(capi::ICU4XZonedDateTimeFormatter* i) : inner(i) {} + ICU4XZonedDateTimeFormatter() = default; + ICU4XZonedDateTimeFormatter(ICU4XZonedDateTimeFormatter&&) noexcept = default; + ICU4XZonedDateTimeFormatter& operator=(ICU4XZonedDateTimeFormatter&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XZonedDateTimeFormatter, ICU4XZonedDateTimeFormatterDeleter> inner; +}; + +#include "ICU4XDataProvider.hpp" +#include "ICU4XLocale.hpp" +#include "ICU4XIsoTimeZoneOptions.hpp" +#include "ICU4XDateTime.hpp" +#include "ICU4XCustomTimeZone.hpp" +#include "ICU4XIsoDateTime.hpp" + +inline diplomat::result<ICU4XZonedDateTimeFormatter, ICU4XError> ICU4XZonedDateTimeFormatter::create_with_lengths(const ICU4XDataProvider& provider, const ICU4XLocale& locale, ICU4XDateLength date_length, ICU4XTimeLength time_length) { + auto diplomat_result_raw_out_value = capi::ICU4XZonedDateTimeFormatter_create_with_lengths(provider.AsFFI(), locale.AsFFI(), static_cast<capi::ICU4XDateLength>(date_length), static_cast<capi::ICU4XTimeLength>(time_length)); + diplomat::result<ICU4XZonedDateTimeFormatter, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XZonedDateTimeFormatter>(ICU4XZonedDateTimeFormatter(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<ICU4XZonedDateTimeFormatter, ICU4XError> ICU4XZonedDateTimeFormatter::create_with_lengths_and_iso_8601_time_zone_fallback(const ICU4XDataProvider& provider, const ICU4XLocale& locale, ICU4XDateLength date_length, ICU4XTimeLength time_length, ICU4XIsoTimeZoneOptions zone_options) { + ICU4XIsoTimeZoneOptions diplomat_wrapped_struct_zone_options = zone_options; + auto diplomat_result_raw_out_value = capi::ICU4XZonedDateTimeFormatter_create_with_lengths_and_iso_8601_time_zone_fallback(provider.AsFFI(), locale.AsFFI(), static_cast<capi::ICU4XDateLength>(date_length), static_cast<capi::ICU4XTimeLength>(time_length), capi::ICU4XIsoTimeZoneOptions{ .format = static_cast<capi::ICU4XIsoTimeZoneFormat>(diplomat_wrapped_struct_zone_options.format), .minutes = static_cast<capi::ICU4XIsoTimeZoneMinuteDisplay>(diplomat_wrapped_struct_zone_options.minutes), .seconds = static_cast<capi::ICU4XIsoTimeZoneSecondDisplay>(diplomat_wrapped_struct_zone_options.seconds) }); + diplomat::result<ICU4XZonedDateTimeFormatter, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok<ICU4XZonedDateTimeFormatter>(ICU4XZonedDateTimeFormatter(diplomat_result_raw_out_value.ok)); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XZonedDateTimeFormatter::format_datetime_with_custom_time_zone_to_writeable(const ICU4XDateTime& datetime, const ICU4XCustomTimeZone& time_zone, W& write) const { + capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write); + auto diplomat_result_raw_out_value = capi::ICU4XZonedDateTimeFormatter_format_datetime_with_custom_time_zone(this->inner.get(), datetime.AsFFI(), time_zone.AsFFI(), &write_writer); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<std::string, ICU4XError> ICU4XZonedDateTimeFormatter::format_datetime_with_custom_time_zone(const ICU4XDateTime& datetime, const ICU4XCustomTimeZone& time_zone) const { + std::string diplomat_writeable_string; + capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); + auto diplomat_result_raw_out_value = capi::ICU4XZonedDateTimeFormatter_format_datetime_with_custom_time_zone(this->inner.get(), datetime.AsFFI(), time_zone.AsFFI(), &diplomat_writeable_out); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string)); +} +template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XZonedDateTimeFormatter::format_iso_datetime_with_custom_time_zone_to_writeable(const ICU4XIsoDateTime& datetime, const ICU4XCustomTimeZone& time_zone, W& write) const { + capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write); + auto diplomat_result_raw_out_value = capi::ICU4XZonedDateTimeFormatter_format_iso_datetime_with_custom_time_zone(this->inner.get(), datetime.AsFFI(), time_zone.AsFFI(), &write_writer); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value; +} +inline diplomat::result<std::string, ICU4XError> ICU4XZonedDateTimeFormatter::format_iso_datetime_with_custom_time_zone(const ICU4XIsoDateTime& datetime, const ICU4XCustomTimeZone& time_zone) const { + std::string diplomat_writeable_string; + capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); + auto diplomat_result_raw_out_value = capi::ICU4XZonedDateTimeFormatter_format_iso_datetime_with_custom_time_zone(this->inner.get(), datetime.AsFFI(), time_zone.AsFFI(), &diplomat_writeable_out); + diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value; + if (diplomat_result_raw_out_value.is_ok) { + diplomat_result_out_value = diplomat::Ok(std::monostate()); + } else { + diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); + } + return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string)); +} +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_ICU4XAnyCalendarKind_void.h b/intl/icu_capi/cpp/include/diplomat_result_ICU4XAnyCalendarKind_void.h new file mode 100644 index 0000000000..f67f66ed4d --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_ICU4XAnyCalendarKind_void.h @@ -0,0 +1,24 @@ +#ifndef diplomat_result_ICU4XAnyCalendarKind_void_H +#define diplomat_result_ICU4XAnyCalendarKind_void_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#include "ICU4XAnyCalendarKind.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_ICU4XAnyCalendarKind_void { + union { + ICU4XAnyCalendarKind ok; + }; + bool is_ok; +} diplomat_result_ICU4XAnyCalendarKind_void; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_ICU4XPluralCategory_void.h b/intl/icu_capi/cpp/include/diplomat_result_ICU4XPluralCategory_void.h new file mode 100644 index 0000000000..b56ef60acb --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_ICU4XPluralCategory_void.h @@ -0,0 +1,24 @@ +#ifndef diplomat_result_ICU4XPluralCategory_void_H +#define diplomat_result_ICU4XPluralCategory_void_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#include "ICU4XPluralCategory.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_ICU4XPluralCategory_void { + union { + ICU4XPluralCategory ok; + }; + bool is_ok; +} diplomat_result_ICU4XPluralCategory_void; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_ICU4XWeekOf_ICU4XError.h b/intl/icu_capi/cpp/include/diplomat_result_ICU4XWeekOf_ICU4XError.h new file mode 100644 index 0000000000..4dee8f941f --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_ICU4XWeekOf_ICU4XError.h @@ -0,0 +1,26 @@ +#ifndef diplomat_result_ICU4XWeekOf_ICU4XError_H +#define diplomat_result_ICU4XWeekOf_ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#include "ICU4XWeekOf.h" +#include "ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_ICU4XWeekOf_ICU4XError { + union { + ICU4XWeekOf ok; + ICU4XError err; + }; + bool is_ok; +} diplomat_result_ICU4XWeekOf_ICU4XError; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_bool_ICU4XError.h b/intl/icu_capi/cpp/include/diplomat_result_bool_ICU4XError.h new file mode 100644 index 0000000000..015930214d --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_bool_ICU4XError.h @@ -0,0 +1,25 @@ +#ifndef diplomat_result_bool_ICU4XError_H +#define diplomat_result_bool_ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#include "ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_bool_ICU4XError { + union { + bool ok; + ICU4XError err; + }; + bool is_ok; +} diplomat_result_bool_ICU4XError; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XBcp47ToIanaMapper_ICU4XError.h b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XBcp47ToIanaMapper_ICU4XError.h new file mode 100644 index 0000000000..0d18fe4076 --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XBcp47ToIanaMapper_ICU4XError.h @@ -0,0 +1,26 @@ +#ifndef diplomat_result_box_ICU4XBcp47ToIanaMapper_ICU4XError_H +#define diplomat_result_box_ICU4XBcp47ToIanaMapper_ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +typedef struct ICU4XBcp47ToIanaMapper ICU4XBcp47ToIanaMapper; +#include "ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_box_ICU4XBcp47ToIanaMapper_ICU4XError { + union { + ICU4XBcp47ToIanaMapper* ok; + ICU4XError err; + }; + bool is_ok; +} diplomat_result_box_ICU4XBcp47ToIanaMapper_ICU4XError; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XBidi_ICU4XError.h b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XBidi_ICU4XError.h new file mode 100644 index 0000000000..f1cd7ca6a3 --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XBidi_ICU4XError.h @@ -0,0 +1,26 @@ +#ifndef diplomat_result_box_ICU4XBidi_ICU4XError_H +#define diplomat_result_box_ICU4XBidi_ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +typedef struct ICU4XBidi ICU4XBidi; +#include "ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_box_ICU4XBidi_ICU4XError { + union { + ICU4XBidi* ok; + ICU4XError err; + }; + bool is_ok; +} diplomat_result_box_ICU4XBidi_ICU4XError; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XCalendar_ICU4XError.h b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XCalendar_ICU4XError.h new file mode 100644 index 0000000000..bffa22c6b0 --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XCalendar_ICU4XError.h @@ -0,0 +1,26 @@ +#ifndef diplomat_result_box_ICU4XCalendar_ICU4XError_H +#define diplomat_result_box_ICU4XCalendar_ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +typedef struct ICU4XCalendar ICU4XCalendar; +#include "ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_box_ICU4XCalendar_ICU4XError { + union { + ICU4XCalendar* ok; + ICU4XError err; + }; + bool is_ok; +} diplomat_result_box_ICU4XCalendar_ICU4XError; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XCanonicalCombiningClassMap_ICU4XError.h b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XCanonicalCombiningClassMap_ICU4XError.h new file mode 100644 index 0000000000..2c05f79671 --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XCanonicalCombiningClassMap_ICU4XError.h @@ -0,0 +1,26 @@ +#ifndef diplomat_result_box_ICU4XCanonicalCombiningClassMap_ICU4XError_H +#define diplomat_result_box_ICU4XCanonicalCombiningClassMap_ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +typedef struct ICU4XCanonicalCombiningClassMap ICU4XCanonicalCombiningClassMap; +#include "ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_box_ICU4XCanonicalCombiningClassMap_ICU4XError { + union { + ICU4XCanonicalCombiningClassMap* ok; + ICU4XError err; + }; + bool is_ok; +} diplomat_result_box_ICU4XCanonicalCombiningClassMap_ICU4XError; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XCanonicalComposition_ICU4XError.h b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XCanonicalComposition_ICU4XError.h new file mode 100644 index 0000000000..66d0386ff8 --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XCanonicalComposition_ICU4XError.h @@ -0,0 +1,26 @@ +#ifndef diplomat_result_box_ICU4XCanonicalComposition_ICU4XError_H +#define diplomat_result_box_ICU4XCanonicalComposition_ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +typedef struct ICU4XCanonicalComposition ICU4XCanonicalComposition; +#include "ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_box_ICU4XCanonicalComposition_ICU4XError { + union { + ICU4XCanonicalComposition* ok; + ICU4XError err; + }; + bool is_ok; +} diplomat_result_box_ICU4XCanonicalComposition_ICU4XError; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XCanonicalDecomposition_ICU4XError.h b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XCanonicalDecomposition_ICU4XError.h new file mode 100644 index 0000000000..cf02637fef --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XCanonicalDecomposition_ICU4XError.h @@ -0,0 +1,26 @@ +#ifndef diplomat_result_box_ICU4XCanonicalDecomposition_ICU4XError_H +#define diplomat_result_box_ICU4XCanonicalDecomposition_ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +typedef struct ICU4XCanonicalDecomposition ICU4XCanonicalDecomposition; +#include "ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_box_ICU4XCanonicalDecomposition_ICU4XError { + union { + ICU4XCanonicalDecomposition* ok; + ICU4XError err; + }; + bool is_ok; +} diplomat_result_box_ICU4XCanonicalDecomposition_ICU4XError; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XCaseMapCloser_ICU4XError.h b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XCaseMapCloser_ICU4XError.h new file mode 100644 index 0000000000..7b2a957399 --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XCaseMapCloser_ICU4XError.h @@ -0,0 +1,26 @@ +#ifndef diplomat_result_box_ICU4XCaseMapCloser_ICU4XError_H +#define diplomat_result_box_ICU4XCaseMapCloser_ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +typedef struct ICU4XCaseMapCloser ICU4XCaseMapCloser; +#include "ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_box_ICU4XCaseMapCloser_ICU4XError { + union { + ICU4XCaseMapCloser* ok; + ICU4XError err; + }; + bool is_ok; +} diplomat_result_box_ICU4XCaseMapCloser_ICU4XError; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XCaseMapper_ICU4XError.h b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XCaseMapper_ICU4XError.h new file mode 100644 index 0000000000..c6e03a748c --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XCaseMapper_ICU4XError.h @@ -0,0 +1,26 @@ +#ifndef diplomat_result_box_ICU4XCaseMapper_ICU4XError_H +#define diplomat_result_box_ICU4XCaseMapper_ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +typedef struct ICU4XCaseMapper ICU4XCaseMapper; +#include "ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_box_ICU4XCaseMapper_ICU4XError { + union { + ICU4XCaseMapper* ok; + ICU4XError err; + }; + bool is_ok; +} diplomat_result_box_ICU4XCaseMapper_ICU4XError; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XCodePointMapData16_ICU4XError.h b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XCodePointMapData16_ICU4XError.h new file mode 100644 index 0000000000..fbe11daad2 --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XCodePointMapData16_ICU4XError.h @@ -0,0 +1,26 @@ +#ifndef diplomat_result_box_ICU4XCodePointMapData16_ICU4XError_H +#define diplomat_result_box_ICU4XCodePointMapData16_ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +typedef struct ICU4XCodePointMapData16 ICU4XCodePointMapData16; +#include "ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_box_ICU4XCodePointMapData16_ICU4XError { + union { + ICU4XCodePointMapData16* ok; + ICU4XError err; + }; + bool is_ok; +} diplomat_result_box_ICU4XCodePointMapData16_ICU4XError; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XCodePointMapData8_ICU4XError.h b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XCodePointMapData8_ICU4XError.h new file mode 100644 index 0000000000..2e203279e3 --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XCodePointMapData8_ICU4XError.h @@ -0,0 +1,26 @@ +#ifndef diplomat_result_box_ICU4XCodePointMapData8_ICU4XError_H +#define diplomat_result_box_ICU4XCodePointMapData8_ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +typedef struct ICU4XCodePointMapData8 ICU4XCodePointMapData8; +#include "ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_box_ICU4XCodePointMapData8_ICU4XError { + union { + ICU4XCodePointMapData8* ok; + ICU4XError err; + }; + bool is_ok; +} diplomat_result_box_ICU4XCodePointMapData8_ICU4XError; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XCodePointSetData_ICU4XError.h b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XCodePointSetData_ICU4XError.h new file mode 100644 index 0000000000..e70e39ba61 --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XCodePointSetData_ICU4XError.h @@ -0,0 +1,26 @@ +#ifndef diplomat_result_box_ICU4XCodePointSetData_ICU4XError_H +#define diplomat_result_box_ICU4XCodePointSetData_ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +typedef struct ICU4XCodePointSetData ICU4XCodePointSetData; +#include "ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_box_ICU4XCodePointSetData_ICU4XError { + union { + ICU4XCodePointSetData* ok; + ICU4XError err; + }; + bool is_ok; +} diplomat_result_box_ICU4XCodePointSetData_ICU4XError; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XCollator_ICU4XError.h b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XCollator_ICU4XError.h new file mode 100644 index 0000000000..abb5c8a598 --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XCollator_ICU4XError.h @@ -0,0 +1,26 @@ +#ifndef diplomat_result_box_ICU4XCollator_ICU4XError_H +#define diplomat_result_box_ICU4XCollator_ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +typedef struct ICU4XCollator ICU4XCollator; +#include "ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_box_ICU4XCollator_ICU4XError { + union { + ICU4XCollator* ok; + ICU4XError err; + }; + bool is_ok; +} diplomat_result_box_ICU4XCollator_ICU4XError; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XComposingNormalizer_ICU4XError.h b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XComposingNormalizer_ICU4XError.h new file mode 100644 index 0000000000..d0c381ef03 --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XComposingNormalizer_ICU4XError.h @@ -0,0 +1,26 @@ +#ifndef diplomat_result_box_ICU4XComposingNormalizer_ICU4XError_H +#define diplomat_result_box_ICU4XComposingNormalizer_ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +typedef struct ICU4XComposingNormalizer ICU4XComposingNormalizer; +#include "ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_box_ICU4XComposingNormalizer_ICU4XError { + union { + ICU4XComposingNormalizer* ok; + ICU4XError err; + }; + bool is_ok; +} diplomat_result_box_ICU4XComposingNormalizer_ICU4XError; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XCustomTimeZone_ICU4XError.h b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XCustomTimeZone_ICU4XError.h new file mode 100644 index 0000000000..4709a89871 --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XCustomTimeZone_ICU4XError.h @@ -0,0 +1,26 @@ +#ifndef diplomat_result_box_ICU4XCustomTimeZone_ICU4XError_H +#define diplomat_result_box_ICU4XCustomTimeZone_ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +typedef struct ICU4XCustomTimeZone ICU4XCustomTimeZone; +#include "ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_box_ICU4XCustomTimeZone_ICU4XError { + union { + ICU4XCustomTimeZone* ok; + ICU4XError err; + }; + bool is_ok; +} diplomat_result_box_ICU4XCustomTimeZone_ICU4XError; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XDataProvider_ICU4XError.h b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XDataProvider_ICU4XError.h new file mode 100644 index 0000000000..a5be844183 --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XDataProvider_ICU4XError.h @@ -0,0 +1,26 @@ +#ifndef diplomat_result_box_ICU4XDataProvider_ICU4XError_H +#define diplomat_result_box_ICU4XDataProvider_ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +typedef struct ICU4XDataProvider ICU4XDataProvider; +#include "ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_box_ICU4XDataProvider_ICU4XError { + union { + ICU4XDataProvider* ok; + ICU4XError err; + }; + bool is_ok; +} diplomat_result_box_ICU4XDataProvider_ICU4XError; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XDataStruct_ICU4XError.h b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XDataStruct_ICU4XError.h new file mode 100644 index 0000000000..d8c1d33e21 --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XDataStruct_ICU4XError.h @@ -0,0 +1,26 @@ +#ifndef diplomat_result_box_ICU4XDataStruct_ICU4XError_H +#define diplomat_result_box_ICU4XDataStruct_ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +typedef struct ICU4XDataStruct ICU4XDataStruct; +#include "ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_box_ICU4XDataStruct_ICU4XError { + union { + ICU4XDataStruct* ok; + ICU4XError err; + }; + bool is_ok; +} diplomat_result_box_ICU4XDataStruct_ICU4XError; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XDateFormatter_ICU4XError.h b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XDateFormatter_ICU4XError.h new file mode 100644 index 0000000000..b6d9671434 --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XDateFormatter_ICU4XError.h @@ -0,0 +1,26 @@ +#ifndef diplomat_result_box_ICU4XDateFormatter_ICU4XError_H +#define diplomat_result_box_ICU4XDateFormatter_ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +typedef struct ICU4XDateFormatter ICU4XDateFormatter; +#include "ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_box_ICU4XDateFormatter_ICU4XError { + union { + ICU4XDateFormatter* ok; + ICU4XError err; + }; + bool is_ok; +} diplomat_result_box_ICU4XDateFormatter_ICU4XError; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XDateTimeFormatter_ICU4XError.h b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XDateTimeFormatter_ICU4XError.h new file mode 100644 index 0000000000..855e74fe6c --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XDateTimeFormatter_ICU4XError.h @@ -0,0 +1,26 @@ +#ifndef diplomat_result_box_ICU4XDateTimeFormatter_ICU4XError_H +#define diplomat_result_box_ICU4XDateTimeFormatter_ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +typedef struct ICU4XDateTimeFormatter ICU4XDateTimeFormatter; +#include "ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_box_ICU4XDateTimeFormatter_ICU4XError { + union { + ICU4XDateTimeFormatter* ok; + ICU4XError err; + }; + bool is_ok; +} diplomat_result_box_ICU4XDateTimeFormatter_ICU4XError; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XDateTime_ICU4XError.h b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XDateTime_ICU4XError.h new file mode 100644 index 0000000000..2d4cb2fe48 --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XDateTime_ICU4XError.h @@ -0,0 +1,26 @@ +#ifndef diplomat_result_box_ICU4XDateTime_ICU4XError_H +#define diplomat_result_box_ICU4XDateTime_ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +typedef struct ICU4XDateTime ICU4XDateTime; +#include "ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_box_ICU4XDateTime_ICU4XError { + union { + ICU4XDateTime* ok; + ICU4XError err; + }; + bool is_ok; +} diplomat_result_box_ICU4XDateTime_ICU4XError; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XDate_ICU4XError.h b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XDate_ICU4XError.h new file mode 100644 index 0000000000..30461b264a --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XDate_ICU4XError.h @@ -0,0 +1,26 @@ +#ifndef diplomat_result_box_ICU4XDate_ICU4XError_H +#define diplomat_result_box_ICU4XDate_ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +typedef struct ICU4XDate ICU4XDate; +#include "ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_box_ICU4XDate_ICU4XError { + union { + ICU4XDate* ok; + ICU4XError err; + }; + bool is_ok; +} diplomat_result_box_ICU4XDate_ICU4XError; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XDecomposingNormalizer_ICU4XError.h b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XDecomposingNormalizer_ICU4XError.h new file mode 100644 index 0000000000..c51d9907bc --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XDecomposingNormalizer_ICU4XError.h @@ -0,0 +1,26 @@ +#ifndef diplomat_result_box_ICU4XDecomposingNormalizer_ICU4XError_H +#define diplomat_result_box_ICU4XDecomposingNormalizer_ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +typedef struct ICU4XDecomposingNormalizer ICU4XDecomposingNormalizer; +#include "ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_box_ICU4XDecomposingNormalizer_ICU4XError { + union { + ICU4XDecomposingNormalizer* ok; + ICU4XError err; + }; + bool is_ok; +} diplomat_result_box_ICU4XDecomposingNormalizer_ICU4XError; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XFixedDecimalFormatter_ICU4XError.h b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XFixedDecimalFormatter_ICU4XError.h new file mode 100644 index 0000000000..8ee245a093 --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XFixedDecimalFormatter_ICU4XError.h @@ -0,0 +1,26 @@ +#ifndef diplomat_result_box_ICU4XFixedDecimalFormatter_ICU4XError_H +#define diplomat_result_box_ICU4XFixedDecimalFormatter_ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +typedef struct ICU4XFixedDecimalFormatter ICU4XFixedDecimalFormatter; +#include "ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_box_ICU4XFixedDecimalFormatter_ICU4XError { + union { + ICU4XFixedDecimalFormatter* ok; + ICU4XError err; + }; + bool is_ok; +} diplomat_result_box_ICU4XFixedDecimalFormatter_ICU4XError; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XFixedDecimal_ICU4XError.h b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XFixedDecimal_ICU4XError.h new file mode 100644 index 0000000000..f45cd78fb9 --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XFixedDecimal_ICU4XError.h @@ -0,0 +1,26 @@ +#ifndef diplomat_result_box_ICU4XFixedDecimal_ICU4XError_H +#define diplomat_result_box_ICU4XFixedDecimal_ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +typedef struct ICU4XFixedDecimal ICU4XFixedDecimal; +#include "ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_box_ICU4XFixedDecimal_ICU4XError { + union { + ICU4XFixedDecimal* ok; + ICU4XError err; + }; + bool is_ok; +} diplomat_result_box_ICU4XFixedDecimal_ICU4XError; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XGeneralCategoryNameToMaskMapper_ICU4XError.h b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XGeneralCategoryNameToMaskMapper_ICU4XError.h new file mode 100644 index 0000000000..98ff137a9a --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XGeneralCategoryNameToMaskMapper_ICU4XError.h @@ -0,0 +1,26 @@ +#ifndef diplomat_result_box_ICU4XGeneralCategoryNameToMaskMapper_ICU4XError_H +#define diplomat_result_box_ICU4XGeneralCategoryNameToMaskMapper_ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +typedef struct ICU4XGeneralCategoryNameToMaskMapper ICU4XGeneralCategoryNameToMaskMapper; +#include "ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_box_ICU4XGeneralCategoryNameToMaskMapper_ICU4XError { + union { + ICU4XGeneralCategoryNameToMaskMapper* ok; + ICU4XError err; + }; + bool is_ok; +} diplomat_result_box_ICU4XGeneralCategoryNameToMaskMapper_ICU4XError; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XGraphemeClusterSegmenter_ICU4XError.h b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XGraphemeClusterSegmenter_ICU4XError.h new file mode 100644 index 0000000000..d560b381a5 --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XGraphemeClusterSegmenter_ICU4XError.h @@ -0,0 +1,26 @@ +#ifndef diplomat_result_box_ICU4XGraphemeClusterSegmenter_ICU4XError_H +#define diplomat_result_box_ICU4XGraphemeClusterSegmenter_ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +typedef struct ICU4XGraphemeClusterSegmenter ICU4XGraphemeClusterSegmenter; +#include "ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_box_ICU4XGraphemeClusterSegmenter_ICU4XError { + union { + ICU4XGraphemeClusterSegmenter* ok; + ICU4XError err; + }; + bool is_ok; +} diplomat_result_box_ICU4XGraphemeClusterSegmenter_ICU4XError; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XGregorianDateFormatter_ICU4XError.h b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XGregorianDateFormatter_ICU4XError.h new file mode 100644 index 0000000000..86b13be912 --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XGregorianDateFormatter_ICU4XError.h @@ -0,0 +1,26 @@ +#ifndef diplomat_result_box_ICU4XGregorianDateFormatter_ICU4XError_H +#define diplomat_result_box_ICU4XGregorianDateFormatter_ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +typedef struct ICU4XGregorianDateFormatter ICU4XGregorianDateFormatter; +#include "ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_box_ICU4XGregorianDateFormatter_ICU4XError { + union { + ICU4XGregorianDateFormatter* ok; + ICU4XError err; + }; + bool is_ok; +} diplomat_result_box_ICU4XGregorianDateFormatter_ICU4XError; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XGregorianDateTimeFormatter_ICU4XError.h b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XGregorianDateTimeFormatter_ICU4XError.h new file mode 100644 index 0000000000..4393d9ffb0 --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XGregorianDateTimeFormatter_ICU4XError.h @@ -0,0 +1,26 @@ +#ifndef diplomat_result_box_ICU4XGregorianDateTimeFormatter_ICU4XError_H +#define diplomat_result_box_ICU4XGregorianDateTimeFormatter_ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +typedef struct ICU4XGregorianDateTimeFormatter ICU4XGregorianDateTimeFormatter; +#include "ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_box_ICU4XGregorianDateTimeFormatter_ICU4XError { + union { + ICU4XGregorianDateTimeFormatter* ok; + ICU4XError err; + }; + bool is_ok; +} diplomat_result_box_ICU4XGregorianDateTimeFormatter_ICU4XError; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XGregorianZonedDateTimeFormatter_ICU4XError.h b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XGregorianZonedDateTimeFormatter_ICU4XError.h new file mode 100644 index 0000000000..270b38ba94 --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XGregorianZonedDateTimeFormatter_ICU4XError.h @@ -0,0 +1,26 @@ +#ifndef diplomat_result_box_ICU4XGregorianZonedDateTimeFormatter_ICU4XError_H +#define diplomat_result_box_ICU4XGregorianZonedDateTimeFormatter_ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +typedef struct ICU4XGregorianZonedDateTimeFormatter ICU4XGregorianZonedDateTimeFormatter; +#include "ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_box_ICU4XGregorianZonedDateTimeFormatter_ICU4XError { + union { + ICU4XGregorianZonedDateTimeFormatter* ok; + ICU4XError err; + }; + bool is_ok; +} diplomat_result_box_ICU4XGregorianZonedDateTimeFormatter_ICU4XError; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XIanaToBcp47Mapper_ICU4XError.h b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XIanaToBcp47Mapper_ICU4XError.h new file mode 100644 index 0000000000..2e05730b0b --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XIanaToBcp47Mapper_ICU4XError.h @@ -0,0 +1,26 @@ +#ifndef diplomat_result_box_ICU4XIanaToBcp47Mapper_ICU4XError_H +#define diplomat_result_box_ICU4XIanaToBcp47Mapper_ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +typedef struct ICU4XIanaToBcp47Mapper ICU4XIanaToBcp47Mapper; +#include "ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_box_ICU4XIanaToBcp47Mapper_ICU4XError { + union { + ICU4XIanaToBcp47Mapper* ok; + ICU4XError err; + }; + bool is_ok; +} diplomat_result_box_ICU4XIanaToBcp47Mapper_ICU4XError; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XIsoDateTime_ICU4XError.h b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XIsoDateTime_ICU4XError.h new file mode 100644 index 0000000000..8a55b47a68 --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XIsoDateTime_ICU4XError.h @@ -0,0 +1,26 @@ +#ifndef diplomat_result_box_ICU4XIsoDateTime_ICU4XError_H +#define diplomat_result_box_ICU4XIsoDateTime_ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +typedef struct ICU4XIsoDateTime ICU4XIsoDateTime; +#include "ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_box_ICU4XIsoDateTime_ICU4XError { + union { + ICU4XIsoDateTime* ok; + ICU4XError err; + }; + bool is_ok; +} diplomat_result_box_ICU4XIsoDateTime_ICU4XError; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XIsoDate_ICU4XError.h b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XIsoDate_ICU4XError.h new file mode 100644 index 0000000000..8528d73b07 --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XIsoDate_ICU4XError.h @@ -0,0 +1,26 @@ +#ifndef diplomat_result_box_ICU4XIsoDate_ICU4XError_H +#define diplomat_result_box_ICU4XIsoDate_ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +typedef struct ICU4XIsoDate ICU4XIsoDate; +#include "ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_box_ICU4XIsoDate_ICU4XError { + union { + ICU4XIsoDate* ok; + ICU4XError err; + }; + bool is_ok; +} diplomat_result_box_ICU4XIsoDate_ICU4XError; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XLineSegmenter_ICU4XError.h b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XLineSegmenter_ICU4XError.h new file mode 100644 index 0000000000..004d3494ae --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XLineSegmenter_ICU4XError.h @@ -0,0 +1,26 @@ +#ifndef diplomat_result_box_ICU4XLineSegmenter_ICU4XError_H +#define diplomat_result_box_ICU4XLineSegmenter_ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +typedef struct ICU4XLineSegmenter ICU4XLineSegmenter; +#include "ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_box_ICU4XLineSegmenter_ICU4XError { + union { + ICU4XLineSegmenter* ok; + ICU4XError err; + }; + bool is_ok; +} diplomat_result_box_ICU4XLineSegmenter_ICU4XError; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XListFormatter_ICU4XError.h b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XListFormatter_ICU4XError.h new file mode 100644 index 0000000000..df40aa2dae --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XListFormatter_ICU4XError.h @@ -0,0 +1,26 @@ +#ifndef diplomat_result_box_ICU4XListFormatter_ICU4XError_H +#define diplomat_result_box_ICU4XListFormatter_ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +typedef struct ICU4XListFormatter ICU4XListFormatter; +#include "ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_box_ICU4XListFormatter_ICU4XError { + union { + ICU4XListFormatter* ok; + ICU4XError err; + }; + bool is_ok; +} diplomat_result_box_ICU4XListFormatter_ICU4XError; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XLocaleCanonicalizer_ICU4XError.h b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XLocaleCanonicalizer_ICU4XError.h new file mode 100644 index 0000000000..a49bb700ca --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XLocaleCanonicalizer_ICU4XError.h @@ -0,0 +1,26 @@ +#ifndef diplomat_result_box_ICU4XLocaleCanonicalizer_ICU4XError_H +#define diplomat_result_box_ICU4XLocaleCanonicalizer_ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +typedef struct ICU4XLocaleCanonicalizer ICU4XLocaleCanonicalizer; +#include "ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_box_ICU4XLocaleCanonicalizer_ICU4XError { + union { + ICU4XLocaleCanonicalizer* ok; + ICU4XError err; + }; + bool is_ok; +} diplomat_result_box_ICU4XLocaleCanonicalizer_ICU4XError; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XLocaleDirectionality_ICU4XError.h b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XLocaleDirectionality_ICU4XError.h new file mode 100644 index 0000000000..740f9d99fa --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XLocaleDirectionality_ICU4XError.h @@ -0,0 +1,26 @@ +#ifndef diplomat_result_box_ICU4XLocaleDirectionality_ICU4XError_H +#define diplomat_result_box_ICU4XLocaleDirectionality_ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +typedef struct ICU4XLocaleDirectionality ICU4XLocaleDirectionality; +#include "ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_box_ICU4XLocaleDirectionality_ICU4XError { + union { + ICU4XLocaleDirectionality* ok; + ICU4XError err; + }; + bool is_ok; +} diplomat_result_box_ICU4XLocaleDirectionality_ICU4XError; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XLocaleDisplayNamesFormatter_ICU4XError.h b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XLocaleDisplayNamesFormatter_ICU4XError.h new file mode 100644 index 0000000000..6b0f09b2a2 --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XLocaleDisplayNamesFormatter_ICU4XError.h @@ -0,0 +1,26 @@ +#ifndef diplomat_result_box_ICU4XLocaleDisplayNamesFormatter_ICU4XError_H +#define diplomat_result_box_ICU4XLocaleDisplayNamesFormatter_ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +typedef struct ICU4XLocaleDisplayNamesFormatter ICU4XLocaleDisplayNamesFormatter; +#include "ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_box_ICU4XLocaleDisplayNamesFormatter_ICU4XError { + union { + ICU4XLocaleDisplayNamesFormatter* ok; + ICU4XError err; + }; + bool is_ok; +} diplomat_result_box_ICU4XLocaleDisplayNamesFormatter_ICU4XError; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XLocaleExpander_ICU4XError.h b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XLocaleExpander_ICU4XError.h new file mode 100644 index 0000000000..c7275e699c --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XLocaleExpander_ICU4XError.h @@ -0,0 +1,26 @@ +#ifndef diplomat_result_box_ICU4XLocaleExpander_ICU4XError_H +#define diplomat_result_box_ICU4XLocaleExpander_ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +typedef struct ICU4XLocaleExpander ICU4XLocaleExpander; +#include "ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_box_ICU4XLocaleExpander_ICU4XError { + union { + ICU4XLocaleExpander* ok; + ICU4XError err; + }; + bool is_ok; +} diplomat_result_box_ICU4XLocaleExpander_ICU4XError; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XLocaleFallbackerWithConfig_ICU4XError.h b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XLocaleFallbackerWithConfig_ICU4XError.h new file mode 100644 index 0000000000..0dc002718e --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XLocaleFallbackerWithConfig_ICU4XError.h @@ -0,0 +1,26 @@ +#ifndef diplomat_result_box_ICU4XLocaleFallbackerWithConfig_ICU4XError_H +#define diplomat_result_box_ICU4XLocaleFallbackerWithConfig_ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +typedef struct ICU4XLocaleFallbackerWithConfig ICU4XLocaleFallbackerWithConfig; +#include "ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_box_ICU4XLocaleFallbackerWithConfig_ICU4XError { + union { + ICU4XLocaleFallbackerWithConfig* ok; + ICU4XError err; + }; + bool is_ok; +} diplomat_result_box_ICU4XLocaleFallbackerWithConfig_ICU4XError; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XLocaleFallbacker_ICU4XError.h b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XLocaleFallbacker_ICU4XError.h new file mode 100644 index 0000000000..3427bf3e3a --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XLocaleFallbacker_ICU4XError.h @@ -0,0 +1,26 @@ +#ifndef diplomat_result_box_ICU4XLocaleFallbacker_ICU4XError_H +#define diplomat_result_box_ICU4XLocaleFallbacker_ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +typedef struct ICU4XLocaleFallbacker ICU4XLocaleFallbacker; +#include "ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_box_ICU4XLocaleFallbacker_ICU4XError { + union { + ICU4XLocaleFallbacker* ok; + ICU4XError err; + }; + bool is_ok; +} diplomat_result_box_ICU4XLocaleFallbacker_ICU4XError; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XLocale_ICU4XError.h b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XLocale_ICU4XError.h new file mode 100644 index 0000000000..f5720b612f --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XLocale_ICU4XError.h @@ -0,0 +1,26 @@ +#ifndef diplomat_result_box_ICU4XLocale_ICU4XError_H +#define diplomat_result_box_ICU4XLocale_ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +typedef struct ICU4XLocale ICU4XLocale; +#include "ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_box_ICU4XLocale_ICU4XError { + union { + ICU4XLocale* ok; + ICU4XError err; + }; + bool is_ok; +} diplomat_result_box_ICU4XLocale_ICU4XError; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XMetazoneCalculator_ICU4XError.h b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XMetazoneCalculator_ICU4XError.h new file mode 100644 index 0000000000..ebd519e0b5 --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XMetazoneCalculator_ICU4XError.h @@ -0,0 +1,26 @@ +#ifndef diplomat_result_box_ICU4XMetazoneCalculator_ICU4XError_H +#define diplomat_result_box_ICU4XMetazoneCalculator_ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +typedef struct ICU4XMetazoneCalculator ICU4XMetazoneCalculator; +#include "ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_box_ICU4XMetazoneCalculator_ICU4XError { + union { + ICU4XMetazoneCalculator* ok; + ICU4XError err; + }; + bool is_ok; +} diplomat_result_box_ICU4XMetazoneCalculator_ICU4XError; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XPluralOperands_ICU4XError.h b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XPluralOperands_ICU4XError.h new file mode 100644 index 0000000000..7c068ba4b8 --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XPluralOperands_ICU4XError.h @@ -0,0 +1,26 @@ +#ifndef diplomat_result_box_ICU4XPluralOperands_ICU4XError_H +#define diplomat_result_box_ICU4XPluralOperands_ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +typedef struct ICU4XPluralOperands ICU4XPluralOperands; +#include "ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_box_ICU4XPluralOperands_ICU4XError { + union { + ICU4XPluralOperands* ok; + ICU4XError err; + }; + bool is_ok; +} diplomat_result_box_ICU4XPluralOperands_ICU4XError; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XPluralRules_ICU4XError.h b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XPluralRules_ICU4XError.h new file mode 100644 index 0000000000..4fa522b850 --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XPluralRules_ICU4XError.h @@ -0,0 +1,26 @@ +#ifndef diplomat_result_box_ICU4XPluralRules_ICU4XError_H +#define diplomat_result_box_ICU4XPluralRules_ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +typedef struct ICU4XPluralRules ICU4XPluralRules; +#include "ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_box_ICU4XPluralRules_ICU4XError { + union { + ICU4XPluralRules* ok; + ICU4XError err; + }; + bool is_ok; +} diplomat_result_box_ICU4XPluralRules_ICU4XError; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XPropertyValueNameToEnumMapper_ICU4XError.h b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XPropertyValueNameToEnumMapper_ICU4XError.h new file mode 100644 index 0000000000..047ef959b0 --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XPropertyValueNameToEnumMapper_ICU4XError.h @@ -0,0 +1,26 @@ +#ifndef diplomat_result_box_ICU4XPropertyValueNameToEnumMapper_ICU4XError_H +#define diplomat_result_box_ICU4XPropertyValueNameToEnumMapper_ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +typedef struct ICU4XPropertyValueNameToEnumMapper ICU4XPropertyValueNameToEnumMapper; +#include "ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_box_ICU4XPropertyValueNameToEnumMapper_ICU4XError { + union { + ICU4XPropertyValueNameToEnumMapper* ok; + ICU4XError err; + }; + bool is_ok; +} diplomat_result_box_ICU4XPropertyValueNameToEnumMapper_ICU4XError; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XRegionDisplayNames_ICU4XError.h b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XRegionDisplayNames_ICU4XError.h new file mode 100644 index 0000000000..fcf7e88a23 --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XRegionDisplayNames_ICU4XError.h @@ -0,0 +1,26 @@ +#ifndef diplomat_result_box_ICU4XRegionDisplayNames_ICU4XError_H +#define diplomat_result_box_ICU4XRegionDisplayNames_ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +typedef struct ICU4XRegionDisplayNames ICU4XRegionDisplayNames; +#include "ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_box_ICU4XRegionDisplayNames_ICU4XError { + union { + ICU4XRegionDisplayNames* ok; + ICU4XError err; + }; + bool is_ok; +} diplomat_result_box_ICU4XRegionDisplayNames_ICU4XError; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XScriptWithExtensions_ICU4XError.h b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XScriptWithExtensions_ICU4XError.h new file mode 100644 index 0000000000..bffd6161aa --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XScriptWithExtensions_ICU4XError.h @@ -0,0 +1,26 @@ +#ifndef diplomat_result_box_ICU4XScriptWithExtensions_ICU4XError_H +#define diplomat_result_box_ICU4XScriptWithExtensions_ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +typedef struct ICU4XScriptWithExtensions ICU4XScriptWithExtensions; +#include "ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_box_ICU4XScriptWithExtensions_ICU4XError { + union { + ICU4XScriptWithExtensions* ok; + ICU4XError err; + }; + bool is_ok; +} diplomat_result_box_ICU4XScriptWithExtensions_ICU4XError; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XSentenceSegmenter_ICU4XError.h b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XSentenceSegmenter_ICU4XError.h new file mode 100644 index 0000000000..a8ab968fa9 --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XSentenceSegmenter_ICU4XError.h @@ -0,0 +1,26 @@ +#ifndef diplomat_result_box_ICU4XSentenceSegmenter_ICU4XError_H +#define diplomat_result_box_ICU4XSentenceSegmenter_ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +typedef struct ICU4XSentenceSegmenter ICU4XSentenceSegmenter; +#include "ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_box_ICU4XSentenceSegmenter_ICU4XError { + union { + ICU4XSentenceSegmenter* ok; + ICU4XError err; + }; + bool is_ok; +} diplomat_result_box_ICU4XSentenceSegmenter_ICU4XError; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XTimeFormatter_ICU4XError.h b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XTimeFormatter_ICU4XError.h new file mode 100644 index 0000000000..0e63cbbc2a --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XTimeFormatter_ICU4XError.h @@ -0,0 +1,26 @@ +#ifndef diplomat_result_box_ICU4XTimeFormatter_ICU4XError_H +#define diplomat_result_box_ICU4XTimeFormatter_ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +typedef struct ICU4XTimeFormatter ICU4XTimeFormatter; +#include "ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_box_ICU4XTimeFormatter_ICU4XError { + union { + ICU4XTimeFormatter* ok; + ICU4XError err; + }; + bool is_ok; +} diplomat_result_box_ICU4XTimeFormatter_ICU4XError; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XTimeZoneFormatter_ICU4XError.h b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XTimeZoneFormatter_ICU4XError.h new file mode 100644 index 0000000000..5f4851051e --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XTimeZoneFormatter_ICU4XError.h @@ -0,0 +1,26 @@ +#ifndef diplomat_result_box_ICU4XTimeZoneFormatter_ICU4XError_H +#define diplomat_result_box_ICU4XTimeZoneFormatter_ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +typedef struct ICU4XTimeZoneFormatter ICU4XTimeZoneFormatter; +#include "ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_box_ICU4XTimeZoneFormatter_ICU4XError { + union { + ICU4XTimeZoneFormatter* ok; + ICU4XError err; + }; + bool is_ok; +} diplomat_result_box_ICU4XTimeZoneFormatter_ICU4XError; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XTime_ICU4XError.h b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XTime_ICU4XError.h new file mode 100644 index 0000000000..3e58b1e4da --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XTime_ICU4XError.h @@ -0,0 +1,26 @@ +#ifndef diplomat_result_box_ICU4XTime_ICU4XError_H +#define diplomat_result_box_ICU4XTime_ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +typedef struct ICU4XTime ICU4XTime; +#include "ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_box_ICU4XTime_ICU4XError { + union { + ICU4XTime* ok; + ICU4XError err; + }; + bool is_ok; +} diplomat_result_box_ICU4XTime_ICU4XError; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XTitlecaseMapper_ICU4XError.h b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XTitlecaseMapper_ICU4XError.h new file mode 100644 index 0000000000..f8b017cfd4 --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XTitlecaseMapper_ICU4XError.h @@ -0,0 +1,26 @@ +#ifndef diplomat_result_box_ICU4XTitlecaseMapper_ICU4XError_H +#define diplomat_result_box_ICU4XTitlecaseMapper_ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +typedef struct ICU4XTitlecaseMapper ICU4XTitlecaseMapper; +#include "ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_box_ICU4XTitlecaseMapper_ICU4XError { + union { + ICU4XTitlecaseMapper* ok; + ICU4XError err; + }; + bool is_ok; +} diplomat_result_box_ICU4XTitlecaseMapper_ICU4XError; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XUnicodeSetData_ICU4XError.h b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XUnicodeSetData_ICU4XError.h new file mode 100644 index 0000000000..6dd14e82b6 --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XUnicodeSetData_ICU4XError.h @@ -0,0 +1,26 @@ +#ifndef diplomat_result_box_ICU4XUnicodeSetData_ICU4XError_H +#define diplomat_result_box_ICU4XUnicodeSetData_ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +typedef struct ICU4XUnicodeSetData ICU4XUnicodeSetData; +#include "ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_box_ICU4XUnicodeSetData_ICU4XError { + union { + ICU4XUnicodeSetData* ok; + ICU4XError err; + }; + bool is_ok; +} diplomat_result_box_ICU4XUnicodeSetData_ICU4XError; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XWeekCalculator_ICU4XError.h b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XWeekCalculator_ICU4XError.h new file mode 100644 index 0000000000..1f547fd383 --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XWeekCalculator_ICU4XError.h @@ -0,0 +1,26 @@ +#ifndef diplomat_result_box_ICU4XWeekCalculator_ICU4XError_H +#define diplomat_result_box_ICU4XWeekCalculator_ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +typedef struct ICU4XWeekCalculator ICU4XWeekCalculator; +#include "ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_box_ICU4XWeekCalculator_ICU4XError { + union { + ICU4XWeekCalculator* ok; + ICU4XError err; + }; + bool is_ok; +} diplomat_result_box_ICU4XWeekCalculator_ICU4XError; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XWordSegmenter_ICU4XError.h b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XWordSegmenter_ICU4XError.h new file mode 100644 index 0000000000..e41c59b661 --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XWordSegmenter_ICU4XError.h @@ -0,0 +1,26 @@ +#ifndef diplomat_result_box_ICU4XWordSegmenter_ICU4XError_H +#define diplomat_result_box_ICU4XWordSegmenter_ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +typedef struct ICU4XWordSegmenter ICU4XWordSegmenter; +#include "ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_box_ICU4XWordSegmenter_ICU4XError { + union { + ICU4XWordSegmenter* ok; + ICU4XError err; + }; + bool is_ok; +} diplomat_result_box_ICU4XWordSegmenter_ICU4XError; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XZonedDateTimeFormatter_ICU4XError.h b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XZonedDateTimeFormatter_ICU4XError.h new file mode 100644 index 0000000000..52a0ab4462 --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_box_ICU4XZonedDateTimeFormatter_ICU4XError.h @@ -0,0 +1,26 @@ +#ifndef diplomat_result_box_ICU4XZonedDateTimeFormatter_ICU4XError_H +#define diplomat_result_box_ICU4XZonedDateTimeFormatter_ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +typedef struct ICU4XZonedDateTimeFormatter ICU4XZonedDateTimeFormatter; +#include "ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_box_ICU4XZonedDateTimeFormatter_ICU4XError { + union { + ICU4XZonedDateTimeFormatter* ok; + ICU4XError err; + }; + bool is_ok; +} diplomat_result_box_ICU4XZonedDateTimeFormatter_ICU4XError; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_int32_t_ICU4XError.h b/intl/icu_capi/cpp/include/diplomat_result_int32_t_ICU4XError.h new file mode 100644 index 0000000000..adbe148dd1 --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_int32_t_ICU4XError.h @@ -0,0 +1,25 @@ +#ifndef diplomat_result_int32_t_ICU4XError_H +#define diplomat_result_int32_t_ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#include "ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_int32_t_ICU4XError { + union { + int32_t ok; + ICU4XError err; + }; + bool is_ok; +} diplomat_result_int32_t_ICU4XError; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_uint16_t_void.h b/intl/icu_capi/cpp/include/diplomat_result_uint16_t_void.h new file mode 100644 index 0000000000..3adeb5f36d --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_uint16_t_void.h @@ -0,0 +1,23 @@ +#ifndef diplomat_result_uint16_t_void_H +#define diplomat_result_uint16_t_void_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_uint16_t_void { + union { + uint16_t ok; + }; + bool is_ok; +} diplomat_result_uint16_t_void; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_void_ICU4XError.h b/intl/icu_capi/cpp/include/diplomat_result_void_ICU4XError.h new file mode 100644 index 0000000000..f092491e34 --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_void_ICU4XError.h @@ -0,0 +1,24 @@ +#ifndef diplomat_result_void_ICU4XError_H +#define diplomat_result_void_ICU4XError_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#include "ICU4XError.h" +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_void_ICU4XError { + union { + ICU4XError err; + }; + bool is_ok; +} diplomat_result_void_ICU4XError; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_result_void_void.h b/intl/icu_capi/cpp/include/diplomat_result_void_void.h new file mode 100644 index 0000000000..2d5cc704e5 --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_result_void_void.h @@ -0,0 +1,20 @@ +#ifndef diplomat_result_void_void_H +#define diplomat_result_void_void_H +#include <stdio.h> +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif +typedef struct diplomat_result_void_void { + bool is_ok; +} diplomat_result_void_void; +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_runtime.h b/intl/icu_capi/cpp/include/diplomat_runtime.h new file mode 100644 index 0000000000..de0f9c76fe --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_runtime.h @@ -0,0 +1,70 @@ +#ifndef DIPLOMAT_RUNTIME_C_H +#define DIPLOMAT_RUNTIME_C_H + +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <sys/types.h> + +// uchar.h doesn't always exist, but char32_t is always available +// in C++ anyway +#ifndef __cplusplus +#ifdef __APPLE__ +#include <stdint.h> +typedef uint16_t char16_t; +typedef uint32_t char32_t; +#else +#include <uchar.h> +#endif +#endif + + +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +typedef struct DiplomatWriteable { + void* context; + char* buf; + size_t len; + size_t cap; + void (*flush)(struct DiplomatWriteable*); + bool (*grow)(struct DiplomatWriteable*, size_t); +} DiplomatWriteable; + +DiplomatWriteable diplomat_simple_writeable(char* buf, size_t buf_size); + +typedef struct DiplomatStringView { + const char* data; + size_t len; +} DiplomatStringView; + +#define MAKE_SLICE_VIEW(name, c_ty) \ + typedef struct Diplomat##name##View { \ + const c_ty* data; \ + size_t len; \ + } Diplomat##name##View; + +MAKE_SLICE_VIEW(I8, int8_t) +MAKE_SLICE_VIEW(U8, uint8_t) +MAKE_SLICE_VIEW(I16, int16_t) +MAKE_SLICE_VIEW(U16, uint16_t) +MAKE_SLICE_VIEW(I32, int32_t) +MAKE_SLICE_VIEW(U32, uint32_t) +MAKE_SLICE_VIEW(I64, int64_t) +MAKE_SLICE_VIEW(U64, uint64_t) +MAKE_SLICE_VIEW(Isize, intptr_t) +MAKE_SLICE_VIEW(Usize, size_t) +MAKE_SLICE_VIEW(F32, float) +MAKE_SLICE_VIEW(F64, double) +MAKE_SLICE_VIEW(Bool, bool) +MAKE_SLICE_VIEW(Char, char32_t) + + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif + +#endif diff --git a/intl/icu_capi/cpp/include/diplomat_runtime.hpp b/intl/icu_capi/cpp/include/diplomat_runtime.hpp new file mode 100644 index 0000000000..841752280d --- /dev/null +++ b/intl/icu_capi/cpp/include/diplomat_runtime.hpp @@ -0,0 +1,175 @@ +#ifndef DIPLOMAT_RUNTIME_CPP_H +#define DIPLOMAT_RUNTIME_CPP_H + +#include <string> +#include <variant> +#include <array> +#include <optional> +#include <type_traits> + +#if __cplusplus >= 202002L +#include<span> +#endif + +#include "diplomat_runtime.h" + +namespace diplomat { + +extern "C" inline void Flush(capi::DiplomatWriteable* w) { + std::string* string = reinterpret_cast<std::string*>(w->context); + string->resize(w->len); +}; + +extern "C" inline bool Grow(capi::DiplomatWriteable* w, uintptr_t requested) { + std::string* string = reinterpret_cast<std::string*>(w->context); + string->resize(requested); + w->cap = string->length(); + w->buf = &(*string)[0]; + return true; +}; + +inline capi::DiplomatWriteable WriteableFromString(std::string& string) { + capi::DiplomatWriteable w; + w.context = &string; + w.buf = &string[0]; + w.len = string.length(); + // Same as length, since C++ strings are not supposed + // to be written to past their len; you resize *first* + w.cap = string.length(); + w.flush = Flush; + w.grow = Grow; + return w; +}; + +template<typename T> struct WriteableTrait { + // static inline capi::DiplomatWriteable Construct(T& t); +}; + + +template<> struct WriteableTrait<std::string> { + static inline capi::DiplomatWriteable Construct(std::string& t) { + return diplomat::WriteableFromString(t); + } +}; + +template<class T> struct Ok { + T inner; + explicit Ok(T&& i): inner(std::move(i)) {} + // We don't want to expose an lvalue-capable constructor in general + // however there is no problem doing this for trivially copyable types + template<typename X = T, typename = typename std::enable_if<std::is_trivially_copyable<X>::value>::type> + explicit Ok(const T& i): inner(i) {} + Ok() = default; + Ok(Ok&&) noexcept = default; + Ok(const Ok &) = default; + Ok& operator=(const Ok&) = default; + Ok& operator=(Ok&&) noexcept = default; +}; + +template<class T> struct Err { + T inner; + explicit Err(T&& i): inner(std::move(i)) {} + // We don't want to expose an lvalue-capable constructor in general + // however there is no problem doing this for trivially copyable types + template<typename X = T, typename = typename std::enable_if<std::is_trivially_copyable<X>::value>::type> + explicit Err(const T& i): inner(i) {} + Err() = default; + Err(Err&&) noexcept = default; + Err(const Err &) = default; + Err& operator=(const Err&) = default; + Err& operator=(Err&&) noexcept = default; +}; + +template<class T, class E> +class result { +private: + std::variant<Ok<T>, Err<E>> val; +public: + explicit result(Ok<T>&& v): val(std::move(v)) {} + explicit result(Err<E>&& v): val(std::move(v)) {} + result() = default; + result(const result &) = default; + result& operator=(const result&) = default; + result& operator=(Ok<T>&& t) { + this->val = Ok<T>(std::move(t)); + return *this; + } + result& operator=(Err<E>&& e) { + this->val = Err<E>(std::move(e)); + return *this; + } + result& operator=(result&&) noexcept = default; + result(result &&) noexcept = default; + ~result() = default; + bool is_ok() const { + return std::holds_alternative<Ok<T>>(this->val); + }; + bool is_err() const { + return std::holds_alternative<Err<E>>(this->val); + }; + + std::optional<T> ok() && { + if (!this->is_ok()) { + return std::nullopt; + } + return std::make_optional(std::move(std::get<Ok<T>>(std::move(this->val)).inner)); + }; + std::optional<E> err() && { + if (!this->is_err()) { + return std::nullopt; + } + return std::make_optional(std::move(std::get<Err<E>>(std::move(this->val)).inner)); + } + + void set_ok(T&& t) { + this->val = Ok<T>(std::move(t)); + } + + void set_err(E&& e) { + this->val = Err<E>(std::move(e)); + } + + template<typename T2> + result<T2, E> replace_ok(T2&& t) { + if (this->is_err()) { + return result<T2, E>(Err<E>(std::get<Err<E>>(std::move(this->val)))); + } else { + return result<T2, E>(Ok<T2>(std::move(t))); + } + } +}; + + +// Use custom std::span on C++17, otherwise use std::span +#if __cplusplus >= 202002L + +template<class T> using span = std::span<T>; + +#else // __cplusplus >= 202002L + +// C++-17-compatible std::span +template<class T> +class span { + +public: + constexpr span(T* data, size_t size) + : data_(data), size_(size) {} + template<size_t N> + explicit constexpr span(std::array<typename std::remove_const<T>::type, N>& arr) + : data_(const_cast<T*>(arr.data())), size_(N) {} + constexpr T* data() const noexcept { + return this->data_; + } + constexpr size_t size() const noexcept { + return this->size_; + } +private: + T* data_; + size_t size_; +}; + +#endif // __cplusplus >= 202002L + +} + +#endif |