From a327db72850a16dcbdc68dffd162ac853868a274 Mon Sep 17 00:00:00 2001 From: Damian Poddebniak Date: Sat, 15 May 2021 19:26:20 +0200 Subject: [PATCH] Add `number` parser. --- src/parse/mod.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/parse/mod.rs b/src/parse/mod.rs index 083fc96..de552a9 100644 --- a/src/parse/mod.rs +++ b/src/parse/mod.rs @@ -4,6 +4,7 @@ use abnf_core::streaming::{is_ALPHA, is_DIGIT}; use nom::{ branch::alt, bytes::streaming::{tag, take_while}, + character::streaming::digit1, combinator::{map_res, opt, recognize}, sequence::tuple, IResult, @@ -35,3 +36,7 @@ pub fn base64(input: &[u8]) -> IResult<&[u8], &str> { Ok((remaining, base64)) } + +pub fn number(input: &[u8]) -> IResult<&[u8], u32> { + map_res(map_res(digit1, from_utf8), str::parse::)(input) // FIXME(perf): use from_utf8_unchecked +}