Skip to content

Commit f141646

Browse files
committed
Increase position outside of XmlSource::skip_one
1 parent 569b794 commit f141646

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed

src/reader/buffered_reader.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,12 @@ macro_rules! impl_buffered_source {
203203
}
204204
}
205205

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

210210
match self.peek_one() $(.$await)? ? {
211211
Some(b) if b == byte => {
212-
*position += 1;
213212
self $(.$reader)? .consume(1);
214213
Ok(true)
215214
}
@@ -220,8 +219,7 @@ macro_rules! impl_buffered_source {
220219
$($async)? fn peek_one(&mut self) -> Result<Option<u8>> {
221220
loop {
222221
break match self $(.$reader)? .fill_buf() $(.$await)? {
223-
Ok(n) if n.is_empty() => Ok(None),
224-
Ok(n) => Ok(Some(n[0])),
222+
Ok(n) => Ok(n.first().cloned()),
225223
Err(ref e) if e.kind() == io::ErrorKind::Interrupted => continue,
226224
Err(e) => Err(Error::Io(e.into())),
227225
};

src/reader/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,8 @@ macro_rules! read_until_open {
279279
}
280280

281281
// If we already at the `<` symbol, do not try to return an empty Text event
282-
if $reader.skip_one(b'<', &mut $self.state.offset) $(.$await)? ? {
282+
if $reader.skip_one(b'<') $(.$await)? ? {
283+
$self.state.offset += 1;
283284
$self.state.state = ParseState::OpenedTag;
284285
// Pass $buf to the next next iteration of parsing loop
285286
return Ok(Err($buf));
@@ -883,8 +884,8 @@ trait XmlSource<'r, B> {
883884
/// `true` if it matched.
884885
///
885886
/// # Parameters
886-
/// - `position`: Will be increased by 1 if byte is matched
887-
fn skip_one(&mut self, byte: u8, position: &mut usize) -> Result<bool>;
887+
/// - `byte`: Character to skip
888+
fn skip_one(&mut self, byte: u8) -> Result<bool>;
888889

889890
/// Return one character without consuming it, so that future `read_*` calls
890891
/// will still include it. On EOF, return `None`.

src/reader/slice_reader.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,12 +321,11 @@ impl<'a> XmlSource<'a, ()> for &'a [u8] {
321321
Ok(())
322322
}
323323

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

0 commit comments

Comments
 (0)