feat: lines macros

This commit is contained in:
PoiScript 2019-01-20 19:04:12 +08:00
parent cc3d915877
commit ed762a8dd4
9 changed files with 105 additions and 75 deletions

View file

@ -112,10 +112,10 @@ macro_rules! starts_with {
#[macro_export]
macro_rules! skip_space {
($src:ident) => {
until!($src, |c| c != b' ').unwrap_or(0)
until!($src, |c| c != b' ' && c != b'\t').unwrap_or(0)
};
($src:ident, $from:expr) => {
until!($src[$from..], |c| c != b' ').unwrap_or(0) + $from
until!($src[$from..], |c| c != b' ' && c != b'\t').unwrap_or(0) + $from
};
}
@ -154,3 +154,12 @@ macro_rules! parse_succ {
);
};
}
#[macro_export]
macro_rules! lines {
($src:ident) => {
memchr::memchr_iter(b'\n', $src.as_bytes())
.map(|i| i + 1)
.chain(std::iter::once($src.len()))
};
}