summaryrefslogtreecommitdiff
path: root/core/src/fpdftext
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2015-11-16 13:09:00 -0500
committerDan Sinclair <dsinclair@chromium.org>2015-11-16 13:09:00 -0500
commit10cfea1fdafc8fcf1edd60bc783e9db9ef6229c0 (patch)
tree3cd1bc8e6a6b33391ea8ad83388a07ca4974f40b /core/src/fpdftext
parentec441e67745054ece5e3d736b60fffa2f7f8d20c (diff)
downloadpdfium-10cfea1fdafc8fcf1edd60bc783e9db9ef6229c0.tar.xz
Merge to XFA: Reland "Cleanup some numeric code.""
This reverts commit 0569ab0b11b723d9bca4ddd642b0cf8828c4bdd1. 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=tsepez@chromium.org Review URL: https://codereview.chromium.org/1449873003 . (cherry picked from commit 3f148915d12f54a946a0c0bf526162b79c39d650) Review URL: https://codereview.chromium.org/1452673002 .
Diffstat (limited to 'core/src/fpdftext')
-rw-r--r--core/src/fpdftext/fpdf_text.cpp8
-rw-r--r--core/src/fpdftext/fpdf_text_int.cpp12
2 files changed, 11 insertions, 9 deletions
diff --git a/core/src/fpdftext/fpdf_text.cpp b/core/src/fpdftext/fpdf_text.cpp
index 55ab483722..0b7a849c75 100644
--- a/core/src/fpdftext/fpdf_text.cpp
+++ b/core/src/fpdftext/fpdf_text.cpp
@@ -14,6 +14,9 @@
#include "third_party/base/nonstd_unique_ptr.h"
#include "txtproc.h"
+#include <cctype>
+#include <cwctype>
+
CFX_ByteString CharFromUnicodeAlt(FX_WCHAR unicode,
int destcp,
const FX_CHAR* defchar) {
@@ -436,10 +439,9 @@ void NormalizeString(CFX_WideString& str) {
static FX_BOOL IsNumber(CFX_WideString& str) {
for (int i = 0; i < str.GetLength(); i++) {
FX_WCHAR ch = str[i];
- if ((ch < '0' || ch > '9') && ch != '-' && ch != '+' && ch != '.' &&
- ch != ' ') {
+ // TODO(dsinclair): --.+ +.-- should probably not be a number.
+ if (!std::iswdigit(ch) && ch != '-' && ch != '+' && ch != '.' && ch != ' ')
return FALSE;
- }
}
return TRUE;
}
diff --git a/core/src/fpdftext/fpdf_text_int.cpp b/core/src/fpdftext/fpdf_text_int.cpp
index f02ca41e1a..0754757940 100644
--- a/core/src/fpdftext/fpdf_text_int.cpp
+++ b/core/src/fpdftext/fpdf_text_int.cpp
@@ -4,7 +4,8 @@
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-#include <ctype.h>
+#include <cctype>
+#include <cwctype>
#include <algorithm>
#include "core/include/fpdfapi/fpdf_module.h"
@@ -2446,8 +2447,8 @@ void CPDF_TextPageFind::ExtractFindWhat(const CFX_WideString& findwhat) {
FX_BOOL CPDF_TextPageFind::IsMatchWholeWord(const CFX_WideString& csPageText,
int startPos,
int endPos) {
- int char_left = 0;
- int char_right = 0;
+ FX_WCHAR char_left = 0;
+ FX_WCHAR char_right = 0;
int char_count = endPos - startPos + 1;
if (char_count < 1) {
return FALSE;
@@ -2463,12 +2464,11 @@ FX_BOOL CPDF_TextPageFind::IsMatchWholeWord(const CFX_WideString& csPageText,
}
if ((char_left > 'A' && char_left < 'a') ||
(char_left > 'a' && char_left < 'z') ||
- (char_left > 0xfb00 && char_left < 0xfb06) ||
- (char_left >= '0' && char_left <= '9') ||
+ (char_left > 0xfb00 && char_left < 0xfb06) || std::iswdigit(char_left) ||
(char_right > 'A' && char_right < 'a') ||
(char_right > 'a' && char_right < 'z') ||
(char_right > 0xfb00 && char_right < 0xfb06) ||
- (char_right >= '0' && char_right <= '9')) {
+ std::iswdigit(char_right)) {
return FALSE;
}
if (!(('A' > char_left || char_left > 'Z') &&