skip parsed line if invalid key:value
This commit is contained in:
@@ -11,8 +11,6 @@ pub enum ParseError {
|
|||||||
IoError(IoError),
|
IoError(IoError),
|
||||||
/// The initial data of an `.osu` file was incorrect.
|
/// The initial data of an `.osu` file was incorrect.
|
||||||
IncorrectFileHeader,
|
IncorrectFileHeader,
|
||||||
/// Line in `.osu` was unexpectedly not of the form `key:value`.
|
|
||||||
BadLine,
|
|
||||||
/// Line in `.osu` that contains a slider was not in the proper format.
|
/// Line in `.osu` that contains a slider was not in the proper format.
|
||||||
InvalidCurvePoints,
|
InvalidCurvePoints,
|
||||||
/// Expected a decimal number, got something else.
|
/// Expected a decimal number, got something else.
|
||||||
@@ -30,7 +28,6 @@ impl fmt::Display for ParseError {
|
|||||||
Self::IncorrectFileHeader => {
|
Self::IncorrectFileHeader => {
|
||||||
write!(f, "expected `osu file format v` at file begin")
|
write!(f, "expected `osu file format v` at file begin")
|
||||||
}
|
}
|
||||||
Self::BadLine => f.write_str("line not in `Key:Value` pattern"),
|
|
||||||
Self::InvalidCurvePoints => f.write_str("invalid curve point"),
|
Self::InvalidCurvePoints => f.write_str("invalid curve point"),
|
||||||
Self::InvalidDecimalNumber => f.write_str("invalid float number"),
|
Self::InvalidDecimalNumber => f.write_str("invalid float number"),
|
||||||
Self::InvalidMode => f.write_str("invalid mode"),
|
Self::InvalidMode => f.write_str("invalid mode"),
|
||||||
@@ -44,7 +41,6 @@ impl StdError for ParseError {
|
|||||||
match self {
|
match self {
|
||||||
Self::IoError(inner) => Some(inner),
|
Self::IoError(inner) => Some(inner),
|
||||||
Self::IncorrectFileHeader => None,
|
Self::IncorrectFileHeader => None,
|
||||||
Self::BadLine => None,
|
|
||||||
Self::InvalidCurvePoints => None,
|
Self::InvalidCurvePoints => None,
|
||||||
Self::InvalidDecimalNumber => None,
|
Self::InvalidDecimalNumber => None,
|
||||||
Self::InvalidMode => None,
|
Self::InvalidMode => None,
|
||||||
|
|||||||
+8
-2
@@ -115,7 +115,10 @@ macro_rules! parse_general_body {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
let (key, value) = $reader.split_colon().ok_or(ParseError::BadLine)?;
|
let (key, value) = match $reader.split_colon() {
|
||||||
|
Some(tuple) => tuple,
|
||||||
|
None => continue,
|
||||||
|
};
|
||||||
|
|
||||||
if key == b"Mode" {
|
if key == b"Mode" {
|
||||||
mode = match value {
|
mode = match value {
|
||||||
@@ -159,7 +162,10 @@ macro_rules! parse_difficulty_body {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
let (key, value) = $reader.split_colon().ok_or(ParseError::BadLine)?;
|
let (key, value) = match $reader.split_colon() {
|
||||||
|
Some(tuple) => tuple,
|
||||||
|
None => continue,
|
||||||
|
};
|
||||||
|
|
||||||
match key {
|
match key {
|
||||||
b"ApproachRate" => {
|
b"ApproachRate" => {
|
||||||
|
|||||||
+7
-3
@@ -186,11 +186,15 @@ impl<R> FileReader<R> {
|
|||||||
|
|
||||||
/// Split the buffer at the first ':', then parse the second half into a string.
|
/// 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.
|
/// Returns `None` if the second half is invalid UTF-8.
|
||||||
pub(crate) fn split_colon(&self) -> Option<(&[u8], &str)> {
|
pub(crate) fn split_colon(&self) -> Option<(&[u8], &str)> {
|
||||||
let idx = self.buf.iter().position(|&byte| byte == b':')?;
|
let idx = match self.buf.iter().position(|&byte| byte == b':') {
|
||||||
let front = &self.buf[..idx];
|
Some(idx) => idx,
|
||||||
|
None => return Some((&self.buf, "")),
|
||||||
|
};
|
||||||
|
|
||||||
let back = std::str::from_utf8(&self.buf[idx + 1..]).ok()?;
|
let back = std::str::from_utf8(&self.buf[idx + 1..]).ok()?;
|
||||||
|
let front = &self.buf[..idx];
|
||||||
|
|
||||||
Some((front, back.trim_start()))
|
Some((front, back.trim_start()))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user