diff --git a/components/time/src/zone/iana.rs b/components/time/src/zone/iana.rs index 4cc339ccc46..042ec56867e 100644 --- a/components/time/src/zone/iana.rs +++ b/components/time/src/zone/iana.rs @@ -192,7 +192,7 @@ impl IanaParserBorrowed<'static> { } } -impl IanaParserBorrowed<'_> { +impl<'a> IanaParserBorrowed<'a> { /// Gets the BCP-47 time zone ID from an IANA time zone ID /// with a case-insensitive lookup. /// @@ -259,7 +259,7 @@ impl IanaParserBorrowed<'_> { /// /// assert!(ids.contains(&TimeZone(tinystr!(8, "uaiev")))); /// ``` - pub fn iter(&self) -> TimeZoneIter { + pub fn iter(&self) -> TimeZoneIter<'a> { TimeZoneIter { inner: self.data.bcp47_ids.iter(), } diff --git a/ffi/capi/bindings/c/IanaParser.h b/ffi/capi/bindings/c/IanaParser.h index 5fbff8a0056..fb61549e213 100644 --- a/ffi/capi/bindings/c/IanaParser.h +++ b/ffi/capi/bindings/c/IanaParser.h @@ -10,6 +10,7 @@ #include "DataError.d.h" #include "DataProvider.d.h" #include "TimeZoneInfo.d.h" +#include "TimeZoneIterator.d.h" #include "IanaParser.d.h" @@ -25,6 +26,8 @@ icu4x_IanaParser_create_with_provider_mv1_result icu4x_IanaParser_create_with_pr TimeZoneInfo* icu4x_IanaParser_parse_mv1(const IanaParser* self, DiplomatStringView value); +TimeZoneIterator* icu4x_IanaParser_iter_mv1(const IanaParser* self); + void icu4x_IanaParser_destroy_mv1(IanaParser* self); diff --git a/ffi/capi/bindings/c/IanaParserExtended.d.h b/ffi/capi/bindings/c/IanaParserExtended.d.h new file mode 100644 index 00000000000..32d15a5240a --- /dev/null +++ b/ffi/capi/bindings/c/IanaParserExtended.d.h @@ -0,0 +1,19 @@ +#ifndef IanaParserExtended_D_H +#define IanaParserExtended_D_H + +#include +#include +#include +#include +#include "diplomat_runtime.h" + + + + + +typedef struct IanaParserExtended IanaParserExtended; + + + + +#endif // IanaParserExtended_D_H diff --git a/ffi/capi/bindings/c/IanaParserExtended.h b/ffi/capi/bindings/c/IanaParserExtended.h new file mode 100644 index 00000000000..26a1ad8fb5a --- /dev/null +++ b/ffi/capi/bindings/c/IanaParserExtended.h @@ -0,0 +1,41 @@ +#ifndef IanaParserExtended_H +#define IanaParserExtended_H + +#include +#include +#include +#include +#include "diplomat_runtime.h" + +#include "DataError.d.h" +#include "DataProvider.d.h" +#include "TimeZoneAndCanonicalAndNormalized.d.h" +#include "TimeZoneAndCanonicalAndNormalizedIterator.d.h" +#include "TimeZoneAndCanonicalIterator.d.h" + +#include "IanaParserExtended.d.h" + + + + + + +IanaParserExtended* icu4x_IanaParserExtended_create_mv1(void); + +typedef struct icu4x_IanaParserExtended_create_with_provider_mv1_result {union {IanaParserExtended* ok; DataError err;}; bool is_ok;} icu4x_IanaParserExtended_create_with_provider_mv1_result; +icu4x_IanaParserExtended_create_with_provider_mv1_result icu4x_IanaParserExtended_create_with_provider_mv1(const DataProvider* provider); + +TimeZoneAndCanonicalAndNormalized icu4x_IanaParserExtended_parse_mv1(const IanaParserExtended* self, DiplomatStringView value); + +TimeZoneAndCanonicalIterator* icu4x_IanaParserExtended_iter_mv1(const IanaParserExtended* self); + +TimeZoneAndCanonicalAndNormalizedIterator* icu4x_IanaParserExtended_iter_all_mv1(const IanaParserExtended* self); + + +void icu4x_IanaParserExtended_destroy_mv1(IanaParserExtended* self); + + + + + +#endif // IanaParserExtended_H diff --git a/ffi/capi/bindings/c/TimeZoneAndCanonical.d.h b/ffi/capi/bindings/c/TimeZoneAndCanonical.d.h new file mode 100644 index 00000000000..94430d91b35 --- /dev/null +++ b/ffi/capi/bindings/c/TimeZoneAndCanonical.d.h @@ -0,0 +1,24 @@ +#ifndef TimeZoneAndCanonical_D_H +#define TimeZoneAndCanonical_D_H + +#include +#include +#include +#include +#include "diplomat_runtime.h" + +#include "TimeZoneInfo.d.h" + + + + +typedef struct TimeZoneAndCanonical { + TimeZoneInfo* time_zone; + DiplomatStringView canonical; +} TimeZoneAndCanonical; + +typedef struct TimeZoneAndCanonical_option {union { TimeZoneAndCanonical ok; }; bool is_ok; } TimeZoneAndCanonical_option; + + + +#endif // TimeZoneAndCanonical_D_H diff --git a/ffi/capi/bindings/c/TimeZoneAndCanonical.h b/ffi/capi/bindings/c/TimeZoneAndCanonical.h new file mode 100644 index 00000000000..cba517ce877 --- /dev/null +++ b/ffi/capi/bindings/c/TimeZoneAndCanonical.h @@ -0,0 +1,23 @@ +#ifndef TimeZoneAndCanonical_H +#define TimeZoneAndCanonical_H + +#include +#include +#include +#include +#include "diplomat_runtime.h" + + +#include "TimeZoneAndCanonical.d.h" + + + + + + + + + + + +#endif // TimeZoneAndCanonical_H diff --git a/ffi/capi/bindings/c/TimeZoneAndCanonicalAndNormalized.d.h b/ffi/capi/bindings/c/TimeZoneAndCanonicalAndNormalized.d.h new file mode 100644 index 00000000000..01fc28ba4d2 --- /dev/null +++ b/ffi/capi/bindings/c/TimeZoneAndCanonicalAndNormalized.d.h @@ -0,0 +1,25 @@ +#ifndef TimeZoneAndCanonicalAndNormalized_D_H +#define TimeZoneAndCanonicalAndNormalized_D_H + +#include +#include +#include +#include +#include "diplomat_runtime.h" + +#include "TimeZoneInfo.d.h" + + + + +typedef struct TimeZoneAndCanonicalAndNormalized { + TimeZoneInfo* time_zone; + DiplomatStringView canonical; + DiplomatStringView normalized; +} TimeZoneAndCanonicalAndNormalized; + +typedef struct TimeZoneAndCanonicalAndNormalized_option {union { TimeZoneAndCanonicalAndNormalized ok; }; bool is_ok; } TimeZoneAndCanonicalAndNormalized_option; + + + +#endif // TimeZoneAndCanonicalAndNormalized_D_H diff --git a/ffi/capi/bindings/c/TimeZoneAndCanonicalAndNormalized.h b/ffi/capi/bindings/c/TimeZoneAndCanonicalAndNormalized.h new file mode 100644 index 00000000000..f84d3b2f448 --- /dev/null +++ b/ffi/capi/bindings/c/TimeZoneAndCanonicalAndNormalized.h @@ -0,0 +1,23 @@ +#ifndef TimeZoneAndCanonicalAndNormalized_H +#define TimeZoneAndCanonicalAndNormalized_H + +#include +#include +#include +#include +#include "diplomat_runtime.h" + + +#include "TimeZoneAndCanonicalAndNormalized.d.h" + + + + + + + + + + + +#endif // TimeZoneAndCanonicalAndNormalized_H diff --git a/ffi/capi/bindings/c/TimeZoneAndCanonicalAndNormalizedIterator.d.h b/ffi/capi/bindings/c/TimeZoneAndCanonicalAndNormalizedIterator.d.h new file mode 100644 index 00000000000..fb83714aca3 --- /dev/null +++ b/ffi/capi/bindings/c/TimeZoneAndCanonicalAndNormalizedIterator.d.h @@ -0,0 +1,19 @@ +#ifndef TimeZoneAndCanonicalAndNormalizedIterator_D_H +#define TimeZoneAndCanonicalAndNormalizedIterator_D_H + +#include +#include +#include +#include +#include "diplomat_runtime.h" + + + + + +typedef struct TimeZoneAndCanonicalAndNormalizedIterator TimeZoneAndCanonicalAndNormalizedIterator; + + + + +#endif // TimeZoneAndCanonicalAndNormalizedIterator_D_H diff --git a/ffi/capi/bindings/c/TimeZoneAndCanonicalAndNormalizedIterator.h b/ffi/capi/bindings/c/TimeZoneAndCanonicalAndNormalizedIterator.h new file mode 100644 index 00000000000..440fddcda19 --- /dev/null +++ b/ffi/capi/bindings/c/TimeZoneAndCanonicalAndNormalizedIterator.h @@ -0,0 +1,29 @@ +#ifndef TimeZoneAndCanonicalAndNormalizedIterator_H +#define TimeZoneAndCanonicalAndNormalizedIterator_H + +#include +#include +#include +#include +#include "diplomat_runtime.h" + +#include "TimeZoneAndCanonicalAndNormalized.d.h" + +#include "TimeZoneAndCanonicalAndNormalizedIterator.d.h" + + + + + + +typedef struct icu4x_TimeZoneAndCanonicalAndNormalizedIterator_next_mv1_result {union {TimeZoneAndCanonicalAndNormalized ok; }; bool is_ok;} icu4x_TimeZoneAndCanonicalAndNormalizedIterator_next_mv1_result; +icu4x_TimeZoneAndCanonicalAndNormalizedIterator_next_mv1_result icu4x_TimeZoneAndCanonicalAndNormalizedIterator_next_mv1(TimeZoneAndCanonicalAndNormalizedIterator* self); + + +void icu4x_TimeZoneAndCanonicalAndNormalizedIterator_destroy_mv1(TimeZoneAndCanonicalAndNormalizedIterator* self); + + + + + +#endif // TimeZoneAndCanonicalAndNormalizedIterator_H diff --git a/ffi/capi/bindings/c/TimeZoneAndCanonicalIterator.d.h b/ffi/capi/bindings/c/TimeZoneAndCanonicalIterator.d.h new file mode 100644 index 00000000000..b64bf184b0e --- /dev/null +++ b/ffi/capi/bindings/c/TimeZoneAndCanonicalIterator.d.h @@ -0,0 +1,19 @@ +#ifndef TimeZoneAndCanonicalIterator_D_H +#define TimeZoneAndCanonicalIterator_D_H + +#include +#include +#include +#include +#include "diplomat_runtime.h" + + + + + +typedef struct TimeZoneAndCanonicalIterator TimeZoneAndCanonicalIterator; + + + + +#endif // TimeZoneAndCanonicalIterator_D_H diff --git a/ffi/capi/bindings/c/TimeZoneAndCanonicalIterator.h b/ffi/capi/bindings/c/TimeZoneAndCanonicalIterator.h new file mode 100644 index 00000000000..8b87b179516 --- /dev/null +++ b/ffi/capi/bindings/c/TimeZoneAndCanonicalIterator.h @@ -0,0 +1,29 @@ +#ifndef TimeZoneAndCanonicalIterator_H +#define TimeZoneAndCanonicalIterator_H + +#include +#include +#include +#include +#include "diplomat_runtime.h" + +#include "TimeZoneAndCanonical.d.h" + +#include "TimeZoneAndCanonicalIterator.d.h" + + + + + + +typedef struct icu4x_TimeZoneAndCanonicalIterator_next_mv1_result {union {TimeZoneAndCanonical ok; }; bool is_ok;} icu4x_TimeZoneAndCanonicalIterator_next_mv1_result; +icu4x_TimeZoneAndCanonicalIterator_next_mv1_result icu4x_TimeZoneAndCanonicalIterator_next_mv1(TimeZoneAndCanonicalIterator* self); + + +void icu4x_TimeZoneAndCanonicalIterator_destroy_mv1(TimeZoneAndCanonicalIterator* self); + + + + + +#endif // TimeZoneAndCanonicalIterator_H diff --git a/ffi/capi/bindings/c/TimeZoneIterator.d.h b/ffi/capi/bindings/c/TimeZoneIterator.d.h new file mode 100644 index 00000000000..411db4e8a72 --- /dev/null +++ b/ffi/capi/bindings/c/TimeZoneIterator.d.h @@ -0,0 +1,19 @@ +#ifndef TimeZoneIterator_D_H +#define TimeZoneIterator_D_H + +#include +#include +#include +#include +#include "diplomat_runtime.h" + + + + + +typedef struct TimeZoneIterator TimeZoneIterator; + + + + +#endif // TimeZoneIterator_D_H diff --git a/ffi/capi/bindings/c/TimeZoneIterator.h b/ffi/capi/bindings/c/TimeZoneIterator.h new file mode 100644 index 00000000000..60bb321b39c --- /dev/null +++ b/ffi/capi/bindings/c/TimeZoneIterator.h @@ -0,0 +1,28 @@ +#ifndef TimeZoneIterator_H +#define TimeZoneIterator_H + +#include +#include +#include +#include +#include "diplomat_runtime.h" + +#include "TimeZoneInfo.d.h" + +#include "TimeZoneIterator.d.h" + + + + + + +TimeZoneInfo* icu4x_TimeZoneIterator_next_mv1(TimeZoneIterator* self); + + +void icu4x_TimeZoneIterator_destroy_mv1(TimeZoneIterator* self); + + + + + +#endif // TimeZoneIterator_H diff --git a/ffi/capi/bindings/cpp/icu4x/IanaParser.d.hpp b/ffi/capi/bindings/cpp/icu4x/IanaParser.d.hpp index fa6d3040415..708bf4ab205 100644 --- a/ffi/capi/bindings/cpp/icu4x/IanaParser.d.hpp +++ b/ffi/capi/bindings/cpp/icu4x/IanaParser.d.hpp @@ -17,6 +17,8 @@ namespace capi { struct IanaParser; } class IanaParser; namespace capi { struct TimeZoneInfo; } class TimeZoneInfo; +namespace capi { struct TimeZoneIterator; } +class TimeZoneIterator; class DataError; } @@ -37,6 +39,8 @@ class IanaParser { inline std::unique_ptr parse(std::string_view value) const; + inline std::unique_ptr iter() const; + inline const icu4x::capi::IanaParser* AsFFI() const; inline icu4x::capi::IanaParser* AsFFI(); inline static const icu4x::IanaParser* FromFFI(const icu4x::capi::IanaParser* ptr); diff --git a/ffi/capi/bindings/cpp/icu4x/IanaParser.hpp b/ffi/capi/bindings/cpp/icu4x/IanaParser.hpp index 71d94726c51..5ca38511645 100644 --- a/ffi/capi/bindings/cpp/icu4x/IanaParser.hpp +++ b/ffi/capi/bindings/cpp/icu4x/IanaParser.hpp @@ -14,6 +14,7 @@ #include "DataError.hpp" #include "DataProvider.hpp" #include "TimeZoneInfo.hpp" +#include "TimeZoneIterator.hpp" namespace icu4x { @@ -27,6 +28,8 @@ namespace capi { icu4x::capi::TimeZoneInfo* icu4x_IanaParser_parse_mv1(const icu4x::capi::IanaParser* self, diplomat::capi::DiplomatStringView value); + icu4x::capi::TimeZoneIterator* icu4x_IanaParser_iter_mv1(const icu4x::capi::IanaParser* self); + void icu4x_IanaParser_destroy_mv1(IanaParser* self); @@ -50,6 +53,11 @@ inline std::unique_ptr icu4x::IanaParser::parse(std::string return std::unique_ptr(icu4x::TimeZoneInfo::FromFFI(result)); } +inline std::unique_ptr icu4x::IanaParser::iter() const { + auto result = icu4x::capi::icu4x_IanaParser_iter_mv1(this->AsFFI()); + return std::unique_ptr(icu4x::TimeZoneIterator::FromFFI(result)); +} + inline const icu4x::capi::IanaParser* icu4x::IanaParser::AsFFI() const { return reinterpret_cast(this); } diff --git a/ffi/capi/bindings/cpp/icu4x/IanaParserExtended.d.hpp b/ffi/capi/bindings/cpp/icu4x/IanaParserExtended.d.hpp new file mode 100644 index 00000000000..803d13d042a --- /dev/null +++ b/ffi/capi/bindings/cpp/icu4x/IanaParserExtended.d.hpp @@ -0,0 +1,62 @@ +#ifndef icu4x_IanaParserExtended_D_HPP +#define icu4x_IanaParserExtended_D_HPP + +#include +#include +#include +#include +#include +#include +#include +#include "../diplomat_runtime.hpp" + +namespace icu4x { +namespace capi { struct DataProvider; } +class DataProvider; +namespace capi { struct IanaParserExtended; } +class IanaParserExtended; +namespace capi { struct TimeZoneAndCanonicalAndNormalizedIterator; } +class TimeZoneAndCanonicalAndNormalizedIterator; +namespace capi { struct TimeZoneAndCanonicalIterator; } +class TimeZoneAndCanonicalIterator; +struct TimeZoneAndCanonicalAndNormalized; +class DataError; +} + + +namespace icu4x { +namespace capi { + struct IanaParserExtended; +} // namespace capi +} // namespace + +namespace icu4x { +class IanaParserExtended { +public: + + inline static std::unique_ptr create(); + + inline static diplomat::result, icu4x::DataError> create_with_provider(const icu4x::DataProvider& provider); + + inline icu4x::TimeZoneAndCanonicalAndNormalized parse(std::string_view value) const; + + inline std::unique_ptr iter() const; + + inline std::unique_ptr iter_all() const; + + inline const icu4x::capi::IanaParserExtended* AsFFI() const; + inline icu4x::capi::IanaParserExtended* AsFFI(); + inline static const icu4x::IanaParserExtended* FromFFI(const icu4x::capi::IanaParserExtended* ptr); + inline static icu4x::IanaParserExtended* FromFFI(icu4x::capi::IanaParserExtended* ptr); + inline static void operator delete(void* ptr); +private: + IanaParserExtended() = delete; + IanaParserExtended(const icu4x::IanaParserExtended&) = delete; + IanaParserExtended(icu4x::IanaParserExtended&&) noexcept = delete; + IanaParserExtended operator=(const icu4x::IanaParserExtended&) = delete; + IanaParserExtended operator=(icu4x::IanaParserExtended&&) noexcept = delete; + static void operator delete[](void*, size_t) = delete; +}; + +} // namespace +#endif // icu4x_IanaParserExtended_D_HPP diff --git a/ffi/capi/bindings/cpp/icu4x/IanaParserExtended.hpp b/ffi/capi/bindings/cpp/icu4x/IanaParserExtended.hpp new file mode 100644 index 00000000000..40dc66ad81d --- /dev/null +++ b/ffi/capi/bindings/cpp/icu4x/IanaParserExtended.hpp @@ -0,0 +1,90 @@ +#ifndef icu4x_IanaParserExtended_HPP +#define icu4x_IanaParserExtended_HPP + +#include "IanaParserExtended.d.hpp" + +#include +#include +#include +#include +#include +#include +#include +#include "../diplomat_runtime.hpp" +#include "DataError.hpp" +#include "DataProvider.hpp" +#include "TimeZoneAndCanonicalAndNormalized.hpp" +#include "TimeZoneAndCanonicalAndNormalizedIterator.hpp" +#include "TimeZoneAndCanonicalIterator.hpp" + + +namespace icu4x { +namespace capi { + extern "C" { + + icu4x::capi::IanaParserExtended* icu4x_IanaParserExtended_create_mv1(void); + + typedef struct icu4x_IanaParserExtended_create_with_provider_mv1_result {union {icu4x::capi::IanaParserExtended* ok; icu4x::capi::DataError err;}; bool is_ok;} icu4x_IanaParserExtended_create_with_provider_mv1_result; + icu4x_IanaParserExtended_create_with_provider_mv1_result icu4x_IanaParserExtended_create_with_provider_mv1(const icu4x::capi::DataProvider* provider); + + icu4x::capi::TimeZoneAndCanonicalAndNormalized icu4x_IanaParserExtended_parse_mv1(const icu4x::capi::IanaParserExtended* self, diplomat::capi::DiplomatStringView value); + + icu4x::capi::TimeZoneAndCanonicalIterator* icu4x_IanaParserExtended_iter_mv1(const icu4x::capi::IanaParserExtended* self); + + icu4x::capi::TimeZoneAndCanonicalAndNormalizedIterator* icu4x_IanaParserExtended_iter_all_mv1(const icu4x::capi::IanaParserExtended* self); + + + void icu4x_IanaParserExtended_destroy_mv1(IanaParserExtended* self); + + } // extern "C" +} // namespace capi +} // namespace + +inline std::unique_ptr icu4x::IanaParserExtended::create() { + auto result = icu4x::capi::icu4x_IanaParserExtended_create_mv1(); + return std::unique_ptr(icu4x::IanaParserExtended::FromFFI(result)); +} + +inline diplomat::result, icu4x::DataError> icu4x::IanaParserExtended::create_with_provider(const icu4x::DataProvider& provider) { + auto result = icu4x::capi::icu4x_IanaParserExtended_create_with_provider_mv1(provider.AsFFI()); + return result.is_ok ? diplomat::result, icu4x::DataError>(diplomat::Ok>(std::unique_ptr(icu4x::IanaParserExtended::FromFFI(result.ok)))) : diplomat::result, icu4x::DataError>(diplomat::Err(icu4x::DataError::FromFFI(result.err))); +} + +inline icu4x::TimeZoneAndCanonicalAndNormalized icu4x::IanaParserExtended::parse(std::string_view value) const { + auto result = icu4x::capi::icu4x_IanaParserExtended_parse_mv1(this->AsFFI(), + {value.data(), value.size()}); + return icu4x::TimeZoneAndCanonicalAndNormalized::FromFFI(result); +} + +inline std::unique_ptr icu4x::IanaParserExtended::iter() const { + auto result = icu4x::capi::icu4x_IanaParserExtended_iter_mv1(this->AsFFI()); + return std::unique_ptr(icu4x::TimeZoneAndCanonicalIterator::FromFFI(result)); +} + +inline std::unique_ptr icu4x::IanaParserExtended::iter_all() const { + auto result = icu4x::capi::icu4x_IanaParserExtended_iter_all_mv1(this->AsFFI()); + return std::unique_ptr(icu4x::TimeZoneAndCanonicalAndNormalizedIterator::FromFFI(result)); +} + +inline const icu4x::capi::IanaParserExtended* icu4x::IanaParserExtended::AsFFI() const { + return reinterpret_cast(this); +} + +inline icu4x::capi::IanaParserExtended* icu4x::IanaParserExtended::AsFFI() { + return reinterpret_cast(this); +} + +inline const icu4x::IanaParserExtended* icu4x::IanaParserExtended::FromFFI(const icu4x::capi::IanaParserExtended* ptr) { + return reinterpret_cast(ptr); +} + +inline icu4x::IanaParserExtended* icu4x::IanaParserExtended::FromFFI(icu4x::capi::IanaParserExtended* ptr) { + return reinterpret_cast(ptr); +} + +inline void icu4x::IanaParserExtended::operator delete(void* ptr) { + icu4x::capi::icu4x_IanaParserExtended_destroy_mv1(reinterpret_cast(ptr)); +} + + +#endif // icu4x_IanaParserExtended_HPP diff --git a/ffi/capi/bindings/cpp/icu4x/TimeZoneAndCanonical.d.hpp b/ffi/capi/bindings/cpp/icu4x/TimeZoneAndCanonical.d.hpp new file mode 100644 index 00000000000..269d01f6a76 --- /dev/null +++ b/ffi/capi/bindings/cpp/icu4x/TimeZoneAndCanonical.d.hpp @@ -0,0 +1,41 @@ +#ifndef icu4x_TimeZoneAndCanonical_D_HPP +#define icu4x_TimeZoneAndCanonical_D_HPP + +#include +#include +#include +#include +#include +#include +#include +#include "../diplomat_runtime.hpp" + +namespace icu4x { +namespace capi { struct TimeZoneInfo; } +class TimeZoneInfo; +} + + +namespace icu4x { +namespace capi { + struct TimeZoneAndCanonical { + icu4x::capi::TimeZoneInfo* time_zone; + diplomat::capi::DiplomatStringView canonical; + }; + + typedef struct TimeZoneAndCanonical_option {union { TimeZoneAndCanonical ok; }; bool is_ok; } TimeZoneAndCanonical_option; +} // namespace capi +} // namespace + + +namespace icu4x { +struct TimeZoneAndCanonical { + std::unique_ptr time_zone; + std::string_view canonical; + + inline icu4x::capi::TimeZoneAndCanonical AsFFI() const; + inline static icu4x::TimeZoneAndCanonical FromFFI(icu4x::capi::TimeZoneAndCanonical c_struct); +}; + +} // namespace +#endif // icu4x_TimeZoneAndCanonical_D_HPP diff --git a/ffi/capi/bindings/cpp/icu4x/TimeZoneAndCanonical.hpp b/ffi/capi/bindings/cpp/icu4x/TimeZoneAndCanonical.hpp new file mode 100644 index 00000000000..06149da193c --- /dev/null +++ b/ffi/capi/bindings/cpp/icu4x/TimeZoneAndCanonical.hpp @@ -0,0 +1,42 @@ +#ifndef icu4x_TimeZoneAndCanonical_HPP +#define icu4x_TimeZoneAndCanonical_HPP + +#include "TimeZoneAndCanonical.d.hpp" + +#include +#include +#include +#include +#include +#include +#include +#include "../diplomat_runtime.hpp" +#include "TimeZoneInfo.hpp" + + +namespace icu4x { +namespace capi { + extern "C" { + + + } // extern "C" +} // namespace capi +} // namespace + + +inline icu4x::capi::TimeZoneAndCanonical icu4x::TimeZoneAndCanonical::AsFFI() const { + return icu4x::capi::TimeZoneAndCanonical { + /* .time_zone = */ time_zone->AsFFI(), + /* .canonical = */ {canonical.data(), canonical.size()}, + }; +} + +inline icu4x::TimeZoneAndCanonical icu4x::TimeZoneAndCanonical::FromFFI(icu4x::capi::TimeZoneAndCanonical c_struct) { + return icu4x::TimeZoneAndCanonical { + /* .time_zone = */ std::unique_ptr(icu4x::TimeZoneInfo::FromFFI(c_struct.time_zone)), + /* .canonical = */ std::string_view(c_struct.canonical.data, c_struct.canonical.len), + }; +} + + +#endif // icu4x_TimeZoneAndCanonical_HPP diff --git a/ffi/capi/bindings/cpp/icu4x/TimeZoneAndCanonicalAndNormalized.d.hpp b/ffi/capi/bindings/cpp/icu4x/TimeZoneAndCanonicalAndNormalized.d.hpp new file mode 100644 index 00000000000..b33ba02e637 --- /dev/null +++ b/ffi/capi/bindings/cpp/icu4x/TimeZoneAndCanonicalAndNormalized.d.hpp @@ -0,0 +1,43 @@ +#ifndef icu4x_TimeZoneAndCanonicalAndNormalized_D_HPP +#define icu4x_TimeZoneAndCanonicalAndNormalized_D_HPP + +#include +#include +#include +#include +#include +#include +#include +#include "../diplomat_runtime.hpp" + +namespace icu4x { +namespace capi { struct TimeZoneInfo; } +class TimeZoneInfo; +} + + +namespace icu4x { +namespace capi { + struct TimeZoneAndCanonicalAndNormalized { + icu4x::capi::TimeZoneInfo* time_zone; + diplomat::capi::DiplomatStringView canonical; + diplomat::capi::DiplomatStringView normalized; + }; + + typedef struct TimeZoneAndCanonicalAndNormalized_option {union { TimeZoneAndCanonicalAndNormalized ok; }; bool is_ok; } TimeZoneAndCanonicalAndNormalized_option; +} // namespace capi +} // namespace + + +namespace icu4x { +struct TimeZoneAndCanonicalAndNormalized { + std::unique_ptr time_zone; + std::string_view canonical; + std::string_view normalized; + + inline icu4x::capi::TimeZoneAndCanonicalAndNormalized AsFFI() const; + inline static icu4x::TimeZoneAndCanonicalAndNormalized FromFFI(icu4x::capi::TimeZoneAndCanonicalAndNormalized c_struct); +}; + +} // namespace +#endif // icu4x_TimeZoneAndCanonicalAndNormalized_D_HPP diff --git a/ffi/capi/bindings/cpp/icu4x/TimeZoneAndCanonicalAndNormalized.hpp b/ffi/capi/bindings/cpp/icu4x/TimeZoneAndCanonicalAndNormalized.hpp new file mode 100644 index 00000000000..a20494740fa --- /dev/null +++ b/ffi/capi/bindings/cpp/icu4x/TimeZoneAndCanonicalAndNormalized.hpp @@ -0,0 +1,44 @@ +#ifndef icu4x_TimeZoneAndCanonicalAndNormalized_HPP +#define icu4x_TimeZoneAndCanonicalAndNormalized_HPP + +#include "TimeZoneAndCanonicalAndNormalized.d.hpp" + +#include +#include +#include +#include +#include +#include +#include +#include "../diplomat_runtime.hpp" +#include "TimeZoneInfo.hpp" + + +namespace icu4x { +namespace capi { + extern "C" { + + + } // extern "C" +} // namespace capi +} // namespace + + +inline icu4x::capi::TimeZoneAndCanonicalAndNormalized icu4x::TimeZoneAndCanonicalAndNormalized::AsFFI() const { + return icu4x::capi::TimeZoneAndCanonicalAndNormalized { + /* .time_zone = */ time_zone->AsFFI(), + /* .canonical = */ {canonical.data(), canonical.size()}, + /* .normalized = */ {normalized.data(), normalized.size()}, + }; +} + +inline icu4x::TimeZoneAndCanonicalAndNormalized icu4x::TimeZoneAndCanonicalAndNormalized::FromFFI(icu4x::capi::TimeZoneAndCanonicalAndNormalized c_struct) { + return icu4x::TimeZoneAndCanonicalAndNormalized { + /* .time_zone = */ std::unique_ptr(icu4x::TimeZoneInfo::FromFFI(c_struct.time_zone)), + /* .canonical = */ std::string_view(c_struct.canonical.data, c_struct.canonical.len), + /* .normalized = */ std::string_view(c_struct.normalized.data, c_struct.normalized.len), + }; +} + + +#endif // icu4x_TimeZoneAndCanonicalAndNormalized_HPP diff --git a/ffi/capi/bindings/cpp/icu4x/TimeZoneAndCanonicalAndNormalizedIterator.d.hpp b/ffi/capi/bindings/cpp/icu4x/TimeZoneAndCanonicalAndNormalizedIterator.d.hpp new file mode 100644 index 00000000000..a6c02e414ae --- /dev/null +++ b/ffi/capi/bindings/cpp/icu4x/TimeZoneAndCanonicalAndNormalizedIterator.d.hpp @@ -0,0 +1,45 @@ +#ifndef icu4x_TimeZoneAndCanonicalAndNormalizedIterator_D_HPP +#define icu4x_TimeZoneAndCanonicalAndNormalizedIterator_D_HPP + +#include +#include +#include +#include +#include +#include +#include +#include "../diplomat_runtime.hpp" + +namespace icu4x { +struct TimeZoneAndCanonicalAndNormalized; +} + + +namespace icu4x { +namespace capi { + struct TimeZoneAndCanonicalAndNormalizedIterator; +} // namespace capi +} // namespace + +namespace icu4x { +class TimeZoneAndCanonicalAndNormalizedIterator { +public: + + inline std::optional next(); + + inline const icu4x::capi::TimeZoneAndCanonicalAndNormalizedIterator* AsFFI() const; + inline icu4x::capi::TimeZoneAndCanonicalAndNormalizedIterator* AsFFI(); + inline static const icu4x::TimeZoneAndCanonicalAndNormalizedIterator* FromFFI(const icu4x::capi::TimeZoneAndCanonicalAndNormalizedIterator* ptr); + inline static icu4x::TimeZoneAndCanonicalAndNormalizedIterator* FromFFI(icu4x::capi::TimeZoneAndCanonicalAndNormalizedIterator* ptr); + inline static void operator delete(void* ptr); +private: + TimeZoneAndCanonicalAndNormalizedIterator() = delete; + TimeZoneAndCanonicalAndNormalizedIterator(const icu4x::TimeZoneAndCanonicalAndNormalizedIterator&) = delete; + TimeZoneAndCanonicalAndNormalizedIterator(icu4x::TimeZoneAndCanonicalAndNormalizedIterator&&) noexcept = delete; + TimeZoneAndCanonicalAndNormalizedIterator operator=(const icu4x::TimeZoneAndCanonicalAndNormalizedIterator&) = delete; + TimeZoneAndCanonicalAndNormalizedIterator operator=(icu4x::TimeZoneAndCanonicalAndNormalizedIterator&&) noexcept = delete; + static void operator delete[](void*, size_t) = delete; +}; + +} // namespace +#endif // icu4x_TimeZoneAndCanonicalAndNormalizedIterator_D_HPP diff --git a/ffi/capi/bindings/cpp/icu4x/TimeZoneAndCanonicalAndNormalizedIterator.hpp b/ffi/capi/bindings/cpp/icu4x/TimeZoneAndCanonicalAndNormalizedIterator.hpp new file mode 100644 index 00000000000..2a5db01f2ae --- /dev/null +++ b/ffi/capi/bindings/cpp/icu4x/TimeZoneAndCanonicalAndNormalizedIterator.hpp @@ -0,0 +1,57 @@ +#ifndef icu4x_TimeZoneAndCanonicalAndNormalizedIterator_HPP +#define icu4x_TimeZoneAndCanonicalAndNormalizedIterator_HPP + +#include "TimeZoneAndCanonicalAndNormalizedIterator.d.hpp" + +#include +#include +#include +#include +#include +#include +#include +#include "../diplomat_runtime.hpp" +#include "TimeZoneAndCanonicalAndNormalized.hpp" + + +namespace icu4x { +namespace capi { + extern "C" { + + typedef struct icu4x_TimeZoneAndCanonicalAndNormalizedIterator_next_mv1_result {union {icu4x::capi::TimeZoneAndCanonicalAndNormalized ok; }; bool is_ok;} icu4x_TimeZoneAndCanonicalAndNormalizedIterator_next_mv1_result; + icu4x_TimeZoneAndCanonicalAndNormalizedIterator_next_mv1_result icu4x_TimeZoneAndCanonicalAndNormalizedIterator_next_mv1(icu4x::capi::TimeZoneAndCanonicalAndNormalizedIterator* self); + + + void icu4x_TimeZoneAndCanonicalAndNormalizedIterator_destroy_mv1(TimeZoneAndCanonicalAndNormalizedIterator* self); + + } // extern "C" +} // namespace capi +} // namespace + +inline std::optional icu4x::TimeZoneAndCanonicalAndNormalizedIterator::next() { + auto result = icu4x::capi::icu4x_TimeZoneAndCanonicalAndNormalizedIterator_next_mv1(this->AsFFI()); + return result.is_ok ? std::optional(icu4x::TimeZoneAndCanonicalAndNormalized::FromFFI(result.ok)) : std::nullopt; +} + +inline const icu4x::capi::TimeZoneAndCanonicalAndNormalizedIterator* icu4x::TimeZoneAndCanonicalAndNormalizedIterator::AsFFI() const { + return reinterpret_cast(this); +} + +inline icu4x::capi::TimeZoneAndCanonicalAndNormalizedIterator* icu4x::TimeZoneAndCanonicalAndNormalizedIterator::AsFFI() { + return reinterpret_cast(this); +} + +inline const icu4x::TimeZoneAndCanonicalAndNormalizedIterator* icu4x::TimeZoneAndCanonicalAndNormalizedIterator::FromFFI(const icu4x::capi::TimeZoneAndCanonicalAndNormalizedIterator* ptr) { + return reinterpret_cast(ptr); +} + +inline icu4x::TimeZoneAndCanonicalAndNormalizedIterator* icu4x::TimeZoneAndCanonicalAndNormalizedIterator::FromFFI(icu4x::capi::TimeZoneAndCanonicalAndNormalizedIterator* ptr) { + return reinterpret_cast(ptr); +} + +inline void icu4x::TimeZoneAndCanonicalAndNormalizedIterator::operator delete(void* ptr) { + icu4x::capi::icu4x_TimeZoneAndCanonicalAndNormalizedIterator_destroy_mv1(reinterpret_cast(ptr)); +} + + +#endif // icu4x_TimeZoneAndCanonicalAndNormalizedIterator_HPP diff --git a/ffi/capi/bindings/cpp/icu4x/TimeZoneAndCanonicalIterator.d.hpp b/ffi/capi/bindings/cpp/icu4x/TimeZoneAndCanonicalIterator.d.hpp new file mode 100644 index 00000000000..369137e1e13 --- /dev/null +++ b/ffi/capi/bindings/cpp/icu4x/TimeZoneAndCanonicalIterator.d.hpp @@ -0,0 +1,45 @@ +#ifndef icu4x_TimeZoneAndCanonicalIterator_D_HPP +#define icu4x_TimeZoneAndCanonicalIterator_D_HPP + +#include +#include +#include +#include +#include +#include +#include +#include "../diplomat_runtime.hpp" + +namespace icu4x { +struct TimeZoneAndCanonical; +} + + +namespace icu4x { +namespace capi { + struct TimeZoneAndCanonicalIterator; +} // namespace capi +} // namespace + +namespace icu4x { +class TimeZoneAndCanonicalIterator { +public: + + inline std::optional next(); + + inline const icu4x::capi::TimeZoneAndCanonicalIterator* AsFFI() const; + inline icu4x::capi::TimeZoneAndCanonicalIterator* AsFFI(); + inline static const icu4x::TimeZoneAndCanonicalIterator* FromFFI(const icu4x::capi::TimeZoneAndCanonicalIterator* ptr); + inline static icu4x::TimeZoneAndCanonicalIterator* FromFFI(icu4x::capi::TimeZoneAndCanonicalIterator* ptr); + inline static void operator delete(void* ptr); +private: + TimeZoneAndCanonicalIterator() = delete; + TimeZoneAndCanonicalIterator(const icu4x::TimeZoneAndCanonicalIterator&) = delete; + TimeZoneAndCanonicalIterator(icu4x::TimeZoneAndCanonicalIterator&&) noexcept = delete; + TimeZoneAndCanonicalIterator operator=(const icu4x::TimeZoneAndCanonicalIterator&) = delete; + TimeZoneAndCanonicalIterator operator=(icu4x::TimeZoneAndCanonicalIterator&&) noexcept = delete; + static void operator delete[](void*, size_t) = delete; +}; + +} // namespace +#endif // icu4x_TimeZoneAndCanonicalIterator_D_HPP diff --git a/ffi/capi/bindings/cpp/icu4x/TimeZoneAndCanonicalIterator.hpp b/ffi/capi/bindings/cpp/icu4x/TimeZoneAndCanonicalIterator.hpp new file mode 100644 index 00000000000..6aa12a1f984 --- /dev/null +++ b/ffi/capi/bindings/cpp/icu4x/TimeZoneAndCanonicalIterator.hpp @@ -0,0 +1,57 @@ +#ifndef icu4x_TimeZoneAndCanonicalIterator_HPP +#define icu4x_TimeZoneAndCanonicalIterator_HPP + +#include "TimeZoneAndCanonicalIterator.d.hpp" + +#include +#include +#include +#include +#include +#include +#include +#include "../diplomat_runtime.hpp" +#include "TimeZoneAndCanonical.hpp" + + +namespace icu4x { +namespace capi { + extern "C" { + + typedef struct icu4x_TimeZoneAndCanonicalIterator_next_mv1_result {union {icu4x::capi::TimeZoneAndCanonical ok; }; bool is_ok;} icu4x_TimeZoneAndCanonicalIterator_next_mv1_result; + icu4x_TimeZoneAndCanonicalIterator_next_mv1_result icu4x_TimeZoneAndCanonicalIterator_next_mv1(icu4x::capi::TimeZoneAndCanonicalIterator* self); + + + void icu4x_TimeZoneAndCanonicalIterator_destroy_mv1(TimeZoneAndCanonicalIterator* self); + + } // extern "C" +} // namespace capi +} // namespace + +inline std::optional icu4x::TimeZoneAndCanonicalIterator::next() { + auto result = icu4x::capi::icu4x_TimeZoneAndCanonicalIterator_next_mv1(this->AsFFI()); + return result.is_ok ? std::optional(icu4x::TimeZoneAndCanonical::FromFFI(result.ok)) : std::nullopt; +} + +inline const icu4x::capi::TimeZoneAndCanonicalIterator* icu4x::TimeZoneAndCanonicalIterator::AsFFI() const { + return reinterpret_cast(this); +} + +inline icu4x::capi::TimeZoneAndCanonicalIterator* icu4x::TimeZoneAndCanonicalIterator::AsFFI() { + return reinterpret_cast(this); +} + +inline const icu4x::TimeZoneAndCanonicalIterator* icu4x::TimeZoneAndCanonicalIterator::FromFFI(const icu4x::capi::TimeZoneAndCanonicalIterator* ptr) { + return reinterpret_cast(ptr); +} + +inline icu4x::TimeZoneAndCanonicalIterator* icu4x::TimeZoneAndCanonicalIterator::FromFFI(icu4x::capi::TimeZoneAndCanonicalIterator* ptr) { + return reinterpret_cast(ptr); +} + +inline void icu4x::TimeZoneAndCanonicalIterator::operator delete(void* ptr) { + icu4x::capi::icu4x_TimeZoneAndCanonicalIterator_destroy_mv1(reinterpret_cast(ptr)); +} + + +#endif // icu4x_TimeZoneAndCanonicalIterator_HPP diff --git a/ffi/capi/bindings/cpp/icu4x/TimeZoneIterator.d.hpp b/ffi/capi/bindings/cpp/icu4x/TimeZoneIterator.d.hpp new file mode 100644 index 00000000000..2e90cad0a10 --- /dev/null +++ b/ffi/capi/bindings/cpp/icu4x/TimeZoneIterator.d.hpp @@ -0,0 +1,46 @@ +#ifndef icu4x_TimeZoneIterator_D_HPP +#define icu4x_TimeZoneIterator_D_HPP + +#include +#include +#include +#include +#include +#include +#include +#include "../diplomat_runtime.hpp" + +namespace icu4x { +namespace capi { struct TimeZoneInfo; } +class TimeZoneInfo; +} + + +namespace icu4x { +namespace capi { + struct TimeZoneIterator; +} // namespace capi +} // namespace + +namespace icu4x { +class TimeZoneIterator { +public: + + inline std::unique_ptr next(); + + inline const icu4x::capi::TimeZoneIterator* AsFFI() const; + inline icu4x::capi::TimeZoneIterator* AsFFI(); + inline static const icu4x::TimeZoneIterator* FromFFI(const icu4x::capi::TimeZoneIterator* ptr); + inline static icu4x::TimeZoneIterator* FromFFI(icu4x::capi::TimeZoneIterator* ptr); + inline static void operator delete(void* ptr); +private: + TimeZoneIterator() = delete; + TimeZoneIterator(const icu4x::TimeZoneIterator&) = delete; + TimeZoneIterator(icu4x::TimeZoneIterator&&) noexcept = delete; + TimeZoneIterator operator=(const icu4x::TimeZoneIterator&) = delete; + TimeZoneIterator operator=(icu4x::TimeZoneIterator&&) noexcept = delete; + static void operator delete[](void*, size_t) = delete; +}; + +} // namespace +#endif // icu4x_TimeZoneIterator_D_HPP diff --git a/ffi/capi/bindings/cpp/icu4x/TimeZoneIterator.hpp b/ffi/capi/bindings/cpp/icu4x/TimeZoneIterator.hpp new file mode 100644 index 00000000000..846c092a4e9 --- /dev/null +++ b/ffi/capi/bindings/cpp/icu4x/TimeZoneIterator.hpp @@ -0,0 +1,56 @@ +#ifndef icu4x_TimeZoneIterator_HPP +#define icu4x_TimeZoneIterator_HPP + +#include "TimeZoneIterator.d.hpp" + +#include +#include +#include +#include +#include +#include +#include +#include "../diplomat_runtime.hpp" +#include "TimeZoneInfo.hpp" + + +namespace icu4x { +namespace capi { + extern "C" { + + icu4x::capi::TimeZoneInfo* icu4x_TimeZoneIterator_next_mv1(icu4x::capi::TimeZoneIterator* self); + + + void icu4x_TimeZoneIterator_destroy_mv1(TimeZoneIterator* self); + + } // extern "C" +} // namespace capi +} // namespace + +inline std::unique_ptr icu4x::TimeZoneIterator::next() { + auto result = icu4x::capi::icu4x_TimeZoneIterator_next_mv1(this->AsFFI()); + return std::unique_ptr(icu4x::TimeZoneInfo::FromFFI(result)); +} + +inline const icu4x::capi::TimeZoneIterator* icu4x::TimeZoneIterator::AsFFI() const { + return reinterpret_cast(this); +} + +inline icu4x::capi::TimeZoneIterator* icu4x::TimeZoneIterator::AsFFI() { + return reinterpret_cast(this); +} + +inline const icu4x::TimeZoneIterator* icu4x::TimeZoneIterator::FromFFI(const icu4x::capi::TimeZoneIterator* ptr) { + return reinterpret_cast(ptr); +} + +inline icu4x::TimeZoneIterator* icu4x::TimeZoneIterator::FromFFI(icu4x::capi::TimeZoneIterator* ptr) { + return reinterpret_cast(ptr); +} + +inline void icu4x::TimeZoneIterator::operator delete(void* ptr) { + icu4x::capi::icu4x_TimeZoneIterator_destroy_mv1(reinterpret_cast(ptr)); +} + + +#endif // icu4x_TimeZoneIterator_HPP diff --git a/ffi/capi/bindings/dart/IanaParser.g.dart b/ffi/capi/bindings/dart/IanaParser.g.dart index b4c2adf6df0..7a30ae1f689 100644 --- a/ffi/capi/bindings/dart/IanaParser.g.dart +++ b/ffi/capi/bindings/dart/IanaParser.g.dart @@ -54,6 +54,14 @@ final class IanaParser implements ffi.Finalizable { final result = _icu4x_IanaParser_parse_mv1(_ffi, value._utf8AllocIn(temp.arena)); return TimeZoneInfo._fromFfi(result, []); } + + /// See the [Rust documentation for `iter`](https://docs.rs/icu/latest/icu/time/zone/iana/struct.IanaParserBorrowed.html#method.iter) for more information. + TimeZoneIterator iter() { + // This lifetime edge depends on lifetimes: 'a + core.List aEdges = [this]; + final result = _icu4x_IanaParser_iter_mv1(_ffi); + return TimeZoneIterator._fromFfi(result, [], aEdges); + } } @meta.RecordUse() @@ -75,3 +83,8 @@ external _ResultOpaqueInt32 _icu4x_IanaParser_create_with_provider_mv1(ffi.Point @ffi.Native Function(ffi.Pointer, _SliceUtf8)>(isLeaf: true, symbol: 'icu4x_IanaParser_parse_mv1') // ignore: non_constant_identifier_names external ffi.Pointer _icu4x_IanaParser_parse_mv1(ffi.Pointer self, _SliceUtf8 value); + +@meta.RecordUse() +@ffi.Native Function(ffi.Pointer)>(isLeaf: true, symbol: 'icu4x_IanaParser_iter_mv1') +// ignore: non_constant_identifier_names +external ffi.Pointer _icu4x_IanaParser_iter_mv1(ffi.Pointer self); diff --git a/ffi/capi/bindings/dart/IanaParserExtended.g.dart b/ffi/capi/bindings/dart/IanaParserExtended.g.dart new file mode 100644 index 00000000000..659c5061a90 --- /dev/null +++ b/ffi/capi/bindings/dart/IanaParserExtended.g.dart @@ -0,0 +1,105 @@ +// generated by diplomat-tool + +part of 'lib.g.dart'; + +/// A mapper between IANA time zone identifiers and BCP-47 time zone identifiers. +/// +/// This mapper supports two-way mapping, but it is optimized for the case of IANA to BCP-47. +/// It also supports normalizing and canonicalizing the IANA strings. +/// +/// See the [Rust documentation for `IanaParserExtended`](https://docs.rs/icu/latest/icu/time/zone/iana/struct.IanaParserExtended.html) for more information. +final class IanaParserExtended implements ffi.Finalizable { + final ffi.Pointer _ffi; + + // These are "used" in the sense that they keep dependencies alive + // ignore: unused_field + final core.List _selfEdge; + + // This takes in a list of lifetime edges (including for &self borrows) + // corresponding to data this may borrow from. These should be flat arrays containing + // references to objects, and this object will hold on to them to keep them alive and + // maintain borrow validity. + IanaParserExtended._fromFfi(this._ffi, this._selfEdge) { + if (_selfEdge.isEmpty) { + _finalizer.attach(this, _ffi.cast()); + } + } + + static final _finalizer = ffi.NativeFinalizer(ffi.Native.addressOf(_icu4x_IanaParserExtended_destroy_mv1)); + + /// Create a new [`IanaParserExtended`] using compiled data + /// + /// See the [Rust documentation for `new`](https://docs.rs/icu/latest/icu/time/zone/iana/struct.IanaParserExtended.html#method.new) for more information. + factory IanaParserExtended() { + final result = _icu4x_IanaParserExtended_create_mv1(); + return IanaParserExtended._fromFfi(result, []); + } + + /// Create a new [`IanaParserExtended`] using a particular data source + /// + /// See the [Rust documentation for `new`](https://docs.rs/icu/latest/icu/time/zone/iana/struct.IanaParserExtended.html#method.new) for more information. + /// + /// Throws [DataError] on failure. + factory IanaParserExtended.withProvider(DataProvider provider) { + final result = _icu4x_IanaParserExtended_create_with_provider_mv1(provider._ffi); + if (!result.isOk) { + throw DataError.values[result.union.err]; + } + return IanaParserExtended._fromFfi(result.union.ok, []); + } + + /// See the [Rust documentation for `parse`](https://docs.rs/icu/latest/icu/time/zone/iana/struct.IanaParserExtendedBorrowed.html#method.parse) for more information. + TimeZoneAndCanonicalAndNormalized parse(String value) { + final temp = _FinalizedArena(); + // This lifetime edge depends on lifetimes: 'a + core.List aEdges = [this]; + final result = _icu4x_IanaParserExtended_parse_mv1(_ffi, value._utf8AllocIn(temp.arena)); + return TimeZoneAndCanonicalAndNormalized._fromFfi(result, aEdges); + } + + /// See the [Rust documentation for `iter`](https://docs.rs/icu/latest/icu/time/zone/iana/struct.IanaParserExtendedBorrowed.html#method.iter) for more information. + TimeZoneAndCanonicalIterator iter() { + // This lifetime edge depends on lifetimes: 'a + core.List aEdges = [this]; + final result = _icu4x_IanaParserExtended_iter_mv1(_ffi); + return TimeZoneAndCanonicalIterator._fromFfi(result, [], aEdges); + } + + /// See the [Rust documentation for `iter_all`](https://docs.rs/icu/latest/icu/time/zone/iana/struct.IanaParserExtendedBorrowed.html#method.iter_all) for more information. + TimeZoneAndCanonicalAndNormalizedIterator iterAll() { + // This lifetime edge depends on lifetimes: 'a + core.List aEdges = [this]; + final result = _icu4x_IanaParserExtended_iter_all_mv1(_ffi); + return TimeZoneAndCanonicalAndNormalizedIterator._fromFfi(result, [], aEdges); + } +} + +@meta.RecordUse() +@ffi.Native)>(isLeaf: true, symbol: 'icu4x_IanaParserExtended_destroy_mv1') +// ignore: non_constant_identifier_names +external void _icu4x_IanaParserExtended_destroy_mv1(ffi.Pointer self); + +@meta.RecordUse() +@ffi.Native Function()>(isLeaf: true, symbol: 'icu4x_IanaParserExtended_create_mv1') +// ignore: non_constant_identifier_names +external ffi.Pointer _icu4x_IanaParserExtended_create_mv1(); + +@meta.RecordUse() +@ffi.Native<_ResultOpaqueInt32 Function(ffi.Pointer)>(isLeaf: true, symbol: 'icu4x_IanaParserExtended_create_with_provider_mv1') +// ignore: non_constant_identifier_names +external _ResultOpaqueInt32 _icu4x_IanaParserExtended_create_with_provider_mv1(ffi.Pointer provider); + +@meta.RecordUse() +@ffi.Native<_TimeZoneAndCanonicalAndNormalizedFfi Function(ffi.Pointer, _SliceUtf8)>(isLeaf: true, symbol: 'icu4x_IanaParserExtended_parse_mv1') +// ignore: non_constant_identifier_names +external _TimeZoneAndCanonicalAndNormalizedFfi _icu4x_IanaParserExtended_parse_mv1(ffi.Pointer self, _SliceUtf8 value); + +@meta.RecordUse() +@ffi.Native Function(ffi.Pointer)>(isLeaf: true, symbol: 'icu4x_IanaParserExtended_iter_mv1') +// ignore: non_constant_identifier_names +external ffi.Pointer _icu4x_IanaParserExtended_iter_mv1(ffi.Pointer self); + +@meta.RecordUse() +@ffi.Native Function(ffi.Pointer)>(isLeaf: true, symbol: 'icu4x_IanaParserExtended_iter_all_mv1') +// ignore: non_constant_identifier_names +external ffi.Pointer _icu4x_IanaParserExtended_iter_all_mv1(ffi.Pointer self); diff --git a/ffi/capi/bindings/dart/TimeZoneAndCanonical.g.dart b/ffi/capi/bindings/dart/TimeZoneAndCanonical.g.dart new file mode 100644 index 00000000000..0a576f4d591 --- /dev/null +++ b/ffi/capi/bindings/dart/TimeZoneAndCanonical.g.dart @@ -0,0 +1,50 @@ +// generated by diplomat-tool + +part of 'lib.g.dart'; + +final class _TimeZoneAndCanonicalFfi extends ffi.Struct { + external ffi.Pointer timeZone; + external _SliceUtf8 canonical; +} + +final class TimeZoneAndCanonical { + final TimeZoneInfo timeZone; + final String canonical; + + // ignore: unused_element + TimeZoneAndCanonical._fromFfi(_TimeZoneAndCanonicalFfi ffi, core.List aEdges) : + timeZone = TimeZoneInfo._fromFfi(ffi.timeZone, []), + canonical = ffi.canonical._toDart(aEdges); + + // If this struct contains any slices, their lifetime-edge-relevant objects (typically _FinalizedArenas) will only + // be constructed here, and can be appended to any relevant lifetime arrays here. AppendArray accepts a list + // of arrays for each lifetime to do so. It accepts multiple lists per lifetime in case the caller needs to tie a lifetime to multiple + // output arrays. Null is equivalent to an empty list: this lifetime is not being borrowed from. + // ignore: unused_element + _TimeZoneAndCanonicalFfi _toFfi(ffi.Allocator temp, {core.List> aAppendArray = const []}) { + final struct = ffi.Struct.create<_TimeZoneAndCanonicalFfi>(); + struct.timeZone = timeZone._ffi; + struct.canonical = canonical._utf8AllocIn(aAppendArray.isNotEmpty ? _FinalizedArena.withLifetime(aAppendArray).arena : temp); + return struct; + } + + @override + bool operator ==(Object other) => + other is TimeZoneAndCanonical && + other.timeZone == timeZone && + other.canonical == canonical; + + @override + int get hashCode => Object.hashAll([ + timeZone, + canonical, + ]); + + // Return all fields corresponding to lifetime `'a` + // without handling lifetime dependencies (this is the job of the caller) + // This is all fields that may be borrowed from if borrowing `'a`, + // assuming that there are no `'other: a`. bounds. In case of such bounds, + // the caller should take care to also call _fieldsForLifetimeOther + // ignore: unused_element + core.List get _fieldsForLifetimeA => [canonical]; +} diff --git a/ffi/capi/bindings/dart/TimeZoneAndCanonicalAndNormalized.g.dart b/ffi/capi/bindings/dart/TimeZoneAndCanonicalAndNormalized.g.dart new file mode 100644 index 00000000000..9996082b286 --- /dev/null +++ b/ffi/capi/bindings/dart/TimeZoneAndCanonicalAndNormalized.g.dart @@ -0,0 +1,56 @@ +// generated by diplomat-tool + +part of 'lib.g.dart'; + +final class _TimeZoneAndCanonicalAndNormalizedFfi extends ffi.Struct { + external ffi.Pointer timeZone; + external _SliceUtf8 canonical; + external _SliceUtf8 normalized; +} + +final class TimeZoneAndCanonicalAndNormalized { + final TimeZoneInfo timeZone; + final String canonical; + final String normalized; + + // ignore: unused_element + TimeZoneAndCanonicalAndNormalized._fromFfi(_TimeZoneAndCanonicalAndNormalizedFfi ffi, core.List aEdges) : + timeZone = TimeZoneInfo._fromFfi(ffi.timeZone, []), + canonical = ffi.canonical._toDart(aEdges), + normalized = ffi.normalized._toDart(aEdges); + + // If this struct contains any slices, their lifetime-edge-relevant objects (typically _FinalizedArenas) will only + // be constructed here, and can be appended to any relevant lifetime arrays here. AppendArray accepts a list + // of arrays for each lifetime to do so. It accepts multiple lists per lifetime in case the caller needs to tie a lifetime to multiple + // output arrays. Null is equivalent to an empty list: this lifetime is not being borrowed from. + // ignore: unused_element + _TimeZoneAndCanonicalAndNormalizedFfi _toFfi(ffi.Allocator temp, {core.List> aAppendArray = const []}) { + final struct = ffi.Struct.create<_TimeZoneAndCanonicalAndNormalizedFfi>(); + struct.timeZone = timeZone._ffi; + struct.canonical = canonical._utf8AllocIn(aAppendArray.isNotEmpty ? _FinalizedArena.withLifetime(aAppendArray).arena : temp); + struct.normalized = normalized._utf8AllocIn(aAppendArray.isNotEmpty ? _FinalizedArena.withLifetime(aAppendArray).arena : temp); + return struct; + } + + @override + bool operator ==(Object other) => + other is TimeZoneAndCanonicalAndNormalized && + other.timeZone == timeZone && + other.canonical == canonical && + other.normalized == normalized; + + @override + int get hashCode => Object.hashAll([ + timeZone, + canonical, + normalized, + ]); + + // Return all fields corresponding to lifetime `'a` + // without handling lifetime dependencies (this is the job of the caller) + // This is all fields that may be borrowed from if borrowing `'a`, + // assuming that there are no `'other: a`. bounds. In case of such bounds, + // the caller should take care to also call _fieldsForLifetimeOther + // ignore: unused_element + core.List get _fieldsForLifetimeA => [canonical, normalized]; +} diff --git a/ffi/capi/bindings/dart/TimeZoneAndCanonicalAndNormalizedIterator.g.dart b/ffi/capi/bindings/dart/TimeZoneAndCanonicalAndNormalizedIterator.g.dart new file mode 100644 index 00000000000..50172ba9f60 --- /dev/null +++ b/ffi/capi/bindings/dart/TimeZoneAndCanonicalAndNormalizedIterator.g.dart @@ -0,0 +1,56 @@ +// generated by diplomat-tool + +part of 'lib.g.dart'; + +/// See the [Rust documentation for `TimeZoneAndCanonicalAndNormalizedIter`](https://docs.rs/icu/latest/icu/time/zone/iana/struct.TimeZoneAndCanonicalAndNormalizedIter.html) for more information. +final class TimeZoneAndCanonicalAndNormalizedIterator implements ffi.Finalizable, core.Iterator { + final ffi.Pointer _ffi; + + // These are "used" in the sense that they keep dependencies alive + // ignore: unused_field + final core.List _selfEdge; + // ignore: unused_field + final core.List _aEdge; + + // This takes in a list of lifetime edges (including for &self borrows) + // corresponding to data this may borrow from. These should be flat arrays containing + // references to objects, and this object will hold on to them to keep them alive and + // maintain borrow validity. + TimeZoneAndCanonicalAndNormalizedIterator._fromFfi(this._ffi, this._selfEdge, this._aEdge) { + if (_selfEdge.isEmpty) { + _finalizer.attach(this, _ffi.cast()); + } + } + + static final _finalizer = ffi.NativeFinalizer(ffi.Native.addressOf(_icu4x_TimeZoneAndCanonicalAndNormalizedIterator_destroy_mv1)); + + TimeZoneAndCanonicalAndNormalized? _current; + + TimeZoneAndCanonicalAndNormalized get current => _current!; + + bool moveNext() { + _current = _iteratorNext(); + return _current != null; + } + + /// See the [Rust documentation for `next`](https://docs.rs/icu/latest/icu/time/zone/iana/struct.TimeZoneAndCanonicalAndNormalizedIter.html#method.next) for more information. + TimeZoneAndCanonicalAndNormalized? _iteratorNext() { + // This lifetime edge depends on lifetimes: 'a + core.List aEdges = [this]; + final result = _icu4x_TimeZoneAndCanonicalAndNormalizedIterator_next_mv1(_ffi); + if (!result.isOk) { + return null; + } + return TimeZoneAndCanonicalAndNormalized._fromFfi(result.union.ok, aEdges); + } +} + +@meta.RecordUse() +@ffi.Native)>(isLeaf: true, symbol: 'icu4x_TimeZoneAndCanonicalAndNormalizedIterator_destroy_mv1') +// ignore: non_constant_identifier_names +external void _icu4x_TimeZoneAndCanonicalAndNormalizedIterator_destroy_mv1(ffi.Pointer self); + +@meta.RecordUse() +@ffi.Native<_ResultTimeZoneAndCanonicalAndNormalizedFfiVoid Function(ffi.Pointer)>(isLeaf: true, symbol: 'icu4x_TimeZoneAndCanonicalAndNormalizedIterator_next_mv1') +// ignore: non_constant_identifier_names +external _ResultTimeZoneAndCanonicalAndNormalizedFfiVoid _icu4x_TimeZoneAndCanonicalAndNormalizedIterator_next_mv1(ffi.Pointer self); diff --git a/ffi/capi/bindings/dart/TimeZoneAndCanonicalIterator.g.dart b/ffi/capi/bindings/dart/TimeZoneAndCanonicalIterator.g.dart new file mode 100644 index 00000000000..3b42d29798c --- /dev/null +++ b/ffi/capi/bindings/dart/TimeZoneAndCanonicalIterator.g.dart @@ -0,0 +1,56 @@ +// generated by diplomat-tool + +part of 'lib.g.dart'; + +/// See the [Rust documentation for `TimeZoneAndCanonicalIter`](https://docs.rs/icu/latest/icu/time/zone/iana/struct.TimeZoneAndCanonicalIter.html) for more information. +final class TimeZoneAndCanonicalIterator implements ffi.Finalizable, core.Iterator { + final ffi.Pointer _ffi; + + // These are "used" in the sense that they keep dependencies alive + // ignore: unused_field + final core.List _selfEdge; + // ignore: unused_field + final core.List _aEdge; + + // This takes in a list of lifetime edges (including for &self borrows) + // corresponding to data this may borrow from. These should be flat arrays containing + // references to objects, and this object will hold on to them to keep them alive and + // maintain borrow validity. + TimeZoneAndCanonicalIterator._fromFfi(this._ffi, this._selfEdge, this._aEdge) { + if (_selfEdge.isEmpty) { + _finalizer.attach(this, _ffi.cast()); + } + } + + static final _finalizer = ffi.NativeFinalizer(ffi.Native.addressOf(_icu4x_TimeZoneAndCanonicalIterator_destroy_mv1)); + + TimeZoneAndCanonical? _current; + + TimeZoneAndCanonical get current => _current!; + + bool moveNext() { + _current = _iteratorNext(); + return _current != null; + } + + /// See the [Rust documentation for `next`](https://docs.rs/icu/latest/icu/time/zone/iana/struct.TimeZoneAndCanonicalIter.html#method.next) for more information. + TimeZoneAndCanonical? _iteratorNext() { + // This lifetime edge depends on lifetimes: 'a + core.List aEdges = [this]; + final result = _icu4x_TimeZoneAndCanonicalIterator_next_mv1(_ffi); + if (!result.isOk) { + return null; + } + return TimeZoneAndCanonical._fromFfi(result.union.ok, aEdges); + } +} + +@meta.RecordUse() +@ffi.Native)>(isLeaf: true, symbol: 'icu4x_TimeZoneAndCanonicalIterator_destroy_mv1') +// ignore: non_constant_identifier_names +external void _icu4x_TimeZoneAndCanonicalIterator_destroy_mv1(ffi.Pointer self); + +@meta.RecordUse() +@ffi.Native<_ResultTimeZoneAndCanonicalFfiVoid Function(ffi.Pointer)>(isLeaf: true, symbol: 'icu4x_TimeZoneAndCanonicalIterator_next_mv1') +// ignore: non_constant_identifier_names +external _ResultTimeZoneAndCanonicalFfiVoid _icu4x_TimeZoneAndCanonicalIterator_next_mv1(ffi.Pointer self); diff --git a/ffi/capi/bindings/dart/TimeZoneIterator.g.dart b/ffi/capi/bindings/dart/TimeZoneIterator.g.dart new file mode 100644 index 00000000000..7ee449464e3 --- /dev/null +++ b/ffi/capi/bindings/dart/TimeZoneIterator.g.dart @@ -0,0 +1,51 @@ +// generated by diplomat-tool + +part of 'lib.g.dart'; + +/// See the [Rust documentation for `TimeZoneIter`](https://docs.rs/icu/latest/icu/time/zone/iana/struct.TimeZoneIter.html) for more information. +final class TimeZoneIterator implements ffi.Finalizable, core.Iterator { + final ffi.Pointer _ffi; + + // These are "used" in the sense that they keep dependencies alive + // ignore: unused_field + final core.List _selfEdge; + // ignore: unused_field + final core.List _aEdge; + + // This takes in a list of lifetime edges (including for &self borrows) + // corresponding to data this may borrow from. These should be flat arrays containing + // references to objects, and this object will hold on to them to keep them alive and + // maintain borrow validity. + TimeZoneIterator._fromFfi(this._ffi, this._selfEdge, this._aEdge) { + if (_selfEdge.isEmpty) { + _finalizer.attach(this, _ffi.cast()); + } + } + + static final _finalizer = ffi.NativeFinalizer(ffi.Native.addressOf(_icu4x_TimeZoneIterator_destroy_mv1)); + + TimeZoneInfo? _current; + + TimeZoneInfo get current => _current!; + + bool moveNext() { + _current = _iteratorNext(); + return _current != null; + } + + /// See the [Rust documentation for `next`](https://docs.rs/icu/latest/icu/time/zone/iana/struct.TimeZoneIter.html#method.next) for more information. + TimeZoneInfo? _iteratorNext() { + final result = _icu4x_TimeZoneIterator_next_mv1(_ffi); + return result.address == 0 ? null : TimeZoneInfo._fromFfi(result, []); + } +} + +@meta.RecordUse() +@ffi.Native)>(isLeaf: true, symbol: 'icu4x_TimeZoneIterator_destroy_mv1') +// ignore: non_constant_identifier_names +external void _icu4x_TimeZoneIterator_destroy_mv1(ffi.Pointer self); + +@meta.RecordUse() +@ffi.Native Function(ffi.Pointer)>(isLeaf: true, symbol: 'icu4x_TimeZoneIterator_next_mv1') +// ignore: non_constant_identifier_names +external ffi.Pointer _icu4x_TimeZoneIterator_next_mv1(ffi.Pointer self); diff --git a/ffi/capi/bindings/dart/lib.g.dart b/ffi/capi/bindings/dart/lib.g.dart index 152f8eeab79..ae4c35fc33f 100644 --- a/ffi/capi/bindings/dart/lib.g.dart +++ b/ffi/capi/bindings/dart/lib.g.dart @@ -83,6 +83,7 @@ part 'GregorianDateFormatter.g.dart'; part 'GregorianZonedDateTimeFormatter.g.dart'; part 'HangulSyllableType.g.dart'; part 'IanaParser.g.dart'; +part 'IanaParserExtended.g.dart'; part 'IndicSyllabicCategory.g.dart'; part 'IsoDate.g.dart'; part 'IsoDateTime.g.dart'; @@ -134,8 +135,13 @@ part 'SentenceSegmenter.g.dart'; part 'Time.g.dart'; part 'TimeFormatter.g.dart'; part 'TimePrecision.g.dart'; +part 'TimeZoneAndCanonical.g.dart'; +part 'TimeZoneAndCanonicalAndNormalized.g.dart'; +part 'TimeZoneAndCanonicalAndNormalizedIterator.g.dart'; +part 'TimeZoneAndCanonicalIterator.g.dart'; part 'TimeZoneInfo.g.dart'; part 'TimeZoneInvalidOffsetError.g.dart'; +part 'TimeZoneIterator.g.dart'; part 'TitlecaseMapper.g.dart'; part 'TitlecaseOptions.g.dart'; part 'TrailingCase.g.dart'; @@ -435,6 +441,56 @@ final class _ResultOpaqueInt32 extends ffi.Struct { } } +final class _ResultTimeZoneAndCanonicalAndNormalizedFfiVoidUnion extends ffi.Union { + external _TimeZoneAndCanonicalAndNormalizedFfi ok; + +} + +final class _ResultTimeZoneAndCanonicalAndNormalizedFfiVoid extends ffi.Struct { + external _ResultTimeZoneAndCanonicalAndNormalizedFfiVoidUnion union; + + @ffi.Bool() + external bool isOk; + + + factory _ResultTimeZoneAndCanonicalAndNormalizedFfiVoid.ok(_TimeZoneAndCanonicalAndNormalizedFfi val) { + final struct = ffi.Struct.create<_ResultTimeZoneAndCanonicalAndNormalizedFfiVoid>(); + struct.isOk = true; + struct.union.ok = val; + return struct; + } + factory _ResultTimeZoneAndCanonicalAndNormalizedFfiVoid.err() { + final struct = ffi.Struct.create<_ResultTimeZoneAndCanonicalAndNormalizedFfiVoid>(); + struct.isOk = false; + return struct; + } +} + +final class _ResultTimeZoneAndCanonicalFfiVoidUnion extends ffi.Union { + external _TimeZoneAndCanonicalFfi ok; + +} + +final class _ResultTimeZoneAndCanonicalFfiVoid extends ffi.Struct { + external _ResultTimeZoneAndCanonicalFfiVoidUnion union; + + @ffi.Bool() + external bool isOk; + + + factory _ResultTimeZoneAndCanonicalFfiVoid.ok(_TimeZoneAndCanonicalFfi val) { + final struct = ffi.Struct.create<_ResultTimeZoneAndCanonicalFfiVoid>(); + struct.isOk = true; + struct.union.ok = val; + return struct; + } + factory _ResultTimeZoneAndCanonicalFfiVoid.err() { + final struct = ffi.Struct.create<_ResultTimeZoneAndCanonicalFfiVoid>(); + struct.isOk = false; + return struct; + } +} + final class _ResultUint16VoidUnion extends ffi.Union { @ffi.Uint16() external int ok; diff --git a/ffi/capi/bindings/js/IanaParser.d.ts b/ffi/capi/bindings/js/IanaParser.d.ts index 524961b9306..e72cd2a1223 100644 --- a/ffi/capi/bindings/js/IanaParser.d.ts +++ b/ffi/capi/bindings/js/IanaParser.d.ts @@ -2,6 +2,7 @@ import type { DataError } from "./DataError" import type { DataProvider } from "./DataProvider" import type { TimeZoneInfo } from "./TimeZoneInfo" +import type { TimeZoneIterator } from "./TimeZoneIterator" import type { pointer, codepoint } from "./diplomat-runtime.d.ts"; @@ -22,5 +23,7 @@ export class IanaParser { parse(value: string): TimeZoneInfo; + iter(): TimeZoneIterator; + constructor(); } \ No newline at end of file diff --git a/ffi/capi/bindings/js/IanaParser.mjs b/ffi/capi/bindings/js/IanaParser.mjs index e482b216a0f..06aad07d584 100644 --- a/ffi/capi/bindings/js/IanaParser.mjs +++ b/ffi/capi/bindings/js/IanaParser.mjs @@ -2,6 +2,7 @@ import { DataError } from "./DataError.mjs" import { DataProvider } from "./DataProvider.mjs" import { TimeZoneInfo } from "./TimeZoneInfo.mjs" +import { TimeZoneIterator } from "./TimeZoneIterator.mjs" import wasm from "./diplomat-wasm.mjs"; import * as diplomatRuntime from "./diplomat-runtime.mjs"; @@ -90,6 +91,19 @@ export class IanaParser { } } + iter() { + // This lifetime edge depends on lifetimes 'a + let aEdges = [this]; + + const result = wasm.icu4x_IanaParser_iter_mv1(this.ffiValue); + + try { + return new TimeZoneIterator(diplomatRuntime.internalConstructor, result, [], aEdges); + } + + finally {} + } + constructor() { if (arguments[0] === diplomatRuntime.exposeConstructor) { return this.#internalConstructor(...Array.prototype.slice.call(arguments, 1)); diff --git a/ffi/capi/bindings/js/IanaParserExtended.d.ts b/ffi/capi/bindings/js/IanaParserExtended.d.ts new file mode 100644 index 00000000000..2c0735db728 --- /dev/null +++ b/ffi/capi/bindings/js/IanaParserExtended.d.ts @@ -0,0 +1,32 @@ +// generated by diplomat-tool +import type { DataError } from "./DataError" +import type { DataProvider } from "./DataProvider" +import type { TimeZoneAndCanonicalAndNormalized } from "./TimeZoneAndCanonicalAndNormalized" +import type { TimeZoneAndCanonicalAndNormalizedIterator } from "./TimeZoneAndCanonicalAndNormalizedIterator" +import type { TimeZoneAndCanonicalIterator } from "./TimeZoneAndCanonicalIterator" +import type { pointer, codepoint } from "./diplomat-runtime.d.ts"; + + +/** A mapper between IANA time zone identifiers and BCP-47 time zone identifiers. +* +*This mapper supports two-way mapping, but it is optimized for the case of IANA to BCP-47. +*It also supports normalizing and canonicalizing the IANA strings. +* +*See the [Rust documentation for `IanaParserExtended`](https://docs.rs/icu/latest/icu/time/zone/iana/struct.IanaParserExtended.html) for more information. +*/ + + +export class IanaParserExtended { + + get ffiValue(): pointer; + + static createWithProvider(provider: DataProvider): IanaParserExtended; + + parse(value: string): TimeZoneAndCanonicalAndNormalized; + + iter(): TimeZoneAndCanonicalIterator; + + iterAll(): TimeZoneAndCanonicalAndNormalizedIterator; + + constructor(); +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/IanaParserExtended.mjs b/ffi/capi/bindings/js/IanaParserExtended.mjs new file mode 100644 index 00000000000..6ccb891c19a --- /dev/null +++ b/ffi/capi/bindings/js/IanaParserExtended.mjs @@ -0,0 +1,137 @@ +// generated by diplomat-tool +import { DataError } from "./DataError.mjs" +import { DataProvider } from "./DataProvider.mjs" +import { TimeZoneAndCanonicalAndNormalized } from "./TimeZoneAndCanonicalAndNormalized.mjs" +import { TimeZoneAndCanonicalAndNormalizedIterator } from "./TimeZoneAndCanonicalAndNormalizedIterator.mjs" +import { TimeZoneAndCanonicalIterator } from "./TimeZoneAndCanonicalIterator.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + + +/** A mapper between IANA time zone identifiers and BCP-47 time zone identifiers. +* +*This mapper supports two-way mapping, but it is optimized for the case of IANA to BCP-47. +*It also supports normalizing and canonicalizing the IANA strings. +* +*See the [Rust documentation for `IanaParserExtended`](https://docs.rs/icu/latest/icu/time/zone/iana/struct.IanaParserExtended.html) for more information. +*/ +const IanaParserExtended_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.icu4x_IanaParserExtended_destroy_mv1(ptr); +}); + +export class IanaParserExtended { + + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + + #internalConstructor(symbol, ptr, selfEdge) { + if (symbol !== diplomatRuntime.internalConstructor) { + console.error("IanaParserExtended is an Opaque type. You cannot call its constructor."); + return; + } + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + + // Are we being borrowed? If not, we can register. + if (this.#selfEdge.length === 0) { + IanaParserExtended_box_destroy_registry.register(this, this.#ptr); + } + + return this; + } + get ffiValue() { + return this.#ptr; + } + + #defaultConstructor() { + const result = wasm.icu4x_IanaParserExtended_create_mv1(); + + try { + return new IanaParserExtended(diplomatRuntime.internalConstructor, result, []); + } + + finally {} + } + + static createWithProvider(provider) { + const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); + + const result = wasm.icu4x_IanaParserExtended_create_with_provider_mv1(diplomatReceive.buffer, provider.ffiValue); + + try { + if (!diplomatReceive.resultFlag) { + const cause = new DataError(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); + throw new globalThis.Error('DataError: ' + cause.value, { cause }); + } + return new IanaParserExtended(diplomatRuntime.internalConstructor, diplomatRuntime.ptrRead(wasm, diplomatReceive.buffer), []); + } + + finally { + diplomatReceive.free(); + } + } + + parse(value) { + let functionCleanupArena = new diplomatRuntime.CleanupArena(); + + const valueSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, value)); + + const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 20, 4, false); + + // This lifetime edge depends on lifetimes 'a + let aEdges = [this]; + + const result = wasm.icu4x_IanaParserExtended_parse_mv1(diplomatReceive.buffer, this.ffiValue, ...valueSlice.splat()); + + try { + return TimeZoneAndCanonicalAndNormalized._fromFFI(diplomatRuntime.internalConstructor, diplomatReceive.buffer, aEdges); + } + + finally { + functionCleanupArena.free(); + + diplomatReceive.free(); + } + } + + iter() { + // This lifetime edge depends on lifetimes 'a + let aEdges = [this]; + + const result = wasm.icu4x_IanaParserExtended_iter_mv1(this.ffiValue); + + try { + return new TimeZoneAndCanonicalIterator(diplomatRuntime.internalConstructor, result, [], aEdges); + } + + finally {} + } + + iterAll() { + // This lifetime edge depends on lifetimes 'a + let aEdges = [this]; + + const result = wasm.icu4x_IanaParserExtended_iter_all_mv1(this.ffiValue); + + try { + return new TimeZoneAndCanonicalAndNormalizedIterator(diplomatRuntime.internalConstructor, result, [], aEdges); + } + + finally {} + } + + constructor() { + if (arguments[0] === diplomatRuntime.exposeConstructor) { + return this.#internalConstructor(...Array.prototype.slice.call(arguments, 1)); + } else if (arguments[0] === diplomatRuntime.internalConstructor) { + return this.#internalConstructor(...arguments); + } else { + return this.#defaultConstructor(...arguments); + } + } +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/TimeZoneAndCanonical.d.ts b/ffi/capi/bindings/js/TimeZoneAndCanonical.d.ts new file mode 100644 index 00000000000..9e032557916 --- /dev/null +++ b/ffi/capi/bindings/js/TimeZoneAndCanonical.d.ts @@ -0,0 +1,13 @@ +// generated by diplomat-tool +import type { TimeZoneInfo } from "./TimeZoneInfo" +import type { pointer, codepoint } from "./diplomat-runtime.d.ts"; + + + +export class TimeZoneAndCanonical { + + get timeZone() : TimeZoneInfo; + + get canonical() : string; + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/TimeZoneAndCanonical.mjs b/ffi/capi/bindings/js/TimeZoneAndCanonical.mjs new file mode 100644 index 00000000000..118c990315b --- /dev/null +++ b/ffi/capi/bindings/js/TimeZoneAndCanonical.mjs @@ -0,0 +1,105 @@ +// generated by diplomat-tool +import { TimeZoneInfo } from "./TimeZoneInfo.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + + + +export class TimeZoneAndCanonical { + + #timeZone; + + get timeZone() { + return this.#timeZone; + } + + #canonical; + + get canonical() { + return this.#canonical; + } + + #internalConstructor(structObj, internalConstructor) { + if (typeof structObj !== "object") { + throw new Error("TimeZoneAndCanonical's constructor takes an object of TimeZoneAndCanonical's fields."); + } + + if (internalConstructor !== diplomatRuntime.internalConstructor) { + throw new Error("TimeZoneAndCanonical is an out struct and can only be created internally."); + } + if ("timeZone" in structObj) { + this.#timeZone = structObj.timeZone; + } else { + throw new Error("Missing required field timeZone."); + } + + if ("canonical" in structObj) { + this.#canonical = structObj.canonical; + } else { + throw new Error("Missing required field canonical."); + } + + return this; + } + + // Return this struct in FFI function friendly format. + // Returns an array that can be expanded with spread syntax (...) + // If this struct contains any slices, their lifetime-edge-relevant information will be + // set up here, and can be appended to any relevant lifetime arrays here. AppendArray accepts a list + // of arrays for each lifetime to do so. It accepts multiple lists per lifetime in case the caller needs to tie a lifetime to multiple + // output arrays. Null is equivalent to an empty list: this lifetime is not being borrowed from. + _intoFFI( + functionCleanupArena, + appendArrayMap + ) { + return [this.#timeZone.ffiValue, ...diplomatRuntime.CleanupArena.maybeCreateWith(functionCleanupArena, ...appendArrayMap['aAppendArray']).alloc(diplomatRuntime.DiplomatBuf.str8(wasm, this.#canonical)).splat()] + } + + static _fromSuppliedValue(internalConstructor, obj) { + if (internalConstructor !== diplomatRuntime.internalConstructor) { + throw new Error("_fromSuppliedValue cannot be called externally."); + } + + if (obj instanceof TimeZoneAndCanonical) { + return obj; + } + + return TimeZoneAndCanonical.fromFields(obj); + } + + _writeToArrayBuffer( + arrayBuffer, + offset, + functionCleanupArena, + appendArrayMap + ) { + diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, this.#timeZone.ffiValue, Uint32Array); + diplomatRuntime.CleanupArena.maybeCreateWith(functionCleanupArena, ...appendArrayMap['aAppendArray']).alloc(diplomatRuntime.DiplomatBuf.str8(wasm, this.#canonical)).writePtrLenToArrayBuffer(arrayBuffer, offset + 4); + } + + static _fromFFI(internalConstructor, ptr, aEdges) { + if (internalConstructor !== diplomatRuntime.internalConstructor) { + throw new Error("TimeZoneAndCanonical._fromFFI is not meant to be called externally. Please use the default constructor."); + } + let structObj = {}; + const timeZoneDeref = diplomatRuntime.ptrRead(wasm, ptr); + structObj.timeZone = new TimeZoneInfo(diplomatRuntime.internalConstructor, timeZoneDeref, []); + const canonicalDeref = ptr + 4; + structObj.canonical = new diplomatRuntime.DiplomatSliceStr(wasm, canonicalDeref, "string8", aEdges).getValue(); + + return new TimeZoneAndCanonical(structObj, internalConstructor); + } + + // Return all fields corresponding to lifetime `'a` + // without handling lifetime dependencies (this is the job of the caller) + // This is all fields that may be borrowed from if borrowing `'a`, + // assuming that there are no `'other: a`. bounds. In case of such bounds, + // the caller should take care to also call _fieldsForLifetimeOther + get _fieldsForLifetimeA() { + return [canonical]; + }; + + constructor(structObj, internalConstructor) { + return this.#internalConstructor(...arguments) + } +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/TimeZoneAndCanonicalAndNormalized.d.ts b/ffi/capi/bindings/js/TimeZoneAndCanonicalAndNormalized.d.ts new file mode 100644 index 00000000000..f3a0bd1aa68 --- /dev/null +++ b/ffi/capi/bindings/js/TimeZoneAndCanonicalAndNormalized.d.ts @@ -0,0 +1,15 @@ +// generated by diplomat-tool +import type { TimeZoneInfo } from "./TimeZoneInfo" +import type { pointer, codepoint } from "./diplomat-runtime.d.ts"; + + + +export class TimeZoneAndCanonicalAndNormalized { + + get timeZone() : TimeZoneInfo; + + get canonical() : string; + + get normalized() : string; + +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/TimeZoneAndCanonicalAndNormalized.mjs b/ffi/capi/bindings/js/TimeZoneAndCanonicalAndNormalized.mjs new file mode 100644 index 00000000000..23fa682f4b9 --- /dev/null +++ b/ffi/capi/bindings/js/TimeZoneAndCanonicalAndNormalized.mjs @@ -0,0 +1,120 @@ +// generated by diplomat-tool +import { TimeZoneInfo } from "./TimeZoneInfo.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + + + +export class TimeZoneAndCanonicalAndNormalized { + + #timeZone; + + get timeZone() { + return this.#timeZone; + } + + #canonical; + + get canonical() { + return this.#canonical; + } + + #normalized; + + get normalized() { + return this.#normalized; + } + + #internalConstructor(structObj, internalConstructor) { + if (typeof structObj !== "object") { + throw new Error("TimeZoneAndCanonicalAndNormalized's constructor takes an object of TimeZoneAndCanonicalAndNormalized's fields."); + } + + if (internalConstructor !== diplomatRuntime.internalConstructor) { + throw new Error("TimeZoneAndCanonicalAndNormalized is an out struct and can only be created internally."); + } + if ("timeZone" in structObj) { + this.#timeZone = structObj.timeZone; + } else { + throw new Error("Missing required field timeZone."); + } + + if ("canonical" in structObj) { + this.#canonical = structObj.canonical; + } else { + throw new Error("Missing required field canonical."); + } + + if ("normalized" in structObj) { + this.#normalized = structObj.normalized; + } else { + throw new Error("Missing required field normalized."); + } + + return this; + } + + // Return this struct in FFI function friendly format. + // Returns an array that can be expanded with spread syntax (...) + // If this struct contains any slices, their lifetime-edge-relevant information will be + // set up here, and can be appended to any relevant lifetime arrays here. AppendArray accepts a list + // of arrays for each lifetime to do so. It accepts multiple lists per lifetime in case the caller needs to tie a lifetime to multiple + // output arrays. Null is equivalent to an empty list: this lifetime is not being borrowed from. + _intoFFI( + functionCleanupArena, + appendArrayMap + ) { + return [this.#timeZone.ffiValue, ...diplomatRuntime.CleanupArena.maybeCreateWith(functionCleanupArena, ...appendArrayMap['aAppendArray']).alloc(diplomatRuntime.DiplomatBuf.str8(wasm, this.#canonical)).splat(), ...diplomatRuntime.CleanupArena.maybeCreateWith(functionCleanupArena, ...appendArrayMap['aAppendArray']).alloc(diplomatRuntime.DiplomatBuf.str8(wasm, this.#normalized)).splat()] + } + + static _fromSuppliedValue(internalConstructor, obj) { + if (internalConstructor !== diplomatRuntime.internalConstructor) { + throw new Error("_fromSuppliedValue cannot be called externally."); + } + + if (obj instanceof TimeZoneAndCanonicalAndNormalized) { + return obj; + } + + return TimeZoneAndCanonicalAndNormalized.fromFields(obj); + } + + _writeToArrayBuffer( + arrayBuffer, + offset, + functionCleanupArena, + appendArrayMap + ) { + diplomatRuntime.writeToArrayBuffer(arrayBuffer, offset + 0, this.#timeZone.ffiValue, Uint32Array); + diplomatRuntime.CleanupArena.maybeCreateWith(functionCleanupArena, ...appendArrayMap['aAppendArray']).alloc(diplomatRuntime.DiplomatBuf.str8(wasm, this.#canonical)).writePtrLenToArrayBuffer(arrayBuffer, offset + 4); + diplomatRuntime.CleanupArena.maybeCreateWith(functionCleanupArena, ...appendArrayMap['aAppendArray']).alloc(diplomatRuntime.DiplomatBuf.str8(wasm, this.#normalized)).writePtrLenToArrayBuffer(arrayBuffer, offset + 12); + } + + static _fromFFI(internalConstructor, ptr, aEdges) { + if (internalConstructor !== diplomatRuntime.internalConstructor) { + throw new Error("TimeZoneAndCanonicalAndNormalized._fromFFI is not meant to be called externally. Please use the default constructor."); + } + let structObj = {}; + const timeZoneDeref = diplomatRuntime.ptrRead(wasm, ptr); + structObj.timeZone = new TimeZoneInfo(diplomatRuntime.internalConstructor, timeZoneDeref, []); + const canonicalDeref = ptr + 4; + structObj.canonical = new diplomatRuntime.DiplomatSliceStr(wasm, canonicalDeref, "string8", aEdges).getValue(); + const normalizedDeref = ptr + 12; + structObj.normalized = new diplomatRuntime.DiplomatSliceStr(wasm, normalizedDeref, "string8", aEdges).getValue(); + + return new TimeZoneAndCanonicalAndNormalized(structObj, internalConstructor); + } + + // Return all fields corresponding to lifetime `'a` + // without handling lifetime dependencies (this is the job of the caller) + // This is all fields that may be borrowed from if borrowing `'a`, + // assuming that there are no `'other: a`. bounds. In case of such bounds, + // the caller should take care to also call _fieldsForLifetimeOther + get _fieldsForLifetimeA() { + return [canonical, normalized]; + }; + + constructor(structObj, internalConstructor) { + return this.#internalConstructor(...arguments) + } +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/TimeZoneAndCanonicalAndNormalizedIterator.d.ts b/ffi/capi/bindings/js/TimeZoneAndCanonicalAndNormalizedIterator.d.ts new file mode 100644 index 00000000000..3768ab5f499 --- /dev/null +++ b/ffi/capi/bindings/js/TimeZoneAndCanonicalAndNormalizedIterator.d.ts @@ -0,0 +1,15 @@ +// generated by diplomat-tool +import type { TimeZoneAndCanonicalAndNormalized } from "./TimeZoneAndCanonicalAndNormalized" +import type { pointer, codepoint } from "./diplomat-runtime.d.ts"; + + +/** See the [Rust documentation for `TimeZoneAndCanonicalAndNormalizedIter`](https://docs.rs/icu/latest/icu/time/zone/iana/struct.TimeZoneAndCanonicalAndNormalizedIter.html) for more information. +*/ + + +export class TimeZoneAndCanonicalAndNormalizedIterator { + + get ffiValue(): pointer; + + next() : IteratorResult; +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/TimeZoneAndCanonicalAndNormalizedIterator.mjs b/ffi/capi/bindings/js/TimeZoneAndCanonicalAndNormalizedIterator.mjs new file mode 100644 index 00000000000..c4d3554eaf2 --- /dev/null +++ b/ffi/capi/bindings/js/TimeZoneAndCanonicalAndNormalizedIterator.mjs @@ -0,0 +1,78 @@ +// generated by diplomat-tool +import { TimeZoneAndCanonicalAndNormalized } from "./TimeZoneAndCanonicalAndNormalized.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + + +/** See the [Rust documentation for `TimeZoneAndCanonicalAndNormalizedIter`](https://docs.rs/icu/latest/icu/time/zone/iana/struct.TimeZoneAndCanonicalAndNormalizedIter.html) for more information. +*/ +const TimeZoneAndCanonicalAndNormalizedIterator_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.icu4x_TimeZoneAndCanonicalAndNormalizedIterator_destroy_mv1(ptr); +}); + +export class TimeZoneAndCanonicalAndNormalizedIterator { + + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + #aEdge = []; + + #internalConstructor(symbol, ptr, selfEdge, aEdge) { + if (symbol !== diplomatRuntime.internalConstructor) { + console.error("TimeZoneAndCanonicalAndNormalizedIterator is an Opaque type. You cannot call its constructor."); + return; + } + + + this.#aEdge = aEdge; + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + + // Are we being borrowed? If not, we can register. + if (this.#selfEdge.length === 0) { + TimeZoneAndCanonicalAndNormalizedIterator_box_destroy_registry.register(this, this.#ptr); + } + + return this; + } + get ffiValue() { + return this.#ptr; + } + + #iteratorNext() { + const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 21, 4, true); + + // This lifetime edge depends on lifetimes 'a + let aEdges = [this]; + + const result = wasm.icu4x_TimeZoneAndCanonicalAndNormalizedIterator_next_mv1(diplomatReceive.buffer, this.ffiValue); + + try { + if (!diplomatReceive.resultFlag) { + return null; + } + return TimeZoneAndCanonicalAndNormalized._fromFFI(diplomatRuntime.internalConstructor, diplomatReceive.buffer, aEdges); + } + + finally { + diplomatReceive.free(); + } + } + + next() { + const out = this.#iteratorNext(); + + return { + value: out, + done: out === null, + }; + } + + constructor(symbol, ptr, selfEdge, aEdge) { + return this.#internalConstructor(...arguments) + } +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/TimeZoneAndCanonicalIterator.d.ts b/ffi/capi/bindings/js/TimeZoneAndCanonicalIterator.d.ts new file mode 100644 index 00000000000..91379b757b9 --- /dev/null +++ b/ffi/capi/bindings/js/TimeZoneAndCanonicalIterator.d.ts @@ -0,0 +1,15 @@ +// generated by diplomat-tool +import type { TimeZoneAndCanonical } from "./TimeZoneAndCanonical" +import type { pointer, codepoint } from "./diplomat-runtime.d.ts"; + + +/** See the [Rust documentation for `TimeZoneAndCanonicalIter`](https://docs.rs/icu/latest/icu/time/zone/iana/struct.TimeZoneAndCanonicalIter.html) for more information. +*/ + + +export class TimeZoneAndCanonicalIterator { + + get ffiValue(): pointer; + + next() : IteratorResult; +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/TimeZoneAndCanonicalIterator.mjs b/ffi/capi/bindings/js/TimeZoneAndCanonicalIterator.mjs new file mode 100644 index 00000000000..182bb704387 --- /dev/null +++ b/ffi/capi/bindings/js/TimeZoneAndCanonicalIterator.mjs @@ -0,0 +1,78 @@ +// generated by diplomat-tool +import { TimeZoneAndCanonical } from "./TimeZoneAndCanonical.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + + +/** See the [Rust documentation for `TimeZoneAndCanonicalIter`](https://docs.rs/icu/latest/icu/time/zone/iana/struct.TimeZoneAndCanonicalIter.html) for more information. +*/ +const TimeZoneAndCanonicalIterator_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.icu4x_TimeZoneAndCanonicalIterator_destroy_mv1(ptr); +}); + +export class TimeZoneAndCanonicalIterator { + + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + #aEdge = []; + + #internalConstructor(symbol, ptr, selfEdge, aEdge) { + if (symbol !== diplomatRuntime.internalConstructor) { + console.error("TimeZoneAndCanonicalIterator is an Opaque type. You cannot call its constructor."); + return; + } + + + this.#aEdge = aEdge; + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + + // Are we being borrowed? If not, we can register. + if (this.#selfEdge.length === 0) { + TimeZoneAndCanonicalIterator_box_destroy_registry.register(this, this.#ptr); + } + + return this; + } + get ffiValue() { + return this.#ptr; + } + + #iteratorNext() { + const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 13, 4, true); + + // This lifetime edge depends on lifetimes 'a + let aEdges = [this]; + + const result = wasm.icu4x_TimeZoneAndCanonicalIterator_next_mv1(diplomatReceive.buffer, this.ffiValue); + + try { + if (!diplomatReceive.resultFlag) { + return null; + } + return TimeZoneAndCanonical._fromFFI(diplomatRuntime.internalConstructor, diplomatReceive.buffer, aEdges); + } + + finally { + diplomatReceive.free(); + } + } + + next() { + const out = this.#iteratorNext(); + + return { + value: out, + done: out === null, + }; + } + + constructor(symbol, ptr, selfEdge, aEdge) { + return this.#internalConstructor(...arguments) + } +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/TimeZoneIterator.d.ts b/ffi/capi/bindings/js/TimeZoneIterator.d.ts new file mode 100644 index 00000000000..b65d886345c --- /dev/null +++ b/ffi/capi/bindings/js/TimeZoneIterator.d.ts @@ -0,0 +1,15 @@ +// generated by diplomat-tool +import type { TimeZoneInfo } from "./TimeZoneInfo" +import type { pointer, codepoint } from "./diplomat-runtime.d.ts"; + + +/** See the [Rust documentation for `TimeZoneIter`](https://docs.rs/icu/latest/icu/time/zone/iana/struct.TimeZoneIter.html) for more information. +*/ + + +export class TimeZoneIterator { + + get ffiValue(): pointer; + + next() : IteratorResult; +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/TimeZoneIterator.mjs b/ffi/capi/bindings/js/TimeZoneIterator.mjs new file mode 100644 index 00000000000..9047aef4b0e --- /dev/null +++ b/ffi/capi/bindings/js/TimeZoneIterator.mjs @@ -0,0 +1,68 @@ +// generated by diplomat-tool +import { TimeZoneInfo } from "./TimeZoneInfo.mjs" +import wasm from "./diplomat-wasm.mjs"; +import * as diplomatRuntime from "./diplomat-runtime.mjs"; + + +/** See the [Rust documentation for `TimeZoneIter`](https://docs.rs/icu/latest/icu/time/zone/iana/struct.TimeZoneIter.html) for more information. +*/ +const TimeZoneIterator_box_destroy_registry = new FinalizationRegistry((ptr) => { + wasm.icu4x_TimeZoneIterator_destroy_mv1(ptr); +}); + +export class TimeZoneIterator { + + // Internal ptr reference: + #ptr = null; + + // Lifetimes are only to keep dependencies alive. + // Since JS won't garbage collect until there are no incoming edges. + #selfEdge = []; + #aEdge = []; + + #internalConstructor(symbol, ptr, selfEdge, aEdge) { + if (symbol !== diplomatRuntime.internalConstructor) { + console.error("TimeZoneIterator is an Opaque type. You cannot call its constructor."); + return; + } + + + this.#aEdge = aEdge; + + this.#ptr = ptr; + this.#selfEdge = selfEdge; + + // Are we being borrowed? If not, we can register. + if (this.#selfEdge.length === 0) { + TimeZoneIterator_box_destroy_registry.register(this, this.#ptr); + } + + return this; + } + get ffiValue() { + return this.#ptr; + } + + #iteratorNext() { + const result = wasm.icu4x_TimeZoneIterator_next_mv1(this.ffiValue); + + try { + return result === 0 ? null : new TimeZoneInfo(diplomatRuntime.internalConstructor, result, []); + } + + finally {} + } + + next() { + const out = this.#iteratorNext(); + + return { + value: out, + done: out === null, + }; + } + + constructor(symbol, ptr, selfEdge, aEdge) { + return this.#internalConstructor(...arguments) + } +} \ No newline at end of file diff --git a/ffi/capi/bindings/js/index.d.ts b/ffi/capi/bindings/js/index.d.ts index 3341048d02e..2b5726a2b64 100644 --- a/ffi/capi/bindings/js/index.d.ts +++ b/ffi/capi/bindings/js/index.d.ts @@ -28,6 +28,10 @@ export { DateTime } from "./DateTime" export { IsoDateTime } from "./IsoDateTime" +export { TimeZoneAndCanonical } from "./TimeZoneAndCanonical" + +export { TimeZoneAndCanonicalAndNormalized } from "./TimeZoneAndCanonicalAndNormalized" + export { Decomposed } from "./Decomposed" export { PluralCategories } from "./PluralCategories" @@ -88,6 +92,14 @@ export { Decimal } from "./Decimal" export { IanaParser } from "./IanaParser" +export { IanaParserExtended } from "./IanaParserExtended" + +export { TimeZoneAndCanonicalAndNormalizedIterator } from "./TimeZoneAndCanonicalAndNormalizedIterator" + +export { TimeZoneAndCanonicalIterator } from "./TimeZoneAndCanonicalIterator" + +export { TimeZoneIterator } from "./TimeZoneIterator" + export { ListFormatter } from "./ListFormatter" export { LocaleCanonicalizer } from "./LocaleCanonicalizer" diff --git a/ffi/capi/bindings/js/index.mjs b/ffi/capi/bindings/js/index.mjs index 70290ca8b24..ec2520e3df0 100644 --- a/ffi/capi/bindings/js/index.mjs +++ b/ffi/capi/bindings/js/index.mjs @@ -26,6 +26,10 @@ export { DateTime } from "./DateTime.mjs" export { IsoDateTime } from "./IsoDateTime.mjs" +export { TimeZoneAndCanonical } from "./TimeZoneAndCanonical.mjs" + +export { TimeZoneAndCanonicalAndNormalized } from "./TimeZoneAndCanonicalAndNormalized.mjs" + export { Decomposed } from "./Decomposed.mjs" export { PluralCategories } from "./PluralCategories.mjs" @@ -86,6 +90,14 @@ export { Decimal } from "./Decimal.mjs" export { IanaParser } from "./IanaParser.mjs" +export { IanaParserExtended } from "./IanaParserExtended.mjs" + +export { TimeZoneAndCanonicalAndNormalizedIterator } from "./TimeZoneAndCanonicalAndNormalizedIterator.mjs" + +export { TimeZoneAndCanonicalIterator } from "./TimeZoneAndCanonicalIterator.mjs" + +export { TimeZoneIterator } from "./TimeZoneIterator.mjs" + export { ListFormatter } from "./ListFormatter.mjs" export { LocaleCanonicalizer } from "./LocaleCanonicalizer.mjs" diff --git a/ffi/capi/src/iana_parser.rs b/ffi/capi/src/iana_parser.rs index d297969d791..d8f77e2c84e 100644 --- a/ffi/capi/src/iana_parser.rs +++ b/ffi/capi/src/iana_parser.rs @@ -7,6 +7,7 @@ #[diplomat::attr(auto, namespace = "icu4x")] pub mod ffi { use alloc::boxed::Box; + use diplomat_runtime::DiplomatStr; use crate::timezone::ffi::TimeZoneInfo; #[cfg(feature = "buffer_provider")] @@ -58,5 +59,170 @@ pub mod ffi { zone_variant: None, }) } + + #[diplomat::rust_link(icu::time::zone::iana::IanaParserBorrowed::iter, FnInStruct)] + pub fn iter<'a>(&'a self) -> Box> { + Box::new(TimeZoneIterator(self.0.as_borrowed().iter())) + } + } + + #[diplomat::opaque] + #[diplomat::rust_link(icu::time::zone::iana::TimeZoneIter, Struct)] + pub struct TimeZoneIterator<'a>(icu_time::zone::iana::TimeZoneIter<'a>); + + impl<'a> TimeZoneIterator<'a> { + #[diplomat::attr(auto, iterator)] + #[diplomat::rust_link(icu::time::zone::iana::TimeZoneIter::next, FnInStruct)] + pub fn next(&mut self) -> Option> { + Some(Box::new(TimeZoneInfo { + time_zone_id: self.0.next()?, + offset: None, + local_time: None, + zone_variant: None, + })) + } + } + + /// A mapper between IANA time zone identifiers and BCP-47 time zone identifiers. + /// + /// This mapper supports two-way mapping, but it is optimized for the case of IANA to BCP-47. + /// It also supports normalizing and canonicalizing the IANA strings. + #[diplomat::opaque] + #[diplomat::rust_link(icu::time::zone::iana::IanaParserExtended, Struct)] + #[diplomat::rust_link( + icu::time::zone::iana::IanaParserExtended::as_borrowed, + FnInStruct, + hidden + )] + #[diplomat::rust_link(icu::time::zone::iana::IanaParserExtendedBorrowed, Struct, hidden)] + #[diplomat::rust_link( + icu::time::zone::iana::IanaParserExtendedBorrowed::new, + FnInStruct, + hidden + )] + pub struct IanaParserExtended( + pub icu_time::zone::iana::IanaParserExtended, + ); + + impl IanaParserExtended { + /// Create a new [`IanaParserExtended`] using compiled data + #[diplomat::rust_link(icu::time::zone::iana::IanaParserExtended::new, FnInStruct)] + #[diplomat::attr(auto, constructor)] + #[cfg(feature = "compiled_data")] + pub fn create() -> Box { + Box::new(IanaParserExtended( + icu_time::zone::iana::IanaParserExtended::new().static_to_owned(), + )) + } + + /// Create a new [`IanaParserExtended`] using a particular data source + #[diplomat::rust_link(icu::time::zone::iana::IanaParserExtended::new, FnInStruct)] + #[diplomat::attr(all(supports = fallible_constructors, supports = named_constructors), named_constructor = "with_provider")] + #[cfg(feature = "buffer_provider")] + pub fn create_with_provider( + provider: &DataProvider, + ) -> Result, DataError> { + Ok(Box::new(IanaParserExtended( + icu_time::zone::iana::IanaParserExtended::try_new_with_buffer_provider( + provider.get()?, + )?, + ))) + } + + #[diplomat::rust_link(icu::time::zone::iana::IanaParserExtendedBorrowed::parse, FnInStruct)] + #[diplomat::rust_link( + icu::time::zone::iana::IanaParserExtendedBorrowed::parse_from_utf8, + FnInStruct, + hidden + )] + pub fn parse<'a>(&'a self, value: &DiplomatStr) -> TimeZoneAndCanonicalAndNormalized<'a> { + let (time_zone_id, canonical, normalized) = self.0.as_borrowed().parse_from_utf8(value); + TimeZoneAndCanonicalAndNormalized { + time_zone: Box::new(TimeZoneInfo { + time_zone_id, + local_time: None, + offset: None, + zone_variant: None, + }), + canonical: canonical.into(), + normalized: normalized.into(), + } + } + + #[diplomat::rust_link(icu::time::zone::iana::IanaParserExtendedBorrowed::iter, FnInStruct)] + pub fn iter<'a>(&'a self) -> Box> { + Box::new(TimeZoneAndCanonicalIterator(self.0.as_borrowed().iter())) + } + + #[diplomat::rust_link( + icu::time::zone::iana::IanaParserExtendedBorrowed::iter_all, + FnInStruct + )] + pub fn iter_all<'a>(&'a self) -> Box> { + Box::new(TimeZoneAndCanonicalAndNormalizedIterator( + self.0.as_borrowed().iter_all(), + )) + } + } + + #[diplomat::out] + pub struct TimeZoneAndCanonical<'a> { + time_zone: Box, + canonical: DiplomatUtf8StrSlice<'a>, + } + + #[diplomat::opaque] + #[diplomat::rust_link(icu::time::zone::iana::TimeZoneAndCanonicalIter, Struct)] + pub struct TimeZoneAndCanonicalIterator<'a>(icu_time::zone::iana::TimeZoneAndCanonicalIter<'a>); + + impl<'a> TimeZoneAndCanonicalIterator<'a> { + #[diplomat::attr(auto, iterator)] + #[diplomat::rust_link(icu::time::zone::iana::TimeZoneAndCanonicalIter::next, FnInStruct)] + pub fn next(&mut self) -> Option> { + let (time_zone_id, canonical) = self.0.next()?; + Some(TimeZoneAndCanonical { + time_zone: Box::new(TimeZoneInfo { + time_zone_id, + local_time: None, + offset: None, + zone_variant: None, + }), + canonical: canonical.into(), + }) + } + } + + #[diplomat::out] + pub struct TimeZoneAndCanonicalAndNormalized<'a> { + time_zone: Box, + canonical: DiplomatUtf8StrSlice<'a>, + normalized: DiplomatUtf8StrSlice<'a>, + } + + #[diplomat::opaque] + #[diplomat::rust_link(icu::time::zone::iana::TimeZoneAndCanonicalAndNormalizedIter, Struct)] + pub struct TimeZoneAndCanonicalAndNormalizedIterator<'a>( + icu_time::zone::iana::TimeZoneAndCanonicalAndNormalizedIter<'a>, + ); + + impl<'a> TimeZoneAndCanonicalAndNormalizedIterator<'a> { + #[diplomat::attr(auto, iterator)] + #[diplomat::rust_link( + icu::time::zone::iana::TimeZoneAndCanonicalAndNormalizedIter::next, + FnInStruct + )] + pub fn next(&mut self) -> Option> { + let (time_zone_id, canonical, normalized) = self.0.next()?; + Some(TimeZoneAndCanonicalAndNormalized { + time_zone: Box::new(TimeZoneInfo { + time_zone_id, + local_time: None, + offset: None, + zone_variant: None, + }), + canonical: canonical.into(), + normalized: normalized.into(), + }) + } } } diff --git a/ffi/capi/tests/missing_apis.txt b/ffi/capi/tests/missing_apis.txt index b3c5df5c1cf..818fc02aa1e 100644 --- a/ffi/capi/tests/missing_apis.txt +++ b/ffi/capi/tests/missing_apis.txt @@ -215,22 +215,7 @@ icu::time::ZonedDateTime::try_offset_only_from_utf8#FnInStruct icu::time::zone::TimeZoneVariant#Enum icu::time::zone::UtcOffsetCalculator::compute_offsets_from_time_zone#FnInStruct icu::time::zone::UtcOffsets#Struct -icu::time::zone::iana::IanaParserBorrowed::iter#FnInStruct -icu::time::zone::iana::IanaParserExtended#Struct -icu::time::zone::iana::IanaParserExtended::new#FnInStruct icu::time::zone::iana::IanaParserExtended::try_new_with_parser#FnInStruct -icu::time::zone::iana::IanaParserExtendedBorrowed#Struct -icu::time::zone::iana::IanaParserExtendedBorrowed::iter#FnInStruct -icu::time::zone::iana::IanaParserExtendedBorrowed::iter_all#FnInStruct -icu::time::zone::iana::IanaParserExtendedBorrowed::new#FnInStruct -icu::time::zone::iana::IanaParserExtendedBorrowed::parse#FnInStruct -icu::time::zone::iana::IanaParserExtendedBorrowed::parse_from_utf8#FnInStruct -icu::time::zone::iana::TimeZoneAndCanonicalAndNormalizedIter#Struct -icu::time::zone::iana::TimeZoneAndCanonicalAndNormalizedIter::next#FnInStruct -icu::time::zone::iana::TimeZoneAndCanonicalIter#Struct -icu::time::zone::iana::TimeZoneAndCanonicalIter::next#FnInStruct -icu::time::zone::iana::TimeZoneIter#Struct -icu::time::zone::iana::TimeZoneIter::next#FnInStruct icu::time::zone::models::AtTime#Enum icu::time::zone::models::Base#Enum icu::time::zone::models::Full#Enum diff --git a/ffi/dart/test/icu_test.dart b/ffi/dart/test/icu_test.dart index 1609c2a56e7..6594664da9d 100644 --- a/ffi/dart/test/icu_test.dart +++ b/ffi/dart/test/icu_test.dart @@ -55,6 +55,12 @@ void main() { ]); }); + test('Time zones', () { + final iter = IanaParserExtended().iterAll(); + iter.moveNext(); + expect(iter.current.canonical, 'Africa/Abidjan'); + }); + test('DateTime formatting', () { final zonedDateTimeIso = ZonedIsoDateTime.tryFromStr( '2025-01-15T14:32:12.34+01[Europe/Zurich]',