summaryrefslogtreecommitdiff
path: root/fxjs
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-11-16 21:45:18 +0000
committerChromium commit bot <commit-bot@chromium.org>2017-11-16 21:45:18 +0000
commit3f1c832dda209cf6682bb75316c07d71332fe6c3 (patch)
tree79e274e65a500bc7964fe4328a6185c805274640 /fxjs
parent40d522134a11867adb95f77c0b7891932e0739a2 (diff)
downloadpdfium-3f1c832dda209cf6682bb75316c07d71332fe6c3.tar.xz
Make WideString::{Format|FormatV} static
This CL moves the Format and FormatV methods from WideString to be static. Bug: pdfium:934 Change-Id: I9941d6a2a5bbf0a82087cd0ea5d0f8fc42eecd3e Reviewed-on: https://pdfium-review.googlesource.com/18630 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'fxjs')
-rw-r--r--fxjs/cfxjse_formcalc_context.cpp4
-rw-r--r--fxjs/cjs_publicmethods.cpp68
-rw-r--r--fxjs/cjs_runtime.cpp4
-rw-r--r--fxjs/cjs_util.cpp33
-rw-r--r--fxjs/cjx_node.cpp23
-rw-r--r--fxjs/cjx_object.cpp4
6 files changed, 65 insertions, 71 deletions
diff --git a/fxjs/cfxjse_formcalc_context.cpp b/fxjs/cfxjse_formcalc_context.cpp
index e7e0e48871..dfd381625c 100644
--- a/fxjs/cfxjse_formcalc_context.cpp
+++ b/fxjs/cfxjse_formcalc_context.cpp
@@ -6260,11 +6260,11 @@ void CFXJSE_FormCalcContext::ThrowArgumentMismatchException() const {
}
void CFXJSE_FormCalcContext::ThrowException(const wchar_t* str, ...) const {
- WideString wsMessage;
va_list arg_ptr;
va_start(arg_ptr, str);
- wsMessage.FormatV(str, arg_ptr);
+ WideString wsMessage = WideString::FormatV(str, arg_ptr);
va_end(arg_ptr);
+
ASSERT(!wsMessage.IsEmpty());
FXJSE_ThrowMessage(wsMessage.UTF8Encode().AsStringView());
}
diff --git a/fxjs/cjs_publicmethods.cpp b/fxjs/cjs_publicmethods.cpp
index 8bcfd3c39b..856fa11732 100644
--- a/fxjs/cjs_publicmethods.cpp
+++ b/fxjs/cjs_publicmethods.cpp
@@ -399,9 +399,8 @@ double CJS_PublicMethods::ParseNormalDate(const WideString& value,
return dt;
}
- WideString swTemp;
- swTemp.Format(L"%d/%d/%d %d:%d:%d", nMonth, nDay, nYear, nHour, nMin, nSec);
- return JS_DateParse(swTemp);
+ return JS_DateParse(WideString::Format(L"%d/%d/%d %d:%d:%d", nMonth, nDay,
+ nYear, nHour, nMin, nSec));
}
double CJS_PublicMethods::MakeRegularDate(const WideString& value,
@@ -707,22 +706,23 @@ WideString CJS_PublicMethods::MakeFormatDate(double dDate,
sPart += c;
break;
case 'm':
- sPart.Format(L"%d", nMonth);
+ sPart = WideString::Format(L"%d", nMonth);
break;
case 'd':
- sPart.Format(L"%d", nDay);
+ sPart = WideString::Format(L"%d", nDay);
break;
case 'H':
- sPart.Format(L"%d", nHour);
+ sPart = WideString::Format(L"%d", nHour);
break;
case 'h':
- sPart.Format(L"%d", nHour > 12 ? nHour - 12 : nHour);
+ sPart =
+ WideString::Format(L"%d", nHour > 12 ? nHour - 12 : nHour);
break;
case 'M':
- sPart.Format(L"%d", nMin);
+ sPart = WideString::Format(L"%d", nMin);
break;
case 's':
- sPart.Format(L"%d", nSec);
+ sPart = WideString::Format(L"%d", nSec);
break;
case 't':
sPart += nHour > 12 ? 'p' : 'a';
@@ -732,25 +732,26 @@ WideString CJS_PublicMethods::MakeFormatDate(double dDate,
} else if (remaining == 1 || format[i + 2] != c) {
switch (c) {
case 'y':
- sPart.Format(L"%02d", nYear - (nYear / 100) * 100);
+ sPart = WideString::Format(L"%02d", nYear - (nYear / 100) * 100);
break;
case 'm':
- sPart.Format(L"%02d", nMonth);
+ sPart = WideString::Format(L"%02d", nMonth);
break;
case 'd':
- sPart.Format(L"%02d", nDay);
+ sPart = WideString::Format(L"%02d", nDay);
break;
case 'H':
- sPart.Format(L"%02d", nHour);
+ sPart = WideString::Format(L"%02d", nHour);
break;
case 'h':
- sPart.Format(L"%02d", nHour > 12 ? nHour - 12 : nHour);
+ sPart =
+ WideString::Format(L"%02d", nHour > 12 ? nHour - 12 : nHour);
break;
case 'M':
- sPart.Format(L"%02d", nMin);
+ sPart = WideString::Format(L"%02d", nMin);
break;
case 's':
- sPart.Format(L"%02d", nSec);
+ sPart = WideString::Format(L"%02d", nSec);
break;
case 't':
sPart = nHour > 12 ? L"pm" : L"am";
@@ -774,7 +775,7 @@ WideString CJS_PublicMethods::MakeFormatDate(double dDate,
} else if (remaining == 3 || format[i + 4] != c) {
switch (c) {
case 'y':
- sPart.Format(L"%04d", nYear);
+ sPart = WideString::Format(L"%04d", nYear);
i += 4;
break;
case 'm':
@@ -1148,9 +1149,8 @@ CJS_Return CJS_PublicMethods::AFDate_FormatEx(
}
if (std::isnan(dDate)) {
- WideString swMsg;
- swMsg.Format(JSGetStringFromID(JSMessage::kParseDateError).c_str(),
- sFormat.c_str());
+ WideString swMsg = WideString::Format(
+ JSGetStringFromID(JSMessage::kParseDateError).c_str(), sFormat.c_str());
AlertIfPossible(pContext, swMsg.c_str());
return CJS_Return(false);
}
@@ -1236,9 +1236,9 @@ CJS_Return CJS_PublicMethods::AFDate_KeystrokeEx(
bool bWrongFormat = false;
double dRet = MakeRegularDate(strValue, sFormat, &bWrongFormat);
if (bWrongFormat || std::isnan(dRet)) {
- WideString swMsg;
- swMsg.Format(JSGetStringFromID(JSMessage::kParseDateError).c_str(),
- sFormat.c_str());
+ WideString swMsg = WideString::Format(
+ JSGetStringFromID(JSMessage::kParseDateError).c_str(),
+ sFormat.c_str());
AlertIfPossible(pContext, swMsg.c_str());
pEvent->Rc() = false;
return CJS_Return(true);
@@ -1552,9 +1552,8 @@ CJS_Return CJS_PublicMethods::AFParseDateEx(
WideString sFormat = pRuntime->ToWideString(params[1]);
double dDate = MakeRegularDate(sValue, sFormat, nullptr);
if (std::isnan(dDate)) {
- WideString swMsg;
- swMsg.Format(JSGetStringFromID(JSMessage::kParseDateError).c_str(),
- sFormat.c_str());
+ WideString swMsg = WideString::Format(
+ JSGetStringFromID(JSMessage::kParseDateError).c_str(), sFormat.c_str());
AlertIfPossible(pRuntime->GetCurrentEventContext(), swMsg.c_str());
return CJS_Return(false);
}
@@ -1706,17 +1705,20 @@ CJS_Return CJS_PublicMethods::AFRange_Validate(
if (bGreaterThan && bLessThan) {
if (dEentValue < dGreaterThan || dEentValue > dLessThan)
- swMsg.Format(JSGetStringFromID(JSMessage::kRangeBetweenError).c_str(),
- pRuntime->ToWideString(params[1]).c_str(),
- pRuntime->ToWideString(params[3]).c_str());
+ swMsg = WideString::Format(
+ JSGetStringFromID(JSMessage::kRangeBetweenError).c_str(),
+ pRuntime->ToWideString(params[1]).c_str(),
+ pRuntime->ToWideString(params[3]).c_str());
} else if (bGreaterThan) {
if (dEentValue < dGreaterThan)
- swMsg.Format(JSGetStringFromID(JSMessage::kRangeGreaterError).c_str(),
- pRuntime->ToWideString(params[1]).c_str());
+ swMsg = WideString::Format(
+ JSGetStringFromID(JSMessage::kRangeGreaterError).c_str(),
+ pRuntime->ToWideString(params[1]).c_str());
} else if (bLessThan) {
if (dEentValue > dLessThan)
- swMsg.Format(JSGetStringFromID(JSMessage::kRangeLessError).c_str(),
- pRuntime->ToWideString(params[3]).c_str());
+ swMsg = WideString::Format(
+ JSGetStringFromID(JSMessage::kRangeLessError).c_str(),
+ pRuntime->ToWideString(params[3]).c_str());
}
if (!swMsg.IsEmpty()) {
diff --git a/fxjs/cjs_runtime.cpp b/fxjs/cjs_runtime.cpp
index 8a3b166cbd..87224af8e2 100644
--- a/fxjs/cjs_runtime.cpp
+++ b/fxjs/cjs_runtime.cpp
@@ -208,8 +208,8 @@ int CJS_Runtime::ExecuteScript(const WideString& script, WideString* info) {
FXJSErr error = {};
int nRet = Execute(script, &error);
if (nRet < 0) {
- info->Format(L"[ Line: %05d { %s } ] : %s", error.linnum - 1, error.srcline,
- error.message);
+ *info = WideString::Format(L"[ Line: %05d { %s } ] : %s", error.linnum - 1,
+ error.srcline, error.message);
}
return nRet;
}
diff --git a/fxjs/cjs_util.cpp b/fxjs/cjs_util.cpp
index 9fc1093158..c7bf027695 100644
--- a/fxjs/cjs_util.cpp
+++ b/fxjs/cjs_util.cpp
@@ -115,19 +115,20 @@ CJS_Return util::printf(CJS_Runtime* pRuntime,
WideString strSegment;
switch (ParseDataType(&c_strFormat)) {
case UTIL_INT:
- strSegment.Format(c_strFormat.c_str(),
- pRuntime->ToInt32(params[iIndex]));
+ strSegment = WideString::Format(c_strFormat.c_str(),
+ pRuntime->ToInt32(params[iIndex]));
break;
case UTIL_DOUBLE:
- strSegment.Format(c_strFormat.c_str(),
- pRuntime->ToDouble(params[iIndex]));
+ strSegment = WideString::Format(c_strFormat.c_str(),
+ pRuntime->ToDouble(params[iIndex]));
break;
case UTIL_STRING:
- strSegment.Format(c_strFormat.c_str(),
- pRuntime->ToWideString(params[iIndex]).c_str());
+ strSegment =
+ WideString::Format(c_strFormat.c_str(),
+ pRuntime->ToWideString(params[iIndex]).c_str());
break;
default:
- strSegment.Format(L"%ls", c_strFormat.c_str());
+ strSegment = WideString::Format(L"%ls", c_strFormat.c_str());
break;
}
c_strResult += strSegment.c_str();
@@ -164,16 +165,16 @@ CJS_Return util::printd(CJS_Runtime* pRuntime,
WideString swResult;
switch (pRuntime->ToInt32(params[0])) {
case 0:
- swResult.Format(L"D:%04d%02d%02d%02d%02d%02d", year, month, day, hour,
- min, sec);
+ swResult = WideString::Format(L"D:%04d%02d%02d%02d%02d%02d", year,
+ month, day, hour, min, sec);
break;
case 1:
- swResult.Format(L"%04d.%02d.%02d %02d:%02d:%02d", year, month, day,
- hour, min, sec);
+ swResult = WideString::Format(L"%04d.%02d.%02d %02d:%02d:%02d", year,
+ month, day, hour, min, sec);
break;
case 2:
- swResult.Format(L"%04d/%02d/%02d %02d:%02d:%02d", year, month, day,
- hour, min, sec);
+ swResult = WideString::Format(L"%04d/%02d/%02d %02d:%02d:%02d", year,
+ month, day, hour, min, sec);
break;
default:
return CJS_Return(JSGetStringFromID(JSMessage::kValueError));
@@ -215,9 +216,6 @@ CJS_Return util::printd(CJS_Runtime* pRuntime,
};
for (size_t i = 0; i < FX_ArraySize(cTableAd); ++i) {
- WideString sValue;
- sValue.Format(L"%d", cTableAd[i].iValue);
-
int iStart = 0;
int iEnd;
while ((iEnd = cFormat.find(cTableAd[i].lpszJSMark, iStart)) != -1) {
@@ -227,7 +225,8 @@ CJS_Return util::printd(CJS_Runtime* pRuntime,
continue;
}
}
- cFormat.replace(iEnd, wcslen(cTableAd[i].lpszJSMark), sValue.c_str());
+ cFormat.replace(iEnd, wcslen(cTableAd[i].lpszJSMark),
+ WideString::Format(L"%d", cTableAd[i].iValue).c_str());
iStart = iEnd;
}
}
diff --git a/fxjs/cjx_node.cpp b/fxjs/cjx_node.cpp
index 17662dada6..b89101ce17 100644
--- a/fxjs/cjx_node.cpp
+++ b/fxjs/cjx_node.cpp
@@ -297,10 +297,7 @@ pdfium::Optional<WideString> CJX_Node::TryAttribute(XFA_Attribute eAttr,
pdfium::Optional<int32_t> iValue = TryInteger(pAttr->eName, bUseDefault);
if (!iValue)
return {};
-
- WideString wsValue;
- wsValue.Format(L"%d", *iValue);
- return {wsValue};
+ return {WideString::Format(L"%d", *iValue)};
}
case XFA_AttributeType::Measure: {
pdfium::Optional<CXFA_Measurement> value =
@@ -1555,9 +1552,8 @@ void CJX_Node::Script_Som_BorderColor(CFXJSE_Value* pValue,
int32_t g;
int32_t b;
std::tie(a, r, g, b) = ArgbDecode(color);
- WideString strColor;
- strColor.Format(L"%d,%d,%d", r, g, b);
- pValue->SetString(strColor.UTF8Encode().AsStringView());
+ pValue->SetString(
+ WideString::Format(L"%d,%d,%d", r, g, b).UTF8Encode().AsStringView());
}
void CJX_Node::Script_Som_BorderWidth(CFXJSE_Value* pValue,
@@ -1610,9 +1606,8 @@ void CJX_Node::Script_Som_FillColor(CFXJSE_Value* pValue,
int32_t g;
int32_t b;
std::tie(a, r, g, b) = ArgbDecode(color);
- WideString wsColor;
- wsColor.Format(L"%d,%d,%d", r, g, b);
- pValue->SetString(wsColor.UTF8Encode().AsStringView());
+ pValue->SetString(
+ WideString::Format(L"%d,%d,%d", r, g, b).UTF8Encode().AsStringView());
}
void CJX_Node::Script_Som_DataNode(CFXJSE_Value* pValue,
@@ -3285,10 +3280,10 @@ bool CJX_Node::SetValue(XFA_Attribute eAttr,
elem->SetString(pInfo->pName, pValue ? L"1" : L"0");
break;
case XFA_AttributeType::Integer: {
- WideString wsValue;
- wsValue.Format(L"%d",
- static_cast<int32_t>(reinterpret_cast<uintptr_t>(pValue)));
- elem->SetString(pInfo->pName, wsValue);
+ elem->SetString(
+ pInfo->pName,
+ WideString::Format(L"%d", static_cast<int32_t>(
+ reinterpret_cast<uintptr_t>(pValue))));
break;
}
default:
diff --git a/fxjs/cjx_object.cpp b/fxjs/cjx_object.cpp
index 80a54fc8a0..49c147ba95 100644
--- a/fxjs/cjx_object.cpp
+++ b/fxjs/cjx_object.cpp
@@ -48,11 +48,9 @@ void CJX_Object::ThrowArgumentMismatchException() const {
}
void CJX_Object::ThrowException(const wchar_t* str, ...) const {
- WideString wsMessage;
va_list arg_ptr;
-
va_start(arg_ptr, str);
- wsMessage.FormatV(str, arg_ptr);
+ WideString wsMessage = WideString::FormatV(str, arg_ptr);
va_end(arg_ptr);
ASSERT(!wsMessage.IsEmpty());