32 lines
978 B
Rust
Raw Normal View History

2020-04-20 14:30:56 -04:00
pub(crate) fn hex_char_for(number: u32) -> char {
2020-05-22 20:50:48 -04:00
debug_assert!(number < 0x10);
2020-04-20 14:30:56 -04:00
std::char::from_u32(if number < 0xA {
0x30 + number
} else {
0x61 - 0xA + number
})
.unwrap()
}
pub(crate) fn is_name(c: char) -> bool {
2020-05-25 00:57:59 -04:00
is_name_start(c) || c.is_ascii_digit() || c == '-'
2020-04-20 14:30:56 -04:00
}
pub(crate) fn is_name_start(c: char) -> bool {
// NOTE: in the dart-sass implementation, identifiers cannot start
// with numbers. We explicitly differentiate from the reference
// implementation here in order to support selectors beginning with numbers.
// This can be considered a hack and in the future it would be nice to refactor
// how this is handled.
c == '_' || c.is_alphanumeric() || c as u32 >= 0x0080
}
2020-04-20 14:35:16 -04:00
2020-04-23 21:30:25 -04:00
pub(crate) fn as_hex(c: char) -> u32 {
match c {
'0'..='9' => c as u32 - '0' as u32,
'A'..='F' => 10 + c as u32 - 'A' as u32,
'a'..='f' => 10 + c as u32 - 'a' as u32,
_ => panic!(),
2020-04-20 14:35:16 -04:00
}
}