diff options
author | Martin Fischer <martin@push-f.com> | 2023-09-15 08:36:30 +0200 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2023-09-28 10:36:08 +0200 |
commit | 2e986862920b438b253fd6e6f11d8f4e5d6f4e27 (patch) | |
tree | 2b9dc395ddc52ff1843580ad0f0f43501d4471d9 /src/tokenizer/machine.rs | |
parent | 01661b3a5060cde9b44ae2543e1186139d99bdd3 (diff) |
chore: use let...else
Diffstat (limited to 'src/tokenizer/machine.rs')
-rw-r--r-- | src/tokenizer/machine.rs | 55 |
1 files changed, 27 insertions, 28 deletions
diff --git a/src/tokenizer/machine.rs b/src/tokenizer/machine.rs index b6291b5..ff72a7c 100644 --- a/src/tokenizer/machine.rs +++ b/src/tokenizer/machine.rs @@ -1801,39 +1801,38 @@ where State::NamedCharacterReference => { let first_char = slf.read_char()?.unwrap(); // unwrap cannot panic since we just unread the char - let char_ref = - try_read_character_reference(first_char, |x| slf.try_read_string(x, true))?; - - if let Some(char_ref) = char_ref { - slf.temporary_buffer.push(first_char); - slf.temporary_buffer.push_str(char_ref.name); - let char_ref_name_last_character = char_ref.name.chars().last(); + let Some(char_ref) = + try_read_character_reference(first_char, |x| slf.try_read_string(x, true))? + else { + slf.unread_char(Some(first_char)); + slf.flush_code_points_consumed_as_character_reference(); + slf.state = State::AmbiguousAmpersand; + return Ok(ControlToken::Continue); + }; - let next_character = slf.read_char()?; - slf.unread_char(next_character); + slf.temporary_buffer.push(first_char); + slf.temporary_buffer.push_str(char_ref.name); + let char_ref_name_last_character = char_ref.name.chars().last(); - if slf.is_consumed_as_part_of_an_attribute() - && char_ref_name_last_character != Some(';') - && matches!(next_character, Some(x) if x == '=' || x.is_ascii_alphanumeric()) - { - slf.flush_code_points_consumed_as_character_reference(); - slf.state = slf.return_state.take().unwrap(); - Ok(ControlToken::Continue) - } else { - if char_ref_name_last_character != Some(';') { - slf.emit_error(Error::MissingSemicolonAfterCharacterReference); - } + let next_character = slf.read_char()?; + slf.unread_char(next_character); - slf.temporary_buffer.clear(); - slf.temporary_buffer.push_str(char_ref.characters); - slf.flush_code_points_consumed_as_character_reference(); - slf.state = slf.return_state.take().unwrap(); - Ok(ControlToken::Continue) - } + if slf.is_consumed_as_part_of_an_attribute() + && char_ref_name_last_character != Some(';') + && matches!(next_character, Some(x) if x == '=' || x.is_ascii_alphanumeric()) + { + slf.flush_code_points_consumed_as_character_reference(); + slf.state = slf.return_state.take().unwrap(); + Ok(ControlToken::Continue) } else { - slf.unread_char(Some(first_char)); + if char_ref_name_last_character != Some(';') { + slf.emit_error(Error::MissingSemicolonAfterCharacterReference); + } + + slf.temporary_buffer.clear(); + slf.temporary_buffer.push_str(char_ref.characters); slf.flush_code_points_consumed_as_character_reference(); - slf.state = State::AmbiguousAmpersand; + slf.state = slf.return_state.take().unwrap(); Ok(ControlToken::Continue) } } |