From 1e25e122849b0e16032f5b3d62bace4d3ce5253d Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Fri, 16 Jun 2017 02:14:40 -0700 Subject: Simplify code in the JS printf/printd implementations. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Iec6749044796945e77cee57e74ab6611f82fa813 Reviewed-on: https://pdfium-review.googlesource.com/6672 Reviewed-by: Nicolás Peña Commit-Queue: Lei Zhang --- fpdfsdk/javascript/util.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'fpdfsdk') 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; } } -- cgit v1.2.3