Skip to content
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
8 changes: 4 additions & 4 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -788,10 +788,10 @@ pub fn parse_until_before<'i: 't, 't, F, T, E>(parser: &mut Parser<'i, 't>,
}
// FIXME: have a special-purpose tokenizer method for this that does less work.
loop {
if delimiters.contains(Delimiters::from_byte((parser.input.tokenizer).next_byte())) {
if delimiters.contains(Delimiters::from_byte(parser.input.tokenizer.next_byte())) {
break
}
if let Ok(token) = (parser.input.tokenizer).next() {
if let Ok(token) = parser.input.tokenizer.next() {
if let Some(block_type) = BlockType::opening(&token) {
consume_until_end_of_block(block_type, &mut parser.input.tokenizer);
}
Expand All @@ -808,11 +808,11 @@ pub fn parse_until_after<'i: 't, 't, F, T, E>(parser: &mut Parser<'i, 't>,
-> Result <T, ParseError<'i, E>>
where F: for<'tt> FnOnce(&mut Parser<'i, 'tt>) -> Result<T, ParseError<'i, E>> {
let result = parser.parse_until_before(delimiters, parse);
let next_byte = (parser.input.tokenizer).next_byte();
let next_byte = parser.input.tokenizer.next_byte();
if next_byte.is_some() && !parser.stop_before.contains(Delimiters::from_byte(next_byte)) {
debug_assert!(delimiters.contains(Delimiters::from_byte(next_byte)));
// We know this byte is ASCII.
(parser.input.tokenizer).advance(1);
parser.input.tokenizer.advance(1);
if next_byte == Some(b'{') {
consume_until_end_of_block(BlockType::CurlyBracket, &mut parser.input.tokenizer);
}
Expand Down
18 changes: 6 additions & 12 deletions src/serializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,23 +132,17 @@ impl<'a> ToCss for Token<'a> {
}
}

fn to_hex_byte(value: u8) -> u8 {
match value {
0...9 => value + b'0',
_ => value - 10 + b'a',
}
}

fn hex_escape<W>(ascii_byte: u8, dest: &mut W) -> fmt::Result where W:fmt::Write {
let high = ascii_byte >> 4;
static HEX_DIGITS: &'static [u8; 16] = b"0123456789abcdef";
let b3;
let b4;
let bytes = if high > 0 {
let low = ascii_byte & 0x0F;
b4 = [b'\\', to_hex_byte(high), to_hex_byte(low), b' '];
let bytes = if ascii_byte > 0x0F {
let high = (ascii_byte >> 4) as usize;
let low = (ascii_byte & 0x0F) as usize;
b4 = [b'\\', HEX_DIGITS[high], HEX_DIGITS[low], b' '];
&b4[..]
} else {
b3 = [b'\\', to_hex_byte(ascii_byte), b' '];
b3 = [b'\\', HEX_DIGITS[ascii_byte as usize], b' '];
&b3[..]
};
dest.write_str(unsafe { str::from_utf8_unchecked(&bytes) })
Expand Down