Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove IanaToBcp47MapperBorrowed::get_bytes #4398

Merged
merged 1 commit into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions components/timezone/src/iana_ids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TimeZoneBcp47Id> {
self.get_bytes(iana_id.as_bytes())
}

#[doc(hidden)]
pub fn get_bytes(&self, iana_id: &[u8]) -> Option<TimeZoneBcp47Id> {
// 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()) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should use manual iteration #4383

Ok(tinystr) => tinystr.to_ascii_lowercase(),
Err(tinystr::TinyStrError::TooLarge { .. }) => {
debug_assert!(false, "IANA string too long for lookup");
Expand Down
16 changes: 9 additions & 7 deletions ffi/capi/src/timezone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down