Skip to content

Commit

Permalink
impl<'a> FindToken<char> for &'a [char]
Browse files Browse the repository at this point in the history
Close #1282.
  • Loading branch information
ctrlcctrlv authored and Geal committed Mar 14, 2022
1 parent dae689e commit bb8ef79
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,18 @@ impl<'a> FindToken<char> for &'a str {
}
}

impl<'a> FindToken<char> for &'a [char] {
fn find_token(&self, token: char) -> bool {
self.iter().any(|i| *i == token)
}
}

impl<'a, 'b> FindToken<&'a char> for &'b [char] {
fn find_token(&self, token: &char) -> bool {
self.find_token(*token)
}
}

/// Look for a substring in self
pub trait FindSubstring<T> {
/// Returns the byte position of the substring if it is found
Expand Down
8 changes: 8 additions & 0 deletions tests/issues.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,11 @@ fn issue_1231_bits_expect_fn_closure() {
}
assert_eq!(example(&[0xff]), Ok((&b""[..], (1, 1))));
}

#[test]
fn issue_1282_findtoken_char() {
use nom::character::complete::one_of;
use nom::error::Error;
let parser = one_of::<_, _, Error<_>>(['a', 'b', 'c'].as_slice());
assert_eq!(parser("aaa"), Ok(("aa", 'a')));
}

0 comments on commit bb8ef79

Please sign in to comment.