summaryrefslogtreecommitdiff
path: root/fpdfsdk/src/javascript/PublicMethods.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'fpdfsdk/src/javascript/PublicMethods.cpp')
-rw-r--r--fpdfsdk/src/javascript/PublicMethods.cpp118
1 files changed, 51 insertions, 67 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) {