I want to match exactly one alphabetic character (a-zA-Z
) with nom.
I know I can match greedily using take_while!
with something like this:
// match one or more alphabetical characters
pub fn alpha_many(input: &[u8]) -> IResult<&[u8], &[u8]> {
take_while!(input, |c| {
(c >= 0x41 && c <= 0x5a) || (c >= 0x61 && c <= 0x7a)
})
}
But I can't find how to match only one byte. There is one_of!
, but I can't use a closure, I have to pass a whole slice:
// match exactly one alphabetical character
pub fn alpha_one(input: &[u8]) -> IResult<&[u8], u8> {
one_of!(
input,
[
0x41, 0x42, 0x43,
// etc until 0x5a and then from 0x61 to 0x7a
// ...
].as_ref()
)
}