anticipate ansi encoding while parsing events

This commit is contained in:
MaxOhn
2022-07-12 22:00:58 +02:00
parent 18e79eab12
commit e81e388f70
2 changed files with 16 additions and 1 deletions
+5 -1
View File
@@ -176,7 +176,11 @@ macro_rules! parse_events_body {
break;
}
let line = $reader.get_line()?;
let line = match $reader.get_line() {
Ok(line) => line,
Err(_) => $reader.get_line_ascii()?, // see ranked map id 49374
};
let mut split = line.split(',');
// We're only interested in breaks
+11
View File
@@ -173,6 +173,17 @@ impl<R> FileReader<R> {
.map_err(|e| ParseError::IoError(IoError::new(IoErrorKind::InvalidData, Box::new(e))))
}
pub(crate) fn get_line_ascii(&mut self) -> Result<&str, ParseError> {
self.buf.iter_mut().for_each(|byte| {
if *byte >= 128 {
*byte = b'?';
}
});
std::str::from_utf8(&self.buf)
.map_err(|e| ParseError::IoError(IoError::new(IoErrorKind::InvalidData, Box::new(e))))
}
/// Split the buffer at the first ':', then parse the second half into a string.
///
/// Returns `None` if there is no ':' or if the second half is invalid UTF-8.