Convert remaining signed indices to size_t in cfgas_formatstring.cpp
Consolidate one private method into its only public caller.
Change-Id: Ibfcd852c4b46e854fdfacb81d9e250094819c776
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/51710
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/xfa/fgas/crt/cfgas_formatstring.cpp b/xfa/fgas/crt/cfgas_formatstring.cpp
index 1d4fd55..d30fa7b 100644
--- a/xfa/fgas/crt/cfgas_formatstring.cpp
+++ b/xfa/fgas/crt/cfgas_formatstring.cpp
@@ -15,6 +15,10 @@
#include "third_party/base/span.h"
#include "xfa/fgas/crt/cfgas_decimal.h"
+// NOTE: Code uses the convention for backwards-looping with unsigned types
+// that exploits the well-defined behaviour for unsigned underflow (and hence
+// the standard x < size() can be used in all cases to validate indices).
+
#define FX_LOCALECATEGORY_DateHash 0xbde9abde
#define FX_LOCALECATEGORY_TimeHash 0x2d71b00f
#define FX_LOCALECATEGORY_DateTimeHash 0x158c72ed
@@ -141,23 +145,25 @@
}
WideString GetLiteralTextReverse(pdfium::span<const wchar_t> pStrPattern,
- int32_t* iPattern) {
+ size_t* iPattern) {
WideString wsOutput;
- if (pStrPattern[*iPattern] != '\'')
+ if (*iPattern >= pStrPattern.size() || pStrPattern[*iPattern] != '\'')
return wsOutput;
(*iPattern)--;
int32_t iQuote = 1;
- while (*iPattern >= 0) {
+
+ while (*iPattern < pStrPattern.size()) {
if (pStrPattern[*iPattern] == '\'') {
iQuote++;
- if (*iPattern - 1 < 0 ||
+ if (*iPattern - 1 >= pStrPattern.size() ||
((pStrPattern[*iPattern - 1] != '\'') && (iQuote % 2 == 0))) {
break;
}
iQuote++;
(*iPattern)--;
} else if (pStrPattern[*iPattern] == '\\' &&
+ *iPattern + 1 < pStrPattern.size() &&
pStrPattern[*iPattern + 1] == 'u') {
(*iPattern)--;
int32_t iKeyValue = 0;
@@ -180,7 +186,7 @@
bool GetNumericDotIndex(const WideString& wsNum,
const WideString& wsDotSymbol,
- int32_t* iDotIndex) {
+ size_t* iDotIndex) {
pdfium::span<const wchar_t> spNum = wsNum.AsSpan();
pdfium::span<const wchar_t> spDotSymbol = wsDotSymbol.AsSpan();
for (size_t ccf = 0; ccf < spNum.size(); ++ccf) {
@@ -200,13 +206,11 @@
}
bool ExtractCountDigits(pdfium::span<const wchar_t> str,
- int count,
- int* cc,
+ size_t count,
+ size_t* cc,
uint32_t* value) {
- for (int i = count; i > 0; --i) {
- if (*cc >= pdfium::CollectionSize<int32_t>(str))
- return false;
- if (!FXSYS_IsDecimalDigit(str[*cc]))
+ for (size_t i = 0; i < count; ++i) {
+ if (*cc >= str.size() || !FXSYS_IsDecimalDigit(str[*cc]))
return false;
*value = *value * 10 + FXSYS_DecimalCharToInt(str[(*cc)++]);
}
@@ -215,7 +219,7 @@
bool ExtractCountDigitsWithOptional(pdfium::span<const wchar_t> str,
int count,
- int* cc,
+ size_t* cc,
uint32_t* value) {
if (!ExtractCountDigits(str, count, cc, value))
return false;
@@ -227,7 +231,7 @@
const WideString& wsDatePattern,
LocaleIface* pLocale,
CFX_DateTime* datetime,
- int32_t* cc) {
+ size_t* cc) {
uint32_t year = 1900;
uint32_t month = 1;
uint32_t day = 1;
@@ -235,12 +239,11 @@
pdfium::span<const wchar_t> spDate = wsDate.AsSpan();
pdfium::span<const wchar_t> spDatePattern = wsDatePattern.AsSpan();
WideStringView wsDateSymbols(gs_wsDateSymbols);
- while (*cc < pdfium::CollectionSize<int32_t>(spDate) &&
- ccf < spDatePattern.size()) {
+ while (*cc < spDate.size() && ccf < spDatePattern.size()) {
if (spDatePattern[ccf] == '\'') {
WideString wsLiteral = GetLiteralText(spDatePattern, &ccf);
int32_t iLiteralLen = wsLiteral.GetLength();
- if (*cc + iLiteralLen > pdfium::CollectionSize<int32_t>(spDate) ||
+ if (*cc + iLiteralLen > spDate.size() ||
wcsncmp(spDate.data() + *cc, wsLiteral.c_str(), iLiteralLen) != 0) {
return false;
}
@@ -318,7 +321,7 @@
*cc += symbol.GetLength();
}
}
- if (*cc < pdfium::CollectionSize<int32_t>(spDate))
+ if (*cc < spDate.size())
return false;
datetime->SetDate(year, month, day);
@@ -348,7 +351,7 @@
const WideString& wsTimePattern,
LocaleIface* pLocale,
CFX_DateTime* datetime,
- int32_t* cc) {
+ size_t* cc) {
uint32_t hour = 0;
uint32_t minute = 0;
uint32_t second = 0;
@@ -359,13 +362,12 @@
bool bHasA = false;
bool bPM = false;
WideStringView wsTimeSymbols(gs_wsTimeSymbols);
- while (*cc < pdfium::CollectionSize<int32_t>(spTime) &&
- ccf < spTimePattern.size()) {
+ while (*cc < spTime.size() && ccf < spTimePattern.size()) {
if (spTimePattern[ccf] == '\'') {
WideString wsLiteral = GetLiteralText(spTimePattern, &ccf);
int32_t iLiteralLen = wsLiteral.GetLength();
- if (*cc + iLiteralLen > pdfium::CollectionSize<int32_t>(spTime) ||
- wcsncmp(spTime.data() + *cc, wsLiteral.c_str(), iLiteralLen)) {
+ if (*cc + iLiteralLen > spTime.size() ||
+ wcsncmp(spTime.data() + *cc, wsLiteral.c_str(), iLiteralLen) != 0) {
return false;
}
*cc += iLiteralLen;
@@ -434,7 +436,7 @@
bPM = true;
}
} else if (symbol.EqualsASCII("Z")) {
- if (*cc + 3 > pdfium::CollectionSize<int32_t>(spTime))
+ if (*cc + 3 > spTime.size())
continue;
WideString tz(spTime[(*cc)++]);
@@ -444,8 +446,7 @@
FX_TIMEZONE tzDiff;
tzDiff.tzHour = 0;
tzDiff.tzMinute = 0;
- if (*cc < pdfium::CollectionSize<int32_t>(spTime) &&
- (spTime[*cc] == '-' || spTime[*cc] == '+')) {
+ if (*cc < spTime.size() && (spTime[*cc] == '-' || spTime[*cc] == '+')) {
*cc += ParseTimeZone(spTime.subspan(*cc), &tzDiff);
}
ResolveZone(tzDiff, pLocale, &hour, &minute);
@@ -717,13 +718,13 @@
if (spDate.size() > 10)
return false;
- int cc = 0;
+ size_t cc = 0;
uint32_t year = 0;
if (!ExtractCountDigits(spDate, 4, &cc, &year))
return false;
if (year < 1900)
return false;
- if (cc >= pdfium::CollectionSize<int32_t>(spDate)) {
+ if (cc >= spDate.size()) {
datetime->SetDate(year, 1, 1);
return true;
}
@@ -732,11 +733,10 @@
cc++;
uint32_t month = 0;
- if (!ExtractCountDigits(spDate, 2, &cc, &month))
+ if (!ExtractCountDigits(spDate, 2, &cc, &month) || month < 1 || month > 12)
return false;
- if (month > 12 || month < 1)
- return false;
- if (cc >= pdfium::CollectionSize<int32_t>(spDate)) {
+
+ if (cc >= spDate.size()) {
datetime->SetDate(year, month, 1);
return true;
}
@@ -766,12 +766,12 @@
if (spTime.empty())
return false;
- int cc = 0;
+ size_t cc = 0;
uint32_t hour = 0;
if (!ExtractCountDigits(spTime, 2, &cc, &hour) || hour >= 24)
return false;
- if (cc >= pdfium::CollectionSize<int32_t>(spTime)) {
+ if (cc >= spTime.size()) {
datetime->SetTime(hour, 0, 0, 0);
return true;
}
@@ -780,12 +780,10 @@
cc++;
uint32_t minute = 0;
- if (!ExtractCountDigits(spTime, 2, &cc, &minute))
- return false;
- if (minute >= 60)
+ if (!ExtractCountDigits(spTime, 2, &cc, &minute) || minute >= 60)
return false;
- if (cc >= pdfium::CollectionSize<int32_t>(spTime)) {
+ if (cc >= spTime.size()) {
datetime->SetTime(hour, minute, 0, 0);
return true;
}
@@ -799,7 +797,7 @@
if (!ExtractCountDigits(spTime, 2, &cc, &second) || second >= 60)
return false;
- if (cc < pdfium::CollectionSize<int32_t>(spTime) && spTime[cc] == '.') {
+ if (cc < spTime.size() && spTime[cc] == '.') {
cc++;
if (!ExtractCountDigits(spTime, 3, &cc, &millisecond))
return false;
@@ -807,13 +805,13 @@
}
// Skip until we find a + or - for the time zone.
- while (cc < pdfium::CollectionSize<int32_t>(spTime)) {
+ while (cc < spTime.size()) {
if (spTime[cc] == '+' || spTime[cc] == '-')
break;
++cc;
}
- if (cc < pdfium::CollectionSize<int32_t>(spTime)) {
+ if (cc < spTime.size()) {
FX_TIMEZONE tzDiff;
tzDiff.tzHour = 0;
tzDiff.tzMinute = 0;
@@ -957,7 +955,7 @@
LocaleIface* CFGAS_FormatString::GetNumericFormat(
const WideString& wsPattern,
- int32_t* iDotIndex,
+ size_t* iDotIndex,
uint32_t* dwStyle,
WideString* wsPurgePattern) const {
*dwStyle = 0;
@@ -1139,7 +1137,7 @@
if (wsSrcNum.IsEmpty() || wsPattern.IsEmpty())
return false;
- int32_t dot_index_f = -1;
+ size_t dot_index_f = wsPattern.GetLength();
uint32_t dwFormatStyle = 0;
WideString wsNumFormat;
LocaleIface* pLocale =
@@ -1160,7 +1158,7 @@
bool bHavePercentSymbol = false;
bool bNeg = false;
bool bReverseParse = false;
- int32_t dot_index = 0;
+ size_t dot_index = 0;
// If we're looking for a '.', 'V' or 'v' and the input string does not
// have a dot index for one of those, then we disable parsing the decimal.
@@ -1176,16 +1174,17 @@
// the number. The second while() walks from the dot forwards to the end of
// the decimal.
- // Use ints for the moment for backwards indexing.
- int cc = dot_index - 1;
- for (int ccf = dot_index_f - 1; ccf >= 0 && cc >= 0;) {
+ size_t cc = dot_index - 1;
+ size_t ccf = dot_index_f - 1;
+ while (ccf < spNumFormat.size() && cc < spSrcNum.size()) {
switch (spNumFormat[ccf]) {
case '\'': {
WideString wsLiteral = GetLiteralTextReverse(spNumFormat, &ccf);
int32_t iLiteralLen = wsLiteral.GetLength();
cc -= iLiteralLen - 1;
- if (cc < 0 || wcsncmp(spSrcNum.data() + cc, wsLiteral.c_str(),
- iLiteralLen) != 0) {
+ if (cc >= spSrcNum.size() ||
+ wcsncmp(spSrcNum.data() + cc, wsLiteral.c_str(), iLiteralLen) !=
+ 0) {
return false;
}
cc--;
@@ -1219,7 +1218,7 @@
cc--;
} else {
cc -= iMinusLen - 1;
- if (cc < 0 ||
+ if (cc >= spSrcNum.size() ||
wcsncmp(spSrcNum.data() + cc, wsMinus.c_str(), iMinusLen) != 0) {
return false;
}
@@ -1230,7 +1229,7 @@
break;
case 'E': {
bool bExpSign = false;
- while (cc >= 0) {
+ while (cc < spSrcNum.size()) {
if (spSrcNum[cc] == 'E' || spSrcNum[cc] == 'e')
break;
if (FXSYS_IsDecimalDigit(spSrcNum[cc])) {
@@ -1242,7 +1241,7 @@
cc--;
continue;
}
- if (cc - iMinusLen + 1 > 0 &&
+ if (cc - iMinusLen + 1 <= spSrcNum.size() &&
wcsncmp(spSrcNum.data() + (cc - iMinusLen + 1), wsMinus.c_str(),
iMinusLen) == 0) {
bExpSign = true;
@@ -1261,7 +1260,7 @@
WideString wsSymbol = pLocale->GetCurrencySymbol();
int32_t iSymbolLen = wsSymbol.GetLength();
cc -= iSymbolLen - 1;
- if (cc < 0 ||
+ if (cc >= spSrcNum.size() ||
wcsncmp(spSrcNum.data() + cc, wsSymbol.c_str(), iSymbolLen) != 0) {
return false;
}
@@ -1271,12 +1270,12 @@
}
case 'r':
case 'R':
- if (ccf - 1 >= 0 &&
+ if (ccf - 1 < spNumFormat.size() &&
((spNumFormat[ccf] == 'R' && spNumFormat[ccf - 1] == 'C') ||
(spNumFormat[ccf] == 'r' && spNumFormat[ccf - 1] == 'c'))) {
if (spNumFormat[ccf] == 'R' && spSrcNum[cc] == ' ') {
cc -= 2;
- } else if (spSrcNum[cc] == 'R' && cc - 1 >= 0 &&
+ } else if (spSrcNum[cc] == 'R' && cc - 1 < spSrcNum.size() &&
spSrcNum[cc - 1] == 'C') {
bNeg = true;
cc -= 2;
@@ -1288,12 +1287,12 @@
break;
case 'b':
case 'B':
- if (ccf - 1 >= 0 &&
+ if (ccf - 1 < spNumFormat.size() &&
((spNumFormat[ccf] == 'B' && spNumFormat[ccf - 1] == 'D') ||
(spNumFormat[ccf] == 'b' && spNumFormat[ccf - 1] == 'd'))) {
if (spNumFormat[ccf] == 'B' && spSrcNum[cc] == ' ') {
cc -= 2;
- } else if (spSrcNum[cc] == 'B' && cc - 1 >= 0 &&
+ } else if (spSrcNum[cc] == 'B' && cc - 1 < spSrcNum.size() &&
spSrcNum[cc - 1] == 'D') {
bNeg = true;
cc -= 2;
@@ -1307,7 +1306,7 @@
WideString wsSymbol = pLocale->GetPercentSymbol();
int32_t iSysmbolLen = wsSymbol.GetLength();
cc -= iSysmbolLen - 1;
- if (cc < 0 ||
+ if (cc >= spSrcNum.size() ||
wcsncmp(spSrcNum.data() + cc, wsSymbol.c_str(), iSysmbolLen) != 0) {
return false;
}
@@ -1322,10 +1321,11 @@
case '8':
return false;
case ',': {
- if (cc >= 0) {
+ if (cc < spSrcNum.size()) {
cc -= iGroupLen - 1;
- if (cc >= 0 && wcsncmp(spSrcNum.data() + cc, wsGroupSymbol.c_str(),
- iGroupLen) == 0) {
+ if (cc < spSrcNum.size() &&
+ wcsncmp(spSrcNum.data() + cc, wsGroupSymbol.c_str(), iGroupLen) ==
+ 0) {
cc--;
} else {
cc += iGroupLen - 1;
@@ -1352,31 +1352,26 @@
ccf--;
}
}
- if (cc >= 0) {
+ if (cc < spSrcNum.size()) {
if (spSrcNum[cc] == '-') {
bNeg = true;
cc--;
}
- if (cc >= 0)
+ if (cc < spSrcNum.size())
return false;
}
- if ((dwFormatStyle & FX_NUMSTYLE_DotVorv) &&
- dot_index < pdfium::CollectionSize<int32_t>(spSrcNum)) {
+ if ((dwFormatStyle & FX_NUMSTYLE_DotVorv) && dot_index < spSrcNum.size())
*wsValue += '.';
- }
+
if (!bReverseParse) {
- cc = (dot_index == pdfium::CollectionSize<int32_t>(spSrcNum))
- ? spSrcNum.size()
- : dot_index + 1;
- for (size_t ccf = dot_index_f + 1;
- cc < pdfium::CollectionSize<int32_t>(spSrcNum) &&
- ccf < spNumFormat.size();
- ++ccf) {
+ cc = (dot_index == spSrcNum.size()) ? spSrcNum.size() : dot_index + 1;
+ for (ccf = dot_index_f + 1;
+ cc < spSrcNum.size() && ccf < spNumFormat.size(); ++ccf) {
switch (spNumFormat[ccf]) {
case '\'': {
WideString wsLiteral = GetLiteralText(spNumFormat, &ccf);
int32_t iLiteralLen = wsLiteral.GetLength();
- if (cc + iLiteralLen > pdfium::CollectionSize<int32_t>(spSrcNum) ||
+ if (cc + iLiteralLen > spSrcNum.size() ||
wcsncmp(spSrcNum.data() + cc, wsLiteral.c_str(), iLiteralLen) !=
0) {
return false;
@@ -1408,7 +1403,7 @@
(spNumFormat[ccf] == 'S' && spSrcNum[cc] == ' ')) {
cc++;
} else {
- if (cc + iMinusLen > pdfium::CollectionSize<int32_t>(spSrcNum) ||
+ if (cc + iMinusLen > spSrcNum.size() ||
wcsncmp(spSrcNum.data() + cc, wsMinus.c_str(), iMinusLen) !=
0) {
return false;
@@ -1418,13 +1413,13 @@
}
break;
case 'E': {
- if (cc >= pdfium::CollectionSize<int32_t>(spSrcNum) ||
+ if (cc >= spSrcNum.size() ||
(spSrcNum[cc] != 'E' && spSrcNum[cc] != 'e')) {
return false;
}
bool bExpSign = false;
cc++;
- if (cc < pdfium::CollectionSize<int32_t>(spSrcNum)) {
+ if (cc < spSrcNum.size()) {
if (spSrcNum[cc] == '+') {
cc++;
} else if (spSrcNum[cc] == '-') {
@@ -1432,10 +1427,9 @@
cc++;
}
}
- while (cc < pdfium::CollectionSize<int32_t>(spSrcNum)) {
+ while (cc < spSrcNum.size()) {
if (!FXSYS_IsDecimalDigit(spSrcNum[cc]))
break;
-
iExponent = iExponent * 10 + FXSYS_DecimalCharToInt(spSrcNum[cc]);
cc++;
}
@@ -1445,7 +1439,7 @@
case '$': {
WideString wsSymbol = pLocale->GetCurrencySymbol();
int32_t iSymbolLen = wsSymbol.GetLength();
- if (cc + iSymbolLen > pdfium::CollectionSize<int32_t>(spSrcNum) ||
+ if (cc + iSymbolLen > spSrcNum.size() ||
wcsncmp(spSrcNum.data() + cc, wsSymbol.c_str(), iSymbolLen) !=
0) {
return false;
@@ -1460,8 +1454,7 @@
(spNumFormat[ccf] == 'c' && spNumFormat[ccf + 1] == 'r'))) {
if (spNumFormat[ccf] == 'C' && spSrcNum[cc] == ' ') {
cc++;
- } else if (spSrcNum[cc] == 'C' &&
- cc + 1 < pdfium::CollectionSize<int32_t>(spSrcNum) &&
+ } else if (spSrcNum[cc] == 'C' && cc + 1 < spSrcNum.size() &&
spSrcNum[cc + 1] == 'R') {
bNeg = true;
cc += 2;
@@ -1476,8 +1469,7 @@
(spNumFormat[ccf] == 'd' && spNumFormat[ccf + 1] == 'b'))) {
if (spNumFormat[ccf] == 'D' && spSrcNum[cc] == ' ') {
cc++;
- } else if (spSrcNum[cc] == 'D' &&
- cc + 1 < pdfium::CollectionSize<int32_t>(spSrcNum) &&
+ } else if (spSrcNum[cc] == 'D' && cc + 1 < spSrcNum.size() &&
spSrcNum[cc + 1] == 'B') {
bNeg = true;
cc += 2;
@@ -1492,7 +1484,7 @@
case '%': {
WideString wsSymbol = pLocale->GetPercentSymbol();
int32_t iSysmbolLen = wsSymbol.GetLength();
- if (cc + iSysmbolLen <= pdfium::CollectionSize<int32_t>(spSrcNum) &&
+ if (cc + iSysmbolLen <= spSrcNum.size() &&
wcsncmp(spSrcNum.data() + cc, wsSymbol.c_str(), iSysmbolLen) ==
0) {
cc += iSysmbolLen;
@@ -1503,14 +1495,13 @@
while (ccf + 1 < spNumFormat.size() && spNumFormat[ccf + 1] == '8')
ccf++;
- while (cc < pdfium::CollectionSize<int32_t>(spSrcNum) &&
- FXSYS_IsDecimalDigit(spSrcNum[cc])) {
+ while (cc < spSrcNum.size() && FXSYS_IsDecimalDigit(spSrcNum[cc])) {
*wsValue += spSrcNum[cc];
cc++;
}
} break;
case ',': {
- if (cc + iGroupLen <= pdfium::CollectionSize<int32_t>(spSrcNum) &&
+ if (cc + iGroupLen <= spSrcNum.size() &&
wcsncmp(spSrcNum.data() + cc, wsGroupSymbol.c_str(), iGroupLen) ==
0) {
cc += iGroupLen;
@@ -1533,7 +1524,7 @@
cc++;
}
}
- if (cc != pdfium::CollectionSize<int32_t>(spSrcNum))
+ if (cc != spSrcNum.size())
return false;
}
if (iExponent || bHavePercentSymbol) {
@@ -1710,7 +1701,7 @@
if (eCategory == FX_DATETIMETYPE_Unknown)
return false;
if (eCategory == FX_DATETIMETYPE_TimeDate) {
- int32_t iStart = 0;
+ size_t iStart = 0;
if (!ParseLocaleTime(wsSrcDateTime, wsTimePattern, pLocale, dtValue,
&iStart)) {
return false;
@@ -1720,7 +1711,7 @@
return false;
}
} else {
- int32_t iStart = 0;
+ size_t iStart = 0;
if ((eCategory & FX_DATETIMETYPE_Date) &&
!ParseLocaleDate(wsSrcDateTime, wsDatePattern, pLocale, dtValue,
&iStart)) {
@@ -1852,13 +1843,13 @@
return iText == spSrcText.size();
}
-bool CFGAS_FormatString::FormatStrNum(WideStringView wsInputNum,
- const WideString& wsPattern,
- WideString* wsOutput) const {
- ASSERT(!wsInputNum.IsEmpty());
- ASSERT(!wsPattern.IsEmpty());
+bool CFGAS_FormatString::FormatNum(const WideString& wsInputNum,
+ const WideString& wsPattern,
+ WideString* wsOutput) const {
+ if (wsInputNum.IsEmpty() || wsPattern.IsEmpty())
+ return false;
- int32_t dot_index_f = -1;
+ size_t dot_index_f = wsPattern.GetLength();
uint32_t dwNumStyle = 0;
WideString wsNumFormat;
LocaleIface* pLocale =
@@ -1866,10 +1857,8 @@
if (!pLocale || wsNumFormat.IsEmpty())
return false;
- int32_t cc = 0;
-
pdfium::span<const wchar_t> spNumFormat = wsNumFormat.AsSpan();
- WideString wsSrcNum(wsInputNum);
+ WideString wsSrcNum = wsInputNum;
wsSrcNum.TrimLeft('0');
if (wsSrcNum.IsEmpty() || wsSrcNum[0] == '.')
wsSrcNum.InsertAtFront('0');
@@ -1883,20 +1872,19 @@
int32_t exponent = 0;
if (dwNumStyle & FX_NUMSTYLE_Exponent) {
int fixed_count = 0;
- if (dot_index_f > 0) {
- for (size_t ccf = 0; ccf < static_cast<size_t>(dot_index_f); ++ccf) {
- switch (spNumFormat[ccf]) {
- case '\'':
- GetLiteralText(spNumFormat, &ccf);
- break;
- case '9':
- case 'z':
- case 'Z':
- fixed_count++;
- break;
- }
+ for (size_t ccf = 0; ccf < dot_index_f; ++ccf) {
+ switch (spNumFormat[ccf]) {
+ case '\'':
+ GetLiteralText(spNumFormat, &ccf);
+ break;
+ case '9':
+ case 'z':
+ case 'Z':
+ fixed_count++;
+ break;
}
}
+
FX_SAFE_UINT32 threshold = 1;
while (fixed_count > 1) {
threshold *= 10;
@@ -1951,14 +1939,13 @@
if (!dot_index.has_value())
dot_index = spSrcNum.size();
- cc = dot_index.value() - 1;
- for (int ccf = dot_index_f - 1; ccf >= 0; --ccf) {
+ size_t cc = dot_index.value() - 1;
+ for (size_t ccf = dot_index_f - 1; ccf < spNumFormat.size(); --ccf) {
switch (spNumFormat[ccf]) {
case '9':
- if (cc >= 0) {
+ if (cc < spSrcNum.size()) {
if (!FXSYS_IsDecimalDigit(spSrcNum[cc]))
return false;
-
wsOutput->InsertAtFront(spSrcNum[cc]);
cc--;
} else {
@@ -1966,20 +1953,18 @@
}
break;
case 'z':
- if (cc >= 0) {
+ if (cc < spSrcNum.size()) {
if (!FXSYS_IsDecimalDigit(spSrcNum[cc]))
return false;
-
if (spSrcNum[0] != '0')
wsOutput->InsertAtFront(spSrcNum[cc]);
cc--;
}
break;
case 'Z':
- if (cc >= 0) {
+ if (cc < spSrcNum.size()) {
if (!FXSYS_IsDecimalDigit(spSrcNum[cc]))
return false;
-
wsOutput->InsertAtFront(spSrcNum[0] == '0' ? L' ' : spSrcNum[cc]);
cc--;
} else {
@@ -2007,7 +1992,7 @@
*wsOutput = pLocale->GetCurrencySymbol() + *wsOutput;
break;
case 'r':
- if (ccf - 1 >= 0 && spNumFormat[ccf - 1] == 'c') {
+ if (ccf - 1 < spNumFormat.size() && spNumFormat[ccf - 1] == 'c') {
if (bNeg)
*wsOutput = L"CR" + *wsOutput;
ccf--;
@@ -2017,7 +2002,7 @@
}
break;
case 'R':
- if (ccf - 1 >= 0 && spNumFormat[ccf - 1] == 'C') {
+ if (ccf - 1 < spNumFormat.size() && spNumFormat[ccf - 1] == 'C') {
*wsOutput = bNeg ? L"CR" : L" " + *wsOutput;
ccf--;
bAddNeg = true;
@@ -2026,7 +2011,7 @@
}
break;
case 'b':
- if (ccf - 1 >= 0 && spNumFormat[ccf - 1] == 'd') {
+ if (ccf - 1 < spNumFormat.size() && spNumFormat[ccf - 1] == 'd') {
if (bNeg)
*wsOutput = L"db" + *wsOutput;
ccf--;
@@ -2036,7 +2021,7 @@
}
break;
case 'B':
- if (ccf - 1 >= 0 && spNumFormat[ccf - 1] == 'D') {
+ if (ccf - 1 < spNumFormat.size() && spNumFormat[ccf - 1] == 'D') {
*wsOutput = bNeg ? L"DB" : L" " + *wsOutput;
ccf--;
bAddNeg = true;
@@ -2048,7 +2033,7 @@
*wsOutput = pLocale->GetPercentSymbol() + *wsOutput;
break;
case ',':
- if (cc >= 0)
+ if (cc < spSrcNum.size())
*wsOutput = wsGroupSymbol + *wsOutput;
break;
case '(':
@@ -2067,11 +2052,10 @@
}
}
- if (cc >= 0) {
+ if (cc < spSrcNum.size()) {
int nPos = dot_index.value() % 3;
wsOutput->clear();
- for (int32_t i = 0;
- i < pdfium::base::checked_cast<int32_t>(dot_index.value()); i++) {
+ for (size_t i = 0; i < dot_index.value(); i++) {
if (i % 3 == nPos && i != 0)
*wsOutput += wsGroupSymbol;
*wsOutput += wsSrcNum[i];
@@ -2084,8 +2068,7 @@
*wsOutput = pLocale->GetMinusSymbol() + *wsOutput;
return true;
}
- if (dot_index_f ==
- pdfium::base::checked_cast<int32_t>(wsNumFormat.GetLength())) {
+ if (dot_index_f == wsNumFormat.GetLength()) {
if (!bAddNeg && bNeg)
*wsOutput = pLocale->GetMinusSymbol() + *wsOutput;
return true;
@@ -2104,17 +2087,15 @@
}
cc = dot_index.value() + 1;
- for (size_t ccf = static_cast<size_t>(dot_index_f + 1);
- ccf < spNumFormat.size(); ++ccf) {
+ for (size_t ccf = dot_index_f + 1; ccf < spNumFormat.size(); ++ccf) {
switch (spNumFormat[ccf]) {
case '\'':
*wsOutput += GetLiteralText(spNumFormat, &ccf);
break;
case '9':
- if (cc < pdfium::CollectionSize<int32_t>(spSrcNum)) {
+ if (cc < spSrcNum.size()) {
if (!FXSYS_IsDecimalDigit(spSrcNum[cc]))
return false;
-
*wsOutput += spSrcNum[cc];
cc++;
} else {
@@ -2122,19 +2103,17 @@
}
break;
case 'z':
- if (cc < pdfium::CollectionSize<int32_t>(spSrcNum)) {
+ if (cc < spSrcNum.size()) {
if (!FXSYS_IsDecimalDigit(spSrcNum[cc]))
return false;
-
*wsOutput += spSrcNum[cc];
cc++;
}
break;
case 'Z':
- if (cc < pdfium::CollectionSize<int32_t>(spSrcNum)) {
+ if (cc < spSrcNum.size()) {
if (!FXSYS_IsDecimalDigit(spSrcNum[cc]))
return false;
-
*wsOutput += spSrcNum[cc];
cc++;
} else {
@@ -2184,8 +2163,7 @@
case '8':
while (ccf + 1 < spNumFormat.size() && spNumFormat[ccf + 1] == '8')
ccf++;
- while (cc < pdfium::CollectionSize<int32_t>(spSrcNum) &&
- FXSYS_IsDecimalDigit(spSrcNum[cc])) {
+ while (cc < spSrcNum.size() && FXSYS_IsDecimalDigit(spSrcNum[cc])) {
*wsOutput += spSrcNum[cc];
cc++;
}
@@ -2211,15 +2189,6 @@
return true;
}
-bool CFGAS_FormatString::FormatNum(const WideString& wsSrcNum,
- const WideString& wsPattern,
- WideString* wsOutput) const {
- if (wsSrcNum.IsEmpty() || wsPattern.IsEmpty())
- return false;
-
- return FormatStrNum(wsSrcNum.AsStringView(), wsPattern, wsOutput);
-}
-
bool CFGAS_FormatString::FormatDateTime(const WideString& wsSrcDateTime,
const WideString& wsPattern,
FX_DATETIMETYPE eDateTimeType,
diff --git a/xfa/fgas/crt/cfgas_formatstring.h b/xfa/fgas/crt/cfgas_formatstring.h
index f2a3253..aed49e0 100644
--- a/xfa/fgas/crt/cfgas_formatstring.h
+++ b/xfa/fgas/crt/cfgas_formatstring.h
@@ -61,12 +61,9 @@
WideString GetTextFormat(const WideString& wsPattern,
WideStringView wsCategory) const;
LocaleIface* GetNumericFormat(const WideString& wsPattern,
- int32_t* iDotIndex,
+ size_t* iDotIndex,
uint32_t* dwStyle,
WideString* wsPurgePattern) const;
- bool FormatStrNum(WideStringView wsInputNum,
- const WideString& wsPattern,
- WideString* wsOutput) const;
FX_DATETIMETYPE GetDateTimeFormat(const WideString& wsPattern,
LocaleIface** pLocale,
WideString* wsDatePattern,