From 9906b7b3b658b5f08a8dc583d733a8dd53fa69bb Mon Sep 17 00:00:00 2001 From: Robert Bastian <4706271+robertbastian@users.noreply.github.com> Date: Fri, 1 Dec 2023 13:05:03 +0100 Subject: [PATCH] Remove `IanaToBcp47MapperBorrowed::get_bytes` --- components/timezone/src/iana_ids.rs | 7 +------ ffi/capi/src/timezone.rs | 16 +++++++++------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/components/timezone/src/iana_ids.rs b/components/timezone/src/iana_ids.rs index 616e486b9dc..5514a005085 100644 --- a/components/timezone/src/iana_ids.rs +++ b/components/timezone/src/iana_ids.rs @@ -105,15 +105,10 @@ impl<'a> IanaToBcp47MapperBorrowed<'a> { /// /// [ECMAScript Temporal]: https://tc39.es/proposal-temporal/#sec-isavailabletimezonename pub fn get(&self, iana_id: &str) -> Option { - self.get_bytes(iana_id.as_bytes()) - } - - #[doc(hidden)] - pub fn get_bytes(&self, iana_id: &[u8]) -> Option { // The longest IANA name in CLDR appears to be "America/Argentina/ComodRivadavia" // which is 32 characters long, so 48 should be plenty. Add a debug assertion // just in case. - let name_for_lookup = match tinystr::TinyAsciiStr::<48>::from_bytes(iana_id) { + let name_for_lookup = match tinystr::TinyAsciiStr::<48>::from_bytes(iana_id.as_bytes()) { Ok(tinystr) => tinystr.to_ascii_lowercase(), Err(tinystr::TinyStrError::TooLarge { .. }) => { debug_assert!(false, "IANA string too long for lookup"); diff --git a/ffi/capi/src/timezone.rs b/ffi/capi/src/timezone.rs index 0757bb4d243..98e7e0b5d10 100644 --- a/ffi/capi/src/timezone.rs +++ b/ffi/capi/src/timezone.rs @@ -147,13 +147,15 @@ pub mod ffi { mapper: &crate::iana_bcp47_mapper::ffi::ICU4XIanaToBcp47Mapper, id: &DiplomatStr, ) -> Result<(), ICU4XError> { - match mapper.0.as_borrowed().get_bytes(id) { - Some(id) => { - self.0.time_zone_id = Some(id); - Ok(()) - } - None => Err(ICU4XError::TimeZoneInvalidIdError), - } + let id = core::str::from_utf8(id).map_err(|_| ICU4XError::TimeZoneInvalidIdError)?; + self.0.time_zone_id = Some( + mapper + .0 + .as_borrowed() + .get(id) + .ok_or(ICU4XError::TimeZoneInvalidIdError)?, + ); + Ok(()) } /// Clears the `time_zone_id` field.