mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 12:22:34 +00:00
fix: remove manual hex parsing in ResultParser
This commit is contained in:
@@ -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<u32> {
|
||||
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)]
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user