Skip to content

Commit

Permalink
Add FFI for ICU4XLocaleFallbackSupplement
Browse files Browse the repository at this point in the history
  • Loading branch information
sffc committed Sep 21, 2023
1 parent 88e35c2 commit 83946f8
Show file tree
Hide file tree
Showing 18 changed files with 190 additions and 3 deletions.
3 changes: 3 additions & 0 deletions ffi/diplomat/c/include/ICU4XLocaleFallbackConfig.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions ffi/diplomat/c/include/ICU4XLocaleFallbackSupplement.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions ffi/diplomat/cpp/docs/source/fallbacker_ffi.rst

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions ffi/diplomat/cpp/include/ICU4XLocaleFallbackConfig.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions ffi/diplomat/cpp/include/ICU4XLocaleFallbackConfig.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions ffi/diplomat/cpp/include/ICU4XLocaleFallbackSupplement.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions ffi/diplomat/cpp/include/ICU4XLocaleFallbackSupplement.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ffi/diplomat/cpp/include/ICU4XLocaleFallbacker.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions ffi/diplomat/js/docs/source/fallbacker_ffi.rst

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions ffi/diplomat/js/include/ICU4XLocaleFallbackConfig.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions ffi/diplomat/js/include/ICU4XLocaleFallbackConfig.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions ffi/diplomat/js/include/ICU4XLocaleFallbackSupplement.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions ffi/diplomat/js/include/ICU4XLocaleFallbackSupplement.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion ffi/diplomat/js/include/ICU4XLocaleFallbacker.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ffi/diplomat/js/include/index.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ffi/diplomat/js/include/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions ffi/diplomat/src/fallbacker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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.
Expand Down Expand Up @@ -170,6 +184,12 @@ impl TryFrom<ffi::ICU4XLocaleFallbackConfig<'_>>
"" => 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)
}
}
1 change: 0 additions & 1 deletion ffi/diplomat/tests/missing_apis.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 83946f8

Please sign in to comment.