diff options
-rw-r--r-- | core/fpdfapi/parser/cpdf_syntax_parser.cpp | 5 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_syntax_parser.h | 1 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_syntax_parser_unittest.cpp | 9 |
3 files changed, 15 insertions, 0 deletions
diff --git a/core/fpdfapi/parser/cpdf_syntax_parser.cpp b/core/fpdfapi/parser/cpdf_syntax_parser.cpp index f7c79bc950..4a7810fc43 100644 --- a/core/fpdfapi/parser/cpdf_syntax_parser.cpp +++ b/core/fpdfapi/parser/cpdf_syntax_parser.cpp @@ -352,6 +352,11 @@ CFX_ByteString CPDF_SyntaxParser::GetNextWord(bool* bIsNumber) { : CFX_ByteString((const char*)m_WordBuffer, m_WordSize); } +CFX_ByteString CPDF_SyntaxParser::PeekNextWord(bool* bIsNumber) { + const CFX_AutoRestorer<FX_FILESIZE> save_pos(&m_Pos); + return GetNextWord(bIsNumber); +} + CFX_ByteString CPDF_SyntaxParser::GetKeyword() { return GetNextWord(nullptr); } diff --git a/core/fpdfapi/parser/cpdf_syntax_parser.h b/core/fpdfapi/parser/cpdf_syntax_parser.h index 88bbc5c9fa..179058edf8 100644 --- a/core/fpdfapi/parser/cpdf_syntax_parser.h +++ b/core/fpdfapi/parser/cpdf_syntax_parser.h @@ -65,6 +65,7 @@ class CPDF_SyntaxParser { bool ReadBlock(uint8_t* pBuf, uint32_t size); bool GetCharAt(FX_FILESIZE pos, uint8_t& ch); CFX_ByteString GetNextWord(bool* bIsNumber); + CFX_ByteString PeekNextWord(bool* bIsNumber); CFX_RetainPtr<IFX_SeekableReadStream> GetFileAccess() const; diff --git a/core/fpdfapi/parser/cpdf_syntax_parser_unittest.cpp b/core/fpdfapi/parser/cpdf_syntax_parser_unittest.cpp index ac7a875af6..6b54c70db6 100644 --- a/core/fpdfapi/parser/cpdf_syntax_parser_unittest.cpp +++ b/core/fpdfapi/parser/cpdf_syntax_parser_unittest.cpp @@ -155,3 +155,12 @@ TEST(cpdf_syntax_parser, GetInvalidReference) { parser.GetObject(nullptr, CPDF_Object::kInvalidObjNum, 0, false); EXPECT_FALSE(ref); } + +TEST(cpdf_syntax_parser, PeekNextWord) { + CPDF_SyntaxParser parser; + uint8_t data[] = " WORD "; + parser.InitParser( + pdfium::MakeRetain<CFX_MemoryStream>(data, sizeof(data), false), 0); + EXPECT_EQ("WORD", parser.PeekNextWord(nullptr)); + EXPECT_EQ("WORD", parser.GetNextWord(nullptr)); +} |