From 8f8d72a749a39845fd03ae259533abe73dc7dcdf Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Tue, 9 Aug 2022 14:04:27 +0200 Subject: Add support for passing `ok`, `nok` as separate states to attempts --- src/content/string.rs | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'src/content/string.rs') diff --git a/src/content/string.rs b/src/content/string.rs index 697ec2c..b3df6ec 100644 --- a/src/content/string.rs +++ b/src/content/string.rs @@ -28,25 +28,27 @@ pub fn start(tokenizer: &mut Tokenizer) -> State { pub fn before(tokenizer: &mut Tokenizer) -> State { match tokenizer.current { None => State::Ok, - _ => tokenizer.attempt_n( - vec![ - StateName::CharacterReferenceStart, - StateName::CharacterEscapeStart, - ], - |ok| { - State::Fn(if ok { - StateName::StringBefore - } else { - StateName::StringBeforeData - }) - }, + Some(b'&') => tokenizer.attempt( + StateName::CharacterReferenceStart, + State::Fn(StateName::StringBefore), + State::Fn(StateName::StringBeforeData), ), + Some(b'\\') => tokenizer.attempt( + StateName::CharacterEscapeStart, + State::Fn(StateName::StringBefore), + State::Fn(StateName::StringBeforeData), + ), + _ => before_data(tokenizer), } } /// At data. pub fn before_data(tokenizer: &mut Tokenizer) -> State { - tokenizer.go(StateName::DataStart, StateName::StringBefore) + tokenizer.attempt( + StateName::DataStart, + State::Fn(StateName::StringBefore), + State::Nok, + ) } /// Resolve whitespace. -- cgit