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 --- fpdfsdk/cpdfsdk_datetime.cpp | 15 +++++---------- fpdfsdk/fpdf_flatten.cpp | 16 ++++++---------- fpdfsdk/fpdf_transformpage.cpp | 14 +++++--------- fpdfsdk/fpdfattachment.cpp | 12 +++++++----- fpdfsdk/fpdfeditpage.cpp | 6 +++--- fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp | 5 ++--- fpdfsdk/pwl/cpwl_font_map.cpp | 4 +--- 7 files changed, 29 insertions(+), 43 deletions(-) (limited to 'fpdfsdk') diff --git a/fpdfsdk/cpdfsdk_datetime.cpp b/fpdfsdk/cpdfsdk_datetime.cpp index ce22cae12f..332ae8e62e 100644 --- a/fpdfsdk/cpdfsdk_datetime.cpp +++ b/fpdfsdk/cpdfsdk_datetime.cpp @@ -264,16 +264,11 @@ CPDFSDK_DateTime& CPDFSDK_DateTime::FromPDFDateTimeString( } ByteString CPDFSDK_DateTime::ToCommonDateTimeString() { - ByteString str1; - str1.Format("%04d-%02u-%02u %02u:%02u:%02u ", m_year, m_month, m_day, m_hour, - m_minute, m_second); - if (m_tzHour < 0) - str1 += "-"; - else - str1 += "+"; - ByteString str2; - str2.Format("%02d:%02u", std::abs(static_cast(m_tzHour)), m_tzMinute); - return str1 + str2; + return ByteString::Format("%04d-%02u-%02u %02u:%02u:%02u ", m_year, m_month, + m_day, m_hour, m_minute, m_second) + + (m_tzHour < 0 ? "-" : "+") + + ByteString::Format("%02d:%02u", std::abs(static_cast(m_tzHour)), + m_tzMinute); } ByteString CPDFSDK_DateTime::ToPDFDateTimeString() { diff --git a/fpdfsdk/fpdf_flatten.cpp b/fpdfsdk/fpdf_flatten.cpp index 35d3617627..07fbd7cd9e 100644 --- a/fpdfsdk/fpdf_flatten.cpp +++ b/fpdfsdk/fpdf_flatten.cpp @@ -173,8 +173,8 @@ uint32_t NewIndirectContentsStream(const ByteString& key, CPDF_Stream* pNewContents = pDocument->NewIndirect( nullptr, 0, pdfium::MakeUnique(pDocument->GetByteStringPool())); - ByteString sStream; - sStream.Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str()); + ByteString sStream = + ByteString::Format("q 1 0 0 1 0 0 cm /%s Do Q", key.c_str()); pNewContents->SetData(sStream.raw_str(), sStream.GetLength()); return pNewContents->GetObjNum(); } @@ -301,10 +301,9 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFPage_Flatten(FPDF_PAGE page, int nFlag) { ByteString key; int nStreams = pdfium::CollectionSize(ObjectArray); if (nStreams > 0) { - ByteString sKey; int i = 0; while (i < INT_MAX) { - sKey.Format("FFT%d", i); + ByteString sKey = ByteString::Format("FFT%d", i); if (!pPageXObject->KeyExist(sKey)) { key = sKey; break; @@ -391,8 +390,7 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFPage_Flatten(FPDF_PAGE page, int nFlag) { if (!pXObject) pXObject = pNewXORes->SetNewFor("XObject"); - ByteString sFormName; - sFormName.Format("F%d", i); + ByteString sFormName = ByteString::Format("F%d", i); pXObject->SetNewFor(sFormName, pDocument, pObj->GetObjNum()); @@ -401,10 +399,8 @@ FPDF_EXPORT int FPDF_CALLCONV FPDFPage_Flatten(FPDF_PAGE page, int nFlag) { ByteString sStream(pAcc->GetData(), pAcc->GetSize()); CFX_Matrix matrix = pAPDic->GetMatrixFor("Matrix"); CFX_Matrix m = GetMatrix(rcAnnot, rcStream, matrix); - ByteString sTemp; - sTemp.Format("q %f 0 0 %f %f %f cm /%s Do Q\n", m.a, m.d, m.e, m.f, - sFormName.c_str()); - sStream += sTemp; + sStream += ByteString::Format("q %f 0 0 %f %f %f cm /%s Do Q\n", m.a, m.d, + m.e, m.f, sFormName.c_str()); pNewXObject->SetDataAndRemoveFilter(sStream.raw_str(), sStream.GetLength()); } pPageDict->RemoveFor("Annots"); diff --git a/fpdfsdk/fpdf_transformpage.cpp b/fpdfsdk/fpdf_transformpage.cpp index dcf19f2be7..b607dffc4e 100644 --- a/fpdfsdk/fpdf_transformpage.cpp +++ b/fpdfsdk/fpdf_transformpage.cpp @@ -114,15 +114,11 @@ FPDFPage_TransFormWithClip(FPDF_PAGE page, textBuf << "q "; CFX_FloatRect rect = CFXFloatRectFromFSRECTF(*clipRect); rect.Normalize(); - ByteString bsClipping; - bsClipping.Format("%f %f %f %f re W* n ", rect.left, rect.bottom, - rect.Width(), rect.Height()); - textBuf << bsClipping; - - ByteString bsMatix; - bsMatix.Format("%f %f %f %f %f %f cm ", matrix->a, matrix->b, matrix->c, - matrix->d, matrix->e, matrix->f); - textBuf << bsMatix; + + textBuf << ByteString::Format("%f %f %f %f re W* n ", rect.left, rect.bottom, + rect.Width(), rect.Height()); + textBuf << ByteString::Format("%f %f %f %f %f %f cm ", matrix->a, matrix->b, + matrix->c, matrix->d, matrix->e, matrix->f); CPDF_Dictionary* pPageDict = pPage->m_pFormDict.Get(); CPDF_Object* pContentObj = GetPageContent(pPageDict); diff --git a/fpdfsdk/fpdfattachment.cpp b/fpdfsdk/fpdfattachment.cpp index 7402114756..8b3c8fe20a 100644 --- a/fpdfsdk/fpdfattachment.cpp +++ b/fpdfsdk/fpdfattachment.cpp @@ -232,11 +232,13 @@ FPDFAttachment_SetFile(FPDF_ATTACHMENT attachment, // Set the creation date of the new attachment in the dictionary. CFX_DateTime dateTime; dateTime.Now(); - ByteString bsDateTime; - bsDateTime.Format("D:%d%02d%02d%02d%02d%02d", dateTime.GetYear(), - dateTime.GetMonth(), dateTime.GetDay(), dateTime.GetHour(), - dateTime.GetMinute(), dateTime.GetSecond()); - pParamsDict->SetNewFor("CreationDate", bsDateTime, false); + pParamsDict->SetNewFor( + "CreationDate", + ByteString::Format("D:%d%02d%02d%02d%02d%02d", dateTime.GetYear(), + dateTime.GetMonth(), dateTime.GetDay(), + dateTime.GetHour(), dateTime.GetMinute(), + dateTime.GetSecond()), + false); // Set the checksum of the new attachment in the dictionary. pParamsDict->SetNewFor( diff --git a/fpdfsdk/fpdfeditpage.cpp b/fpdfsdk/fpdfeditpage.cpp index db726b74f0..a032bf6607 100644 --- a/fpdfsdk/fpdfeditpage.cpp +++ b/fpdfsdk/fpdfeditpage.cpp @@ -105,9 +105,9 @@ FPDF_EXPORT FPDF_DOCUMENT FPDF_CALLCONV FPDF_CreateNewDocument() { if (time(¤tTime) != -1) { tm* pTM = localtime(¤tTime); if (pTM) { - DateStr.Format("D:%04d%02d%02d%02d%02d%02d", pTM->tm_year + 1900, - pTM->tm_mon + 1, pTM->tm_mday, pTM->tm_hour, pTM->tm_min, - pTM->tm_sec); + DateStr = ByteString::Format( + "D:%04d%02d%02d%02d%02d%02d", pTM->tm_year + 1900, pTM->tm_mon + 1, + pTM->tm_mday, pTM->tm_hour, pTM->tm_min, pTM->tm_sec); } } } diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp index 374fe566fc..bc6c7dbe13 100644 --- a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp +++ b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp @@ -434,9 +434,8 @@ void CPDFXFA_DocEnvironment::ExportData(CXFA_FFDoc* hDoc, return; RetainPtr fileWrite = MakeSeekableStream(pFileHandler); - ByteString content; if (fileType == FXFA_SAVEAS_XML) { - content = "\r\n"; + ByteString content = "\r\n"; fileWrite->WriteBlock(content.c_str(), fileWrite->GetSize(), content.GetLength()); CXFA_FFDoc* ffdoc = m_pContext->GetXFADocView()->GetDoc(); @@ -492,7 +491,7 @@ void CPDFXFA_DocEnvironment::ExportData(CXFA_FFDoc* hDoc, ByteString bPath = wPath.UTF8Encode(); const char* szFormat = "\n"; - content.Format(szFormat, bPath.c_str()); + ByteString content = ByteString::Format(szFormat, bPath.c_str()); fileWrite->WriteBlock(content.c_str(), fileWrite->GetSize(), content.GetLength()); } diff --git a/fpdfsdk/pwl/cpwl_font_map.cpp b/fpdfsdk/pwl/cpwl_font_map.cpp index 522b6ef67f..4a2ac4bcb8 100644 --- a/fpdfsdk/pwl/cpwl_font_map.cpp +++ b/fpdfsdk/pwl/cpwl_font_map.cpp @@ -260,9 +260,7 @@ CPDF_Font* CPWL_FontMap::AddSystemFont(CPDF_Document* pDoc, ByteString CPWL_FontMap::EncodeFontAlias(const ByteString& sFontName, int32_t nCharset) { - ByteString sPostfix; - sPostfix.Format("_%02X", nCharset); - return EncodeFontAlias(sFontName) + sPostfix; + return EncodeFontAlias(sFontName) + ByteString::Format("_%02X", nCharset); } ByteString CPWL_FontMap::EncodeFontAlias(const ByteString& sFontName) { -- cgit v1.2.3