summaryrefslogtreecommitdiff
path: root/core/fxcrt/fx_basic_util.cpp
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2016-05-12 15:52:14 -0700
committerCommit bot <commit-bot@chromium.org>2016-05-12 15:52:14 -0700
commit28c7844c1ef5ea0c8727b890e9ff56b593119a00 (patch)
treea96e31bbff3c221a0030e3a8a6501a5f81379d0f /core/fxcrt/fx_basic_util.cpp
parentade9465067098d9f94a13f61741cebf4bb8aac47 (diff)
downloadpdfium-28c7844c1ef5ea0c8727b890e9ff56b593119a00.tar.xz
Add CFX_ByteStringC::CharAt() to avoid c_str() and casts.
Most of the time, we want to operate on chars as if they were unsigned, but there are a few places where we need the default (questionably signed) values. Consolidate the casting in a single place rather than forcing callers to get a char* ptr. BUG=pdfium:493 Review-Url: https://codereview.chromium.org/1972053003
Diffstat (limited to 'core/fxcrt/fx_basic_util.cpp')
-rw-r--r--core/fxcrt/fx_basic_util.cpp42
1 files changed, 20 insertions, 22 deletions
diff --git a/core/fxcrt/fx_basic_util.cpp b/core/fxcrt/fx_basic_util.cpp
index f69185653f..abb2b9472a 100644
--- a/core/fxcrt/fx_basic_util.cpp
+++ b/core/fxcrt/fx_basic_util.cpp
@@ -97,19 +97,19 @@ void CFX_PrivateData::ClearAll() {
void FX_atonum(const CFX_ByteStringC& strc, FX_BOOL& bInteger, void* pData) {
if (strc.Find('.') == -1) {
bInteger = TRUE;
- int cc = 0, integer = 0;
- const FX_CHAR* str = strc.c_str();
- int len = strc.GetLength();
- FX_BOOL bNegative = FALSE;
- if (str[0] == '+') {
+ int cc = 0;
+ int integer = 0;
+ FX_STRSIZE len = strc.GetLength();
+ bool bNegative = false;
+ if (strc[0] == '+') {
cc++;
- } else if (str[0] == '-') {
- bNegative = TRUE;
+ } else if (strc[0] == '-') {
+ bNegative = true;
cc++;
}
- while (cc < len && std::isdigit(str[cc])) {
+ while (cc < len && std::isdigit(strc[cc])) {
// TODO(dsinclair): This is not the right way to handle overflow.
- integer = integer * 10 + FXSYS_toDecimalDigit(str[cc]);
+ integer = integer * 10 + FXSYS_toDecimalDigit(strc.CharAt(cc));
if (integer < 0)
break;
cc++;
@@ -124,31 +124,30 @@ void FX_atonum(const CFX_ByteStringC& strc, FX_BOOL& bInteger, void* pData) {
}
}
FX_FLOAT FX_atof(const CFX_ByteStringC& strc) {
- if (strc.GetLength() == 0) {
+ if (strc.IsEmpty())
return 0.0;
- }
+
int cc = 0;
- FX_BOOL bNegative = FALSE;
- const FX_CHAR* str = strc.c_str();
+ bool bNegative = false;
int len = strc.GetLength();
- if (str[0] == '+') {
+ if (strc[0] == '+') {
cc++;
- } else if (str[0] == '-') {
+ } else if (strc[0] == '-') {
bNegative = TRUE;
cc++;
}
while (cc < len) {
- if (str[cc] != '+' && str[cc] != '-') {
+ if (strc[cc] != '+' && strc[cc] != '-') {
break;
}
cc++;
}
FX_FLOAT value = 0;
while (cc < len) {
- if (str[cc] == '.') {
+ if (strc[cc] == '.') {
break;
}
- value = value * 10 + FXSYS_toDecimalDigit(str[cc]);
+ value = value * 10 + FXSYS_toDecimalDigit(strc.CharAt(cc));
cc++;
}
static const FX_FLOAT fraction_scales[] = {
@@ -156,14 +155,13 @@ FX_FLOAT FX_atof(const CFX_ByteStringC& strc) {
0.00001f, 0.000001f, 0.0000001f, 0.00000001f,
0.000000001f, 0.0000000001f, 0.00000000001f};
int scale = 0;
- if (cc < len && str[cc] == '.') {
+ if (cc < len && strc[cc] == '.') {
cc++;
while (cc < len) {
- value += fraction_scales[scale] * FXSYS_toDecimalDigit(str[cc]);
+ value += fraction_scales[scale] * FXSYS_toDecimalDigit(strc.CharAt(cc));
scale++;
- if (scale == sizeof fraction_scales / sizeof(FX_FLOAT)) {
+ if (scale == FX_ArraySize(fraction_scales))
break;
- }
cc++;
}
}