summaryrefslogtreecommitdiff
path: root/fpdfsdk
diff options
context:
space:
mode:
Diffstat (limited to 'fpdfsdk')
-rw-r--r--fpdfsdk/src/javascript/PublicMethods.cpp118
-rw-r--r--fpdfsdk/src/javascript/PublicMethods.h12
-rw-r--r--fpdfsdk/src/javascript/public_methods_embeddertest.cpp23
-rw-r--r--fpdfsdk/src/javascript/util.cpp5
4 files changed, 70 insertions, 88 deletions
diff --git a/fpdfsdk/src/javascript/PublicMethods.cpp b/fpdfsdk/src/javascript/PublicMethods.cpp
index c2e15fb116..6db31de1e7 100644
--- a/fpdfsdk/src/javascript/PublicMethods.cpp
+++ b/fpdfsdk/src/javascript/PublicMethods.cpp
@@ -103,7 +103,7 @@ FX_BOOL CJS_PublicMethods::IsNumber(const FX_WCHAR* string) {
} else {
return FALSE;
}
- } else if (!IsDigit(c)) {
+ } else if (!FXSYS_iswdigit(c)) {
return FALSE;
}
p++;
@@ -112,30 +112,14 @@ FX_BOOL CJS_PublicMethods::IsNumber(const FX_WCHAR* string) {
return TRUE;
}
-FX_BOOL CJS_PublicMethods::IsDigit(wchar_t ch) {
- return (ch >= L'0' && ch <= L'9');
-}
-
-FX_BOOL CJS_PublicMethods::IsDigit(char ch) {
- return std::isdigit(ch);
-}
-
-FX_BOOL CJS_PublicMethods::IsAlphabetic(wchar_t ch) {
- return ((ch >= L'a' && ch <= L'z') || (ch >= L'A' && ch <= L'Z'));
-}
-
-FX_BOOL CJS_PublicMethods::IsAlphaNumeric(wchar_t ch) {
- return (IsDigit(ch) || IsAlphabetic(ch));
-}
-
FX_BOOL CJS_PublicMethods::maskSatisfied(wchar_t c_Change, wchar_t c_Mask) {
switch (c_Mask) {
case L'9':
- return IsDigit(c_Change);
+ return FXSYS_iswdigit(c_Change);
case L'A':
- return IsAlphabetic(c_Change);
+ return FXSYS_iswalpha(c_Change);
case L'O':
- return IsAlphaNumeric(c_Change);
+ return FXSYS_iswalnum(c_Change);
case L'X':
return TRUE;
default:
@@ -254,7 +238,7 @@ double CJS_PublicMethods::ParseNumber(const FX_WCHAR* swSource,
while (p <= pEnd) {
c = *p;
- if (IsDigit(c)) {
+ if (FXSYS_iswdigit(c)) {
swDigits += c;
bDigitExist = TRUE;
} else {
@@ -396,12 +380,12 @@ int CJS_PublicMethods::ParseStringInteger(const CFX_WideString& string,
break;
FX_WCHAR c = string.GetAt(i);
- if (IsDigit((wchar_t)c)) {
- nRet = nRet * 10 + FXSYS_toDecimalDigitWide(c);
- nSkip = i - nStart + 1;
- if (nSkip >= nMaxStep)
- break;
- } else
+ if (!FXSYS_iswdigit(c))
+ break;
+
+ nRet = nRet * 10 + FXSYS_toDecimalDigitWide(c);
+ nSkip = i - nStart + 1;
+ if (nSkip >= nMaxStep)
break;
}
@@ -416,18 +400,18 @@ CFX_WideString CJS_PublicMethods::ParseStringString(
nSkip = 0;
for (int i = nStart, sz = string.GetLength(); i < sz; i++) {
FX_WCHAR c = string.GetAt(i);
- if ((c >= L'a' && c <= L'z') || (c >= L'A' && c <= L'Z')) {
- swRet += c;
- nSkip = i - nStart + 1;
- } else
+ if (!FXSYS_iswdigit(c))
break;
+
+ swRet += c;
+ nSkip = i - nStart + 1;
}
return swRet;
}
double CJS_PublicMethods::ParseNormalDate(const CFX_WideString& value,
- FX_BOOL& bWrongFormat) {
+ bool* bWrongFormat) {
double dt = JS_GetDateTime();
int nYear = JS_GetYearFromTime(dt);
@@ -448,7 +432,7 @@ double CJS_PublicMethods::ParseNormalDate(const CFX_WideString& value,
break;
FX_WCHAR c = value.GetAt(i);
- if (IsDigit((wchar_t)c)) {
+ if (FXSYS_iswdigit(c)) {
number[nIndex++] = ParseStringInteger(value, i, nSkip, 4);
i += nSkip;
} else {
@@ -469,7 +453,8 @@ double CJS_PublicMethods::ParseNormalDate(const CFX_WideString& value,
nMonth = number[1];
}
- bWrongFormat = FALSE;
+ if (bWrongFormat)
+ *bWrongFormat = false;
} else if (nIndex == 3) {
// case1: year/month/day
// case2: month/day/year
@@ -492,9 +477,11 @@ double CJS_PublicMethods::ParseNormalDate(const CFX_WideString& value,
nYear = number[2];
}
- bWrongFormat = FALSE;
+ if (bWrongFormat)
+ *bWrongFormat = false;
} else {
- bWrongFormat = TRUE;
+ if (bWrongFormat)
+ *bWrongFormat = true;
return dt;
}
@@ -505,7 +492,7 @@ double CJS_PublicMethods::ParseNormalDate(const CFX_WideString& value,
double CJS_PublicMethods::MakeRegularDate(const CFX_WideString& value,
const CFX_WideString& format,
- FX_BOOL& bWrongFormat) {
+ bool* bWrongFormat) {
double dt = JS_GetDateTime();
if (format.IsEmpty() || value.IsEmpty())
@@ -522,7 +509,7 @@ double CJS_PublicMethods::MakeRegularDate(const CFX_WideString& value,
FX_BOOL bPm = FALSE;
FX_BOOL bExit = FALSE;
- bWrongFormat = FALSE;
+ bool bBadFormat = false;
int i = 0;
int j = 0;
@@ -707,7 +694,7 @@ double CJS_PublicMethods::MakeRegularDate(const CFX_WideString& value,
}
} else {
if (j >= value.GetLength() || format.GetAt(i) != value.GetAt(j)) {
- bWrongFormat = TRUE;
+ bBadFormat = true;
bExit = TRUE;
}
i++;
@@ -715,7 +702,7 @@ double CJS_PublicMethods::MakeRegularDate(const CFX_WideString& value,
}
if (oldj == j) {
- bWrongFormat = TRUE;
+ bBadFormat = true;
bExit = TRUE;
}
}
@@ -725,7 +712,7 @@ double CJS_PublicMethods::MakeRegularDate(const CFX_WideString& value,
if (value.GetLength() <= j) {
bExit = TRUE;
} else if (format.GetAt(i) != value.GetAt(j)) {
- bWrongFormat = TRUE;
+ bBadFormat = true;
bExit = TRUE;
}
@@ -742,24 +729,24 @@ double CJS_PublicMethods::MakeRegularDate(const CFX_WideString& value,
nYear += 2000;
if (nMonth < 1 || nMonth > 12)
- bWrongFormat = TRUE;
+ bBadFormat = true;
if (nDay < 1 || nDay > 31)
- bWrongFormat = TRUE;
+ bBadFormat = true;
if (nHour < 0 || nHour > 24)
- bWrongFormat = TRUE;
+ bBadFormat = true;
if (nMin < 0 || nMin > 60)
- bWrongFormat = TRUE;
+ bBadFormat = true;
if (nSec < 0 || nSec > 60)
- bWrongFormat = TRUE;
+ bBadFormat = true;
double dRet = 0;
- if (bWrongFormat) {
- dRet = ParseNormalDate(value, bWrongFormat);
+ if (bBadFormat) {
+ dRet = ParseNormalDate(value, &bBadFormat);
} else {
dRet = JS_MakeDate(JS_MakeDay(nYear, nMonth - 1, nDay),
JS_MakeTime(nHour, nMin, nSec, 0));
@@ -770,9 +757,11 @@ double CJS_PublicMethods::MakeRegularDate(const CFX_WideString& value,
}
if (JS_PortIsNan(dRet)) {
- dRet = ParseNormalDate(value, bWrongFormat);
+ dRet = ParseNormalDate(value, &bBadFormat);
}
+ if (bWrongFormat)
+ *bWrongFormat = bBadFormat;
return dRet;
}
@@ -1175,8 +1164,8 @@ FX_BOOL CJS_PublicMethods::AFNumber_Keystroke(
bRc = FALSE;
return TRUE;
}
- if (it != w_strChange2.begin()) // sign's position is not correct
- {
+ // sign's position is not correct
+ if (it != w_strChange2.begin()) {
FX_BOOL& bRc = pEvent->Rc();
bRc = FALSE;
return TRUE;
@@ -1190,7 +1179,7 @@ FX_BOOL CJS_PublicMethods::AFNumber_Keystroke(
continue;
}
- if (!IsDigit(*it)) {
+ if (!FXSYS_iswdigit(*it)) {
FX_BOOL& bRc = pEvent->Rc();
bRc = FALSE;
return TRUE;
@@ -1242,7 +1231,7 @@ FX_BOOL CJS_PublicMethods::AFPercent_Format(
double dValue = atof(strValue);
dValue *= 100;
if (iDec > 0)
- dValue += DOUBLE_CORRECT; //УÕý
+ dValue += DOUBLE_CORRECT;
int iDec2;
int iNegative = 0;
@@ -1330,7 +1319,6 @@ FX_BOOL CJS_PublicMethods::AFDate_FormatEx(IJS_Context* cc,
return TRUE;
CFX_WideString sFormat = params[0].ToCFXWideString();
- FX_BOOL bWrongFormat = FALSE;
double dDate = 0.0f;
if (strValue.Find(L"GMT") != -1) {
@@ -1338,7 +1326,7 @@ FX_BOOL CJS_PublicMethods::AFDate_FormatEx(IJS_Context* cc,
// such as "Tue Aug 11 14:24:16 GMT+08002009"
dDate = MakeInterDate(strValue);
} else {
- dDate = MakeRegularDate(strValue, sFormat, bWrongFormat);
+ dDate = MakeRegularDate(strValue, sFormat, nullptr);
}
if (JS_PortIsNan(dDate)) {
@@ -1445,8 +1433,8 @@ FX_BOOL CJS_PublicMethods::AFDate_KeystrokeEx(
return TRUE;
CFX_WideString sFormat = params[0].ToCFXWideString();
- FX_BOOL bWrongFormat = FALSE;
- double dRet = MakeRegularDate(strValue, sFormat, bWrongFormat);
+ bool bWrongFormat = FALSE;
+ double dRet = MakeRegularDate(strValue, sFormat, &bWrongFormat);
if (bWrongFormat || JS_PortIsNan(dRet)) {
CFX_WideString swMsg;
swMsg.Format(JSGetStringFromID(pContext, IDS_STRING_JSPARSEDATE).c_str(),
@@ -1841,8 +1829,7 @@ FX_BOOL CJS_PublicMethods::AFParseDateEx(IJS_Context* cc,
CFX_WideString sValue = params[0].ToCFXWideString();
CFX_WideString sFormat = params[1].ToCFXWideString();
- FX_BOOL bWrongFormat = FALSE;
- double dDate = MakeRegularDate(sValue, sFormat, bWrongFormat);
+ double dDate = MakeRegularDate(sValue, sFormat, nullptr);
if (JS_PortIsNan(dDate)) {
CFX_WideString swMsg;
@@ -1944,20 +1931,17 @@ FX_BOOL CJS_PublicMethods::AFSimple_Calculate(
dTemp +=
ParseStringToNumber(pFormCtrl->GetExportValue().c_str());
break;
- } else
- continue;
+ }
}
}
break;
}
case FIELDTYPE_LISTBOX: {
- dTemp = 0.0;
if (pFormField->CountSelectedItems() > 1)
break;
- else {
- dTemp = ParseStringToNumber(pFormField->GetValue().c_str());
- break;
- }
+
+ dTemp = ParseStringToNumber(pFormField->GetValue().c_str());
+ break;
}
default:
break;
@@ -2057,7 +2041,7 @@ FX_BOOL CJS_PublicMethods::AFExtractNums(IJS_Context* cc,
int nIndex = 0;
for (int i = 0, sz = str.GetLength(); i < sz; i++) {
FX_WCHAR wc = str.GetAt(i);
- if (IsDigit((wchar_t)wc)) {
+ if (FXSYS_iswdigit(wc)) {
sPart += wc;
} else {
if (sPart.GetLength() > 0) {
diff --git a/fpdfsdk/src/javascript/PublicMethods.h b/fpdfsdk/src/javascript/PublicMethods.h
index 80465035ea..013c4ce1a4 100644
--- a/fpdfsdk/src/javascript/PublicMethods.h
+++ b/fpdfsdk/src/javascript/PublicMethods.h
@@ -11,7 +11,8 @@
class CJS_PublicMethods : public CJS_Object {
public:
- CJS_PublicMethods(v8::Local<v8::Object> pObject) : CJS_Object(pObject) {}
+ explicit CJS_PublicMethods(v8::Local<v8::Object> pObject)
+ : CJS_Object(pObject) {}
~CJS_PublicMethods() override {}
public:
@@ -140,7 +141,7 @@ class CJS_PublicMethods : public CJS_Object {
int& nSkip);
static double MakeRegularDate(const CFX_WideString& value,
const CFX_WideString& format,
- FX_BOOL& bWrongFormat);
+ bool* bWrongFormat);
static CFX_WideString MakeFormatDate(double dDate,
const CFX_WideString& format);
static FX_BOOL ConvertStringToNumber(const FX_WCHAR* swSource,
@@ -148,7 +149,7 @@ class CJS_PublicMethods : public CJS_Object {
FX_BOOL& bDot);
static double ParseStringToNumber(const FX_WCHAR* swSource);
static double ParseNormalDate(const CFX_WideString& value,
- FX_BOOL& bWrongFormat);
+ bool* bWrongFormat);
static double MakeInterDate(CFX_WideString strValue);
static double ParseNumber(const FX_WCHAR* swSource,
FX_BOOL& bAllDigits,
@@ -168,11 +169,6 @@ class CJS_PublicMethods : public CJS_Object {
static FX_BOOL IsNumber(const FX_CHAR* string);
static FX_BOOL IsNumber(const FX_WCHAR* string);
- static FX_BOOL IsDigit(char ch);
- static FX_BOOL IsDigit(wchar_t ch);
- static FX_BOOL IsAlphabetic(wchar_t ch);
- static FX_BOOL IsAlphaNumeric(wchar_t ch);
-
static FX_BOOL maskSatisfied(wchar_t c_Change, wchar_t c_Mask);
static FX_BOOL isReservedMaskChar(wchar_t ch);
diff --git a/fpdfsdk/src/javascript/public_methods_embeddertest.cpp b/fpdfsdk/src/javascript/public_methods_embeddertest.cpp
index ca38430ae8..d9e22049f0 100644
--- a/fpdfsdk/src/javascript/public_methods_embeddertest.cpp
+++ b/fpdfsdk/src/javascript/public_methods_embeddertest.cpp
@@ -23,13 +23,13 @@ TEST_F(PublicMethodsEmbedderTest, MakeRegularDate) {
v8::Isolate::Scope isolate_scope(isolate());
v8::HandleScope handle_scope(isolate());
v8::Context::Scope context_scope(GetV8Context());
- FX_BOOL bWrongFormat;
+ bool bWrongFormat;
double date;
// 1968
bWrongFormat = false;
date = CJS_PublicMethods::MakeRegularDate(L"06/25/1968", L"mm/dd/yyyy",
- bWrongFormat);
+ &bWrongFormat);
date = RoundDownDate(date);
EXPECT_DOUBLE_EQ(-47865600000, date);
EXPECT_FALSE(bWrongFormat);
@@ -37,7 +37,7 @@ TEST_F(PublicMethodsEmbedderTest, MakeRegularDate) {
// 1968
bWrongFormat = false;
date = CJS_PublicMethods::MakeRegularDate(L"25061968", L"ddmmyyyy",
- bWrongFormat);
+ &bWrongFormat);
date = RoundDownDate(date);
EXPECT_DOUBLE_EQ(-47865600000, date);
EXPECT_FALSE(bWrongFormat);
@@ -45,7 +45,7 @@ TEST_F(PublicMethodsEmbedderTest, MakeRegularDate) {
// 1968
bWrongFormat = false;
date = CJS_PublicMethods::MakeRegularDate(L"19680625", L"yyyymmdd",
- bWrongFormat);
+ &bWrongFormat);
date = RoundDownDate(date);
EXPECT_DOUBLE_EQ(-47865600000, date);
EXPECT_FALSE(bWrongFormat);
@@ -53,14 +53,15 @@ TEST_F(PublicMethodsEmbedderTest, MakeRegularDate) {
// 1985
bWrongFormat = false;
date = CJS_PublicMethods::MakeRegularDate(L"31121985", L"ddmmyyyy",
- bWrongFormat);
+ &bWrongFormat);
date = RoundDownDate(date);
EXPECT_DOUBLE_EQ(504835200000.0, date);
EXPECT_FALSE(bWrongFormat);
// 2085, the other '85.
bWrongFormat = false;
- date = CJS_PublicMethods::MakeRegularDate(L"311285", L"ddmmyy", bWrongFormat);
+ date =
+ CJS_PublicMethods::MakeRegularDate(L"311285", L"ddmmyy", &bWrongFormat);
date = RoundDownDate(date);
EXPECT_DOUBLE_EQ(3660595200000.0, date);
EXPECT_FALSE(bWrongFormat);
@@ -68,14 +69,15 @@ TEST_F(PublicMethodsEmbedderTest, MakeRegularDate) {
// 1995
bWrongFormat = false;
date = CJS_PublicMethods::MakeRegularDate(L"01021995", L"ddmmyyyy",
- bWrongFormat);
+ &bWrongFormat);
date = RoundDownDate(date);
EXPECT_DOUBLE_EQ(791596800000.0, date);
EXPECT_FALSE(bWrongFormat);
// 2095, the other '95.
bWrongFormat = false;
- date = CJS_PublicMethods::MakeRegularDate(L"010295", L"ddmmyy", bWrongFormat);
+ date =
+ CJS_PublicMethods::MakeRegularDate(L"010295", L"ddmmyy", &bWrongFormat);
date = RoundDownDate(date);
EXPECT_DOUBLE_EQ(3947356800000.0, date);
EXPECT_FALSE(bWrongFormat);
@@ -83,14 +85,15 @@ TEST_F(PublicMethodsEmbedderTest, MakeRegularDate) {
// 2005
bWrongFormat = false;
date = CJS_PublicMethods::MakeRegularDate(L"01022005", L"ddmmyyyy",
- bWrongFormat);
+ &bWrongFormat);
date = RoundDownDate(date);
EXPECT_DOUBLE_EQ(1107216000000.0, date);
EXPECT_FALSE(bWrongFormat);
// 2005
bWrongFormat = false;
- date = CJS_PublicMethods::MakeRegularDate(L"010205", L"ddmmyy", bWrongFormat);
+ date =
+ CJS_PublicMethods::MakeRegularDate(L"010205", L"ddmmyy", &bWrongFormat);
date = RoundDownDate(date);
EXPECT_DOUBLE_EQ(1107216000000.0, date);
EXPECT_FALSE(bWrongFormat);
diff --git a/fpdfsdk/src/javascript/util.cpp b/fpdfsdk/src/javascript/util.cpp
index 30df53ea72..cb9c9b2231 100644
--- a/fpdfsdk/src/javascript/util.cpp
+++ b/fpdfsdk/src/javascript/util.cpp
@@ -105,7 +105,7 @@ int util::ParstDataType(std::wstring* sFormat) {
return UTIL_STRING;
}
if (c == L'.' || c == L'+' || c == L'-' || c == L'#' || c == L' ' ||
- CJS_PublicMethods::IsDigit(c)) {
+ FXSYS_iswdigit(c)) {
continue;
}
break;
@@ -502,8 +502,7 @@ FX_BOOL util::scand(IJS_Context* cc,
CFX_WideString sDate = params[1].ToCFXWideString();
double dDate = JS_GetDateTime();
if (sDate.GetLength() > 0) {
- FX_BOOL bWrongFormat = FALSE;
- dDate = CJS_PublicMethods::MakeRegularDate(sDate, sFormat, bWrongFormat);
+ dDate = CJS_PublicMethods::MakeRegularDate(sDate, sFormat, nullptr);
}
if (!JS_PortIsNan(dDate)) {