mirror of
https://codeberg.org/icewind/tf-log-parser.git
synced 2026-06-03 18:24:09 +02:00
minor parse optimizations
This commit is contained in:
parent
3f51270509
commit
97ad9d634b
3 changed files with 13 additions and 3 deletions
|
|
@ -285,7 +285,14 @@ fn param_parse_with<'a, T, P: Fn(&'a str) -> IResult<&'a str, T>>(
|
||||||
|
|
||||||
let input = &input[has_open as usize..];
|
let input = &input[has_open as usize..];
|
||||||
|
|
||||||
Ok((input.trim_start_matches(' '), value))
|
debug_assert!(
|
||||||
|
input.is_empty() || input.as_bytes()[0] == b' ',
|
||||||
|
"\"{}\" starts with space",
|
||||||
|
input
|
||||||
|
);
|
||||||
|
|
||||||
|
let input = &input[(!input.is_empty() as usize)..];
|
||||||
|
Ok((input, value))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -138,6 +138,7 @@ pub struct LineSplit<'a> {
|
||||||
|
|
||||||
impl<'a> LineSplit<'a> {
|
impl<'a> LineSplit<'a> {
|
||||||
pub fn new(input: &'a str) -> Self {
|
pub fn new(input: &'a str) -> Self {
|
||||||
|
let input = &input[2..]; //skip first
|
||||||
LineSplit {
|
LineSplit {
|
||||||
input,
|
input,
|
||||||
start: 0,
|
start: 0,
|
||||||
|
|
@ -152,7 +153,7 @@ impl<'a> Iterator for LineSplit<'a> {
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
match self.iter.next() {
|
match self.iter.next() {
|
||||||
Some(next) => {
|
Some(next) => {
|
||||||
let line = &self.input[self.start..next];
|
let line = &self.input[self.start..next - 1]; // -1 for the newline we strip
|
||||||
self.start = next + 2;
|
self.start = next + 2;
|
||||||
Some(line)
|
Some(line)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,11 +30,13 @@ fn event_parser(input: &str) -> Result<RawEvent> {
|
||||||
|
|
||||||
let (input, ty) = event_type_parser(&input[1..])?;
|
let (input, ty) = event_type_parser(&input[1..])?;
|
||||||
|
|
||||||
|
let params = &input[(!input.is_empty() as usize)..];
|
||||||
|
|
||||||
Ok(RawEvent {
|
Ok(RawEvent {
|
||||||
date,
|
date,
|
||||||
subject,
|
subject,
|
||||||
ty,
|
ty,
|
||||||
params: &input[1..],
|
params,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue