summaryrefslogtreecommitdiff
path: root/xfa
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-06-05 09:46:45 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-06-05 13:58:40 +0000
commit7211eac14643bbbaf41bfc205c244668f46be440 (patch)
tree6dacdf2a39b60695d0811d8ff63b650ebe56e3c1 /xfa
parentaf680b17e0e1b94e40afa6a01ba3bbdead2d6035 (diff)
downloadpdfium-7211eac14643bbbaf41bfc205c244668f46be440.tar.xz
Cleaning up some XFA locale related code
This CL removes some unused locale related code and formats other bits. Change-Id: I172fc16a634a8982c00bfaf84fdcd4cd277eb36d Reviewed-on: https://pdfium-review.googlesource.com/6077 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'xfa')
-rw-r--r--xfa/fgas/crt/cfgas_formatstring.cpp789
-rw-r--r--xfa/fgas/crt/cfgas_formatstring.h7
-rw-r--r--xfa/fxfa/app/cxfa_ffnumericedit.cpp2
-rw-r--r--xfa/fxfa/cxfa_widgetacc.cpp3
-rw-r--r--xfa/fxfa/parser/cxfa_localevalue.cpp334
-rw-r--r--xfa/fxfa/parser/cxfa_localevalue.h40
6 files changed, 566 insertions, 609 deletions
diff --git a/xfa/fgas/crt/cfgas_formatstring.cpp b/xfa/fgas/crt/cfgas_formatstring.cpp
index 30dba7bf99..aa8f53aaf0 100644
--- a/xfa/fgas/crt/cfgas_formatstring.cpp
+++ b/xfa/fgas/crt/cfgas_formatstring.cpp
@@ -21,6 +21,10 @@
#define FX_LOCALECATEGORY_ZeroHash 0x568cb500
#define FX_LOCALECATEGORY_NullHash 0x052931bb
+#define FX_NUMSTYLE_Percent 0x01
+#define FX_NUMSTYLE_Exponent 0x02
+#define FX_NUMSTYLE_DotVorv 0x04
+
namespace {
struct FX_LOCALESUBCATEGORYINFO {
@@ -126,9 +130,9 @@ CFX_WideString GetLiteralText(const wchar_t* pStrPattern,
wchar_t ch = pStrPattern[iPattern++];
iKeyValue = ConvertHex(iKeyValue, ch);
}
- if (iKeyValue != 0) {
- wsOutput += (wchar_t)(iKeyValue & 0x0000FFFF);
- }
+ if (iKeyValue != 0)
+ wsOutput += static_cast<wchar_t>(iKeyValue & 0x0000FFFF);
+
continue;
}
wsOutput += pStrPattern[iPattern++];
@@ -139,9 +143,9 @@ CFX_WideString GetLiteralText(const wchar_t* pStrPattern,
CFX_WideString GetLiteralTextReverse(const wchar_t* pStrPattern,
int32_t& iPattern) {
CFX_WideString wsOutput;
- if (pStrPattern[iPattern] != '\'') {
+ if (pStrPattern[iPattern] != '\'')
return wsOutput;
- }
+
iPattern--;
int32_t iQuote = 1;
while (iPattern >= 0) {
@@ -192,11 +196,11 @@ bool GetNumericDotIndex(const CFX_WideString& wsNum,
ccf++;
}
iDotIndex = wsNum.Find('.');
- if (iDotIndex < 0) {
- iDotIndex = iLenf;
- return false;
- }
- return true;
+ if (iDotIndex >= 0)
+ return true;
+
+ iDotIndex = iLenf;
+ return false;
}
bool ParseLocaleDate(const CFX_WideString& wsDate,
@@ -239,21 +243,19 @@ bool ParseLocaleDate(const CFX_WideString& wsDate,
}
uint32_t dwSymbol = (dwCharSymbol << 8) | (dwSymbolNum + '0');
if (dwSymbol == FXBSTR_ID(0, 0, 'D', '1')) {
- if (!FXSYS_isDecimalDigit(str[cc])) {
+ if (!FXSYS_isDecimalDigit(str[cc]))
return false;
- }
+
day = str[cc++] - '0';
- if (cc < len && FXSYS_isDecimalDigit(str[cc])) {
+ if (cc < len && FXSYS_isDecimalDigit(str[cc]))
day = day * 10 + str[cc++] - '0';
- }
} else if (dwSymbol == FXBSTR_ID(0, 0, 'D', '2')) {
- if (!FXSYS_isDecimalDigit(str[cc])) {
+ if (!FXSYS_isDecimalDigit(str[cc]))
return false;
- }
+
day = str[cc++] - '0';
- if (cc < len) {
+ if (cc < len)
day = day * 10 + str[cc++] - '0';
- }
} else if (dwSymbol == FXBSTR_ID(0, 0, 'J', '1')) {
int i = 0;
while (cc < len && i < 3 && FXSYS_isDecimalDigit(str[cc])) {
@@ -263,21 +265,19 @@ bool ParseLocaleDate(const CFX_WideString& wsDate,
} else if (dwSymbol == FXBSTR_ID(0, 0, 'J', '3')) {
cc += 3;
} else if (dwSymbol == FXBSTR_ID(0, 0, 'M', '1')) {
- if (!FXSYS_isDecimalDigit(str[cc])) {
+ if (!FXSYS_isDecimalDigit(str[cc]))
return false;
- }
+
month = str[cc++] - '0';
- if (cc < len && FXSYS_isDecimalDigit(str[cc])) {
+ if (cc < len && FXSYS_isDecimalDigit(str[cc]))
month = month * 10 + str[cc++] - '0';
- }
} else if (dwSymbol == FXBSTR_ID(0, 0, 'M', '2')) {
- if (!FXSYS_isDecimalDigit(str[cc])) {
+ if (!FXSYS_isDecimalDigit(str[cc]))
return false;
- }
+
month = str[cc++] - '0';
- if (cc < len) {
+ if (cc < len)
month = month * 10 + str[cc++] - '0';
- }
} else if (dwSymbol == FXBSTR_ID(0, 0, 'M', '3')) {
CFX_WideString wsMonthNameAbbr;
uint16_t i = 0;
@@ -301,9 +301,8 @@ bool ParseLocaleDate(const CFX_WideString& wsDate,
wsMonthName = pLocale->GetMonthName(i, false);
if (wsMonthName.IsEmpty())
continue;
- if (!wcsncmp(wsMonthName.c_str(), str + cc, wsMonthName.GetLength())) {
+ if (!wcsncmp(wsMonthName.c_str(), str + cc, wsMonthName.GetLength()))
break;
- }
}
if (i < 12) {
cc += wsMonthName.GetLength();
@@ -323,9 +322,8 @@ bool ParseLocaleDate(const CFX_WideString& wsDate,
break;
}
}
- if (i < 12) {
+ if (i < 12)
cc += wsDayNameAbbr.GetLength();
- }
} else if (dwSymbol == FXBSTR_ID(0, 0, 'E', '4')) {
CFX_WideString wsDayName;
int32_t i = 0;
@@ -333,44 +331,38 @@ bool ParseLocaleDate(const CFX_WideString& wsDate,
wsDayName = pLocale->GetDayName(i, false);
if (wsDayName == L"")
continue;
- if (!wcsncmp(wsDayName.c_str(), str + cc, wsDayName.GetLength())) {
+ if (!wcsncmp(wsDayName.c_str(), str + cc, wsDayName.GetLength()))
break;
- }
}
- if (i < 12) {
+ if (i < 12)
cc += wsDayName.GetLength();
- }
} else if (dwSymbol == FXBSTR_ID(0, 0, 'e', '1')) {
cc += 1;
} else if (dwSymbol == FXBSTR_ID(0, 0, 'G', '1')) {
cc += 2;
} else if (dwSymbol == FXBSTR_ID(0, 0, 'Y', '2')) {
- if (cc + 2 > len) {
- return false;
- }
- if (!FXSYS_isDecimalDigit(str[cc])) {
+ if (cc + 2 > len || !FXSYS_isDecimalDigit(str[cc]))
return false;
- }
+
year = str[cc++] - '0';
- if (cc >= len || !FXSYS_isDecimalDigit(str[cc])) {
+ if (cc >= len || !FXSYS_isDecimalDigit(str[cc]))
return false;
- }
+
year = year * 10 + str[cc++] - '0';
- if (year <= 29) {
+ if (year <= 29)
year += 2000;
- } else {
+ else
year += 1900;
- }
} else if (dwSymbol == FXBSTR_ID(0, 0, 'Y', '4')) {
int i = 0;
year = 0;
- if (cc + 4 > len) {
+ if (cc + 4 > len)
return false;
- }
+
while (i < 4) {
- if (!FXSYS_isDecimalDigit(str[cc])) {
+ if (!FXSYS_isDecimalDigit(str[cc]))
return false;
- }
+
year = year * 10 + str[cc] - '0';
cc++;
i++;
@@ -398,12 +390,11 @@ void ResolveZone(uint8_t& wHour,
(tzLocale.tzHour < 0 ? -tzLocale.tzMinute : tzLocale.tzMinute);
iMinuteDiff -= tzDiff.tzHour * 60 +
(tzDiff.tzHour < 0 ? -tzDiff.tzMinute : tzDiff.tzMinute);
- while (iMinuteDiff > 1440) {
+ while (iMinuteDiff > 1440)
iMinuteDiff -= 1440;
- }
- while (iMinuteDiff < 0) {
+ while (iMinuteDiff < 0)
iMinuteDiff += 1440;
- }
+
wHour = iMinuteDiff / 60;
wMinute = iMinuteDiff % 60;
}
@@ -436,19 +427,22 @@ bool ParseLocaleTime(const CFX_WideString& wsTime,
cc += iLiteralLen;
ccf++;
continue;
- } else if (wsTimeSymbols.Find(strf[ccf]) == -1) {
+ }
+ if (wsTimeSymbols.Find(strf[ccf]) == -1) {
if (strf[ccf] != str[cc])
return false;
cc++;
ccf++;
continue;
}
+
uint32_t dwSymbolNum = 1;
wchar_t dwCharSymbol = strf[ccf++];
while (ccf < lenf && strf[ccf] == dwCharSymbol) {
ccf++;
dwSymbolNum++;
}
+
uint32_t dwSymbol = (dwCharSymbol << 8) | (dwSymbolNum + '0');
if (dwSymbol == FXBSTR_ID(0, 0, 'k', '1') ||
dwSymbol == FXBSTR_ID(0, 0, 'H', '1') ||
@@ -458,79 +452,71 @@ bool ParseLocaleTime(const CFX_WideString& wsTime,
return false;
}
hour = str[cc++] - '0';
- if (cc < len && FXSYS_isDecimalDigit(str[cc])) {
+ if (cc < len && FXSYS_isDecimalDigit(str[cc]))
hour = hour * 10 + str[cc++] - '0';
- }
- if (dwSymbol == FXBSTR_ID(0, 0, 'K', '1') && hour == 24) {
+ if (dwSymbol == FXBSTR_ID(0, 0, 'K', '1') && hour == 24)
hour = 0;
- }
} else if (dwSymbol == FXBSTR_ID(0, 0, 'k', '2') ||
dwSymbol == FXBSTR_ID(0, 0, 'H', '2') ||
dwSymbol == FXBSTR_ID(0, 0, 'h', '2') ||
dwSymbol == FXBSTR_ID(0, 0, 'K', '2')) {
- if (!FXSYS_isDecimalDigit(str[cc])) {
+ if (!FXSYS_isDecimalDigit(str[cc]))
return false;
- }
+
hour = str[cc++] - '0';
- if (cc >= len) {
+ if (cc >= len)
return false;
- }
- if (!FXSYS_isDecimalDigit(str[cc])) {
+ if (!FXSYS_isDecimalDigit(str[cc]))
return false;
- }
+
hour = hour * 10 + str[cc++] - '0';
- if (dwSymbol == FXBSTR_ID(0, 0, 'K', '2') && hour == 24) {
+ if (dwSymbol == FXBSTR_ID(0, 0, 'K', '2') && hour == 24)
hour = 0;
- }
} else if (dwSymbol == FXBSTR_ID(0, 0, 'M', '1')) {
- if (!FXSYS_isDecimalDigit(str[cc])) {
+ if (!FXSYS_isDecimalDigit(str[cc]))
return false;
- }
+
minute = str[cc++] - '0';
- if (cc < len && FXSYS_isDecimalDigit(str[cc])) {
+ if (cc < len && FXSYS_isDecimalDigit(str[cc]))
minute = minute * 10 + str[cc++] - '0';
- }
} else if (dwSymbol == FXBSTR_ID(0, 0, 'M', '2')) {
- if (!FXSYS_isDecimalDigit(str[cc])) {
+ if (!FXSYS_isDecimalDigit(str[cc]))
return false;
- }
+
minute = str[cc++] - '0';
- if (cc >= len) {
+ if (cc >= len)
return false;
- }
- if (!FXSYS_isDecimalDigit(str[cc])) {
+ if (!FXSYS_isDecimalDigit(str[cc]))
return false;
- }
+
minute = minute * 10 + str[cc++] - '0';
} else if (dwSymbol == FXBSTR_ID(0, 0, 'S', '1')) {
- if (!FXSYS_isDecimalDigit(str[cc])) {
+ if (!FXSYS_isDecimalDigit(str[cc]))
return false;
- }
+
second = str[cc++] - '0';
- if (cc < len && FXSYS_isDecimalDigit(str[cc])) {
+ if (cc < len && FXSYS_isDecimalDigit(str[cc]))
second = second * 10 + str[cc++] - '0';
- }
} else if (dwSymbol == FXBSTR_ID(0, 0, 'S', '2')) {
- if (!FXSYS_isDecimalDigit(str[cc])) {
+ if (!FXSYS_isDecimalDigit(str[cc]))
return false;
- }
+
second = str[cc++] - '0';
- if (cc >= len) {
+ if (cc >= len)
return false;
- }
- if (!FXSYS_isDecimalDigit(str[cc])) {
+ if (!FXSYS_isDecimalDigit(str[cc]))
return false;
- }
+
second = second * 10 + str[cc++] - '0';
} else if (dwSymbol == FXBSTR_ID(0, 0, 'F', '3')) {
- if (cc + 3 >= len) {
+ if (cc + 3 >= len)
return false;
- }
+
int i = 0;
while (i < 3) {
- if (!FXSYS_isDecimalDigit(str[cc])) {
+ if (!FXSYS_isDecimalDigit(str[cc]))
return false;
- }
+
millisecond = millisecond * 10 + str[cc++] - '0';
i++;
}
@@ -548,9 +534,9 @@ bool ParseLocaleTime(const CFX_WideString& wsTime,
bPM = true;
}
} else if (dwSymbol == FXBSTR_ID(0, 0, 'Z', '1')) {
- if (cc + 3 > len) {
+ if (cc + 3 > len)
continue;
- }
+
uint32_t dwHash = str[cc++];
dwHash = (dwHash << 8) | str[cc++];
dwHash = (dwHash << 8) | str[cc++];
@@ -588,13 +574,11 @@ bool ParseLocaleTime(const CFX_WideString& wsTime,
if (bHasA) {
if (bPM) {
hour += 12;
- if (hour == 24) {
+ if (hour == 24)
hour = 12;
- }
} else {
- if (hour == 12) {
+ if (hour == 12)
hour = 0;
- }
}
}
datetime->SetTime(hour, minute, second, millisecond);
@@ -679,10 +663,12 @@ bool DateFormat(const CFX_WideString& wsDatePattern,
wsResult += GetLiteralText(strf, ccf, lenf);
ccf++;
continue;
- } else if (wsDateSymbols.Find(strf[ccf]) == -1) {
+ }
+ if (wsDateSymbols.Find(strf[ccf]) == -1) {
wsResult += strf[ccf++];
continue;
}
+
uint32_t dwSymbolNum = 1;
wchar_t dwCharSymbol = strf[ccf++];
while (ccf < lenf && strf[ccf] == dwCharSymbol) {
@@ -700,18 +686,18 @@ bool DateFormat(const CFX_WideString& wsDatePattern,
wsResult += wsDay;
} else if (dwSymbol == FXBSTR_ID(0, 0, 'J', '1')) {
uint16_t nDays = 0;
- for (int i = 1; i < month; i++) {
+ for (int i = 1; i < month; i++)
nDays += GetSolarMonthDays(year, i);
- }
+
nDays += day;
CFX_WideString wsDays;
wsDays.Format(L"%d", nDays);
wsResult += wsDays;
} else if (dwSymbol == FXBSTR_ID(0, 0, 'J', '3')) {
uint16_t nDays = 0;
- for (int i = 1; i < month; i++) {
+ for (int i = 1; i < month; i++)
nDays += GetSolarMonthDays(year, i);
- }
+
nDays += day;
CFX_WideString wsDays;
wsDays.Format(L"%03d", nDays);
@@ -786,20 +772,22 @@ bool TimeFormat(const CFX_WideString& wsTimePattern,
uint16_t wHour = hour;
bool bPM = false;
if (wsTimePattern.Find('A') != -1) {
- if (wHour >= 12) {
+ if (wHour >= 12)
bPM = true;
- }
}
+
CFX_WideStringC wsTimeSymbols(gs_wsTimeSymbols);
while (ccf < lenf) {
if (strf[ccf] == '\'') {
wsResult += GetLiteralText(strf, ccf, lenf);
ccf++;
continue;
- } else if (wsTimeSymbols.Find(strf[ccf]) == -1) {
+ }
+ if (wsTimeSymbols.Find(strf[ccf]) == -1) {
wsResult += strf[ccf++];
continue;
}
+
uint32_t dwSymbolNum = 1;
wchar_t dwCharSymbol = strf[ccf++];
while (ccf < lenf && strf[ccf] == dwCharSymbol) {
@@ -808,16 +796,16 @@ bool TimeFormat(const CFX_WideString& wsTimePattern,
}
uint32_t dwSymbol = (dwCharSymbol << 8) | (dwSymbolNum + '0');
if (dwSymbol == FXBSTR_ID(0, 0, 'h', '1')) {
- if (wHour > 12) {
+ if (wHour > 12)
wHour -= 12;
- }
+
CFX_WideString wsHour;
wsHour.Format(L"%d", wHour == 0 ? 12 : wHour);
wsResult += wsHour;
} else if (dwSymbol == FXBSTR_ID(0, 0, 'h', '2')) {
- if (wHour > 12) {
+ if (wHour > 12)
wHour -= 12;
- }
+
CFX_WideString wsHour;
wsHour.Format(L"%02d", wHour == 0 ? 12 : wHour);
wsResult += wsHour;
@@ -830,9 +818,9 @@ bool TimeFormat(const CFX_WideString& wsTimePattern,
wsHour.Format(L"%02d", wHour == 0 ? 24 : wHour);
wsResult += wsHour;
} else if (dwSymbol == FXBSTR_ID(0, 0, 'k', '1')) {
- if (wHour > 12) {
+ if (wHour > 12)
wHour -= 12;
- }
+
CFX_WideString wsHour;
wsHour.Format(L"%d", wHour);
wsResult += wsHour;
@@ -841,9 +829,9 @@ bool TimeFormat(const CFX_WideString& wsTimePattern,
wsHour.Format(L"%d", wHour);
wsResult += wsHour;
} else if (dwSymbol == FXBSTR_ID(0, 0, 'k', '2')) {
- if (wHour > 12) {
+ if (wHour > 12)
wHour -= 12;
- }
+
CFX_WideString wsHour;
wsHour.Format(L"%02d", wHour);
wsResult += wsHour;
@@ -922,74 +910,67 @@ bool FX_DateFromCanonical(const CFX_WideString& wsDate,
int32_t month = 1;
int32_t day = 1;
uint16_t wYear = 0;
- int cc_start = 0, cc = 0;
+ int cc_start = 0;
+ int cc = 0;
const wchar_t* str = wsDate.c_str();
int len = wsDate.GetLength();
- if (len > 10) {
+ if (len > 10)
return false;
- }
+
while (cc < len && cc < 4) {
- if (!FXSYS_isDecimalDigit(str[cc])) {
+ if (!FXSYS_isDecimalDigit(str[cc]))
return false;
- }
+
wYear = wYear * 10 + str[cc++] - '0';
}
year = wYear;
- if (cc < 4 || wYear < 1900) {
+ if (cc < 4 || wYear < 1900)
return false;
- }
if (cc < len) {
- if (str[cc] == '-') {
+ if (str[cc] == '-')
cc++;
- }
+
cc_start = cc;
uint8_t tmpM = 0;
while (cc < len && cc < cc_start + 2) {
- if (!FXSYS_isDecimalDigit(str[cc])) {
+ if (!FXSYS_isDecimalDigit(str[cc]))
return false;
- }
+
tmpM = tmpM * 10 + str[cc++] - '0';
}
month = tmpM;
- if (cc == cc_start + 1 || tmpM > 12 || tmpM < 1) {
+ if (cc == cc_start + 1 || tmpM > 12 || tmpM < 1)
return false;
- }
if (cc < len) {
- if (str[cc] == '-') {
+ if (str[cc] == '-')
cc++;
- }
+
uint8_t tmpD = 0;
cc_start = cc;
while (cc < len && cc < cc_start + 2) {
- if (!FXSYS_isDecimalDigit(str[cc])) {
+ if (!FXSYS_isDecimalDigit(str[cc]))
return false;
- }
+
tmpD = tmpD * 10 + str[cc++] - '0';
}
day = tmpD;
- if (tmpD < 1) {
+ if (tmpD < 1)
return false;
- }
if ((tmpM == 1 || tmpM == 3 || tmpM == 5 || tmpM == 7 || tmpM == 8 ||
tmpM == 10 || tmpM == 12) &&
tmpD > 31) {
return false;
}
- if ((tmpM == 4 || tmpM == 6 || tmpM == 9 || tmpM == 11) && tmpD > 30) {
+ if ((tmpM == 4 || tmpM == 6 || tmpM == 9 || tmpM == 11) && tmpD > 30)
return false;
- }
- bool iLeapYear;
- if ((wYear % 4 == 0 && wYear % 100 != 0) || wYear % 400 == 0) {
- iLeapYear = true;
- } else {
- iLeapYear = false;
- }
- if ((iLeapYear && tmpM == 2 && tmpD > 29) ||
- (!iLeapYear && tmpM == 2 && tmpD > 28)) {
+
+ bool iLeapYear =
+ ((wYear % 4 == 0 && wYear % 100 != 0) || wYear % 400 == 0);
+ if (tmpM == 2 && tmpD > (iLeapYear ? 29 : 28))
return false;
- }
}
}
+
datetime->SetDate(year, month, day);
return true;
}
@@ -1004,54 +985,52 @@ bool FX_TimeFromCanonical(const CFX_WideStringC& wsTime,
uint8_t minute = 0;
uint8_t second = 0;
uint16_t millisecond = 0;
- int cc_start = 0, cc = cc_start;
+ int cc_start = 0;
+ int cc = 0;
const wchar_t* str = wsTime.c_str();
int len = wsTime.GetLength();
while (cc < len && cc < 2) {
- if (!FXSYS_isDecimalDigit(str[cc])) {
+ if (!FXSYS_isDecimalDigit(str[cc]))
return false;
- }
+
hour = hour * 10 + str[cc++] - '0';
}
- if (cc < 2 || hour >= 24) {
+ if (cc < 2 || hour >= 24)
return false;
- }
if (cc < len) {
- if (str[cc] == ':') {
+ if (str[cc] == ':')
cc++;
- }
+
cc_start = cc;
while (cc < len && cc < cc_start + 2) {
- if (!FXSYS_isDecimalDigit(str[cc])) {
+ if (!FXSYS_isDecimalDigit(str[cc]))
return false;
- }
+
minute = minute * 10 + str[cc++] - '0';
}
- if (cc == cc_start + 1 || minute >= 60) {
+ if (cc == cc_start + 1 || minute >= 60)
return false;
- }
if (cc < len) {
- if (str[cc] == ':') {
+ if (str[cc] == ':')
cc++;
- }
+
cc_start = cc;
while (cc < len && cc < cc_start + 2) {
- if (!FXSYS_isDecimalDigit(str[cc])) {
+ if (!FXSYS_isDecimalDigit(str[cc]))
return false;
- }
+
second = second * 10 + str[cc++] - '0';
}
- if (cc == cc_start + 1 || second >= 60) {
+ if (cc == cc_start + 1 || second >= 60)
return false;
- }
if (cc < len) {
if (str[cc] == '.') {
cc++;
cc_start = cc;
while (cc < len && cc < cc_start + 3) {
- if (!FXSYS_isDecimalDigit(str[cc])) {
+ if (!FXSYS_isDecimalDigit(str[cc]))
return false;
- }
+
millisecond = millisecond * 10 + str[cc++] - '0';
}
if (cc < cc_start + 3)
@@ -1063,6 +1042,7 @@ bool FX_TimeFromCanonical(const CFX_WideStringC& wsTime,
tzDiff.tzMinute = 0;
if (str[cc] != 'Z')
cc += ParseTimeZone(str + cc, len - cc, &tzDiff);
+
ResolveZone(hour, minute, tzDiff, pLocale);
}
}
@@ -1115,12 +1095,10 @@ FX_LOCALECATEGORY CFGAS_FormatString::GetCategory(
CFX_WideString wsCategory(pStr[ccf]);
ccf++;
while (true) {
- if (ccf == iLenf) {
+ if (ccf == iLenf)
return eCategory;
- }
- if (pStr[ccf] == '.' || pStr[ccf] == '(') {
+ if (pStr[ccf] == '.' || pStr[ccf] == '(')
break;
- }
if (pStr[ccf] == '{') {
bBraceOpen = true;
break;
@@ -1128,16 +1106,15 @@ FX_LOCALECATEGORY CFGAS_FormatString::GetCategory(
wsCategory += pStr[ccf];
ccf++;
}
+
uint32_t dwHash = FX_HashCode_GetW(wsCategory.AsStringC(), false);
if (dwHash == FX_LOCALECATEGORY_DateHash) {
- if (eCategory == FX_LOCALECATEGORY_Time) {
+ if (eCategory == FX_LOCALECATEGORY_Time)
return FX_LOCALECATEGORY_DateTime;
- }
eCategory = FX_LOCALECATEGORY_Date;
} else if (dwHash == FX_LOCALECATEGORY_TimeHash) {
- if (eCategory == FX_LOCALECATEGORY_Date) {
+ if (eCategory == FX_LOCALECATEGORY_Date)
return FX_LOCALECATEGORY_DateTime;
- }
eCategory = FX_LOCALECATEGORY_Time;
} else if (dwHash == FX_LOCALECATEGORY_DateTimeHash) {
return FX_LOCALECATEGORY_DateTime;
@@ -1158,10 +1135,9 @@ FX_LOCALECATEGORY CFGAS_FormatString::GetCategory(
return eCategory;
}
-IFX_Locale* CFGAS_FormatString::GetTextFormat(const CFX_WideString& wsPattern,
- const CFX_WideStringC& wsCategory,
- CFX_WideString& wsPurgePattern) {
- IFX_Locale* pLocale = nullptr;
+void CFGAS_FormatString::GetTextFormat(const CFX_WideString& wsPattern,
+ const CFX_WideStringC& wsCategory,
+ CFX_WideString& wsPurgePattern) {
int32_t ccf = 0;
int32_t iLenf = wsPattern.GetLength();
const wchar_t* pStr = wsPattern.c_str();
@@ -1180,17 +1156,15 @@ IFX_Locale* CFGAS_FormatString::GetTextFormat(const CFX_WideString& wsPattern,
wsSearchCategory += pStr[ccf];
ccf++;
}
- if (wsSearchCategory != wsCategory) {
+ if (wsSearchCategory != wsCategory)
continue;
- }
+
while (ccf < iLenf) {
if (pStr[ccf] == '(') {
ccf++;
CFX_WideString wsLCID;
- while (ccf < iLenf && pStr[ccf] != ')') {
+ while (ccf < iLenf && pStr[ccf] != ')')
wsLCID += pStr[ccf++];
- }
- pLocale = GetPatternLocale(wsLCID);
} else if (pStr[ccf] == '{') {
bBrackOpen = true;
break;
@@ -1202,17 +1176,10 @@ IFX_Locale* CFGAS_FormatString::GetTextFormat(const CFX_WideString& wsPattern,
}
ccf++;
}
- if (!bBrackOpen) {
+ if (!bBrackOpen)
wsPurgePattern = wsPattern;
- }
- if (!pLocale) {
- pLocale = m_pLocaleMgr->GetDefLocale();
- }
- return pLocale;
}
-#define FX_NUMSTYLE_Percent 0x01
-#define FX_NUMSTYLE_Exponent 0x02
-#define FX_NUMSTYLE_DotVorv 0x04
+
IFX_Locale* CFGAS_FormatString::GetNumericFormat(
const CFX_WideString& wsPattern,
int32_t& iDotIndex,
@@ -1248,19 +1215,19 @@ IFX_Locale* CFGAS_FormatString::GetNumericFormat(
if (pStr[ccf] == '(') {
ccf++;
CFX_WideString wsLCID;
- while (ccf < iLenf && pStr[ccf] != ')') {
+ while (ccf < iLenf && pStr[ccf] != ')')
wsLCID += pStr[ccf++];
- }
- pLocale = GetPatternLocale(wsLCID);
+
+ pLocale = m_pLocaleMgr->GetLocaleByName(wsLCID);
} else if (pStr[ccf] == '{') {
bBrackOpen = true;
break;
} else if (pStr[ccf] == '.') {
CFX_WideString wsSubCategory;
ccf++;
- while (ccf < iLenf && pStr[ccf] != '(' && pStr[ccf] != '{') {
+ while (ccf < iLenf && pStr[ccf] != '(' && pStr[ccf] != '{')
wsSubCategory += pStr[ccf++];
- }
+
uint32_t dwSubHash =
FX_HashCode_GetW(wsSubCategory.AsStringC(), false);
FX_LOCALENUMSUBCATEGORY eSubCategory = FX_LOCALENUMPATTERN_Decimal;
@@ -1284,9 +1251,9 @@ IFX_Locale* CFGAS_FormatString::GetNumericFormat(
dwStyle |= FX_NUMSTYLE_DotVorv;
}
wsPurgePattern += wsSubCategory;
- if (eSubCategory == FX_LOCALENUMPATTERN_Percent) {
+ if (eSubCategory == FX_LOCALENUMPATTERN_Percent)
dwStyle |= FX_NUMSTYLE_Percent;
- }
+
continue;
}
ccf++;
@@ -1309,12 +1276,10 @@ IFX_Locale* CFGAS_FormatString::GetNumericFormat(
}
ccf++;
}
- if (!bFindDot) {
+ if (!bFindDot)
iDotIndex = wsPurgePattern.GetLength();
- }
- if (!pLocale) {
+ if (!pLocale)
pLocale = m_pLocaleMgr->GetDefLocale();
- }
return pLocale;
}
@@ -1322,15 +1287,16 @@ bool CFGAS_FormatString::ParseText(const CFX_WideString& wsSrcText,
const CFX_WideString& wsPattern,
CFX_WideString& wsValue) {
wsValue.clear();
- if (wsSrcText.IsEmpty() || wsPattern.IsEmpty()) {
+ if (wsSrcText.IsEmpty() || wsPattern.IsEmpty())
return false;
- }
+
CFX_WideString wsTextFormat;
GetTextFormat(wsPattern, L"text", wsTextFormat);
- if (wsTextFormat.IsEmpty()) {
+ if (wsTextFormat.IsEmpty())
return false;
- }
- int32_t iText = 0, iPattern = 0;
+
+ int32_t iText = 0;
+ int32_t iPattern = 0;
const wchar_t* pStrText = wsSrcText.c_str();
int32_t iLenText = wsSrcText.GetLength();
const wchar_t* pStrPattern = wsTextFormat.c_str();
@@ -1414,7 +1380,6 @@ bool CFGAS_FormatString::ParseNum(const CFX_WideString& wsSrcNum,
int32_t iGroupLen = wsGroupSymbol.GetLength();
CFX_WideString wsMinus = pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Minus);
int32_t iMinusLen = wsMinus.GetLength();
- int cc = 0, ccf = 0;
const wchar_t* str = wsSrcNum.c_str();
int len = wsSrcNum.GetLength();
const wchar_t* strf = wsNumFormat.c_str();
@@ -1428,25 +1393,25 @@ bool CFGAS_FormatString::ParseNum(const CFX_WideString& wsSrcNum,
bReverseParse = true;
}
bReverseParse = false;
- ccf = dot_index_f - 1;
- cc = dot_index - 1;
+ int ccf = dot_index_f - 1;
+ int cc = dot_index - 1;
while (ccf >= 0 && cc >= 0) {
switch (strf[ccf]) {
case '\'': {
CFX_WideString wsLiteral = GetLiteralTextReverse(strf, ccf);
int32_t iLiteralLen = wsLiteral.GetLength();
cc -= iLiteralLen - 1;
- if (cc < 0 || wcsncmp(str + cc, wsLiteral.c_str(), iLiteralLen)) {
+ if (cc < 0 || wcsncmp(str + cc, wsLiteral.c_str(), iLiteralLen))
return false;
- }
+
cc--;
ccf--;
break;
}
case '9':
- if (!FXSYS_isDecimalDigit(str[cc])) {
+ if (!FXSYS_isDecimalDigit(str[cc]))
return false;
- }
+
wsValue = str[cc] + wsValue;
cc--;
ccf--;
@@ -1474,9 +1439,9 @@ bool CFGAS_FormatString::ParseNum(const CFX_WideString& wsSrcNum,
cc--;
} else {
cc -= iMinusLen - 1;
- if (cc < 0 || wcsncmp(str + cc, wsMinus.c_str(), iMinusLen)) {
+ if (cc < 0 || wcsncmp(str + cc, wsMinus.c_str(), iMinusLen))
return false;
- }
+
cc--;
bNeg = true;
}
@@ -1487,54 +1452,57 @@ bool CFGAS_FormatString::ParseNum(const CFX_WideString& wsSrcNum,
cc--;
} else {
cc -= iMinusLen - 1;
- if (cc < 0 || wcsncmp(str + cc, wsMinus.c_str(), iMinusLen)) {
+ if (cc < 0 || wcsncmp(str + cc, wsMinus.c_str(), iMinusLen))
return false;
- }
+
cc--;
bNeg = true;
}
ccf--;
break;
case 'E': {
- if (cc >= dot_index) {
+ if (cc >= dot_index)
return false;
- }
+
bool bExpSign = false;
while (cc >= 0) {
- if (str[cc] == 'E' || str[cc] == 'e') {
+ if (str[cc] == 'E' || str[cc] == 'e')
break;
- }
if (FXSYS_isDecimalDigit(str[cc])) {
iExponent = iExponent + (str[cc] - '0') * 10;
cc--;
continue;
- } else if (str[cc] == '+') {
+ }
+ if (str[cc] == '+') {
cc--;
continue;
- } else if (cc - iMinusLen + 1 > 0 &&
- !wcsncmp(str + (cc - iMinusLen + 1), wsMinus.c_str(),
- iMinusLen)) {
+ }
+ if (cc - iMinusLen + 1 > 0 && !wcsncmp(str + (cc - iMinusLen + 1),
+ wsMinus.c_str(), iMinusLen)) {
bExpSign = true;
cc -= iMinusLen;
- } else {
- return false;
+ continue;
}
+
+ return false;
}
cc--;
iExponent = bExpSign ? -iExponent : iExponent;
ccf--;
- } break;
+ break;
+ }
case '$': {
CFX_WideString wsSymbol =
pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_CurrencySymbol);
int32_t iSymbolLen = wsSymbol.GetLength();
cc -= iSymbolLen - 1;
- if (cc < 0 || wcsncmp(str + cc, wsSymbol.c_str(), iSymbolLen)) {
+ if (cc < 0 || wcsncmp(str + cc, wsSymbol.c_str(), iSymbolLen))
return false;
- }
+
cc--;
ccf--;
- } break;
+ break;
+ }
case 'r':
if (ccf - 1 >= 0 && strf[ccf - 1] == 'c') {
if (str[cc] == 'R' && cc - 1 >= 0 && str[cc - 1] == 'C') {
@@ -1592,13 +1560,14 @@ bool CFGAS_FormatString::ParseNum(const CFX_WideString& wsSrcNum,
pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Percent);
int32_t iSysmbolLen = wsSymbol.GetLength();
cc -= iSysmbolLen - 1;
- if (cc < 0 || wcsncmp(str + cc, wsSymbol.c_str(), iSysmbolLen)) {
+ if (cc < 0 || wcsncmp(str + cc, wsSymbol.c_str(), iSysmbolLen))
return false;
- }
+
cc--;
ccf--;
bHavePercentSymbol = true;
- } break;
+ break;
+ }
case '8':
return false;
case ',': {
@@ -1612,29 +1581,30 @@ bool CFGAS_FormatString::ParseNum(const CFX_WideString& wsSrcNum,
}
}
ccf--;
- } break;
+ break;
+ }
case '(':
- if (str[cc] == L'(') {
+ if (str[cc] == L'(')
bNeg = true;
- } else if (str[cc] != L' ') {
+ else if (str[cc] != L' ')
return false;
- }
+
cc--;
ccf--;
break;
case ')':
- if (str[cc] == L')') {
+ if (str[cc] == L')')
bNeg = true;
- } else if (str[cc] != L' ') {
+ else if (str[cc] != L' ')
return false;
- }
+
cc--;
ccf--;
break;
default:
- if (strf[ccf] != str[cc]) {
+ if (strf[ccf] != str[cc])
return false;
- }
+
cc--;
ccf--;
}
@@ -1644,13 +1614,11 @@ bool CFGAS_FormatString::ParseNum(const CFX_WideString& wsSrcNum,
bNeg = true;
cc--;
}
- if (cc >= 0) {
+ if (cc >= 0)
return false;
- }
}
- if (dot_index < len && (dwFormatStyle & FX_NUMSTYLE_DotVorv)) {
+ if (dot_index < len && (dwFormatStyle & FX_NUMSTYLE_DotVorv))
wsValue += '.';
- }
if (!bReverseParse) {
ccf = dot_index_f + 1;
cc = (dot_index == len) ? len : dot_index + 1;
@@ -1668,10 +1636,10 @@ bool CFGAS_FormatString::ParseNum(const CFX_WideString& wsSrcNum,
break;
}
case '9':
- if (!FXSYS_isDecimalDigit(str[cc])) {
+ if (!FXSYS_isDecimalDigit(str[cc]))
return false;
- }
- { wsValue += str[cc]; }
+
+ wsValue += str[cc];
cc++;
ccf++;
break;
@@ -1720,9 +1688,9 @@ bool CFGAS_FormatString::ParseNum(const CFX_WideString& wsSrcNum,
ccf++;
break;
case 'E': {
- if (cc >= len || (str[cc] != 'E' && str[cc] != 'e')) {
+ if (cc >= len || (str[cc] != 'E' && str[cc] != 'e'))
return false;
- }
+
bool bExpSign = false;
cc++;
if (cc < len) {
@@ -1734,15 +1702,16 @@ bool CFGAS_FormatString::ParseNum(const CFX_WideString& wsSrcNum,
}
}
while (cc < len) {
- if (!FXSYS_isDecimalDigit(str[cc])) {
+ if (!FXSYS_isDecimalDigit(str[cc]))
break;
- }
+
iExponent = iExponent * 10 + str[cc] - '0';
cc++;
}
iExponent = bExpSign ? -iExponent : iExponent;
ccf++;
- } break;
+ break;
+ }
case '$': {
CFX_WideString wsSymbol =
pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_CurrencySymbol);
@@ -1753,7 +1722,8 @@ bool CFGAS_FormatString::ParseNum(const CFX_WideString& wsSrcNum,
}
cc += iSymbolLen;
ccf++;
- } break;
+ break;
+ }
case 'c':
if (ccf + 1 < lenf && strf[ccf + 1] == 'r') {
if (str[cc] == 'C' && cc + 1 < len && str[cc + 1] == 'R') {
@@ -1810,9 +1780,9 @@ bool CFGAS_FormatString::ParseNum(const CFX_WideString& wsSrcNum,
bHavePercentSymbol = true;
} break;
case '8': {
- while (ccf < lenf && strf[ccf] == '8') {
+ while (ccf < lenf && strf[ccf] == '8')
ccf++;
- }
+
while (cc < len && FXSYS_isDecimalDigit(str[cc])) {
wsValue += str[cc];
cc++;
@@ -1824,36 +1794,36 @@ bool CFGAS_FormatString::ParseNum(const CFX_WideString& wsSrcNum,
cc += iGroupLen;
}
ccf++;
- } break;
+ break;
+ }
case '(':
- if (str[cc] == L'(') {
+ if (str[cc] == L'(')
bNeg = true;
- } else if (str[cc] != L' ') {
+ else if (str[cc] != L' ')
return false;
- }
+
cc++;
ccf++;
break;
case ')':
- if (str[cc] == L')') {
+ if (str[cc] == L')')
bNeg = true;
- } else if (str[cc] != L' ') {
+ else if (str[cc] != L' ')
return false;
- }
+
cc++;
ccf++;
break;
default:
- if (strf[ccf] != str[cc]) {
+ if (strf[ccf] != str[cc])
return false;
- }
+
cc++;
ccf++;
}
}
- if (cc != len) {
+ if (cc != len)
return false;
- }
}
if (iExponent || bHavePercentSymbol) {
CFX_Decimal decimal = CFX_Decimal(wsValue.AsStringC());
@@ -1861,14 +1831,14 @@ bool CFGAS_FormatString::ParseNum(const CFX_WideString& wsSrcNum,
decimal = decimal *
CFX_Decimal(FXSYS_pow(10, static_cast<float>(iExponent)), 3);
}
- if (bHavePercentSymbol) {
+ if (bHavePercentSymbol)
decimal = decimal / CFX_Decimal(100);
- }
+
wsValue = decimal;
}
- if (bNeg) {
+ if (bNeg)
wsValue = L'-' + wsValue;
- }
+
return true;
}
@@ -1901,9 +1871,9 @@ FX_DATETIMETYPE CFGAS_FormatString::GetDateTimeFormat(
wsDatePattern = wsPattern.Left(ccf);
wsTimePattern = wsPattern.Right(wsPattern.GetLength() - ccf);
wsTimePattern.SetAt(0, ' ');
- if (!pLocale) {
+ if (!pLocale)
pLocale = m_pLocaleMgr->GetDefLocale();
- }
+
return FX_DATETIMETYPE_DateTime;
}
wsCategory += pStr[ccf];
@@ -1912,9 +1882,8 @@ FX_DATETIMETYPE CFGAS_FormatString::GetDateTimeFormat(
if (!(iFindCategory & 1) && wsCategory == L"date") {
iFindCategory |= 1;
eCategory = FX_LOCALECATEGORY_Date;
- if (iFindCategory & 2) {
+ if (iFindCategory & 2)
iFindCategory = 4;
- }
} else if (!(iFindCategory & 2) && wsCategory == L"time") {
iFindCategory |= 2;
eCategory = FX_LOCALECATEGORY_Time;
@@ -1928,19 +1897,19 @@ FX_DATETIMETYPE CFGAS_FormatString::GetDateTimeFormat(
if (pStr[ccf] == '(') {
ccf++;
CFX_WideString wsLCID;
- while (ccf < iLenf && pStr[ccf] != ')') {
+ while (ccf < iLenf && pStr[ccf] != ')')
wsLCID += pStr[ccf++];
- }
- pLocale = GetPatternLocale(wsLCID);
+
+ pLocale = m_pLocaleMgr->GetLocaleByName(wsLCID);
} else if (pStr[ccf] == '{') {
bBraceOpen = true;
break;
} else if (pStr[ccf] == '.') {
CFX_WideString wsSubCategory;
ccf++;
- while (ccf < iLenf && pStr[ccf] != '(' && pStr[ccf] != '{') {
+ while (ccf < iLenf && pStr[ccf] != '(' && pStr[ccf] != '{')
wsSubCategory += pStr[ccf++];
- }
+
uint32_t dwSubHash =
FX_HashCode_GetW(wsSubCategory.AsStringC(), false);
FX_LOCALEDATETIMESUBCATEGORY eSubCategory =
@@ -1953,10 +1922,10 @@ FX_DATETIMETYPE CFGAS_FormatString::GetDateTimeFormat(
break;
}
}
- if (!pLocale) {
+ if (!pLocale)
pLocale = m_pLocaleMgr->GetDefLocale();
- }
ASSERT(pLocale);
+
switch (eCategory) {
case FX_LOCALECATEGORY_Date:
wsDatePattern =
@@ -1982,11 +1951,11 @@ FX_DATETIMETYPE CFGAS_FormatString::GetDateTimeFormat(
} else if (pStr[ccf] == '}') {
bBraceOpen = false;
if (!wsTempPattern.IsEmpty()) {
- if (eCategory == FX_LOCALECATEGORY_Time) {
+ if (eCategory == FX_LOCALECATEGORY_Time)
wsTimePattern = wsTempPattern;
- } else if (eCategory == FX_LOCALECATEGORY_Date) {
+ else if (eCategory == FX_LOCALECATEGORY_Date)
wsDatePattern = wsTempPattern;
- }
+
wsTempPattern.clear();
}
} else {
@@ -1994,16 +1963,15 @@ FX_DATETIMETYPE CFGAS_FormatString::GetDateTimeFormat(
}
ccf++;
}
+
if (!wsTempPattern.IsEmpty()) {
- if (eCategory == FX_LOCALECATEGORY_Date) {
+ if (eCategory == FX_LOCALECATEGORY_Date)
wsDatePattern += wsTempPattern;
- } else {
+ else
wsTimePattern += wsTempPattern;
- }
}
- if (!pLocale) {
+ if (!pLocale)
pLocale = m_pLocaleMgr->GetDefLocale();
- }
if (!iFindCategory) {
wsTimePattern.clear();
wsDatePattern = wsPattern;
@@ -2017,22 +1985,19 @@ bool CFGAS_FormatString::ParseDateTime(const CFX_WideString& wsSrcDateTime,
CFX_DateTime* dtValue) {
dtValue->Reset();
- if (wsSrcDateTime.IsEmpty() || wsPattern.IsEmpty()) {
+ if (wsSrcDateTime.IsEmpty() || wsPattern.IsEmpty())
return false;
- }
+
CFX_WideString wsDatePattern, wsTimePattern;
IFX_Locale* pLocale = nullptr;
FX_DATETIMETYPE eCategory =
GetDateTimeFormat(wsPattern, pLocale, wsDatePattern, wsTimePattern);
- if (!pLocale) {
+ if (!pLocale)
return false;
- }
- if (eCategory == FX_DATETIMETYPE_Unknown) {
+ if (eCategory == FX_DATETIMETYPE_Unknown)
eCategory = eDateTimeType;
- }
- if (eCategory == FX_DATETIMETYPE_Unknown) {
+ if (eCategory == FX_DATETIMETYPE_Unknown)
return false;
- }
if (eCategory == FX_DATETIMETYPE_TimeDate) {
int32_t iStart = 0;
if (!ParseLocaleTime(wsSrcDateTime, wsTimePattern, pLocale, dtValue,
@@ -2058,11 +2023,14 @@ bool CFGAS_FormatString::ParseDateTime(const CFX_WideString& wsSrcDateTime,
}
return true;
}
+
bool CFGAS_FormatString::ParseZero(const CFX_WideString& wsSrcText,
const CFX_WideString& wsPattern) {
CFX_WideString wsTextFormat;
GetTextFormat(wsPattern, L"zero", wsTextFormat);
- int32_t iText = 0, iPattern = 0;
+
+ int32_t iText = 0;
+ int32_t iPattern = 0;
const wchar_t* pStrText = wsSrcText.c_str();
int32_t iLenText = wsSrcText.GetLength();
const wchar_t* pStrPattern = wsTextFormat.c_str();
@@ -2079,20 +2047,23 @@ bool CFGAS_FormatString::ParseZero(const CFX_WideString& wsSrcText,
iText += iLiteralLen;
iPattern++;
continue;
- } else if (pStrPattern[iPattern] != pStrText[iText]) {
- return false;
- } else {
- iText++;
- iPattern++;
}
+ if (pStrPattern[iPattern] != pStrText[iText])
+ return false;
+
+ iText++;
+ iPattern++;
}
return iPattern == iLenPattern && iText == iLenText;
}
+
bool CFGAS_FormatString::ParseNull(const CFX_WideString& wsSrcText,
const CFX_WideString& wsPattern) {
CFX_WideString wsTextFormat;
GetTextFormat(wsPattern, L"null", wsTextFormat);
- int32_t iText = 0, iPattern = 0;
+
+ int32_t iText = 0;
+ int32_t iPattern = 0;
const wchar_t* pStrText = wsSrcText.c_str();
int32_t iLenText = wsSrcText.GetLength();
const wchar_t* pStrPattern = wsTextFormat.c_str();
@@ -2109,28 +2080,31 @@ bool CFGAS_FormatString::ParseNull(const CFX_WideString& wsSrcText,
iText += iLiteralLen;
iPattern++;
continue;
- } else if (pStrPattern[iPattern] != pStrText[iText]) {
- return false;
- } else {
- iText++;
- iPattern++;
}
+ if (pStrPattern[iPattern] != pStrText[iText])
+ return false;
+
+ iText++;
+ iPattern++;
}
return iPattern == iLenPattern && iText == iLenText;
}
+
bool CFGAS_FormatString::FormatText(const CFX_WideString& wsSrcText,
const CFX_WideString& wsPattern,
CFX_WideString& wsOutput) {
- if (wsPattern.IsEmpty()) {
+ if (wsPattern.IsEmpty())
return false;
- }
+
int32_t iLenText = wsSrcText.GetLength();
- if (iLenText == 0) {
+ if (iLenText == 0)
return false;
- }
+
CFX_WideString wsTextFormat;
GetTextFormat(wsPattern, L"text", wsTextFormat);
- int32_t iText = 0, iPattern = 0;
+
+ int32_t iText = 0;
+ int32_t iPattern = 0;
const wchar_t* pStrText = wsSrcText.c_str();
const wchar_t* pStrPattern = wsTextFormat.c_str();
int32_t iLenPattern = wsTextFormat.GetLength();
@@ -2142,16 +2116,16 @@ bool CFGAS_FormatString::FormatText(const CFX_WideString& wsSrcText,
break;
}
case 'A':
- if (iText >= iLenText || !FXSYS_iswalpha(pStrText[iText])) {
+ if (iText >= iLenText || !FXSYS_iswalpha(pStrText[iText]))
return false;
- }
+
wsOutput += pStrText[iText++];
iPattern++;
break;
case 'X':
- if (iText >= iLenText) {
+ if (iText >= iLenText)
return false;
- }
+
wsOutput += pStrText[iText++];
iPattern++;
break;
@@ -2165,9 +2139,9 @@ bool CFGAS_FormatString::FormatText(const CFX_WideString& wsSrcText,
iPattern++;
break;
case '9':
- if (iText >= iLenText || !FXSYS_isDecimalDigit(pStrText[iText])) {
+ if (iText >= iLenText || !FXSYS_isDecimalDigit(pStrText[iText]))
return false;
- }
+
wsOutput += pStrText[iText++];
iPattern++;
break;
@@ -2182,30 +2156,31 @@ bool CFGAS_FormatString::FormatText(const CFX_WideString& wsSrcText,
bool CFGAS_FormatString::FormatStrNum(const CFX_WideStringC& wsInputNum,
const CFX_WideString& wsPattern,
CFX_WideString& wsOutput) {
- if (wsInputNum.IsEmpty() || wsPattern.IsEmpty()) {
+ if (wsInputNum.IsEmpty() || wsPattern.IsEmpty())
return false;
- }
+
int32_t dot_index_f = -1;
uint32_t dwNumStyle = 0;
CFX_WideString wsNumFormat;
IFX_Locale* pLocale =
GetNumericFormat(wsPattern, dot_index_f, dwNumStyle, wsNumFormat);
- if (!pLocale || wsNumFormat.IsEmpty()) {
+ if (!pLocale || wsNumFormat.IsEmpty())
return false;
- }
+
int32_t cc = 0, ccf = 0;
const wchar_t* strf = wsNumFormat.c_str();
int lenf = wsNumFormat.GetLength();
CFX_WideString wsSrcNum(wsInputNum);
wsSrcNum.TrimLeft('0');
- if (wsSrcNum.IsEmpty() || wsSrcNum[0] == '.') {
+ if (wsSrcNum.IsEmpty() || wsSrcNum[0] == '.')
wsSrcNum.Insert(0, '0');
- }
+
CFX_Decimal decimal = CFX_Decimal(wsSrcNum.AsStringC());
if (dwNumStyle & FX_NUMSTYLE_Percent) {
decimal = decimal * CFX_Decimal(100);
wsSrcNum = decimal;
}
+
int32_t exponent = 0;
if (dwNumStyle & FX_NUMSTYLE_Exponent) {
int fixed_count = 0;
@@ -2222,6 +2197,7 @@ bool CFGAS_FormatString::FormatStrNum(const CFX_WideStringC& wsInputNum,
}
ccf++;
}
+
int threshold = 1;
while (fixed_count > 1) {
threshold *= 10;
@@ -2244,6 +2220,7 @@ bool CFGAS_FormatString::FormatStrNum(const CFX_WideStringC& wsInputNum,
}
}
}
+
bool bTrimTailZeros = false;
int32_t iTreading =
GetNumTrailingLimit(wsNumFormat, dot_index_f, bTrimTailZeros);
@@ -2256,6 +2233,7 @@ bool CFGAS_FormatString::FormatStrNum(const CFX_WideStringC& wsInputNum,
wsSrcNum.TrimRight(L"0");
wsSrcNum.TrimRight(L".");
}
+
CFX_WideString wsGroupSymbol =
pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Grouping);
bool bNeg = false;
@@ -2263,22 +2241,23 @@ bool CFGAS_FormatString::FormatStrNum(const CFX_WideStringC& wsInputNum,
bNeg = true;
wsSrcNum.Delete(0, 1);
}
+
bool bAddNeg = false;
const wchar_t* str = wsSrcNum.c_str();
int len = wsSrcNum.GetLength();
int dot_index = wsSrcNum.Find('.');
- if (dot_index == -1) {
+ if (dot_index == -1)
dot_index = len;
- }
+
ccf = dot_index_f - 1;
cc = dot_index - 1;
while (ccf >= 0) {
switch (strf[ccf]) {
case '9':
if (cc >= 0) {
- if (!FXSYS_isDecimalDigit(str[cc])) {
+ if (!FXSYS_isDecimalDigit(str[cc]))
return false;
- }
+
wsOutput = str[cc] + wsOutput;
cc--;
} else {
@@ -2288,26 +2267,24 @@ bool CFGAS_FormatString::FormatStrNum(const CFX_WideStringC& wsInputNum,
break;
case 'z':
if (cc >= 0) {
- if (!FXSYS_isDecimalDigit(str[cc])) {
+ if (!FXSYS_isDecimalDigit(str[cc]))
return false;
- }
- if (str[0] != '0') {
+ if (str[0] != '0')
wsOutput = str[cc] + wsOutput;
- }
+
cc--;
}
ccf--;
break;
case 'Z':
if (cc >= 0) {
- if (!FXSYS_isDecimalDigit(str[cc])) {
+ if (!FXSYS_isDecimalDigit(str[cc]))
return false;
- }
- if (str[0] == '0') {
+ if (str[0] == '0')
wsOutput = L' ' + wsOutput;
- } else {
+ else
wsOutput = str[cc] + wsOutput;
- }
+
cc--;
} else {
wsOutput = L' ' + wsOutput;
@@ -2336,52 +2313,52 @@ bool CFGAS_FormatString::FormatStrNum(const CFX_WideStringC& wsInputNum,
CFX_WideString wsExp;
wsExp.Format(L"E%+d", exponent);
wsOutput = wsExp + wsOutput;
- }
ccf--;
break;
+ }
case '$': {
wsOutput =
pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_CurrencySymbol) +
wsOutput;
- }
ccf--;
break;
+ }
case 'r':
if (ccf - 1 >= 0 && strf[ccf - 1] == 'c') {
- if (bNeg) {
+ if (bNeg)
wsOutput = L"CR" + wsOutput;
- }
+
ccf -= 2;
bAddNeg = true;
}
break;
case 'R':
if (ccf - 1 >= 0 && strf[ccf - 1] == 'C') {
- if (bNeg) {
+ if (bNeg)
wsOutput = L"CR" + wsOutput;
- } else {
+ else
wsOutput = L" " + wsOutput;
- }
+
ccf -= 2;
bAddNeg = true;
}
break;
case 'b':
if (ccf - 1 >= 0 && strf[ccf - 1] == 'd') {
- if (bNeg) {
+ if (bNeg)
wsOutput = L"db" + wsOutput;
- }
+
ccf -= 2;
bAddNeg = true;
}
break;
case 'B':
if (ccf - 1 >= 0 && strf[ccf - 1] == 'D') {
- if (bNeg) {
+ if (bNeg)
wsOutput = L"DB" + wsOutput;
- } else {
+ else
wsOutput = L" " + wsOutput;
- }
+
ccf -= 2;
bAddNeg = true;
}
@@ -2389,30 +2366,30 @@ bool CFGAS_FormatString::FormatStrNum(const CFX_WideStringC& wsInputNum,
case '%': {
wsOutput =
pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Percent) + wsOutput;
- }
ccf--;
break;
+ }
case ',':
- if (cc >= 0) {
+ if (cc >= 0)
wsOutput = wsGroupSymbol + wsOutput;
- }
+
ccf--;
break;
case '(':
- if (bNeg) {
+ if (bNeg)
wsOutput = L"(" + wsOutput;
- } else {
+ else
wsOutput = L" " + wsOutput;
- }
+
bAddNeg = true;
ccf--;
break;
case ')':
- if (bNeg) {
+ if (bNeg)
wsOutput = L")" + wsOutput;
- } else {
+ else
wsOutput = L" " + wsOutput;
- }
+
ccf--;
break;
case '\'':
@@ -2424,13 +2401,13 @@ bool CFGAS_FormatString::FormatStrNum(const CFX_WideStringC& wsInputNum,
ccf--;
}
}
+
if (cc >= 0) {
int nPos = dot_index % 3;
wsOutput.clear();
for (int32_t i = 0; i < dot_index; i++) {
- if (i % 3 == nPos && i != 0) {
+ if (i % 3 == nPos && i != 0)
wsOutput += wsGroupSymbol;
- }
wsOutput += wsSrcNum[i];
}
if (dot_index < len) {
@@ -2456,14 +2433,12 @@ bool CFGAS_FormatString::FormatStrNum(const CFX_WideStringC& wsInputNum,
if (strf[dot_index_f] == 'V') {
wsOutput += wsDotSymbol;
} else if (strf[dot_index_f] == '.') {
- if (dot_index < len) {
+ if (dot_index < len)
+ wsOutput += wsDotSymbol;
+ else if (strf[dot_index_f + 1] == '9' || strf[dot_index_f + 1] == 'Z')
wsOutput += wsDotSymbol;
- } else {
- if (strf[dot_index_f + 1] == '9' || strf[dot_index_f + 1] == 'Z') {
- wsOutput += wsDotSymbol;
- }
- }
}
+
ccf = dot_index_f + 1;
cc = dot_index + 1;
while (ccf < lenf) {
@@ -2474,9 +2449,9 @@ bool CFGAS_FormatString::FormatStrNum(const CFX_WideStringC& wsInputNum,
break;
case '9':
if (cc < len) {
- if (!FXSYS_isDecimalDigit(str[cc])) {
+ if (!FXSYS_isDecimalDigit(str[cc]))
return false;
- }
+
wsOutput += str[cc];
cc++;
} else {
@@ -2486,9 +2461,9 @@ bool CFGAS_FormatString::FormatStrNum(const CFX_WideStringC& wsInputNum,
break;
case 'z':
if (cc < len) {
- if (!FXSYS_isDecimalDigit(str[cc])) {
+ if (!FXSYS_isDecimalDigit(str[cc]))
return false;
- }
+
wsOutput += str[cc];
cc++;
}
@@ -2496,9 +2471,9 @@ bool CFGAS_FormatString::FormatStrNum(const CFX_WideStringC& wsInputNum,
break;
case 'Z':
if (cc < len) {
- if (!FXSYS_isDecimalDigit(str[cc])) {
+ if (!FXSYS_isDecimalDigit(str[cc]))
return false;
- }
+
wsOutput += str[cc];
cc++;
} else {
@@ -2511,7 +2486,8 @@ bool CFGAS_FormatString::FormatStrNum(const CFX_WideStringC& wsInputNum,
wsExp.Format(L"E%+d", exponent);
wsOutput += wsExp;
ccf++;
- } break;
+ break;
+ }
case '$':
wsOutput +=
pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_CurrencySymbol);
@@ -2519,40 +2495,40 @@ bool CFGAS_FormatString::FormatStrNum(const CFX_WideStringC& wsInputNum,
break;
case 'c':
if (ccf + 1 < lenf && strf[ccf + 1] == 'r') {
- if (bNeg) {
+ if (bNeg)
wsOutput += L"CR";
- }
+
ccf += 2;
bAddNeg = true;
}
break;
case 'C':
if (ccf + 1 < lenf && strf[ccf + 1] == 'R') {
- if (bNeg) {
+ if (bNeg)
wsOutput += L"CR";
- } else {
+ else
wsOutput += L" ";
- }
+
ccf += 2;
bAddNeg = true;
}
break;
case 'd':
if (ccf + 1 < lenf && strf[ccf + 1] == 'b') {
- if (bNeg) {
+ if (bNeg)
wsOutput += L"db";
- }
+
ccf += 2;
bAddNeg = true;
}
break;
case 'D':
if (ccf + 1 < lenf && strf[ccf + 1] == 'B') {
- if (bNeg) {
+ if (bNeg)
wsOutput += L"DB";
- } else {
+ else
wsOutput += L" ";
- }
+
ccf += 2;
bAddNeg = true;
}
@@ -2574,20 +2550,20 @@ bool CFGAS_FormatString::FormatStrNum(const CFX_WideStringC& wsInputNum,
ccf++;
break;
case '(':
- if (bNeg) {
+ if (bNeg)
wsOutput += '(';
- } else {
+ else
wsOutput += ' ';
- }
+
bAddNeg = true;
ccf++;
break;
case ')':
- if (bNeg) {
+ if (bNeg)
wsOutput += ')';
- } else {
+ else
wsOutput += ' ';
- }
+
ccf++;
break;
default:
@@ -2604,9 +2580,8 @@ bool CFGAS_FormatString::FormatStrNum(const CFX_WideStringC& wsInputNum,
bool CFGAS_FormatString::FormatNum(const CFX_WideString& wsSrcNum,
const CFX_WideString& wsPattern,
CFX_WideString& wsOutput) {
- if (wsSrcNum.IsEmpty() || wsPattern.IsEmpty()) {
+ if (wsSrcNum.IsEmpty() || wsPattern.IsEmpty())
return false;
- }
return FormatStrNum(wsSrcNum.AsStringC(), wsPattern, wsOutput);
}
@@ -2614,16 +2589,16 @@ bool CFGAS_FormatString::FormatDateTime(const CFX_WideString& wsSrcDateTime,
const CFX_WideString& wsPattern,
CFX_WideString& wsOutput,
FX_DATETIMETYPE eDateTimeType) {
- if (wsSrcDateTime.IsEmpty() || wsPattern.IsEmpty()) {
+ if (wsSrcDateTime.IsEmpty() || wsPattern.IsEmpty())
return false;
- }
+
CFX_WideString wsDatePattern, wsTimePattern;
IFX_Locale* pLocale = nullptr;
FX_DATETIMETYPE eCategory =
GetDateTimeFormat(wsPattern, pLocale, wsDatePattern, wsTimePattern);
- if (!pLocale) {
+ if (!pLocale)
return false;
- }
+
if (eCategory == FX_DATETIMETYPE_Unknown) {
if (eDateTimeType == FX_DATETIMETYPE_Time) {
wsTimePattern = wsDatePattern;
@@ -2631,9 +2606,9 @@ bool CFGAS_FormatString::FormatDateTime(const CFX_WideString& wsSrcDateTime,
}
eCategory = eDateTimeType;
}
- if (eCategory == FX_DATETIMETYPE_Unknown) {
+ if (eCategory == FX_DATETIMETYPE_Unknown)
return false;
- }
+
CFX_DateTime dt;
int32_t iT = wsSrcDateTime.Find(L"T");
if (iT < 0) {
@@ -2666,9 +2641,9 @@ bool CFGAS_FormatString::FormatDateTime(const CFX_WideString& wsSrcDateTime,
bool CFGAS_FormatString::FormatZero(const CFX_WideString& wsPattern,
CFX_WideString& wsOutput) {
- if (wsPattern.IsEmpty()) {
+ if (wsPattern.IsEmpty())
return false;
- }
+
CFX_WideString wsTextFormat;
GetTextFormat(wsPattern, L"zero", wsTextFormat);
int32_t iPattern = 0;
@@ -2686,11 +2661,12 @@ bool CFGAS_FormatString::FormatZero(const CFX_WideString& wsPattern,
}
return true;
}
+
bool CFGAS_FormatString::FormatNull(const CFX_WideString& wsPattern,
CFX_WideString& wsOutput) {
- if (wsPattern.IsEmpty()) {
+ if (wsPattern.IsEmpty())
return false;
- }
+
CFX_WideString wsTextFormat;
GetTextFormat(wsPattern, L"null", wsTextFormat);
int32_t iPattern = 0;
@@ -2701,15 +2677,8 @@ bool CFGAS_FormatString::FormatNull(const CFX_WideString& wsPattern,
wsOutput += GetLiteralText(pStrPattern, iPattern, iLenPattern);
iPattern++;
continue;
- } else {
- wsOutput += pStrPattern[iPattern++];
- continue;
}
+ wsOutput += pStrPattern[iPattern++];
}
return true;
}
-
-IFX_Locale* CFGAS_FormatString::GetPatternLocale(
- const CFX_WideString& wsLocale) {
- return m_pLocaleMgr->GetLocaleByName(wsLocale);
-}
diff --git a/xfa/fgas/crt/cfgas_formatstring.h b/xfa/fgas/crt/cfgas_formatstring.h
index be3c310fa5..a8cb917697 100644
--- a/xfa/fgas/crt/cfgas_formatstring.h
+++ b/xfa/fgas/crt/cfgas_formatstring.h
@@ -53,9 +53,9 @@ class CFGAS_FormatString {
bool FormatNull(const CFX_WideString& wsPattern, CFX_WideString& wsOutput);
private:
- IFX_Locale* GetTextFormat(const CFX_WideString& wsPattern,
- const CFX_WideStringC& wsCategory,
- CFX_WideString& wsPurgePattern);
+ void GetTextFormat(const CFX_WideString& wsPattern,
+ const CFX_WideStringC& wsCategory,
+ CFX_WideString& wsPurgePattern);
IFX_Locale* GetNumericFormat(const CFX_WideString& wsPattern,
int32_t& iDotIndex,
uint32_t& dwStyle,
@@ -67,7 +67,6 @@ class CFGAS_FormatString {
IFX_Locale*& pLocale,
CFX_WideString& wsDatePattern,
CFX_WideString& wsTimePattern);
- IFX_Locale* GetPatternLocale(const CFX_WideString& wsLocale);
CXFA_LocaleMgr* m_pLocaleMgr;
};
diff --git a/xfa/fxfa/app/cxfa_ffnumericedit.cpp b/xfa/fxfa/app/cxfa_ffnumericedit.cpp
index a2aad63daa..09ea524ee4 100644
--- a/xfa/fxfa/app/cxfa_ffnumericedit.cpp
+++ b/xfa/fxfa/app/cxfa_ffnumericedit.cpp
@@ -91,7 +91,7 @@ bool CXFA_FFNumericEdit::OnValidate(CFWL_Widget* pWidget,
CFX_WideString wsFormat;
CXFA_LocaleValue widgetValue = XFA_GetLocaleValue(m_pDataAcc.Get());
- widgetValue.GetNumbericFormat(wsFormat, iLeads, iFracs);
+ widgetValue.GetNumericFormat(wsFormat, iLeads, iFracs);
return widgetValue.ValidateNumericTemp(wsText, wsFormat,
m_pDataAcc->GetLocal());
}
diff --git a/xfa/fxfa/cxfa_widgetacc.cpp b/xfa/fxfa/cxfa_widgetacc.cpp
index d4a6125408..3c136df0ff 100644
--- a/xfa/fxfa/cxfa_widgetacc.cpp
+++ b/xfa/fxfa/cxfa_widgetacc.cpp
@@ -409,7 +409,8 @@ int32_t CXFA_WidgetAcc::ProcessFormatTestValidate(CXFA_Validate validate,
return XFA_EVENTERROR_NotExist;
CXFA_LocaleValue lcValue = XFA_GetLocaleValue(this);
- if (!lcValue.ValidateValue(lcValue.GetValue(), wsPicture, pLocale)) {
+ if (!lcValue.ValidateValue(lcValue.GetValue(), wsPicture, pLocale,
+ nullptr)) {
IXFA_AppProvider* pAppProvider = GetAppProvider();
if (!pAppProvider)
return XFA_EVENTERROR_NotExist;
diff --git a/xfa/fxfa/parser/cxfa_localevalue.cpp b/xfa/fxfa/parser/cxfa_localevalue.cpp
index c563f44082..113c8cc46e 100644
--- a/xfa/fxfa/parser/cxfa_localevalue.cpp
+++ b/xfa/fxfa/parser/cxfa_localevalue.cpp
@@ -16,41 +16,83 @@
#include "xfa/fxfa/parser/cxfa_localemgr.h"
#include "xfa/fxfa/parser/xfa_utils.h"
-CXFA_LocaleValue::CXFA_LocaleValue() {
- m_dwType = XFA_VT_NULL;
- m_bValid = true;
- m_pLocaleMgr = nullptr;
+namespace {
+
+FX_LOCALECATEGORY ValueCategory(FX_LOCALECATEGORY eCategory,
+ uint32_t dwValueType) {
+ if (eCategory != FX_LOCALECATEGORY_Unknown)
+ return eCategory;
+
+ switch (dwValueType) {
+ case XFA_VT_BOOLEAN:
+ case XFA_VT_INTEGER:
+ case XFA_VT_DECIMAL:
+ case XFA_VT_FLOAT:
+ return FX_LOCALECATEGORY_Num;
+ case XFA_VT_TEXT:
+ return FX_LOCALECATEGORY_Text;
+ case XFA_VT_DATE:
+ return FX_LOCALECATEGORY_Date;
+ case XFA_VT_TIME:
+ return FX_LOCALECATEGORY_Time;
+ case XFA_VT_DATETIME:
+ return FX_LOCALECATEGORY_DateTime;
+ }
+ return FX_LOCALECATEGORY_Unknown;
}
-CXFA_LocaleValue::CXFA_LocaleValue(const CXFA_LocaleValue& value) {
- m_dwType = XFA_VT_NULL;
- m_bValid = true;
- m_pLocaleMgr = nullptr;
- *this = value;
-}
-CXFA_LocaleValue::CXFA_LocaleValue(uint32_t dwType,
- CXFA_LocaleMgr* pLocaleMgr) {
- m_dwType = dwType;
- m_bValid = (m_dwType != XFA_VT_NULL);
- m_pLocaleMgr = pLocaleMgr;
+
+bool ValueSplitDateTime(const CFX_WideString& wsDateTime,
+ CFX_WideString& wsDate,
+ CFX_WideString& wsTime) {
+ wsDate = L"";
+ wsTime = L"";
+ if (wsDateTime.IsEmpty())
+ return false;
+
+ int nSplitIndex = wsDateTime.Find('T');
+ if (nSplitIndex < 0)
+ nSplitIndex = wsDateTime.Find(' ');
+ if (nSplitIndex < 0)
+ return false;
+
+ wsDate = wsDateTime.Left(nSplitIndex);
+ wsTime = wsDateTime.Right(wsDateTime.GetLength() - nSplitIndex - 1);
+ return true;
}
+
+} // namespace
+
+CXFA_LocaleValue::CXFA_LocaleValue()
+ : m_pLocaleMgr(nullptr), m_dwType(XFA_VT_NULL), m_bValid(true) {}
+
+CXFA_LocaleValue::CXFA_LocaleValue(const CXFA_LocaleValue& value)
+ : m_pLocaleMgr(value.m_pLocaleMgr),
+ m_wsValue(value.m_wsValue),
+ m_dwType(value.m_dwType),
+ m_bValid(value.m_bValid) {}
+
+CXFA_LocaleValue::CXFA_LocaleValue(uint32_t dwType, CXFA_LocaleMgr* pLocaleMgr)
+ : m_pLocaleMgr(pLocaleMgr),
+ m_dwType(dwType),
+ m_bValid(m_dwType != XFA_VT_NULL) {}
+
CXFA_LocaleValue::CXFA_LocaleValue(uint32_t dwType,
const CFX_WideString& wsValue,
- CXFA_LocaleMgr* pLocaleMgr) {
- m_wsValue = wsValue;
- m_dwType = dwType;
- m_pLocaleMgr = pLocaleMgr;
- m_bValid = ValidateCanonicalValue(wsValue, dwType);
-}
+ CXFA_LocaleMgr* pLocaleMgr)
+ : m_pLocaleMgr(pLocaleMgr),
+ m_wsValue(wsValue),
+ m_dwType(dwType),
+ m_bValid(ValidateCanonicalValue(wsValue, dwType)) {}
+
CXFA_LocaleValue::CXFA_LocaleValue(uint32_t dwType,
const CFX_WideString& wsValue,
const CFX_WideString& wsFormat,
IFX_Locale* pLocale,
- CXFA_LocaleMgr* pLocaleMgr) {
- m_pLocaleMgr = pLocaleMgr;
- m_bValid = true;
- m_dwType = dwType;
- m_bValid = ParsePatternValue(wsValue, wsFormat, pLocale);
-}
+ CXFA_LocaleMgr* pLocaleMgr)
+ : m_pLocaleMgr(pLocaleMgr),
+ m_dwType(dwType),
+ m_bValid(ParsePatternValue(wsValue, wsFormat, pLocale)) {}
+
CXFA_LocaleValue& CXFA_LocaleValue::operator=(const CXFA_LocaleValue& value) {
m_wsValue = value.m_wsValue;
m_dwType = value.m_dwType;
@@ -58,28 +100,8 @@ CXFA_LocaleValue& CXFA_LocaleValue::operator=(const CXFA_LocaleValue& value) {
m_pLocaleMgr = value.m_pLocaleMgr;
return *this;
}
+
CXFA_LocaleValue::~CXFA_LocaleValue() {}
-static FX_LOCALECATEGORY XFA_ValugeCategory(FX_LOCALECATEGORY eCategory,
- uint32_t dwValueType) {
- if (eCategory == FX_LOCALECATEGORY_Unknown) {
- switch (dwValueType) {
- case XFA_VT_BOOLEAN:
- case XFA_VT_INTEGER:
- case XFA_VT_DECIMAL:
- case XFA_VT_FLOAT:
- return FX_LOCALECATEGORY_Num;
- case XFA_VT_TEXT:
- return FX_LOCALECATEGORY_Text;
- case XFA_VT_DATE:
- return FX_LOCALECATEGORY_Date;
- case XFA_VT_TIME:
- return FX_LOCALECATEGORY_Time;
- case XFA_VT_DATETIME:
- return FX_LOCALECATEGORY_DateTime;
- }
- }
- return eCategory;
-}
bool CXFA_LocaleValue::ValidateValue(const CFX_WideString& wsValue,
const CFX_WideString& wsPattern,
@@ -99,35 +121,29 @@ bool CXFA_LocaleValue::ValidateValue(const CFX_WideString& wsValue,
int32_t i = 0;
for (; i < iCount && !bRet; i++) {
CFX_WideString wsFormat = wsPatterns[i];
- FX_LOCALECATEGORY eCategory = pFormat->GetCategory(wsFormat);
- eCategory = XFA_ValugeCategory(eCategory, m_dwType);
- switch (eCategory) {
+ switch (ValueCategory(pFormat->GetCategory(wsFormat), m_dwType)) {
case FX_LOCALECATEGORY_Null:
bRet = pFormat->ParseNull(wsValue, wsFormat);
- if (!bRet) {
+ if (!bRet)
bRet = wsValue.IsEmpty();
- }
break;
case FX_LOCALECATEGORY_Zero:
bRet = pFormat->ParseZero(wsValue, wsFormat);
- if (!bRet) {
+ if (!bRet)
bRet = wsValue == L"0";
- }
break;
case FX_LOCALECATEGORY_Num: {
CFX_WideString fNum;
bRet = pFormat->ParseNum(wsValue, wsFormat, fNum);
- if (!bRet) {
+ if (!bRet)
bRet = pFormat->FormatNum(wsValue, wsFormat, wsOutput);
- }
break;
}
case FX_LOCALECATEGORY_Text:
bRet = pFormat->ParseText(wsValue, wsFormat, wsOutput);
wsOutput.clear();
- if (!bRet) {
+ if (!bRet)
bRet = pFormat->FormatText(wsValue, wsFormat, wsOutput);
- }
break;
case FX_LOCALECATEGORY_Date: {
CFX_DateTime dt;
@@ -169,19 +185,12 @@ bool CXFA_LocaleValue::ValidateValue(const CFX_WideString& wsValue,
}
if (bRet && pMatchFormat)
*pMatchFormat = wsPatterns[i - 1];
-
if (pLocale)
m_pLocaleMgr->SetDefLocale(locale);
return bRet;
}
-CFX_WideString CXFA_LocaleValue::GetValue() const {
- return m_wsValue;
-}
-uint32_t CXFA_LocaleValue::GetType() const {
- return m_dwType;
-}
double CXFA_LocaleValue::GetDoubleNum() const {
if (m_bValid && (m_dwType == XFA_VT_BOOLEAN || m_dwType == XFA_VT_INTEGER ||
m_dwType == XFA_VT_DECIMAL || m_dwType == XFA_VT_FLOAT)) {
@@ -189,7 +198,8 @@ double CXFA_LocaleValue::GetDoubleNum() const {
uint32_t dwFractional = 0;
int32_t nExponent = 0;
int32_t cc = 0;
- bool bNegative = false, bExpSign = false;
+ bool bNegative = false;
+ bool bExpSign = false;
const wchar_t* str = m_wsValue.c_str();
int len = m_wsValue.GetLength();
while (FXSYS_iswspace(str[cc]) && cc < len)
@@ -214,6 +224,7 @@ double CXFA_LocaleValue::GetDoubleNum() const {
cc++;
nIntegralLen++;
}
+
nIntegral = bNegative ? -nIntegral : nIntegral;
int32_t scale = 0;
double fraction = 0.0;
@@ -261,24 +272,22 @@ double CXFA_LocaleValue::GetDoubleNum() const {
}
CFX_DateTime CXFA_LocaleValue::GetDate() const {
- if (m_bValid && m_dwType == XFA_VT_DATE) {
- CFX_DateTime dt;
- FX_DateFromCanonical(m_wsValue, &dt);
- return dt;
- }
- return CFX_DateTime();
+ if (!m_bValid || m_dwType != XFA_VT_DATE)
+ return CFX_DateTime();
+
+ CFX_DateTime dt;
+ FX_DateFromCanonical(m_wsValue, &dt);
+ return dt;
}
CFX_DateTime CXFA_LocaleValue::GetTime() const {
- if (m_bValid && m_dwType == XFA_VT_TIME) {
- ASSERT(m_pLocaleMgr);
+ if (!m_bValid || m_dwType != XFA_VT_TIME)
+ return CFX_DateTime();
- CFX_DateTime dt;
- FX_TimeFromCanonical(m_wsValue.AsStringC(), &dt,
- m_pLocaleMgr->GetDefLocale());
- return dt;
- }
- return CFX_DateTime();
+ CFX_DateTime dt;
+ FX_TimeFromCanonical(m_wsValue.AsStringC(), &dt,
+ m_pLocaleMgr->GetDefLocale());
+ return dt;
}
bool CXFA_LocaleValue::SetDate(const CFX_DateTime& d) {
@@ -339,18 +348,16 @@ bool CXFA_LocaleValue::FormatSinglePattern(CFX_WideString& wsResult,
wsResult.clear();
bool bRet = false;
auto pFormat = pdfium::MakeUnique<CFGAS_FormatString>(m_pLocaleMgr);
- FX_LOCALECATEGORY eCategory = pFormat->GetCategory(wsFormat);
- eCategory = XFA_ValugeCategory(eCategory, m_dwType);
+ FX_LOCALECATEGORY eCategory =
+ ValueCategory(pFormat->GetCategory(wsFormat), m_dwType);
switch (eCategory) {
case FX_LOCALECATEGORY_Null:
- if (m_wsValue.IsEmpty()) {
+ if (m_wsValue.IsEmpty())
bRet = pFormat->FormatNull(wsFormat, wsResult);
- }
break;
case FX_LOCALECATEGORY_Zero:
- if (m_wsValue == L"0") {
+ if (m_wsValue == L"0")
bRet = pFormat->FormatZero(wsFormat, wsResult);
- }
break;
case FX_LOCALECATEGORY_Num:
bRet = pFormat->FormatNum(m_wsValue, wsFormat, wsResult);
@@ -384,39 +391,20 @@ bool CXFA_LocaleValue::FormatSinglePattern(CFX_WideString& wsResult,
return bRet;
}
-static bool XFA_ValueSplitDateTime(const CFX_WideString& wsDateTime,
- CFX_WideString& wsDate,
- CFX_WideString& wsTime) {
- wsDate = L"";
- wsTime = L"";
- if (wsDateTime.IsEmpty()) {
- return false;
- }
- int nSplitIndex = -1;
- nSplitIndex = wsDateTime.Find('T');
- if (nSplitIndex < 0) {
- nSplitIndex = wsDateTime.Find(' ');
- }
- if (nSplitIndex < 0) {
- return false;
- }
- wsDate = wsDateTime.Left(nSplitIndex);
- wsTime = wsDateTime.Right(wsDateTime.GetLength() - nSplitIndex - 1);
- return true;
-}
bool CXFA_LocaleValue::ValidateCanonicalValue(const CFX_WideString& wsValue,
uint32_t dwVType) {
- if (wsValue.IsEmpty()) {
+ if (wsValue.IsEmpty())
return true;
- }
+
CFX_DateTime dt;
switch (dwVType) {
case XFA_VT_DATE: {
if (ValidateCanonicalDate(wsValue, &dt))
return true;
- CFX_WideString wsDate, wsTime;
- if (XFA_ValueSplitDateTime(wsValue, wsDate, wsTime) &&
+ CFX_WideString wsDate;
+ CFX_WideString wsTime;
+ if (ValueSplitDateTime(wsValue, wsDate, wsTime) &&
ValidateCanonicalDate(wsDate, &dt)) {
return true;
}
@@ -426,8 +414,9 @@ bool CXFA_LocaleValue::ValidateCanonicalValue(const CFX_WideString& wsValue,
if (ValidateCanonicalTime(wsValue))
return true;
- CFX_WideString wsDate, wsTime;
- if (XFA_ValueSplitDateTime(wsValue, wsDate, wsTime) &&
+ CFX_WideString wsDate;
+ CFX_WideString wsTime;
+ if (ValueSplitDateTime(wsValue, wsDate, wsTime) &&
ValidateCanonicalTime(wsTime)) {
return true;
}
@@ -435,7 +424,7 @@ bool CXFA_LocaleValue::ValidateCanonicalValue(const CFX_WideString& wsValue,
}
case XFA_VT_DATETIME: {
CFX_WideString wsDate, wsTime;
- if (XFA_ValueSplitDateTime(wsValue, wsDate, wsTime) &&
+ if (ValueSplitDateTime(wsValue, wsDate, wsTime) &&
ValidateCanonicalDate(wsDate, &dt) && ValidateCanonicalTime(wsTime)) {
return true;
}
@@ -443,82 +432,80 @@ bool CXFA_LocaleValue::ValidateCanonicalValue(const CFX_WideString& wsValue,
}
return true;
}
+
bool CXFA_LocaleValue::ValidateCanonicalDate(const CFX_WideString& wsDate,
CFX_DateTime* unDate) {
- const uint16_t LastDay[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
- const uint16_t wCountY = 4, wCountM = 2, wCountD = 2;
+ static const uint16_t LastDay[12] = {31, 28, 31, 30, 31, 30,
+ 31, 31, 30, 31, 30, 31};
+ static const uint16_t wCountY = 4;
+ static const uint16_t wCountM = 2;
+ static const uint16_t wCountD = 2;
int nLen = wsDate.GetLength();
- if (nLen < wCountY || nLen > wCountY + wCountM + wCountD + 2) {
+ if (nLen < wCountY || nLen > wCountY + wCountM + wCountD + 2)
return false;
- }
+
const bool bSymbol = wsDate.Find(0x2D) != -1;
uint16_t wYear = 0;
uint16_t wMonth = 0;
uint16_t wDay = 0;
const wchar_t* pDate = wsDate.c_str();
- int nIndex = 0, nStart = 0;
+ int nIndex = 0;
+ int nStart = 0;
while (pDate[nIndex] != '\0' && nIndex < wCountY) {
- if (!FXSYS_isDecimalDigit(pDate[nIndex])) {
+ if (!FXSYS_isDecimalDigit(pDate[nIndex]))
return false;
- }
+
wYear = (pDate[nIndex] - '0') + wYear * 10;
nIndex++;
}
if (bSymbol) {
- if (pDate[nIndex] != 0x2D) {
+ if (pDate[nIndex] != 0x2D)
return false;
- }
nIndex++;
}
+
nStart = nIndex;
while (pDate[nIndex] != '\0' && nIndex - nStart < wCountM && nIndex < nLen) {
- if (!FXSYS_isDecimalDigit(pDate[nIndex])) {
+ if (!FXSYS_isDecimalDigit(pDate[nIndex]))
return false;
- }
+
wMonth = (pDate[nIndex] - '0') + wMonth * 10;
nIndex++;
}
if (bSymbol) {
- if (pDate[nIndex] != 0x2D) {
+ if (pDate[nIndex] != 0x2D)
return false;
- }
nIndex++;
}
+
nStart = nIndex;
while (pDate[nIndex] != '\0' && nIndex - nStart < wCountD && nIndex < nLen) {
- if (!FXSYS_isDecimalDigit(pDate[nIndex])) {
+ if (!FXSYS_isDecimalDigit(pDate[nIndex]))
return false;
- }
+
wDay = (pDate[nIndex] - '0') + wDay * 10;
nIndex++;
}
- if (nIndex != nLen) {
+ if (nIndex != nLen)
return false;
- }
- if (wYear < 1900 || wYear > 2029) {
+ if (wYear < 1900 || wYear > 2029)
return false;
- }
if (wMonth < 1 || wMonth > 12) {
- if (wMonth == 0 && nLen == wCountY) {
+ if (wMonth == 0 && nLen == wCountY)
return true;
- }
return false;
}
if (wDay < 1) {
- if (wDay == 0 && (nLen == wCountY + wCountM)) {
+ if (wDay == 0 && (nLen == wCountY + wCountM))
return true;
- }
return false;
}
if (wMonth == 2) {
if (wYear % 400 == 0 || (wYear % 100 != 0 && wYear % 4 == 0)) {
- if (wDay > 29) {
- return false;
- }
- } else {
- if (wDay > 28) {
+ if (wDay > 29)
return false;
- }
+ } else if (wDay > 28) {
+ return false;
}
} else if (wDay > LastDay[wMonth - 1]) {
return false;
@@ -533,6 +520,7 @@ bool CXFA_LocaleValue::ValidateCanonicalTime(const CFX_WideString& wsTime) {
int nLen = wsTime.GetLength();
if (nLen < 2)
return false;
+
const uint16_t wCountH = 2;
const uint16_t wCountM = 2;
const uint16_t wCountS = 2;
@@ -556,6 +544,7 @@ bool CXFA_LocaleValue::ValidateCanonicalTime(const CFX_WideString& wsTime) {
return false;
nIndex++;
}
+
nStart = nIndex;
while (nIndex - nStart < wCountM && nIndex < nLen && pTime[nIndex]) {
if (!FXSYS_isDecimalDigit(pTime[nIndex]))
@@ -635,14 +624,11 @@ bool CXFA_LocaleValue::ParsePatternValue(const CFX_WideString& wsValue,
int32_t iCount = pdfium::CollectionSize<int32_t>(wsPatterns);
for (int32_t i = 0; i < iCount && !bRet; i++) {
CFX_WideString wsFormat = wsPatterns[i];
- FX_LOCALECATEGORY eCategory = pFormat->GetCategory(wsFormat);
- eCategory = XFA_ValugeCategory(eCategory, m_dwType);
- switch (eCategory) {
+ switch (ValueCategory(pFormat->GetCategory(wsFormat), m_dwType)) {
case FX_LOCALECATEGORY_Null:
bRet = pFormat->ParseNull(wsValue, wsFormat);
- if (bRet) {
+ if (bRet)
m_wsValue.clear();
- }
break;
case FX_LOCALECATEGORY_Zero:
bRet = pFormat->ParseZero(wsValue, wsFormat);
@@ -652,9 +638,8 @@ bool CXFA_LocaleValue::ParsePatternValue(const CFX_WideString& wsValue,
case FX_LOCALECATEGORY_Num: {
CFX_WideString fNum;
bRet = pFormat->ParseNum(wsValue, wsFormat, fNum);
- if (bRet) {
+ if (bRet)
m_wsValue = fNum;
- }
break;
}
case FX_LOCALECATEGORY_Text:
@@ -702,19 +687,18 @@ bool CXFA_LocaleValue::ParsePatternValue(const CFX_WideString& wsValue,
return bRet;
}
-void CXFA_LocaleValue::GetNumbericFormat(CFX_WideString& wsFormat,
- int32_t nIntLen,
- int32_t nDecLen,
- bool bSign) {
+void CXFA_LocaleValue::GetNumericFormat(CFX_WideString& wsFormat,
+ int32_t nIntLen,
+ int32_t nDecLen) {
ASSERT(wsFormat.IsEmpty());
ASSERT(nIntLen >= -1 && nDecLen >= -1);
- int32_t nTotalLen = (nIntLen >= 0 ? nIntLen : 2) + (bSign ? 1 : 0) +
+
+ int32_t nTotalLen = (nIntLen >= 0 ? nIntLen : 2) + 1 +
(nDecLen >= 0 ? nDecLen : 2) + (nDecLen == 0 ? 0 : 1);
wchar_t* lpBuf = wsFormat.GetBuffer(nTotalLen);
int32_t nPos = 0;
- if (bSign) {
- lpBuf[nPos++] = L's';
- }
+ lpBuf[nPos++] = L's';
+
if (nIntLen == -1) {
lpBuf[nPos++] = L'z';
lpBuf[nPos++] = L'*';
@@ -738,37 +722,37 @@ void CXFA_LocaleValue::GetNumbericFormat(CFX_WideString& wsFormat,
}
wsFormat.ReleaseBuffer(nTotalLen);
}
-bool CXFA_LocaleValue::ValidateNumericTemp(CFX_WideString& wsNumeric,
- CFX_WideString& wsFormat,
- IFX_Locale* pLocale,
- int32_t* pos) {
- if (wsFormat.IsEmpty() || wsNumeric.IsEmpty()) {
+
+bool CXFA_LocaleValue::ValidateNumericTemp(const CFX_WideString& wsNumeric,
+ const CFX_WideString& wsFormat,
+ IFX_Locale* pLocale) {
+ if (wsFormat.IsEmpty() || wsNumeric.IsEmpty())
return true;
- }
+
const wchar_t* pNum = wsNumeric.c_str();
const wchar_t* pFmt = wsFormat.c_str();
- int32_t n = 0, nf = 0;
+ int32_t n = 0;
+ int32_t nf = 0;
wchar_t c = pNum[n];
wchar_t cf = pFmt[nf];
if (cf == L's') {
- if (c == L'-' || c == L'+') {
+ if (c == L'-' || c == L'+')
++n;
- }
++nf;
}
+
bool bLimit = true;
int32_t nCount = wsNumeric.GetLength();
int32_t nCountFmt = wsFormat.GetLength();
while (n < nCount && (bLimit ? nf < nCountFmt : true) &&
FXSYS_isDecimalDigit(c = pNum[n])) {
if (bLimit == true) {
- if ((cf = pFmt[nf]) == L'*') {
+ if ((cf = pFmt[nf]) == L'*')
bLimit = false;
- } else if (cf == L'z') {
+ else if (cf == L'z')
nf++;
- } else {
+ else
return false;
- }
}
n++;
}
@@ -781,6 +765,7 @@ bool CXFA_LocaleValue::ValidateNumericTemp(CFX_WideString& wsNumeric,
ASSERT(cf == L'z' || cf == L'*');
++nf;
}
+
CFX_WideString wsDecimalSymbol;
if (pLocale)
wsDecimalSymbol = pLocale->GetNumbericSymbol(FX_LOCALENUMSYMBOL_Decimal);
@@ -798,13 +783,12 @@ bool CXFA_LocaleValue::ValidateNumericTemp(CFX_WideString& wsNumeric,
while (n < nCount && (bLimit ? nf < nCountFmt : true) &&
FXSYS_isDecimalDigit(c = pNum[n])) {
if (bLimit == true) {
- if ((cf = pFmt[nf]) == L'*') {
+ if ((cf = pFmt[nf]) == L'*')
bLimit = false;
- } else if (cf == L'z') {
+ else if (cf == L'z')
nf++;
- } else {
+ else
return false;
- }
}
n++;
}
diff --git a/xfa/fxfa/parser/cxfa_localevalue.h b/xfa/fxfa/parser/cxfa_localevalue.h
index d263dba476..caf4b0c0f1 100644
--- a/xfa/fxfa/parser/cxfa_localevalue.h
+++ b/xfa/fxfa/parser/cxfa_localevalue.h
@@ -44,11 +44,30 @@ class CXFA_LocaleValue {
bool ValidateValue(const CFX_WideString& wsValue,
const CFX_WideString& wsPattern,
IFX_Locale* pLocale,
- CFX_WideString* pMatchFormat = nullptr);
+ CFX_WideString* pMatchFormat);
+
bool FormatPatterns(CFX_WideString& wsResult,
const CFX_WideString& wsFormat,
IFX_Locale* pLocale,
XFA_VALUEPICTURE eValueType) const;
+
+ void GetNumericFormat(CFX_WideString& wsFormat,
+ int32_t nIntLen,
+ int32_t nDecLen);
+ bool ValidateNumericTemp(const CFX_WideString& wsNumeric,
+ const CFX_WideString& wsFormat,
+ IFX_Locale* pLocale);
+
+ CFX_WideString GetValue() const { return m_wsValue; }
+ uint32_t GetType() const { return m_dwType; }
+ double GetDoubleNum() const;
+ bool SetDate(const CFX_DateTime& d);
+ CFX_DateTime GetDate() const;
+ CFX_DateTime GetTime() const;
+
+ bool IsValid() const { return m_bValid; }
+
+ private:
bool FormatSinglePattern(CFX_WideString& wsResult,
const CFX_WideString& wsFormat,
IFX_Locale* pLocale,
@@ -57,29 +76,14 @@ class CXFA_LocaleValue {
bool ValidateCanonicalDate(const CFX_WideString& wsDate,
CFX_DateTime* unDate);
bool ValidateCanonicalTime(const CFX_WideString& wsTime);
- void GetNumbericFormat(CFX_WideString& wsFormat,
- int32_t nIntLen,
- int32_t nDecLen,
- bool bSign = true);
- bool ValidateNumericTemp(CFX_WideString& wsNumeric,
- CFX_WideString& wsFormat,
- IFX_Locale* pLocale = nullptr,
- int32_t* pos = nullptr);
-
- CFX_WideString GetValue() const;
- uint32_t GetType() const;
- double GetDoubleNum() const;
- CFX_DateTime GetDate() const;
- CFX_DateTime GetTime() const;
- bool SetDate(const CFX_DateTime& d);
+
bool SetTime(const CFX_DateTime& t);
bool SetDateTime(const CFX_DateTime& dt);
- bool IsValid() const { return m_bValid; }
- private:
bool ParsePatternValue(const CFX_WideString& wsValue,
const CFX_WideString& wsPattern,
IFX_Locale* pLocale);
+
CXFA_LocaleMgr* m_pLocaleMgr;
CFX_WideString m_wsValue;
uint32_t m_dwType;