diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /intl/icu_capi/cpp/include/ICU4XLocaleFallbackerWithConfig.hpp | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'intl/icu_capi/cpp/include/ICU4XLocaleFallbackerWithConfig.hpp')
-rw-r--r-- | intl/icu_capi/cpp/include/ICU4XLocaleFallbackerWithConfig.hpp | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/intl/icu_capi/cpp/include/ICU4XLocaleFallbackerWithConfig.hpp b/intl/icu_capi/cpp/include/ICU4XLocaleFallbackerWithConfig.hpp new file mode 100644 index 0000000000..41f23cd0b0 --- /dev/null +++ b/intl/icu_capi/cpp/include/ICU4XLocaleFallbackerWithConfig.hpp @@ -0,0 +1,60 @@ +#ifndef ICU4XLocaleFallbackerWithConfig_HPP +#define ICU4XLocaleFallbackerWithConfig_HPP +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> +#include <algorithm> +#include <memory> +#include <variant> +#include <optional> +#include "diplomat_runtime.hpp" + +#include "ICU4XLocaleFallbackerWithConfig.h" + +class ICU4XLocale; +class ICU4XLocaleFallbackIterator; + +/** + * A destruction policy for using ICU4XLocaleFallbackerWithConfig with std::unique_ptr. + */ +struct ICU4XLocaleFallbackerWithConfigDeleter { + void operator()(capi::ICU4XLocaleFallbackerWithConfig* l) const noexcept { + capi::ICU4XLocaleFallbackerWithConfig_destroy(l); + } +}; + +/** + * An object that runs the ICU4X locale fallback algorithm with specific configurations. + * + * See the [Rust documentation for `LocaleFallbacker`](https://docs.rs/icu/latest/icu/locid_transform/fallback/struct.LocaleFallbacker.html) for more information. + * + * See the [Rust documentation for `LocaleFallbackerWithConfig`](https://docs.rs/icu/latest/icu/locid_transform/fallback/struct.LocaleFallbackerWithConfig.html) for more information. + */ +class ICU4XLocaleFallbackerWithConfig { + public: + + /** + * Creates an iterator from a locale with each step of fallback. + * + * See the [Rust documentation for `fallback_for`](https://docs.rs/icu/latest/icu/locid_transform/fallback/struct.LocaleFallbacker.html#method.fallback_for) for more information. + * + * Lifetimes: `this` must live at least as long as the output. + */ + ICU4XLocaleFallbackIterator fallback_for_locale(const ICU4XLocale& locale) const; + inline const capi::ICU4XLocaleFallbackerWithConfig* AsFFI() const { return this->inner.get(); } + inline capi::ICU4XLocaleFallbackerWithConfig* AsFFIMut() { return this->inner.get(); } + inline explicit ICU4XLocaleFallbackerWithConfig(capi::ICU4XLocaleFallbackerWithConfig* i) : inner(i) {} + ICU4XLocaleFallbackerWithConfig() = default; + ICU4XLocaleFallbackerWithConfig(ICU4XLocaleFallbackerWithConfig&&) noexcept = default; + ICU4XLocaleFallbackerWithConfig& operator=(ICU4XLocaleFallbackerWithConfig&& other) noexcept = default; + private: + std::unique_ptr<capi::ICU4XLocaleFallbackerWithConfig, ICU4XLocaleFallbackerWithConfigDeleter> inner; +}; + +#include "ICU4XLocale.hpp" +#include "ICU4XLocaleFallbackIterator.hpp" + +inline ICU4XLocaleFallbackIterator ICU4XLocaleFallbackerWithConfig::fallback_for_locale(const ICU4XLocale& locale) const { + return ICU4XLocaleFallbackIterator(capi::ICU4XLocaleFallbackerWithConfig_fallback_for_locale(this->inner.get(), locale.AsFFI())); +} +#endif |