summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2017-06-16 02:14:40 -0700
committerChromium commit bot <commit-bot@chromium.org>2017-06-16 19:48:59 +0000
commit1e25e122849b0e16032f5b3d62bace4d3ce5253d (patch)
treef1e66f2b38ea584596b0cfb3e522bf5a80f29e7c
parent77e3fc5cebfb19aed09f920536200e017cff9a0b (diff)
downloadpdfium-1e25e122849b0e16032f5b3d62bace4d3ce5253d.tar.xz
Simplify code in the JS printf/printd implementations.
Change-Id: Iec6749044796945e77cee57e74ab6611f82fa813 Reviewed-on: https://pdfium-review.googlesource.com/6672 Reviewed-by: Nicolás Peña <npm@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
-rw-r--r--fpdfsdk/javascript/util.cpp10
1 files changed, 4 insertions, 6 deletions
diff --git a/fpdfsdk/javascript/util.cpp b/fpdfsdk/javascript/util.cpp
index bc968a59d9..72b94ab302 100644
--- a/fpdfsdk/javascript/util.cpp
+++ b/fpdfsdk/javascript/util.cpp
@@ -165,7 +165,7 @@ bool util::printf(CJS_Runtime* pRuntime,
strSegment.Format(L"%S", c_strFormat.c_str());
break;
}
- c_strResult += strSegment.GetBuffer(strSegment.GetLength() + 1);
+ c_strResult += strSegment.c_str();
}
c_strResult.erase(c_strResult.begin());
@@ -256,18 +256,15 @@ bool util::printd(CJS_Runtime* pRuntime,
int iMin = jsDate.GetMinutes(pRuntime);
int iSec = jsDate.GetSeconds(pRuntime);
- TbConvertAdditional cTableAd[] = {
+ static const TbConvertAdditional cTableAd[] = {
{L"m", iMonth + 1}, {L"d", iDay},
{L"H", iHour}, {L"h", iHour > 12 ? iHour - 12 : iHour},
{L"M", iMin}, {L"s", iSec},
};
for (size_t i = 0; i < FX_ArraySize(cTableAd); ++i) {
- wchar_t tszValue[16];
CFX_WideString sValue;
sValue.Format(L"%d", cTableAd[i].iValue);
- memcpy(tszValue, (wchar_t*)sValue.GetBuffer(sValue.GetLength() + 1),
- (sValue.GetLength() + 1) * sizeof(wchar_t));
int iStart = 0;
int iEnd;
@@ -278,7 +275,8 @@ bool util::printd(CJS_Runtime* pRuntime,
continue;
}
}
- cFormat.replace(iEnd, FXSYS_wcslen(cTableAd[i].lpszJSMark), tszValue);
+ cFormat.replace(iEnd, FXSYS_wcslen(cTableAd[i].lpszJSMark),
+ sValue.c_str());
iStart = iEnd;
}
}