• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 The PDFium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 
7 #ifndef CORE_FPDFAPI_PARSER_CPDF_SIMPLE_PARSER_H_
8 #define CORE_FPDFAPI_PARSER_CPDF_SIMPLE_PARSER_H_
9 
10 #include <stdint.h>
11 
12 #include <optional>
13 
14 #include "core/fxcrt/bytestring.h"
15 #include "core/fxcrt/span.h"
16 
17 class CPDF_SimpleParser {
18  public:
19   explicit CPDF_SimpleParser(pdfium::span<const uint8_t> input);
20   ~CPDF_SimpleParser();
21 
22   ByteStringView GetWord();
23 
SetCurrentPosition(uint32_t position)24   void SetCurrentPosition(uint32_t position) { cur_position_ = position; }
GetCurrentPosition()25   uint32_t GetCurrentPosition() const { return cur_position_; }
26 
27  private:
28   // Returns the ByteStringView of the subspan of `data_` from `start_position`
29   // to `cur_position_`.
30   ByteStringView GetDataToCurrentPosition(uint32_t start_position) const;
31 
32   // Skips whitespace and comment lines. Returns the first parseable character
33   // if `data_` can still be parsed, nullopt otherwise.
34   std::optional<uint8_t> SkipSpacesAndComments();
35 
36   ByteStringView HandleName();
37   ByteStringView HandleBeginAngleBracket();
38   ByteStringView HandleEndAngleBracket();
39   ByteStringView HandleParentheses();
40   ByteStringView HandleNonDelimiter();
41 
42   const pdfium::span<const uint8_t> data_;
43 
44   // The current unread position.
45   uint32_t cur_position_ = 0;
46 };
47 
48 #endif  // CORE_FPDFAPI_PARSER_CPDF_SIMPLE_PARSER_H_
49