MCPcopy Create free account
hub / github.com/csskit/csskit / consume_ident_sequence

Method consume_ident_sequence

crates/css_lexer/src/private.rs:202–321  ·  view source on GitHub ↗
(&mut self, atoms: &dyn DynAtomSet)

Source from the content-addressed store, hash-verified

200 }
201
202 fn consume_ident_sequence(&mut self, atoms: &dyn DynAtomSet) -> (u32, bool, bool, bool, u32, bool) {
203 let mut dashed_ident = false;
204 let mut contains_non_lower_ascii = false;
205 let mut contains_escape = false;
206
207 let remaining = self.remaining_bytes();
208 if !remaining.is_empty() {
209 let bytes = remaining;
210 let end = bytes.len();
211 let mut i = 0;
212 if bytes.len() >= 2 && bytes[0] == b'-' && bytes[1] == b'-' {
213 i = 2;
214 dashed_ident = true;
215 }
216 let scan_start = i;
217 while i < end {
218 let byte = bytes[i];
219 if !is_ident_byte(byte) {
220 break;
221 }
222 contains_non_lower_ascii |= byte.wrapping_sub(b'A') < 26;
223 i += 1;
224 }
225
226 let ascii_len = (i - scan_start) as u32;
227 let len = i as u32;
228 if ascii_len > 0 {
229 let next_byte = if i < end { bytes[i] } else { b' ' };
230 if next_byte < 128 && !is_ident_byte(next_byte) && next_byte != b'\\' && next_byte != 0 {
231 // SAFETY: the fast path only scans ASCII ident bytes, which are valid UTF-8.
232 let ident_str = unsafe { std::str::from_utf8_unchecked(&bytes[..i]) };
233 self.advance_n(i);
234 let atom_bits =
235 if dashed_ident { atoms.str_to_bits(&ident_str[2..]) } else { atoms.str_to_bits(ident_str) };
236 return (
237 len,
238 contains_non_lower_ascii,
239 dashed_ident,
240 false,
241 atom_bits,
242 ascii_len == 3 && is_url_ident(ident_str),
243 );
244 }
245 }
246 }
247
248 let str = self.remaining_str();
249 let mut len: u32 = 0;
250 let mut small_ident = SmallStrBuf::<MAX_SMALL_IDENT_SIZE>::new();
251
252 loop {
253 let c = self.peek_char();
254 if c == EOF && self.at_end() {
255 break;
256 }
257 // Most common case first: lowercase ASCII, digits, or dash (except leading dash)
258 if is_ident_ascii_lower_or_digit(c) || (c == '-' && len > 0) {
259 self.pos += 1; // ASCII, 1 byte

Callers 4

consume_numeric_tokenMethod · 0.80
consume_hash_tokenMethod · 0.80
read_next_tokenMethod · 0.80

Calls 15

is_ident_byteFunction · 0.85
is_url_identFunction · 0.85
is_identFunction · 0.85
is_escape_sequenceFunction · 0.85
remaining_bytesMethod · 0.80
advance_nMethod · 0.80
remaining_strMethod · 0.80
peek_charMethod · 0.80
peek_char_atMethod · 0.80
over_capacityMethod · 0.80

Tested by

no test coverage detected