From 6f9b1d7eff38d503de231fc7260f012af774ce62 Mon Sep 17 00:00:00 2001 From: Artem Strygin Date: Thu, 7 Sep 2017 18:19:27 +0300 Subject: Implement CPDF_SyntaxParser::PeekNextWord. Change-Id: I92c0bd417d9c5be59c36401efae89406e482756a Reviewed-on: https://pdfium-review.googlesource.com/12650 Commit-Queue: Art Snake Reviewed-by: dsinclair --- core/fpdfapi/parser/cpdf_syntax_parser.cpp | 5 +++++ core/fpdfapi/parser/cpdf_syntax_parser.h | 1 + core/fpdfapi/parser/cpdf_syntax_parser_unittest.cpp | 9 +++++++++ 3 files changed, 15 insertions(+) (limited to 'core/fpdfapi') 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 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 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(data, sizeof(data), false), 0); + EXPECT_EQ("WORD", parser.PeekNextWord(nullptr)); + EXPECT_EQ("WORD", parser.GetNextWord(nullptr)); +} -- cgit v1.2.3