Skip to content

Commit

Permalink
Update anychar to use InputSplit
Browse files Browse the repository at this point in the history
  • Loading branch information
Stargateur committed Oct 30, 2021
1 parent 1fc4fa7 commit 5a75405
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
17 changes: 7 additions & 10 deletions src/character/complete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::lib::std::ops::{Range, RangeFrom, RangeTo};
use crate::traits::{
AsChar, FindToken, InputIter, InputLength, InputTake, InputTakeAtPosition, Slice,
};
use crate::traits::{Compare, CompareResult};
use crate::traits::{Compare, CompareResult, InputSplit};

/// Recognizes one character.
///
Expand Down Expand Up @@ -308,16 +308,13 @@ where
/// ```
pub fn anychar<T, E: ParseError<T>>(input: T) -> IResult<T, char, E>
where
T: InputIter + InputLength + Slice<RangeFrom<usize>>,
<T as InputIter>::Item: AsChar,
T: InputSplit,
<T as InputSplit>::Item: AsChar,
{
let mut it = input.iter_indices();
match it.next() {
None => Err(Err::Error(E::from_error_kind(input, ErrorKind::Eof))),
Some((_, c)) => match it.next() {
None => Ok((input.slice(input.input_len()..), c.as_char())),
Some((idx, _)) => Ok((input.slice(idx..), c.as_char())),
},
if let Some((first, tail)) = input.split_first() {
Ok((tail, first.as_char()))
} else {
Err(Err::Error(E::from_error_kind(input, ErrorKind::Eof)))
}
}

Expand Down
17 changes: 7 additions & 10 deletions src/character/streaming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::lib::std::ops::{Range, RangeFrom, RangeTo};
use crate::traits::{
AsChar, FindToken, InputIter, InputLength, InputTake, InputTakeAtPosition, Slice,
};
use crate::traits::{Compare, CompareResult};
use crate::traits::{Compare, CompareResult, InputSplit};

/// Recognizes one character.
///
Expand Down Expand Up @@ -288,16 +288,13 @@ where
/// ```
pub fn anychar<T, E: ParseError<T>>(input: T) -> IResult<T, char, E>
where
T: InputIter + InputLength + Slice<RangeFrom<usize>>,
<T as InputIter>::Item: AsChar,
T: InputSplit,
<T as InputSplit>::Item: AsChar,
{
let mut it = input.iter_indices();
match it.next() {
None => Err(Err::Incomplete(Needed::new(1))),
Some((_, c)) => match it.next() {
None => Ok((input.slice(input.input_len()..), c.as_char())),
Some((idx, _)) => Ok((input.slice(idx..), c.as_char())),
},
if let Some((first, tail)) = input.split_first() {
Ok((tail, first.as_char()))
} else {
Err(Err::Incomplete(Needed::new(1)))
}
}

Expand Down

0 comments on commit 5a75405

Please sign in to comment.