Convert closure to member function of `State`
@@ -1131,6 +1131,27 @@ impl<'b, 'i, R: BufRead + 'i> BufferedInput<'b, 'i, &'b mut Vec<u8>> for R {
/// Inside a double-quoted attribute value
DoubleQ,
}
+ impl State {
+ fn find<'b>(&mut self, end_byte: u8, bytes: &'b [u8]) -> Option<(&'b [u8], usize)> {
+ for i in memchr::memchr3_iter(end_byte, b'\'', b'"', bytes) {
+ *self = match (*self, bytes[i]) {
+ (State::Elem, b) if b == end_byte => {
+ // only allowed to match `end_byte` while we are in state `Elem`
+ return Some((&bytes[..i], i + 1));
+ }
+ (State::Elem, b'\'') => State::SingleQ,
+ (State::Elem, b'\"') => State::DoubleQ,
+
+ // the only end_byte that gets us out if the same character
+ (State::SingleQ, b'\'') | (State::DoubleQ, b'\"') => State::Elem,
+
+ // all other bytes: no state change
+ _ => *self,
+ };
+ }
+ None
+ }
+ }
let mut state = State::Elem;
let mut read = 0;
let mut done = false;
@@ -1154,26 +1175,7 @@ impl<'b, 'i, R: BufRead + 'i> BufferedInput<'b, 'i, &'b mut Vec<u8>> for R {
}
};
- let mut find = |end_byte, bytes| -> Option<(&[u8], usize)> {
- for i in memchr::memchr3_iter(end_byte, b'\'', b'"', bytes) {
- state = match (state, bytes[i]) {
- (State::Elem, b) if b == end_byte => {
- // only allowed to match `end_byte` while we are in state `Elem`
- return Some((&bytes[..i], i + 1));
- }
- (State::Elem, b'\'') => State::SingleQ,
- (State::Elem, b'\"') => State::DoubleQ,
-
- // the only end_byte that gets us out if the same character
- (State::SingleQ, b'\'') | (State::DoubleQ, b'\"') => State::Elem,
-
- // all other bytes: no state change
- _ => state,
- };
- }
- None
- };
- if let Some((consumed, used)) = find(b'>', available) {
+ if let Some((consumed, used)) = state.find(b'>', available) {
done = true;
buf.extend_from_slice(consumed);
used
