Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(313)

Side by Side Diff: core/fpdfapi/parser/cpdf_syntax_parser.cpp

Issue 2509123002: Make CPDF_Object subclass constructors intern strings (Closed)
Patch Set: Nits Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/fpdfapi/parser/cpdf_syntax_parser.h ('k') | core/fpdfdoc/cpdf_filespec_unittest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 PDFium Authors. All rights reserved. 1 // Copyright 2016 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "core/fpdfapi/parser/cpdf_syntax_parser.h" 7 #include "core/fpdfapi/parser/cpdf_syntax_parser.h"
8 8
9 #include <vector> 9 #include <vector>
10 10
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 if (word == "true" || word == "false") 395 if (word == "true" || word == "false")
396 return pdfium::MakeUnique<CPDF_Boolean>(word == "true"); 396 return pdfium::MakeUnique<CPDF_Boolean>(word == "true");
397 397
398 if (word == "null") 398 if (word == "null")
399 return pdfium::MakeUnique<CPDF_Null>(); 399 return pdfium::MakeUnique<CPDF_Null>();
400 400
401 if (word == "(") { 401 if (word == "(") {
402 CFX_ByteString str = ReadString(); 402 CFX_ByteString str = ReadString();
403 if (m_pCryptoHandler && bDecrypt) 403 if (m_pCryptoHandler && bDecrypt)
404 m_pCryptoHandler->Decrypt(objnum, gennum, str); 404 m_pCryptoHandler->Decrypt(objnum, gennum, str);
405 return pdfium::MakeUnique<CPDF_String>(MaybeIntern(str), false); 405 return pdfium::MakeUnique<CPDF_String>(m_pPool, str, false);
406 } 406 }
407 if (word == "<") { 407 if (word == "<") {
408 CFX_ByteString str = ReadHexString(); 408 CFX_ByteString str = ReadHexString();
409 if (m_pCryptoHandler && bDecrypt) 409 if (m_pCryptoHandler && bDecrypt)
410 m_pCryptoHandler->Decrypt(objnum, gennum, str); 410 m_pCryptoHandler->Decrypt(objnum, gennum, str);
411 return pdfium::MakeUnique<CPDF_String>(MaybeIntern(str), true); 411 return pdfium::MakeUnique<CPDF_String>(m_pPool, str, true);
412 } 412 }
413 if (word == "[") { 413 if (word == "[") {
414 std::unique_ptr<CPDF_Array> pArray = pdfium::MakeUnique<CPDF_Array>(); 414 std::unique_ptr<CPDF_Array> pArray = pdfium::MakeUnique<CPDF_Array>();
415 while (std::unique_ptr<CPDF_Object> pObj = 415 while (std::unique_ptr<CPDF_Object> pObj =
416 GetObject(pObjList, objnum, gennum, true)) { 416 GetObject(pObjList, objnum, gennum, true)) {
417 pArray->Add(std::move(pObj)); 417 pArray->Add(std::move(pObj));
418 } 418 }
419 return std::move(pArray); 419 return std::move(pArray);
420 } 420 }
421 if (word[0] == '/') { 421 if (word[0] == '/') {
422 return pdfium::MakeUnique<CPDF_Name>(MaybeIntern( 422 return pdfium::MakeUnique<CPDF_Name>(
423 PDF_NameDecode(CFX_ByteStringC(m_WordBuffer + 1, m_WordSize - 1)))); 423 m_pPool,
424 PDF_NameDecode(CFX_ByteStringC(m_WordBuffer + 1, m_WordSize - 1)));
424 } 425 }
425 if (word == "<<") { 426 if (word == "<<") {
426 int32_t nKeys = 0; 427 int32_t nKeys = 0;
427 FX_FILESIZE dwSignValuePos = 0; 428 FX_FILESIZE dwSignValuePos = 0;
428 std::unique_ptr<CPDF_Dictionary> pDict = 429 std::unique_ptr<CPDF_Dictionary> pDict =
429 pdfium::MakeUnique<CPDF_Dictionary>(m_pPool); 430 pdfium::MakeUnique<CPDF_Dictionary>(m_pPool);
430 while (1) { 431 while (1) {
431 CFX_ByteString key = GetNextWord(nullptr); 432 CFX_ByteString key = GetNextWord(nullptr);
432 if (key.IsEmpty()) 433 if (key.IsEmpty())
433 return nullptr; 434 return nullptr;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 if (word == "true" || word == "false") 516 if (word == "true" || word == "false")
516 return pdfium::MakeUnique<CPDF_Boolean>(word == "true"); 517 return pdfium::MakeUnique<CPDF_Boolean>(word == "true");
517 518
518 if (word == "null") 519 if (word == "null")
519 return pdfium::MakeUnique<CPDF_Null>(); 520 return pdfium::MakeUnique<CPDF_Null>();
520 521
521 if (word == "(") { 522 if (word == "(") {
522 CFX_ByteString str = ReadString(); 523 CFX_ByteString str = ReadString();
523 if (m_pCryptoHandler) 524 if (m_pCryptoHandler)
524 m_pCryptoHandler->Decrypt(objnum, gennum, str); 525 m_pCryptoHandler->Decrypt(objnum, gennum, str);
525 return pdfium::MakeUnique<CPDF_String>(MaybeIntern(str), false); 526 return pdfium::MakeUnique<CPDF_String>(m_pPool, str, false);
526 } 527 }
527 if (word == "<") { 528 if (word == "<") {
528 CFX_ByteString str = ReadHexString(); 529 CFX_ByteString str = ReadHexString();
529 if (m_pCryptoHandler) 530 if (m_pCryptoHandler)
530 m_pCryptoHandler->Decrypt(objnum, gennum, str); 531 m_pCryptoHandler->Decrypt(objnum, gennum, str);
531 return pdfium::MakeUnique<CPDF_String>(MaybeIntern(str), true); 532 return pdfium::MakeUnique<CPDF_String>(m_pPool, str, true);
532 } 533 }
533 if (word == "[") { 534 if (word == "[") {
534 std::unique_ptr<CPDF_Array> pArray = pdfium::MakeUnique<CPDF_Array>(); 535 std::unique_ptr<CPDF_Array> pArray = pdfium::MakeUnique<CPDF_Array>();
535 while (std::unique_ptr<CPDF_Object> pObj = 536 while (std::unique_ptr<CPDF_Object> pObj =
536 GetObject(pObjList, objnum, gennum, true)) { 537 GetObject(pObjList, objnum, gennum, true)) {
537 pArray->Add(std::move(pObj)); 538 pArray->Add(std::move(pObj));
538 } 539 }
539 return m_WordBuffer[0] == ']' ? std::move(pArray) : nullptr; 540 return m_WordBuffer[0] == ']' ? std::move(pArray) : nullptr;
540 } 541 }
541 if (word[0] == '/') { 542 if (word[0] == '/') {
542 return pdfium::MakeUnique<CPDF_Name>(MaybeIntern( 543 return pdfium::MakeUnique<CPDF_Name>(
543 PDF_NameDecode(CFX_ByteStringC(m_WordBuffer + 1, m_WordSize - 1)))); 544 m_pPool,
545 PDF_NameDecode(CFX_ByteStringC(m_WordBuffer + 1, m_WordSize - 1)));
544 } 546 }
545 if (word == "<<") { 547 if (word == "<<") {
546 std::unique_ptr<CPDF_Dictionary> pDict = 548 std::unique_ptr<CPDF_Dictionary> pDict =
547 pdfium::MakeUnique<CPDF_Dictionary>(m_pPool); 549 pdfium::MakeUnique<CPDF_Dictionary>(m_pPool);
548 while (1) { 550 while (1) {
549 FX_FILESIZE SavedPos = m_Pos; 551 FX_FILESIZE SavedPos = m_Pos;
550 CFX_ByteString key = GetNextWord(nullptr); 552 CFX_ByteString key = GetNextWord(nullptr);
551 if (key.IsEmpty()) 553 if (key.IsEmpty())
552 return nullptr; 554 return nullptr;
553 555
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
909 if (limit && m_Pos == limit) 911 if (limit && m_Pos == limit)
910 return -1; 912 return -1;
911 } 913 }
912 return -1; 914 return -1;
913 } 915 }
914 916
915 void CPDF_SyntaxParser::SetEncrypt( 917 void CPDF_SyntaxParser::SetEncrypt(
916 std::unique_ptr<CPDF_CryptoHandler> pCryptoHandler) { 918 std::unique_ptr<CPDF_CryptoHandler> pCryptoHandler) {
917 m_pCryptoHandler = std::move(pCryptoHandler); 919 m_pCryptoHandler = std::move(pCryptoHandler);
918 } 920 }
919
920 CFX_ByteString CPDF_SyntaxParser::MaybeIntern(const CFX_ByteString& str) {
921 return m_pPool ? m_pPool->Intern(str) : str;
922 }
OLDNEW
« no previous file with comments | « core/fpdfapi/parser/cpdf_syntax_parser.h ('k') | core/fpdfdoc/cpdf_filespec_unittest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698