diff --git a/src/client/result/ResultParser.rs b/src/client/result/ResultParser.rs index b411f62..e9e262c 100644 --- a/src/client/result/ResultParser.rs +++ b/src/client/result/ResultParser.rs @@ -226,17 +226,23 @@ pub fn unescapeBackslash(escaped: &str) -> String { unescaped } -pub fn parseHexDigit(c: char) -> i32 { - if c.is_ascii_digit() { - return (c as u8 - b'0') as i32; - } - if ('a'..='f').contains(&c) { - return 10 + (c as u8 - b'a') as i32; - } - if ('A'..='F').contains(&c) { - return 10 + (c as u8 - b'A') as i32; - } - -1 +#[inline(always)] +pub fn parseHexDigit(c: char) -> Option { + c.to_digit(16) + // let Some(v) = c.to_digit(16) else { + // return -1 + // }; + // v as i32 + // if c.is_ascii_digit() { + // return (c as u8 - b'0') as i32; + // } + // if ('a'..='f').contains(&c) { + // return 10 + (c as u8 - b'a') as i32; + // } + // if ('A'..='F').contains(&c) { + // return 10 + (c as u8 - b'A') as i32; + // } + // -1 } #[inline(always)] diff --git a/src/client/result/VCardResultParser.rs b/src/client/result/VCardResultParser.rs index b5e4e9c..a36dc4a 100644 --- a/src/client/result/VCardResultParser.rs +++ b/src/client/result/VCardResultParser.rs @@ -337,8 +337,10 @@ fn decodeQuotedPrintable(value: &str, charset: &str) -> String { let nextChar = value.chars().nth(i + 1).unwrap(); if nextChar != '\r' && nextChar != '\n' { let nextNextChar = value.chars().nth(i + 2).unwrap(); - let firstDigit = ResultParser::parseHexDigit(nextChar); - let secondDigit = ResultParser::parseHexDigit(nextNextChar); + let firstDigit = + ResultParser::parseHexDigit(nextChar).map_or_else(|| -1, |d| d as i32); + let secondDigit = + ResultParser::parseHexDigit(nextNextChar).map_or_else(|| -1, |d| d as i32); if firstDigit >= 0 && secondDigit >= 0 { fragmentBuffer.push(((firstDigit << 4) + secondDigit) as u8); } // else ignore it, assume it was incorrectly encoded