Skip to content
Open
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
1 change: 0 additions & 1 deletion Cargo.lock

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

1 change: 0 additions & 1 deletion components/collections/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ yoke = { workspace = true, features = ["derive"] }
zerofrom = { workspace = true, features = ["derive"] }
zerovec = { workspace = true, features = ["derive", "yoke"] }
potential_utf = { workspace = true, features = ["zerovec"] }
utf8_iter = { workspace = true }

serde = { workspace = true, features = ["derive"], optional = true }
databake = { workspace = true, features = ["derive"], optional = true }
Expand Down
19 changes: 14 additions & 5 deletions components/collections/src/codepointinvliststringlist/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,22 @@ impl<'data> CodePointInversionListAndStringList<'data> {

/// See [`Self::contains_str`]
pub fn contains_utf8(&self, s: &[u8]) -> bool {
use utf8_iter::Utf8CharsEx;
let mut chars = s.chars();
if let Some(first_char) = chars.next() {
if chars.next().is_none() {
return self.contains(first_char);
let single_char = s.get(0).and_then(|&first_byte| {
if first_byte.is_ascii() && s.len() == 1 {
return Some(first_byte as char);
}
let utf8_len = first_byte.leading_ones() as usize;
if utf8_len != s.len() {
return None;
}

str::from_utf8(&s[..utf8_len]).ok()?.chars().next()
});

if let Some(single_char) = single_char {
return self.contains(single_char);
}

self.str_list
.binary_search_by(|t| t.as_bytes().cmp(s))
.is_ok()
Expand Down
699 changes: 695 additions & 4 deletions components/collections/src/codepointtrie/cptrie.rs

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions components/collections/src/codepointtrie/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ pub enum Error {
/// [`CodePointTrie`](super::CodePointTrie) must be constructed from data vector long enough to accommodate fast-path access
#[displaydoc("CodePointTrie must be constructed from data vector long enough to accommodate fast-path access")]
DataTooShortForFastAccess,
/// [`CodePointTrie`](super::CodePointTrie) must be constructed from data vector long enough to accommodate direct ASCII access
#[displaydoc("CodePointTrie must be constructed from data vector long enough to accommodate direct ASCII access")]
DataTooShortForAsciiAccess,
}

impl core::error::Error for Error {}
Loading
Loading