From 275e260a6cd4a8e506ba974feb85ebcd926c1739 Mon Sep 17 00:00:00 2001 From: Ryan Harrison Date: Mon, 18 Sep 2017 14:23:18 -0400 Subject: Convert string class names Automated using git grep & sed. Replace StringC classes with StringView classes. Remove the CFX_ prefix and put string classes in fxcrt namespace. Change AsStringC() to AsStringView(). Rename tests from TEST(fxcrt, *String*Foo) to TEST(*String*, Foo). Couple of tests needed to have their names regularlized. BUG=pdfium:894 Change-Id: I7ca038685c8d803795f3ed02545124f7a224c83d Reviewed-on: https://pdfium-review.googlesource.com/14151 Reviewed-by: Tom Sepez Commit-Queue: Ryan Harrison --- core/fpdfapi/edit/cpdf_creator.cpp | 34 ++++++++--------- core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp | 16 ++++---- core/fpdfapi/edit/cpdf_pagecontentgenerator.h | 4 +- .../edit/cpdf_pagecontentgenerator_unittest.cpp | 43 +++++++++++----------- 4 files changed, 48 insertions(+), 49 deletions(-) (limited to 'core/fpdfapi/edit') diff --git a/core/fpdfapi/edit/cpdf_creator.cpp b/core/fpdfapi/edit/cpdf_creator.cpp index 38a21ba0cb..c3143b5322 100644 --- a/core/fpdfapi/edit/cpdf_creator.cpp +++ b/core/fpdfapi/edit/cpdf_creator.cpp @@ -33,7 +33,7 @@ class CFX_FileBufferArchive : public IFX_ArchiveStream { bool WriteBlock(const void* pBuf, size_t size) override; bool WriteByte(uint8_t byte) override; bool WriteDWord(uint32_t i) override; - bool WriteString(const CFX_ByteStringC& str) override; + bool WriteString(const ByteStringView& str) override; FX_FILESIZE CurrentOffset() const override { return offset_; } @@ -105,7 +105,7 @@ bool CFX_FileBufferArchive::WriteDWord(uint32_t i) { return WriteBlock(buf, static_cast(FXSYS_strlen(buf))); } -bool CFX_FileBufferArchive::WriteString(const CFX_ByteStringC& str) { +bool CFX_FileBufferArchive::WriteString(const ByteStringView& str) { return WriteBlock(str.raw_str(), str.GetLength()); } @@ -220,7 +220,7 @@ bool CPDF_Creator::WriteDirectObj(uint32_t objnum, break; case CPDF_Object::STRING: { - CFX_ByteString str = pObj->GetString(); + ByteString str = pObj->GetString(); bool bHex = pObj->AsString()->IsHex(); if (!m_pCryptoHandler || !bEncrypt) { if (!pObj->WriteTo(m_Archive.get())) @@ -229,9 +229,9 @@ bool CPDF_Creator::WriteDirectObj(uint32_t objnum, } CPDF_Encryptor encryptor(m_pCryptoHandler.Get(), objnum, (uint8_t*)str.c_str(), str.GetLength()); - CFX_ByteString content = PDF_EncodeString( - CFX_ByteString(encryptor.GetData(), encryptor.GetSize()), bHex); - if (!m_Archive->WriteString(content.AsStringC())) + ByteString content = PDF_EncodeString( + ByteString(encryptor.GetData(), encryptor.GetSize()), bHex); + if (!m_Archive->WriteString(content.AsStringView())) return false; break; } @@ -290,10 +290,10 @@ bool CPDF_Creator::WriteDirectObj(uint32_t objnum, bool bSignDict = p->IsSignatureDict(); for (const auto& it : *p) { bool bSignValue = false; - const CFX_ByteString& key = it.first; + const ByteString& key = it.first; CPDF_Object* pValue = it.second.get(); if (!m_Archive->WriteString("/") || - !m_Archive->WriteString(PDF_NameEncode(key).AsStringC())) { + !m_Archive->WriteString(PDF_NameEncode(key).AsStringView())) { return false; } @@ -521,11 +521,11 @@ int32_t CPDF_Creator::WriteDoc_Stage3() { m_XrefStart = m_Archive->CurrentOffset(); if (!IsIncremental() || !m_pParser->IsXRefStream()) { if (!IsIncremental() || m_pParser->GetLastXRefOffset() == 0) { - CFX_ByteString str; + ByteString str; str = pdfium::ContainsKey(m_ObjectOffsets, 1) ? "xref\r\n" : "xref\r\n0 1\r\n0000000000 65535 f\r\n"; - if (!m_Archive->WriteString(str.AsStringC())) + if (!m_Archive->WriteString(str.AsStringView())) return -1; m_CurObjNum = 1; @@ -542,7 +542,7 @@ int32_t CPDF_Creator::WriteDoc_Stage3() { } } if (m_iStage == 81) { - CFX_ByteString str; + ByteString str; uint32_t i = m_CurObjNum; uint32_t j; while (i <= dwLastObjNum) { @@ -575,7 +575,7 @@ int32_t CPDF_Creator::WriteDoc_Stage3() { m_iStage = 90; } if (m_iStage == 82) { - CFX_ByteString str; + ByteString str; uint32_t iCount = pdfium::CollectionSize(m_NewObjNumArray); uint32_t i = m_CurObjNum; while (i < iCount) { @@ -627,7 +627,7 @@ int32_t CPDF_Creator::WriteDoc_Stage4() { if (m_pParser) { CPDF_Dictionary* p = m_pParser->GetTrailer(); for (const auto& it : *p) { - const CFX_ByteString& key = it.first; + const ByteString& key = it.first; CPDF_Object* pValue = it.second.get(); if (key == "Encrypt" || key == "Size" || key == "Filter" || key == "Index" || key == "Length" || key == "Prev" || key == "W" || @@ -635,7 +635,7 @@ int32_t CPDF_Creator::WriteDoc_Stage4() { continue; } if (!m_Archive->WriteString(("/")) || - !m_Archive->WriteString(PDF_NameEncode(key).AsStringC())) { + !m_Archive->WriteString(PDF_NameEncode(key).AsStringView())) { return -1; } if (!pValue->IsInline()) { @@ -782,7 +782,7 @@ void CPDF_Creator::InitID() { } else { std::vector buffer = GenerateFileID((uint32_t)(uintptr_t)this, m_dwLastObjNum); - CFX_ByteString bsBuffer(buffer.data(), buffer.size()); + ByteString bsBuffer(buffer.data(), buffer.size()); m_pIDArray->AddNew(bsBuffer, true); } } @@ -795,7 +795,7 @@ void CPDF_Creator::InitID() { } std::vector buffer = GenerateFileID((uint32_t)(uintptr_t)this, m_dwLastObjNum); - CFX_ByteString bsBuffer(buffer.data(), buffer.size()); + ByteString bsBuffer(buffer.data(), buffer.size()); m_pIDArray->AddNew(bsBuffer, true); return; } @@ -803,7 +803,7 @@ void CPDF_Creator::InitID() { m_pIDArray->Add(m_pIDArray->GetObjectAt(0)->Clone()); if (m_pEncryptDict && !pOldIDArray && m_pParser && !idArrayPreExisting) { if (m_pEncryptDict->GetStringFor("Filter") == "Standard") { - CFX_ByteString user_pass = m_pParser->GetPassword(); + ByteString user_pass = m_pParser->GetPassword(); uint32_t flag = PDF_ENCRYPT_CONTENT; CPDF_SecurityHandler handler; handler.OnCreate(m_pEncryptDict.Get(), m_pIDArray.get(), diff --git a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp index 9153bf4cea..c0c6604671 100644 --- a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp +++ b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp @@ -121,9 +121,9 @@ void CPDF_PageContentGenerator::GenerateContent() { pStream->GetObjNum()); } -CFX_ByteString CPDF_PageContentGenerator::RealizeResource( +ByteString CPDF_PageContentGenerator::RealizeResource( uint32_t dwResourceObjNum, - const CFX_ByteString& bsType) { + const ByteString& bsType) { ASSERT(dwResourceObjNum); if (!m_pObjHolder->m_pResources) { m_pObjHolder->m_pResources = m_pDocument->NewIndirect(); @@ -135,7 +135,7 @@ CFX_ByteString CPDF_PageContentGenerator::RealizeResource( if (!pResList) pResList = m_pObjHolder->m_pResources->SetNewFor(bsType); - CFX_ByteString name; + ByteString name; int idnum = 1; while (1) { name.Format("FX%c%d", bsType[0], idnum); @@ -188,7 +188,7 @@ void CPDF_PageContentGenerator::ProcessImage(std::ostringstream* buf, pImage->ConvertStreamToIndirectObject(); uint32_t dwObjNum = pStream->GetObjNum(); - CFX_ByteString name = RealizeResource(dwObjNum, "XObject"); + ByteString name = RealizeResource(dwObjNum, "XObject"); if (bWasInline) pImageObj->SetImage(m_pDocument->GetPageData()->GetImage(dwObjNum)); @@ -295,7 +295,7 @@ void CPDF_PageContentGenerator::ProcessGraphics(std::ostringstream* buf, return; } - CFX_ByteString name; + ByteString name; auto it = m_pObjHolder->m_GraphicsMap.find(graphD); if (it != m_pObjHolder->m_GraphicsMap.end()) { name = it->second; @@ -330,7 +330,7 @@ void CPDF_PageContentGenerator::ProcessDefaultGraphics( defaultGraphics.strokeAlpha = 1.0f; defaultGraphics.blendType = FXDIB_BLEND_NORMAL; auto it = m_pObjHolder->m_GraphicsMap.find(defaultGraphics); - CFX_ByteString name; + ByteString name; if (it != m_pObjHolder->m_GraphicsMap.end()) { name = it->second; } else { @@ -368,7 +368,7 @@ void CPDF_PageContentGenerator::ProcessText(std::ostringstream* buf, return; fontD.baseFont = pFont->GetBaseFont(); auto it = m_pObjHolder->m_FontsMap.find(fontD); - CFX_ByteString dictName; + ByteString dictName; if (it != m_pObjHolder->m_FontsMap.end()) { dictName = it->second; } else { @@ -387,7 +387,7 @@ void CPDF_PageContentGenerator::ProcessText(std::ostringstream* buf, } *buf << "/" << PDF_NameEncode(dictName) << " " << pTextObj->GetFontSize() << " Tf "; - CFX_ByteString text; + ByteString text; for (uint32_t charcode : pTextObj->m_CharCodes) { if (charcode != CPDF_Font::kInvalidCharCode) pFont->AppendChar(&text, charcode); diff --git a/core/fpdfapi/edit/cpdf_pagecontentgenerator.h b/core/fpdfapi/edit/cpdf_pagecontentgenerator.h index 518d358451..433ad3361a 100644 --- a/core/fpdfapi/edit/cpdf_pagecontentgenerator.h +++ b/core/fpdfapi/edit/cpdf_pagecontentgenerator.h @@ -37,8 +37,8 @@ class CPDF_PageContentGenerator { void ProcessGraphics(std::ostringstream* buf, CPDF_PageObject* pPageObj); void ProcessDefaultGraphics(std::ostringstream* buf); void ProcessText(std::ostringstream* buf, CPDF_TextObject* pTextObj); - CFX_ByteString RealizeResource(uint32_t dwResourceObjNum, - const CFX_ByteString& bsType); + ByteString RealizeResource(uint32_t dwResourceObjNum, + const ByteString& bsType); CFX_UnownedPtr const m_pObjHolder; CFX_UnownedPtr const m_pDocument; diff --git a/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp b/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp index 1dd6d25e2a..a0db869410 100644 --- a/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp +++ b/core/fpdfapi/edit/cpdf_pagecontentgenerator_unittest.cpp @@ -36,8 +36,8 @@ class CPDF_PageContentGeneratorTest : public testing::Test { } CPDF_Dictionary* TestGetResource(CPDF_PageContentGenerator* pGen, - const CFX_ByteString& type, - const CFX_ByteString& name) { + const ByteString& type, + const ByteString& name) { return pGen->m_pObjHolder->m_pResources->GetDictFor(type)->GetDictFor(name); } @@ -58,7 +58,7 @@ TEST_F(CPDF_PageContentGeneratorTest, ProcessRect) { CPDF_PageContentGenerator generator(pTestPage.get()); std::ostringstream buf; TestProcessPath(&generator, &buf, pPathObj.get()); - EXPECT_EQ("q 1 0 0 1 0 0 cm 10 5 3 25 re B* Q\n", CFX_ByteString(buf)); + EXPECT_EQ("q 1 0 0 1 0 0 cm 10 5 3 25 re B* Q\n", ByteString(buf)); pPathObj = pdfium::MakeUnique(); pPathObj->m_Path.AppendPoint(CFX_PointF(0, 0), FXPT_TYPE::MoveTo, false); @@ -71,7 +71,7 @@ TEST_F(CPDF_PageContentGeneratorTest, ProcessRect) { buf.str(""); TestProcessPath(&generator, &buf, pPathObj.get()); - EXPECT_EQ("q 1 0 0 1 0 0 cm 0 0 5.2 3.78 re n Q\n", CFX_ByteString(buf)); + EXPECT_EQ("q 1 0 0 1 0 0 cm 0 0 5.2 3.78 re n Q\n", ByteString(buf)); } TEST_F(CPDF_PageContentGeneratorTest, ProcessPath) { @@ -105,7 +105,7 @@ TEST_F(CPDF_PageContentGeneratorTest, ProcessPath) { EXPECT_EQ( "q 1 0 0 1 0 0 cm 3.102 4.67 m 5.45 0.29 l 4.24 3.15 4.65 2.98 3.456 0.24" " c 10.6 11.15 l 11 12.5 l 11.46 12.67 11.84 12.96 12 13.64 c h f Q\n", - CFX_ByteString(buf)); + ByteString(buf)); } TEST_F(CPDF_PageContentGeneratorTest, ProcessGraphics) { @@ -132,7 +132,7 @@ TEST_F(CPDF_PageContentGeneratorTest, ProcessGraphics) { CPDF_PageContentGenerator generator(pTestPage.get()); std::ostringstream buf; TestProcessPath(&generator, &buf, pPathObj.get()); - CFX_ByteString pathString(buf); + ByteString pathString(buf); // Color RGB values used are integers divided by 255. EXPECT_EQ("q 0.501961 0.701961 0.34902 rg 1 0.901961 0 RG /", @@ -150,7 +150,7 @@ TEST_F(CPDF_PageContentGeneratorTest, ProcessGraphics) { pPathObj->m_GraphState.SetLineWidth(10.5f); buf.str(""); TestProcessPath(&generator, &buf, pPathObj.get()); - CFX_ByteString pathString2(buf); + ByteString pathString2(buf); EXPECT_EQ("q 0.501961 0.701961 0.34902 rg 1 0.901961 0 RG 10.5 w /", pathString2.Left(55)); EXPECT_EQ(" gs 1 0 0 1 0 0 cm 1 2 m 3 4 l 5 6 l h B Q\n", @@ -185,25 +185,25 @@ TEST_F(CPDF_PageContentGeneratorTest, ProcessStandardText) { pTextObj->SetText("Hello World"); std::ostringstream buf; TestProcessText(&generator, &buf, pTextObj.get()); - CFX_ByteString textString(buf); + ByteString textString(buf); auto firstResourceAt = textString.Find('/'); ASSERT_TRUE(firstResourceAt.has_value()); firstResourceAt = firstResourceAt.value() + 1; auto secondResourceAt = textString.ReverseFind('/'); ASSERT_TRUE(secondResourceAt.has_value()); secondResourceAt = secondResourceAt.value() + 1; - CFX_ByteString firstString = textString.Left(firstResourceAt.value()); - CFX_ByteString midString = + ByteString firstString = textString.Left(firstResourceAt.value()); + ByteString midString = textString.Mid(firstResourceAt.value(), secondResourceAt.value() - firstResourceAt.value()); - CFX_ByteString lastString = + ByteString lastString = textString.Right(textString.GetLength() - secondResourceAt.value()); // q and Q must be outside the BT .. ET operations - CFX_ByteString compareString1 = + ByteString compareString1 = "q 0.501961 0.701961 0.34902 rg 1 0.901961 0 RG /"; // Color RGB values used are integers divided by 255. - CFX_ByteString compareString2 = " gs BT 1 0 0 1 100 100 Tm /"; - CFX_ByteString compareString3 = " 10 Tf <48656C6C6F20576F726C64> Tj ET Q\n"; + ByteString compareString2 = " gs BT 1 0 0 1 100 100 Tm /"; + ByteString compareString3 = " 10 Tf <48656C6C6F20576F726C64> Tj ET Q\n"; EXPECT_LT(compareString1.GetLength() + compareString2.GetLength() + compareString3.GetLength(), textString.GetLength()); @@ -257,17 +257,16 @@ TEST_F(CPDF_PageContentGeneratorTest, ProcessText) { TestProcessText(&generator, &buf, pTextObj.get()); } - CFX_ByteString textString(buf); + ByteString textString(buf); auto firstResourceAt = textString.Find('/'); ASSERT_TRUE(firstResourceAt.has_value()); firstResourceAt = firstResourceAt.value() + 1; - CFX_ByteString firstString = textString.Left(firstResourceAt.value()); - CFX_ByteString lastString = + ByteString firstString = textString.Left(firstResourceAt.value()); + ByteString lastString = textString.Right(textString.GetLength() - firstResourceAt.value()); // q and Q must be outside the BT .. ET operations - CFX_ByteString compareString1 = "q BT 1 0 0 1 0 0 Tm /"; - CFX_ByteString compareString2 = - " 15.5 Tf <4920616D20696E646972656374> Tj ET Q\n"; + ByteString compareString1 = "q BT 1 0 0 1 0 0 Tm /"; + ByteString compareString2 = " 15.5 Tf <4920616D20696E646972656374> Tj ET Q\n"; EXPECT_LT(compareString1.GetLength() + compareString2.GetLength(), textString.GetLength()); EXPECT_EQ(compareString1, textString.Left(compareString1.GetLength())); @@ -305,7 +304,7 @@ TEST_F(CPDF_PageContentGeneratorTest, ProcessEmptyForm) { CPDF_PageContentGenerator generator(pTestForm.get()); std::ostringstream buf; generator.ProcessPageObjects(&buf); - EXPECT_EQ("", CFX_ByteString(buf)); + EXPECT_EQ("", ByteString(buf)); } TEST_F(CPDF_PageContentGeneratorTest, ProcessFormWithPath) { @@ -330,5 +329,5 @@ TEST_F(CPDF_PageContentGeneratorTest, ProcessFormWithPath) { CPDF_PageContentGenerator generator(pTestForm.get()); std::ostringstream process_buf; generator.ProcessPageObjects(&process_buf); - EXPECT_EQ(content, CFX_ByteString(process_buf)); + EXPECT_EQ(content, ByteString(process_buf)); } -- cgit v1.2.3