|
|
|||
File indexing completed on 2025-12-10 10:23:47
0001 //======================================================================== 0002 // 0003 // Lexer.h 0004 // 0005 // Copyright 1996-2003 Glyph & Cog, LLC 0006 // 0007 //======================================================================== 0008 0009 //======================================================================== 0010 // 0011 // Modified under the Poppler project - http://poppler.freedesktop.org 0012 // 0013 // All changes made under the Poppler project to this file are licensed 0014 // under GPL version 2 or later 0015 // 0016 // Copyright (C) 2006, 2007, 2010, 2013, 2017-2019 Albert Astals Cid <aacid@kde.org> 0017 // Copyright (C) 2006 Krzysztof Kowalczyk <kkowalczyk@gmail.com> 0018 // Copyright (C) 2013 Adrian Johnson <ajohnson@redneon.com> 0019 // Copyright (C) 2013 Thomas Freitag <Thomas.Freitag@alfa.de> 0020 // Copyright (C) 2019 Adam Reichold <adam.reichold@t-online.de> 0021 // 0022 // To see a description of the changes please see the Changelog file that 0023 // came with your tarball or type make ChangeLog if you are building from git 0024 // 0025 //======================================================================== 0026 0027 #ifndef LEXER_H 0028 #define LEXER_H 0029 0030 #include "Object.h" 0031 #include "Stream.h" 0032 0033 class XRef; 0034 0035 #define tokBufSize 128 // size of token buffer 0036 0037 //------------------------------------------------------------------------ 0038 // Lexer 0039 //------------------------------------------------------------------------ 0040 0041 class POPPLER_PRIVATE_EXPORT Lexer 0042 { 0043 public: 0044 // Construct a lexer for a single stream. Deletes the stream when 0045 // lexer is deleted. 0046 Lexer(XRef *xrefA, Stream *str); 0047 0048 // Construct a lexer for a stream or array of streams (assumes obj 0049 // is either a stream or array of streams). 0050 Lexer(XRef *xrefA, Object *obj); 0051 0052 // Destructor. 0053 ~Lexer(); 0054 0055 Lexer(const Lexer &) = delete; 0056 Lexer &operator=(const Lexer &) = delete; 0057 0058 // Get the next object from the input stream. 0059 Object getObj(int objNum = -1); 0060 Object getObj(const char *cmdA, int objNum); 0061 template<typename T> 0062 Object getObj(T) = delete; 0063 0064 // Skip to the beginning of the next line in the input stream. 0065 void skipToNextLine(); 0066 0067 // Skip over one character. 0068 void skipChar() { getChar(); } 0069 0070 // Get stream. 0071 Stream *getStream() { return curStr.isStream() ? curStr.getStream() : nullptr; } 0072 0073 // Get current position in file. This is only used for error 0074 // messages. 0075 Goffset getPos() const { return curStr.isStream() ? curStr.getStream()->getPos() : -1; } 0076 0077 // Set position in file. 0078 void setPos(Goffset pos) 0079 { 0080 if (curStr.isStream()) { 0081 curStr.getStream()->setPos(pos); 0082 } 0083 } 0084 0085 // Returns true if <c> is a whitespace character. 0086 static bool isSpace(int c); 0087 0088 // often (e.g. ~30% on PDF Refernce 1.6 pdf file from Adobe site) getChar 0089 // is called right after lookChar. In order to avoid expensive re-doing 0090 // getChar() of underlying stream, we cache the last value found by 0091 // lookChar() in lookCharLastValueCached. A special value 0092 // LOOK_VALUE_NOT_CACHED that should never be part of stream indicates 0093 // that no value was cached 0094 static const int LOOK_VALUE_NOT_CACHED = -3; 0095 int lookCharLastValueCached; 0096 0097 XRef *getXRef() const { return xref; } 0098 bool hasXRef() const { return xref != nullptr; } 0099 0100 private: 0101 int getChar(bool comesFromLook = false); 0102 int lookChar(); 0103 0104 Array *streams; // array of input streams 0105 int strPtr; // index of current stream 0106 Object curStr; // current stream 0107 bool freeArray; // should lexer free the streams array? 0108 char tokBuf[tokBufSize]; // temporary token buffer 0109 0110 XRef *xref; 0111 }; 0112 0113 #endif
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|