mirror of
https://codeberg.org/icewind/tf-log-parser.git
synced 2026-06-03 10:14:10 +02:00
split -> memchr
This commit is contained in:
parent
c09508e9fa
commit
0a110dc0f0
3 changed files with 13 additions and 4 deletions
|
|
@ -18,6 +18,7 @@ serde_json = "1"
|
|||
main_error = "0.1"
|
||||
paste = "1"
|
||||
logos = "0.12"
|
||||
memchr = "2.5.0"
|
||||
|
||||
[dev-dependencies]
|
||||
criterion = "0.4"
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
extern crate core;
|
||||
|
||||
pub use crate::common::{SteamId3, SubjectData, SubjectError, SubjectId};
|
||||
use crate::event::GameEventError;
|
||||
pub use crate::module::EventHandler;
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ use logos::{Lexer, Logos};
|
|||
use nom::{IResult, Needed};
|
||||
use std::convert::{TryFrom, TryInto};
|
||||
use std::num::ParseIntError;
|
||||
use memchr::memchr;
|
||||
|
||||
/// Event that has only been minimally parsed.
|
||||
/// that way we can decide if we're interested in handling the event before parsing further
|
||||
|
|
@ -113,7 +114,7 @@ pub fn against_subject_parser(input: &str) -> IResult<&str, RawSubject> {
|
|||
|
||||
pub fn subject_parser(input: &str) -> Result<(&str, RawSubject)> {
|
||||
if let Some(input) = input.strip_prefix('"') {
|
||||
let (player, input) = input.split_once('"').ok_or(Error::Incomplete)?;
|
||||
let (player, input) = split_once(input, b'"', 1)?;
|
||||
if player.ends_with("e>") {
|
||||
Ok((input, RawSubject::Console))
|
||||
} else {
|
||||
|
|
@ -126,15 +127,20 @@ pub fn subject_parser(input: &str) -> Result<(&str, RawSubject)> {
|
|||
} else if &input[6..7] == "b" {
|
||||
Ok((&input[11..], RawSubject::Team(Team::Blue)))
|
||||
} else {
|
||||
let (_, input) = input[7..].split_once('"').ok_or(Error::Incomplete)?;
|
||||
let (_, input) = split_once(&input[7..], b'"', 1)?;
|
||||
Ok((input, RawSubject::Team(Team::Spectator)))
|
||||
}
|
||||
} else {
|
||||
let (system, _) = input.split_once(' ').ok_or(Error::Incomplete)?;
|
||||
Ok((&input[system.len()..], RawSubject::System(system)))
|
||||
let (system, input) = split_once(input, b' ', 0)?;
|
||||
Ok((input, RawSubject::System(system)))
|
||||
}
|
||||
}
|
||||
|
||||
fn split_once(input: &str, delim: u8, offset: usize) -> Result<(&str, &str)> {
|
||||
let end = memchr(delim, input.as_bytes()).ok_or(Error::Incomplete)?;
|
||||
Ok((&input[..end], &input[(end + offset)..]))
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Logos)]
|
||||
pub enum RawEventType {
|
||||
#[token(r#"joined"#)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue