From 1c4735aed9442a8e442214a23a3df94bd8fc99b5 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Thu, 16 Nov 2017 22:08:07 +0000 Subject: Convert ByteString::{Format|FormatV} to static methods This CL moves the Format and FormatV methods of ByteString to be static. Bug: pdfium:934 Change-Id: I9c30455a789aff9f619b9d5bf89c0712644f2d9a Reviewed-on: https://pdfium-review.googlesource.com/18650 Commit-Queue: dsinclair Reviewed-by: Tom Sepez --- fxjs/cfxjse_class.cpp | 3 +-- fxjs/cfxjse_formcalc_context.cpp | 43 +++++++++++++++------------------------- fxjs/cjx_node.cpp | 7 ++----- 3 files changed, 19 insertions(+), 34 deletions(-) (limited to 'fxjs') diff --git a/fxjs/cfxjse_class.cpp b/fxjs/cfxjse_class.cpp index 8f4334f89e..b2e747b4fd 100644 --- a/fxjs/cfxjse_class.cpp +++ b/fxjs/cfxjse_class.cpp @@ -108,8 +108,7 @@ void Context_GlobalObjToString( return; if (info.This() == info.Holder() && lpClass->name) { - ByteString szStringVal; - szStringVal.Format("[object %s]", lpClass->name); + ByteString szStringVal = ByteString::Format("[object %s]", lpClass->name); info.GetReturnValue().Set(v8::String::NewFromUtf8( info.GetIsolate(), szStringVal.c_str(), v8::String::kNormalString, szStringVal.GetLength())); diff --git a/fxjs/cfxjse_formcalc_context.cpp b/fxjs/cfxjse_formcalc_context.cpp index dfd381625c..f3c4ebe462 100644 --- a/fxjs/cfxjse_formcalc_context.cpp +++ b/fxjs/cfxjse_formcalc_context.cpp @@ -1114,16 +1114,10 @@ void CFXJSE_FormCalcContext::Date(CFXJSE_Value* pThis, time(¤tTime); struct tm* pTmStruct = gmtime(¤tTime); - ByteString bufferYear; - ByteString bufferMon; - ByteString bufferDay; - bufferYear.Format("%d", pTmStruct->tm_year + 1900); - bufferMon.Format("%02d", pTmStruct->tm_mon + 1); - bufferDay.Format("%02d", pTmStruct->tm_mday); - - ByteString bufferCurrent = bufferYear + bufferMon + bufferDay; - args.GetReturnValue()->SetInteger( - DateString2Num(bufferCurrent.AsStringView())); + args.GetReturnValue()->SetInteger(DateString2Num( + ByteString::Format("%d%02d%02d", pTmStruct->tm_year + 1900, + pTmStruct->tm_mon + 1, pTmStruct->tm_mday) + .AsStringView())); } // static @@ -1489,11 +1483,10 @@ void CFXJSE_FormCalcContext::Num2Date(CFXJSE_Value* pThis, } } - ByteString szIsoDateString; - szIsoDateString.Format("%d%02d%02d", iYear + i, iMonth, iDay); - ByteString szLocalDateString = - IsoDate2Local(pThis, szIsoDateString.AsStringView(), - formatString.AsStringView(), localString.AsStringView()); + ByteString szLocalDateString = IsoDate2Local( + pThis, + ByteString::Format("%d%02d%02d", iYear + i, iMonth, iDay).AsStringView(), + formatString.AsStringView(), localString.AsStringView()); args.GetReturnValue()->SetString(szLocalDateString.AsStringView()); } @@ -2019,9 +2012,8 @@ ByteString CFXJSE_FormCalcContext::Local2IsoDate( wsFormat, pLocale, pMgr) .GetDate(); - ByteString strIsoDate; - strIsoDate.Format("%4d-%02d-%02d", dt.GetYear(), dt.GetMonth(), dt.GetDay()); - return strIsoDate; + return ByteString::Format("%4d-%02d-%02d", dt.GetYear(), dt.GetMonth(), + dt.GetDay()); } // static @@ -2213,9 +2205,10 @@ ByteString CFXJSE_FormCalcContext::Num2AllTime(CFXJSE_Value* pThis, iSec += iZoneSec; } - ByteString strIsoTime; - strIsoTime.Format("%02d:%02d:%02d", iHour, iMin, iSec); - return IsoTime2Local(pThis, strIsoTime.AsStringView(), szFormat, szLocale); + return IsoTime2Local( + pThis, + ByteString::Format("%02d:%02d:%02d", iHour, iMin, iSec).AsStringView(), + szFormat, szLocale); } // static @@ -4232,14 +4225,13 @@ void CFXJSE_FormCalcContext::Str(CFXJSE_Value* pThis, 0, static_cast(ValueToFloat(pThis, precisionValue.get()))); } - ByteString numberString; ByteString formatStr = "%"; if (iPrecision) { formatStr += "."; formatStr += ByteString::FormatInteger(iPrecision); } formatStr += "f"; - numberString.Format(formatStr.c_str(), fNumber); + ByteString numberString = ByteString::Format(formatStr.c_str(), fNumber); const char* pData = numberString.c_str(); int32_t iLength = numberString.GetLength(); @@ -4505,11 +4497,8 @@ void CFXJSE_FormCalcContext::WordNum(CFXJSE_Value* pThis, return; } - ByteString numberString; - numberString.Format("%.2f", fNumber); - args.GetReturnValue()->SetString( - WordUS(numberString, iIdentifier).AsStringView()); + WordUS(ByteString::Format("%.2f", fNumber), iIdentifier).AsStringView()); } // static diff --git a/fxjs/cjx_node.cpp b/fxjs/cjx_node.cpp index b89101ce17..07b96b895f 100644 --- a/fxjs/cjx_node.cpp +++ b/fxjs/cjx_node.cpp @@ -1761,15 +1761,12 @@ void CJX_Node::Script_Som_FontColor(CFXJSE_Value* pValue, return; } - FX_ARGB color = fontData.GetColor(); int32_t a; int32_t r; int32_t g; int32_t b; - std::tie(a, r, g, b) = ArgbDecode(color); - ByteString bsColor; - bsColor.Format("%d,%d,%d", r, g, b); - pValue->SetString(bsColor.AsStringView()); + std::tie(a, r, g, b) = ArgbDecode(fontData.GetColor()); + pValue->SetString(ByteString::Format("%d,%d,%d", r, g, b).AsStringView()); } void CJX_Node::Script_Field_FormatMessage(CFXJSE_Value* pValue, -- cgit v1.2.3