From 589f7e0a57675efce9810c15a3e9b7c49bf0bc90 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Thu, 29 Oct 2015 14:56:26 -0400 Subject: 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 . --- core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp | 2 +- .../src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp | 31 +++++++--------------- 2 files changed, 10 insertions(+), 23 deletions(-) (limited to 'core/src/fpdfapi/fpdf_page') diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp index 3057948959..cc9b0fcbe8 100644 --- a/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp +++ b/core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp @@ -1540,7 +1540,7 @@ CFX_ByteString _FPDF_ByteStringFromHex(CFX_BinaryBuf& src_buf) { FX_DWORD size = src_buf.GetSize(); for (FX_DWORD i = 0; i < size; i++) { uint8_t ch = str[i]; - if (ch >= '0' && ch <= '9') { + if (std::isdigit(ch)) { if (bFirst) { code = (ch - '0') * 16; } else { diff --git a/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp b/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp index 1fa27e3805..88e2269c7a 100644 --- a/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp +++ b/core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp @@ -7,6 +7,7 @@ #include "../../../include/fpdfapi/fpdf_page.h" #include "../../../include/fpdfapi/fpdf_module.h" #include "../../../include/fxcodec/fx_codec.h" +#include "../../../include/fxcrt/fx_ext.h" #include "pageint.h" #include @@ -875,34 +876,20 @@ CFX_ByteString CPDF_StreamParser::ReadHexString() { FX_BOOL bFirst = TRUE; int code = 0; while (1) { - if (ch == '>') { + if (ch == '>') break; - } - if (ch >= '0' && ch <= '9') { - if (bFirst) { - code = (ch - '0') * 16; - } else { - code += ch - '0'; - buf.AppendChar((char)code); - } - bFirst = !bFirst; - } else if (ch >= 'A' && ch <= 'F') { - if (bFirst) { - code = (ch - 'A' + 10) * 16; - } else { - code += ch - 'A' + 10; - buf.AppendChar((char)code); - } - bFirst = !bFirst; - } else if (ch >= 'a' && ch <= 'f') { + + if (std::isxdigit(ch)) { + int val = HexCharToDigit(ch); if (bFirst) { - code = (ch - 'a' + 10) * 16; + code = val * 16; } else { - code += ch - 'a' + 10; - buf.AppendChar((char)code); + code += val; + buf.AppendByte((uint8_t)code); } bFirst = !bFirst; } + if (!PositionIsInBounds()) break; -- cgit v1.2.3