diff --git a/ffi/diplomat/c/include/ICU4XLocaleFallbackConfig.h b/ffi/diplomat/c/include/ICU4XLocaleFallbackConfig.h index b3741e6bf0f..b40d1154187 100644 --- a/ffi/diplomat/c/include/ICU4XLocaleFallbackConfig.h +++ b/ffi/diplomat/c/include/ICU4XLocaleFallbackConfig.h @@ -7,6 +7,7 @@ #include "diplomat_runtime.h" #include "ICU4XLocaleFallbackPriority.h" +#include "ICU4XLocaleFallbackSupplement.h" #ifdef __cplusplus namespace capi { #endif @@ -14,11 +15,13 @@ namespace capi { typedef struct ICU4XLocaleFallbackConfig { ICU4XLocaleFallbackPriority priority; DiplomatStringView extension_key; + ICU4XLocaleFallbackSupplement fallback_supplement; } ICU4XLocaleFallbackConfig; #ifdef __cplusplus } // namespace capi #endif #include "ICU4XLocaleFallbackPriority.h" +#include "ICU4XLocaleFallbackSupplement.h" #ifdef __cplusplus namespace capi { extern "C" { diff --git a/ffi/diplomat/c/include/ICU4XLocaleFallbackSupplement.h b/ffi/diplomat/c/include/ICU4XLocaleFallbackSupplement.h new file mode 100644 index 00000000000..952483c724c --- /dev/null +++ b/ffi/diplomat/c/include/ICU4XLocaleFallbackSupplement.h @@ -0,0 +1,31 @@ +#ifndef ICU4XLocaleFallbackSupplement_H +#define ICU4XLocaleFallbackSupplement_H +#include +#include +#include +#include +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef enum ICU4XLocaleFallbackSupplement { + ICU4XLocaleFallbackSupplement_None = 0, + ICU4XLocaleFallbackSupplement_Collation = 1, +} ICU4XLocaleFallbackSupplement; +#ifdef __cplusplus +} // namespace capi +#endif +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +void ICU4XLocaleFallbackSupplement_destroy(ICU4XLocaleFallbackSupplement* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/ffi/diplomat/cpp/docs/source/fallbacker_ffi.rst b/ffi/diplomat/cpp/docs/source/fallbacker_ffi.rst index 0133fd6e133..a4b17b785c8 100644 --- a/ffi/diplomat/cpp/docs/source/fallbacker_ffi.rst +++ b/ffi/diplomat/cpp/docs/source/fallbacker_ffi.rst @@ -18,6 +18,11 @@ An empty string is considered ``None``. + .. cpp:member:: ICU4XLocaleFallbackSupplement fallback_supplement + + Fallback supplement data key to customize fallback rules. + + .. cpp:class:: ICU4XLocaleFallbackIterator An iterator over the locale under fallback. @@ -52,6 +57,17 @@ .. cpp:enumerator:: Collation +.. cpp:enum-struct:: ICU4XLocaleFallbackSupplement + + What additional data is required to load when performing fallback. + + See the `Rust documentation for LocaleFallbackSupplement `__ for more information. + + + .. cpp:enumerator:: None + + .. cpp:enumerator:: Collation + .. cpp:class:: ICU4XLocaleFallbacker An object that runs the ICU4X locale fallback algorithm. diff --git a/ffi/diplomat/cpp/include/ICU4XLocaleFallbackConfig.h b/ffi/diplomat/cpp/include/ICU4XLocaleFallbackConfig.h index b3741e6bf0f..b40d1154187 100644 --- a/ffi/diplomat/cpp/include/ICU4XLocaleFallbackConfig.h +++ b/ffi/diplomat/cpp/include/ICU4XLocaleFallbackConfig.h @@ -7,6 +7,7 @@ #include "diplomat_runtime.h" #include "ICU4XLocaleFallbackPriority.h" +#include "ICU4XLocaleFallbackSupplement.h" #ifdef __cplusplus namespace capi { #endif @@ -14,11 +15,13 @@ namespace capi { typedef struct ICU4XLocaleFallbackConfig { ICU4XLocaleFallbackPriority priority; DiplomatStringView extension_key; + ICU4XLocaleFallbackSupplement fallback_supplement; } ICU4XLocaleFallbackConfig; #ifdef __cplusplus } // namespace capi #endif #include "ICU4XLocaleFallbackPriority.h" +#include "ICU4XLocaleFallbackSupplement.h" #ifdef __cplusplus namespace capi { extern "C" { diff --git a/ffi/diplomat/cpp/include/ICU4XLocaleFallbackConfig.hpp b/ffi/diplomat/cpp/include/ICU4XLocaleFallbackConfig.hpp index 4325a86669a..8c177d718af 100644 --- a/ffi/diplomat/cpp/include/ICU4XLocaleFallbackConfig.hpp +++ b/ffi/diplomat/cpp/include/ICU4XLocaleFallbackConfig.hpp @@ -12,6 +12,7 @@ #include "ICU4XLocaleFallbackConfig.h" #include "ICU4XLocaleFallbackPriority.hpp" +#include "ICU4XLocaleFallbackSupplement.hpp" /** @@ -31,6 +32,11 @@ struct ICU4XLocaleFallbackConfig { * An empty string is considered `None`. */ std::string_view extension_key; + + /** + * Fallback supplement data key to customize fallback rules. + */ + ICU4XLocaleFallbackSupplement fallback_supplement; }; diff --git a/ffi/diplomat/cpp/include/ICU4XLocaleFallbackSupplement.h b/ffi/diplomat/cpp/include/ICU4XLocaleFallbackSupplement.h new file mode 100644 index 00000000000..952483c724c --- /dev/null +++ b/ffi/diplomat/cpp/include/ICU4XLocaleFallbackSupplement.h @@ -0,0 +1,31 @@ +#ifndef ICU4XLocaleFallbackSupplement_H +#define ICU4XLocaleFallbackSupplement_H +#include +#include +#include +#include +#include "diplomat_runtime.h" + +#ifdef __cplusplus +namespace capi { +#endif + +typedef enum ICU4XLocaleFallbackSupplement { + ICU4XLocaleFallbackSupplement_None = 0, + ICU4XLocaleFallbackSupplement_Collation = 1, +} ICU4XLocaleFallbackSupplement; +#ifdef __cplusplus +} // namespace capi +#endif +#ifdef __cplusplus +namespace capi { +extern "C" { +#endif + +void ICU4XLocaleFallbackSupplement_destroy(ICU4XLocaleFallbackSupplement* self); + +#ifdef __cplusplus +} // extern "C" +} // namespace capi +#endif +#endif diff --git a/ffi/diplomat/cpp/include/ICU4XLocaleFallbackSupplement.hpp b/ffi/diplomat/cpp/include/ICU4XLocaleFallbackSupplement.hpp new file mode 100644 index 00000000000..a357bb4929c --- /dev/null +++ b/ffi/diplomat/cpp/include/ICU4XLocaleFallbackSupplement.hpp @@ -0,0 +1,26 @@ +#ifndef ICU4XLocaleFallbackSupplement_HPP +#define ICU4XLocaleFallbackSupplement_HPP +#include +#include +#include +#include +#include +#include +#include +#include "diplomat_runtime.hpp" + +#include "ICU4XLocaleFallbackSupplement.h" + + + +/** + * What additional data is required to load when performing fallback. + * + * See the [Rust documentation for `LocaleFallbackSupplement`](https://docs.rs/icu/latest/icu/locid_transform/fallback/enum.LocaleFallbackSupplement.html) for more information. + */ +enum struct ICU4XLocaleFallbackSupplement { + None = 0, + Collation = 1, +}; + +#endif diff --git a/ffi/diplomat/cpp/include/ICU4XLocaleFallbacker.hpp b/ffi/diplomat/cpp/include/ICU4XLocaleFallbacker.hpp index 21fbda0bdc3..fc3471a6918 100644 --- a/ffi/diplomat/cpp/include/ICU4XLocaleFallbacker.hpp +++ b/ffi/diplomat/cpp/include/ICU4XLocaleFallbacker.hpp @@ -85,7 +85,7 @@ inline ICU4XLocaleFallbacker ICU4XLocaleFallbacker::create_without_data() { } inline diplomat::result ICU4XLocaleFallbacker::for_config(ICU4XLocaleFallbackConfig config) const { ICU4XLocaleFallbackConfig diplomat_wrapped_struct_config = config; - auto diplomat_result_raw_out_value = capi::ICU4XLocaleFallbacker_for_config(this->inner.get(), capi::ICU4XLocaleFallbackConfig{ .priority = static_cast(diplomat_wrapped_struct_config.priority), .extension_key = { diplomat_wrapped_struct_config.extension_key.data(), diplomat_wrapped_struct_config.extension_key.size() } }); + auto diplomat_result_raw_out_value = capi::ICU4XLocaleFallbacker_for_config(this->inner.get(), capi::ICU4XLocaleFallbackConfig{ .priority = static_cast(diplomat_wrapped_struct_config.priority), .extension_key = { diplomat_wrapped_struct_config.extension_key.data(), diplomat_wrapped_struct_config.extension_key.size() }, .fallback_supplement = static_cast(diplomat_wrapped_struct_config.fallback_supplement) }); diplomat::result diplomat_result_out_value; if (diplomat_result_raw_out_value.is_ok) { diplomat_result_out_value = diplomat::Ok(std::move(ICU4XLocaleFallbackerWithConfig(diplomat_result_raw_out_value.ok))); diff --git a/ffi/diplomat/js/docs/source/fallbacker_ffi.rst b/ffi/diplomat/js/docs/source/fallbacker_ffi.rst index e8b26a436cc..e3bd0ae2bb9 100644 --- a/ffi/diplomat/js/docs/source/fallbacker_ffi.rst +++ b/ffi/diplomat/js/docs/source/fallbacker_ffi.rst @@ -18,6 +18,11 @@ An empty string is considered ``None``. + .. js:attribute:: fallback_supplement + + Fallback supplement data key to customize fallback rules. + + .. js:class:: ICU4XLocaleFallbackIterator An iterator over the locale under fallback. @@ -46,6 +51,13 @@ See the `Rust documentation for LocaleFallbackPriority `__ for more information. +.. js:class:: ICU4XLocaleFallbackSupplement + + What additional data is required to load when performing fallback. + + See the `Rust documentation for LocaleFallbackSupplement `__ for more information. + + .. js:class:: ICU4XLocaleFallbacker An object that runs the ICU4X locale fallback algorithm. diff --git a/ffi/diplomat/js/include/ICU4XLocaleFallbackConfig.d.ts b/ffi/diplomat/js/include/ICU4XLocaleFallbackConfig.d.ts index 30bc9d99f76..58c1f792326 100644 --- a/ffi/diplomat/js/include/ICU4XLocaleFallbackConfig.d.ts +++ b/ffi/diplomat/js/include/ICU4XLocaleFallbackConfig.d.ts @@ -1,4 +1,5 @@ import { ICU4XLocaleFallbackPriority } from "./ICU4XLocaleFallbackPriority"; +import { ICU4XLocaleFallbackSupplement } from "./ICU4XLocaleFallbackSupplement"; /** @@ -9,4 +10,5 @@ import { ICU4XLocaleFallbackPriority } from "./ICU4XLocaleFallbackPriority"; export class ICU4XLocaleFallbackConfig { priority: ICU4XLocaleFallbackPriority; extension_key: string; + fallback_supplement: ICU4XLocaleFallbackSupplement; } diff --git a/ffi/diplomat/js/include/ICU4XLocaleFallbackConfig.js b/ffi/diplomat/js/include/ICU4XLocaleFallbackConfig.js index 56e883cdaea..f327a084bee 100644 --- a/ffi/diplomat/js/include/ICU4XLocaleFallbackConfig.js +++ b/ffi/diplomat/js/include/ICU4XLocaleFallbackConfig.js @@ -1,6 +1,7 @@ import wasm from "./diplomat-wasm.mjs" import * as diplomatRuntime from "./diplomat-runtime.js" import { ICU4XLocaleFallbackPriority_js_to_rust, ICU4XLocaleFallbackPriority_rust_to_js } from "./ICU4XLocaleFallbackPriority.js" +import { ICU4XLocaleFallbackSupplement_js_to_rust, ICU4XLocaleFallbackSupplement_rust_to_js } from "./ICU4XLocaleFallbackSupplement.js" export class ICU4XLocaleFallbackConfig { constructor(underlying, edges_a) { @@ -9,5 +10,6 @@ export class ICU4XLocaleFallbackConfig { const [ptr, size] = new Uint32Array(wasm.memory.buffer, underlying + 4, 2); return diplomatRuntime.readString(wasm, ptr, size); })(); + this.fallback_supplement = ICU4XLocaleFallbackSupplement_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, underlying + 12)]; } } diff --git a/ffi/diplomat/js/include/ICU4XLocaleFallbackSupplement.d.ts b/ffi/diplomat/js/include/ICU4XLocaleFallbackSupplement.d.ts new file mode 100644 index 00000000000..8fc00bb1b08 --- /dev/null +++ b/ffi/diplomat/js/include/ICU4XLocaleFallbackSupplement.d.ts @@ -0,0 +1,15 @@ + +/** + + * What additional data is required to load when performing fallback. + + * See the {@link https://docs.rs/icu/latest/icu/locid_transform/fallback/enum.LocaleFallbackSupplement.html Rust documentation for `LocaleFallbackSupplement`} for more information. + */ +export enum ICU4XLocaleFallbackSupplement { + /** + */ + None = 'None', + /** + */ + Collation = 'Collation', +} \ No newline at end of file diff --git a/ffi/diplomat/js/include/ICU4XLocaleFallbackSupplement.js b/ffi/diplomat/js/include/ICU4XLocaleFallbackSupplement.js new file mode 100644 index 00000000000..c9caa34aeaf --- /dev/null +++ b/ffi/diplomat/js/include/ICU4XLocaleFallbackSupplement.js @@ -0,0 +1,17 @@ +import wasm from "./diplomat-wasm.mjs" +import * as diplomatRuntime from "./diplomat-runtime.js" + +export const ICU4XLocaleFallbackSupplement_js_to_rust = { + "None": 0, + "Collation": 1, +}; + +export const ICU4XLocaleFallbackSupplement_rust_to_js = { + [0]: "None", + [1]: "Collation", +}; + +export const ICU4XLocaleFallbackSupplement = { + "None": "None", + "Collation": "Collation", +}; diff --git a/ffi/diplomat/js/include/ICU4XLocaleFallbacker.js b/ffi/diplomat/js/include/ICU4XLocaleFallbacker.js index 0ec01f33f30..8163c11bac5 100644 --- a/ffi/diplomat/js/include/ICU4XLocaleFallbacker.js +++ b/ffi/diplomat/js/include/ICU4XLocaleFallbacker.js @@ -2,6 +2,7 @@ import wasm from "./diplomat-wasm.mjs" import * as diplomatRuntime from "./diplomat-runtime.js" import { ICU4XError_js_to_rust, ICU4XError_rust_to_js } from "./ICU4XError.js" import { ICU4XLocaleFallbackPriority_js_to_rust, ICU4XLocaleFallbackPriority_rust_to_js } from "./ICU4XLocaleFallbackPriority.js" +import { ICU4XLocaleFallbackSupplement_js_to_rust, ICU4XLocaleFallbackSupplement_rust_to_js } from "./ICU4XLocaleFallbackSupplement.js" import { ICU4XLocaleFallbackerWithConfig } from "./ICU4XLocaleFallbackerWithConfig.js" const ICU4XLocaleFallbacker_box_destroy_registry = new FinalizationRegistry(underlying => { @@ -43,9 +44,10 @@ export class ICU4XLocaleFallbacker { const field_priority_arg_config = arg_config["priority"]; const field_extension_key_arg_config = arg_config["extension_key"]; const buf_field_extension_key_arg_config = diplomatRuntime.DiplomatBuf.str(wasm, field_extension_key_arg_config); + const field_fallback_supplement_arg_config = arg_config["fallback_supplement"]; const diplomat_out = (() => { const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4); - wasm.ICU4XLocaleFallbacker_for_config(diplomat_receive_buffer, this.underlying, ICU4XLocaleFallbackPriority_js_to_rust[field_priority_arg_config], buf_field_extension_key_arg_config.ptr, buf_field_extension_key_arg_config.size); + wasm.ICU4XLocaleFallbacker_for_config(diplomat_receive_buffer, this.underlying, ICU4XLocaleFallbackPriority_js_to_rust[field_priority_arg_config], buf_field_extension_key_arg_config.ptr, buf_field_extension_key_arg_config.size, ICU4XLocaleFallbackSupplement_js_to_rust[field_fallback_supplement_arg_config]); const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4); if (is_ok) { const ok_value = new ICU4XLocaleFallbackerWithConfig(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, [this]); diff --git a/ffi/diplomat/js/include/index.d.ts b/ffi/diplomat/js/include/index.d.ts index 6595829c3be..9e966117926 100644 --- a/ffi/diplomat/js/include/index.d.ts +++ b/ffi/diplomat/js/include/index.d.ts @@ -83,6 +83,7 @@ export { ICU4XLocaleExpander } from './ICU4XLocaleExpander.js'; export { ICU4XLocaleFallbackConfig } from './ICU4XLocaleFallbackConfig.js'; export { ICU4XLocaleFallbackIterator } from './ICU4XLocaleFallbackIterator.js'; export { ICU4XLocaleFallbackPriority } from './ICU4XLocaleFallbackPriority.js'; +export { ICU4XLocaleFallbackSupplement } from './ICU4XLocaleFallbackSupplement.js'; export { ICU4XLocaleFallbacker } from './ICU4XLocaleFallbacker.js'; export { ICU4XLocaleFallbackerWithConfig } from './ICU4XLocaleFallbackerWithConfig.js'; export { ICU4XLogger } from './ICU4XLogger.js'; diff --git a/ffi/diplomat/js/include/index.js b/ffi/diplomat/js/include/index.js index 17008b51ebc..eed06fd21e7 100644 --- a/ffi/diplomat/js/include/index.js +++ b/ffi/diplomat/js/include/index.js @@ -83,6 +83,7 @@ export { ICU4XLocaleExpander } from './ICU4XLocaleExpander.js'; export { ICU4XLocaleFallbackConfig } from './ICU4XLocaleFallbackConfig.js'; export { ICU4XLocaleFallbackIterator } from './ICU4XLocaleFallbackIterator.js'; export { ICU4XLocaleFallbackPriority } from './ICU4XLocaleFallbackPriority.js'; +export { ICU4XLocaleFallbackSupplement } from './ICU4XLocaleFallbackSupplement.js'; export { ICU4XLocaleFallbacker } from './ICU4XLocaleFallbacker.js'; export { ICU4XLocaleFallbackerWithConfig } from './ICU4XLocaleFallbackerWithConfig.js'; export { ICU4XLogger } from './ICU4XLogger.js'; diff --git a/ffi/diplomat/src/fallbacker.rs b/ffi/diplomat/src/fallbacker.rs index 92d45460d5d..d616d503684 100644 --- a/ffi/diplomat/src/fallbacker.rs +++ b/ffi/diplomat/src/fallbacker.rs @@ -39,6 +39,18 @@ pub mod ffi { Collation = 2, } + /// What additional data is required to load when performing fallback. + #[diplomat::rust_link(icu::locid_transform::fallback::LocaleFallbackSupplement, Enum)] + #[diplomat::rust_link( + icu::locid_transform::fallback::LocaleFallbackSupplement::const_default, + FnInEnum, + hidden + )] + pub enum ICU4XLocaleFallbackSupplement { + None = 0, + Collation = 1, + } + /// Collection of configurations for the ICU4X fallback algorithm. #[diplomat::rust_link(icu::locid_transform::fallback::LocaleFallbackConfig, Struct)] #[diplomat::rust_link( @@ -51,6 +63,8 @@ pub mod ffi { pub priority: ICU4XLocaleFallbackPriority, /// An empty string is considered `None`. pub extension_key: &'a str, + /// Fallback supplement data key to customize fallback rules. + pub fallback_supplement: ICU4XLocaleFallbackSupplement, } /// An object that runs the ICU4X locale fallback algorithm with specific configurations. @@ -170,6 +184,12 @@ impl TryFrom> "" => None, s => Some(s.parse()?), }; + result.fallback_supplement = match other.fallback_supplement { + ffi::ICU4XLocaleFallbackSupplement::None => None, + ffi::ICU4XLocaleFallbackSupplement::Collation => { + Some(icu_locid_transform::fallback::LocaleFallbackSupplement::Collation) + } + }; Ok(result) } } diff --git a/ffi/diplomat/tests/missing_apis.txt b/ffi/diplomat/tests/missing_apis.txt index e2bf4f60429..33caa29238c 100644 --- a/ffi/diplomat/tests/missing_apis.txt +++ b/ffi/diplomat/tests/missing_apis.txt @@ -14,7 +14,6 @@ # Please check in with @Manishearth, @robertbastian, or @sffc if you have questions -icu::locid_transform::fallback::LocaleFallbackSupplement#Enum icu::properties::bidi_data::BidiAuxiliaryProperties#Struct icu::properties::bidi_data::BidiAuxiliaryProperties::from_data#FnInStruct icu::properties::bidi_data::BidiAuxiliaryPropertiesBorrowed#Struct