Skip to content

Commit

Permalink
Use UnvalidatedStr for casemap unfold keys
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Jul 15, 2023
1 parent 553f49d commit 0660fe0
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions experimental/casemap/src/provider/unfold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#[cfg(feature = "datagen")]
use alloc::string::String;
use icu_provider::prelude::*;
use zerovec::ule::UnvalidatedStr;
use zerovec::ZeroMap;

/// Reverse case folding data. Maps from multi-character strings back
Expand All @@ -28,7 +29,7 @@ use zerovec::ZeroMap;
pub struct CaseMapUnfoldData<'data> {
#[cfg_attr(feature = "serde", serde(borrow))]
/// The actual map. Maps from strings to a list of codepoints, stored as a contiguous UTF-8 string
pub map: ZeroMap<'data, str, str>,
pub map: ZeroMap<'data, UnvalidatedStr, str>,
}

impl<'data> CaseMapUnfoldData<'data> {
Expand Down Expand Up @@ -75,7 +76,10 @@ impl<'data> CaseMapUnfoldData<'data> {
.ok_or(DataError::custom("Unfold: unpaired surrogate in key"))?;
let val = Self::decode_string(&row[string_width..])
.ok_or(DataError::custom("Unfold: unpaired surrogate in value"))?;
if map.try_append(key.as_ref(), val.as_ref()).is_some() {
if map
.try_append(UnvalidatedStr::from_str(&key), val.as_ref())
.is_some()
{
return Err(DataError::custom("Unfold: keys not sorted/unique"));
}
}
Expand All @@ -92,6 +96,6 @@ impl<'data> CaseMapUnfoldData<'data> {
// Given a string, returns another string representing the set of characters
// that case fold to that string.
pub(crate) fn get(&self, key: &str) -> Option<&str> {
self.map.get(key)
self.map.get(UnvalidatedStr::from_str(key))
}
}

0 comments on commit 0660fe0

Please sign in to comment.