Skip to content

Commit

Permalink
Increase position outside of XmlSource::skip_one
Browse files Browse the repository at this point in the history
  • Loading branch information
Mingun authored and dralley committed Jun 9, 2024
1 parent 704ce89 commit 33b9dc5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
6 changes: 2 additions & 4 deletions src/reader/buffered_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,12 @@ macro_rules! impl_buffered_source {
}
}

$($async)? fn skip_one(&mut self, byte: u8, position: &mut usize) -> Result<bool> {
$($async)? fn skip_one(&mut self, byte: u8) -> Result<bool> {
// search byte must be within the ascii range
debug_assert!(byte.is_ascii());

match self.peek_one() $(.$await)? ? {
Some(b) if b == byte => {
*position += 1;
self $(.$reader)? .consume(1);
Ok(true)
}
Expand All @@ -219,8 +218,7 @@ macro_rules! impl_buffered_source {
$($async)? fn peek_one(&mut self) -> Result<Option<u8>> {
loop {
break match self $(.$reader)? .fill_buf() $(.$await)? {
Ok(n) if n.is_empty() => Ok(None),
Ok(n) => Ok(Some(n[0])),
Ok(n) => Ok(n.first().cloned()),
Err(ref e) if e.kind() == io::ErrorKind::Interrupted => continue,
Err(e) => Err(Error::Io(e.into())),
};
Expand Down
7 changes: 4 additions & 3 deletions src/reader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,8 @@ macro_rules! read_until_open {
}

// If we already at the `<` symbol, do not try to return an empty Text event
if $reader.skip_one(b'<', &mut $self.state.offset) $(.$await)? ? {
if $reader.skip_one(b'<') $(.$await)? ? {
$self.state.offset += 1;
$self.state.state = ParseState::OpenedTag;
// Pass $buf to the next next iteration of parsing loop
return Ok(Err($buf));
Expand Down Expand Up @@ -889,8 +890,8 @@ trait XmlSource<'r, B> {
/// `true` if it matched.
///
/// # Parameters
/// - `position`: Will be increased by 1 if byte is matched
fn skip_one(&mut self, byte: u8, position: &mut usize) -> Result<bool>;
/// - `byte`: Character to skip
fn skip_one(&mut self, byte: u8) -> Result<bool>;

/// Return one character without consuming it, so that future `read_*` calls
/// will still include it. On EOF, return `None`.
Expand Down
3 changes: 1 addition & 2 deletions src/reader/slice_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,12 +322,11 @@ impl<'a> XmlSource<'a, ()> for &'a [u8] {
Ok(())
}

fn skip_one(&mut self, byte: u8, position: &mut usize) -> Result<bool> {
fn skip_one(&mut self, byte: u8) -> Result<bool> {
// search byte must be within the ascii range
debug_assert!(byte.is_ascii());
if self.first() == Some(&byte) {
*self = &self[1..];
*position += 1;
Ok(true)
} else {
Ok(false)
Expand Down

0 comments on commit 33b9dc5

Please sign in to comment.