diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2015-10-29 14:56:26 -0400 |
---|---|---|
committer | Dan Sinclair <dsinclair@chromium.org> | 2015-10-29 14:56:26 -0400 |
commit | 589f7e0a57675efce9810c15a3e9b7c49bf0bc90 (patch) | |
tree | 6839707c05c00f227744ffc3788665cb1cb5b7bd /core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp | |
parent | 6ed0028f1cf12ee53e9e7f657b7ba186c77a42f3 (diff) | |
download | pdfium-589f7e0a57675efce9810c15a3e9b7c49bf0bc90.tar.xz |
Cleanup some numeric code.
This changes the various comparisons of char >= '0' && char <= '9' and
char < '0' || char > '9' to use std::isdigit checks. It also cleans up
a handful of hex to digit conversions to call one common method.
R=thestig@chromium.org
Review URL: https://codereview.chromium.org/1415933005 .
Diffstat (limited to 'core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp')
-rw-r--r-- | core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp index 255d0ce29c..eaff29d812 100644 --- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp +++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_decode.cpp @@ -8,6 +8,7 @@ #include "../../../include/fpdfapi/fpdf_parser.h" #include "../../../include/fpdfapi/fpdf_module.h" #include "../../../include/fxcodec/fx_codec.h" +#include "../../../include/fxcrt/fx_ext.h" #define _STREAM_MAX_SIZE_ 20 * 1024 * 1024 @@ -135,23 +136,20 @@ FX_DWORD _HexDecode(const uint8_t* src_buf, continue; int digit; - if (ch <= '9' && ch >= '0') { - digit = ch - '0'; - } else if (ch <= 'f' && ch >= 'a') { - digit = ch - 'a' + 10; - } else if (ch <= 'F' && ch >= 'A') { - digit = ch - 'A' + 10; + if (std::isxdigit(ch)) { + digit = HexCharToDigit(ch); } else if (ch == '>') { i++; break; } else { continue; } - if (bFirstDigit) { + + if (bFirstDigit) dest_buf[dest_size] = digit * 16; - } else { + else dest_buf[dest_size++] += digit; - } + bFirstDigit = !bFirstDigit; } if (!bFirstDigit) { |