GraphemeClusterSegmenter.hpp (5038B)
1 #ifndef icu4x_GraphemeClusterSegmenter_HPP 2 #define icu4x_GraphemeClusterSegmenter_HPP 3 4 #include "GraphemeClusterSegmenter.d.hpp" 5 6 #include <stdio.h> 7 #include <stdint.h> 8 #include <stddef.h> 9 #include <stdbool.h> 10 #include <memory> 11 #include <functional> 12 #include <optional> 13 #include <cstdlib> 14 #include "../diplomat_runtime.hpp" 15 #include "DataError.hpp" 16 #include "DataProvider.hpp" 17 #include "GraphemeClusterBreakIteratorLatin1.hpp" 18 #include "GraphemeClusterBreakIteratorUtf16.hpp" 19 #include "GraphemeClusterBreakIteratorUtf8.hpp" 20 21 22 namespace icu4x { 23 namespace capi { 24 extern "C" { 25 26 icu4x::capi::GraphemeClusterSegmenter* icu4x_GraphemeClusterSegmenter_create_mv1(void); 27 28 typedef struct icu4x_GraphemeClusterSegmenter_create_with_provider_mv1_result {union {icu4x::capi::GraphemeClusterSegmenter* ok; icu4x::capi::DataError err;}; bool is_ok;} icu4x_GraphemeClusterSegmenter_create_with_provider_mv1_result; 29 icu4x_GraphemeClusterSegmenter_create_with_provider_mv1_result icu4x_GraphemeClusterSegmenter_create_with_provider_mv1(const icu4x::capi::DataProvider* provider); 30 31 icu4x::capi::GraphemeClusterBreakIteratorUtf8* icu4x_GraphemeClusterSegmenter_segment_utf8_mv1(const icu4x::capi::GraphemeClusterSegmenter* self, diplomat::capi::DiplomatStringView input); 32 33 icu4x::capi::GraphemeClusterBreakIteratorUtf16* icu4x_GraphemeClusterSegmenter_segment_utf16_mv1(const icu4x::capi::GraphemeClusterSegmenter* self, diplomat::capi::DiplomatString16View input); 34 35 icu4x::capi::GraphemeClusterBreakIteratorLatin1* icu4x_GraphemeClusterSegmenter_segment_latin1_mv1(const icu4x::capi::GraphemeClusterSegmenter* self, diplomat::capi::DiplomatU8View input); 36 37 void icu4x_GraphemeClusterSegmenter_destroy_mv1(GraphemeClusterSegmenter* self); 38 39 } // extern "C" 40 } // namespace capi 41 } // namespace 42 43 inline std::unique_ptr<icu4x::GraphemeClusterSegmenter> icu4x::GraphemeClusterSegmenter::create() { 44 auto result = icu4x::capi::icu4x_GraphemeClusterSegmenter_create_mv1(); 45 return std::unique_ptr<icu4x::GraphemeClusterSegmenter>(icu4x::GraphemeClusterSegmenter::FromFFI(result)); 46 } 47 48 inline diplomat::result<std::unique_ptr<icu4x::GraphemeClusterSegmenter>, icu4x::DataError> icu4x::GraphemeClusterSegmenter::create_with_provider(const icu4x::DataProvider& provider) { 49 auto result = icu4x::capi::icu4x_GraphemeClusterSegmenter_create_with_provider_mv1(provider.AsFFI()); 50 return result.is_ok ? diplomat::result<std::unique_ptr<icu4x::GraphemeClusterSegmenter>, icu4x::DataError>(diplomat::Ok<std::unique_ptr<icu4x::GraphemeClusterSegmenter>>(std::unique_ptr<icu4x::GraphemeClusterSegmenter>(icu4x::GraphemeClusterSegmenter::FromFFI(result.ok)))) : diplomat::result<std::unique_ptr<icu4x::GraphemeClusterSegmenter>, icu4x::DataError>(diplomat::Err<icu4x::DataError>(icu4x::DataError::FromFFI(result.err))); 51 } 52 53 inline std::unique_ptr<icu4x::GraphemeClusterBreakIteratorUtf8> icu4x::GraphemeClusterSegmenter::segment(std::string_view input) const { 54 auto result = icu4x::capi::icu4x_GraphemeClusterSegmenter_segment_utf8_mv1(this->AsFFI(), 55 {input.data(), input.size()}); 56 return std::unique_ptr<icu4x::GraphemeClusterBreakIteratorUtf8>(icu4x::GraphemeClusterBreakIteratorUtf8::FromFFI(result)); 57 } 58 59 inline std::unique_ptr<icu4x::GraphemeClusterBreakIteratorUtf16> icu4x::GraphemeClusterSegmenter::segment16(std::u16string_view input) const { 60 auto result = icu4x::capi::icu4x_GraphemeClusterSegmenter_segment_utf16_mv1(this->AsFFI(), 61 {input.data(), input.size()}); 62 return std::unique_ptr<icu4x::GraphemeClusterBreakIteratorUtf16>(icu4x::GraphemeClusterBreakIteratorUtf16::FromFFI(result)); 63 } 64 65 inline std::unique_ptr<icu4x::GraphemeClusterBreakIteratorLatin1> icu4x::GraphemeClusterSegmenter::segment_latin1(diplomat::span<const uint8_t> input) const { 66 auto result = icu4x::capi::icu4x_GraphemeClusterSegmenter_segment_latin1_mv1(this->AsFFI(), 67 {input.data(), input.size()}); 68 return std::unique_ptr<icu4x::GraphemeClusterBreakIteratorLatin1>(icu4x::GraphemeClusterBreakIteratorLatin1::FromFFI(result)); 69 } 70 71 inline const icu4x::capi::GraphemeClusterSegmenter* icu4x::GraphemeClusterSegmenter::AsFFI() const { 72 return reinterpret_cast<const icu4x::capi::GraphemeClusterSegmenter*>(this); 73 } 74 75 inline icu4x::capi::GraphemeClusterSegmenter* icu4x::GraphemeClusterSegmenter::AsFFI() { 76 return reinterpret_cast<icu4x::capi::GraphemeClusterSegmenter*>(this); 77 } 78 79 inline const icu4x::GraphemeClusterSegmenter* icu4x::GraphemeClusterSegmenter::FromFFI(const icu4x::capi::GraphemeClusterSegmenter* ptr) { 80 return reinterpret_cast<const icu4x::GraphemeClusterSegmenter*>(ptr); 81 } 82 83 inline icu4x::GraphemeClusterSegmenter* icu4x::GraphemeClusterSegmenter::FromFFI(icu4x::capi::GraphemeClusterSegmenter* ptr) { 84 return reinterpret_cast<icu4x::GraphemeClusterSegmenter*>(ptr); 85 } 86 87 inline void icu4x::GraphemeClusterSegmenter::operator delete(void* ptr) { 88 icu4x::capi::icu4x_GraphemeClusterSegmenter_destroy_mv1(reinterpret_cast<icu4x::capi::GraphemeClusterSegmenter*>(ptr)); 89 } 90 91 92 #endif // icu4x_GraphemeClusterSegmenter_HPP