feat: lines macros
This commit is contained in:
parent
cc3d915877
commit
ed762a8dd4
9 changed files with 105 additions and 75 deletions
13
src/utils.rs
13
src/utils.rs
|
|
@ -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()))
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue