From c8451a74d31f3e0f78efac8f855b8a558bbddddf Mon Sep 17 00:00:00 2001 From: Clyde Gerber Date: Thu, 2 Nov 2023 15:40:47 -0400 Subject: [PATCH] feat: Implement uloc_openAvailableByType() - Add a new feature for ICU4C version 6.5 and above in which the new implementation will be available. - Change the signature of ULoc::get_available() to more closely match the ICU4C uloc_getAvailable() function signature. - Add the function ULoc::get_available_locales() to return an (uncached) collection of available locales. - Add the function ULoc::get_available_locales_by_type() to return a collection of available locales for the specified type. - Correct some configuration tags that used the plural 'features' incorrectly and were not functioning correctly as a result. --- rust_icu_uloc/src/lib.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/rust_icu_uloc/src/lib.rs b/rust_icu_uloc/src/lib.rs index 37a1940..767837e 100644 --- a/rust_icu_uloc/src/lib.rs +++ b/rust_icu_uloc/src/lib.rs @@ -369,8 +369,8 @@ impl ULoc { /// Implements `uloc_getAvailable`. pub fn get_available(n: i32) -> Result { - if n >= Self::count_available() { - panic!("n is greater than or equal to the value returned from count_available()"); + if (0 > n) || (n >= Self::count_available()) { + panic!("n is negative or greater than or equal to the value returned from count_available()"); } let label = unsafe { ffi::CStr::from_ptr(versioned_function!(uloc_getAvailable)(n)).to_str().unwrap() }; ULoc::try_from(label) @@ -1295,8 +1295,14 @@ mod tests { } #[test] - #[should_panic(expected = "n is greater than or equal to the value returned from count_available()")] - fn test_get_available_error() { + #[should_panic(expected = "n is negative or greater than or equal to the value returned from count_available()")] + fn test_get_available_negative() { + let _ = ULoc::get_available(-1); + } + + #[test] + #[should_panic(expected = "n is negative or greater than or equal to the value returned from count_available()")] + fn test_get_available_overrun() { let index = ULoc::count_available(); let _ = ULoc::get_available(index); }