1 // Copyright 2016 PDFium Authors. All rights reserved. 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_FPDF_PARSER_UTILITY_H_ 8 #define CORE_FPDFAPI_PARSER_FPDF_PARSER_UTILITY_H_ 9 10 #include "core/fxcrt/fx_string.h" 11 #include "core/fxcrt/retain_ptr.h" 12 13 class IFX_SeekableReadStream; 14 class CPDF_Dictionary; 15 class CPDF_Object; 16 17 // Use the accessors below instead of directly accessing PDF_CharType. 18 extern const char PDF_CharType[256]; 19 PDFCharIsWhitespace(uint8_t c)20inline bool PDFCharIsWhitespace(uint8_t c) { 21 return PDF_CharType[c] == 'W'; 22 } PDFCharIsNumeric(uint8_t c)23inline bool PDFCharIsNumeric(uint8_t c) { 24 return PDF_CharType[c] == 'N'; 25 } PDFCharIsDelimiter(uint8_t c)26inline bool PDFCharIsDelimiter(uint8_t c) { 27 return PDF_CharType[c] == 'D'; 28 } PDFCharIsOther(uint8_t c)29inline bool PDFCharIsOther(uint8_t c) { 30 return PDF_CharType[c] == 'R'; 31 } 32 PDFCharIsLineEnding(uint8_t c)33inline bool PDFCharIsLineEnding(uint8_t c) { 34 return c == '\r' || c == '\n'; 35 } 36 37 constexpr int32_t kInvalidHeaderOffset = -1; 38 39 // On success, return a positive offset value to the PDF header.. If the header 40 // cannot be found, or if there is an error reading from |pFile|, then return 41 // |kInvalidHeaderOffset|. 42 int32_t GetHeaderOffset(const RetainPtr<IFX_SeekableReadStream>& pFile); 43 44 int32_t GetDirectInteger(CPDF_Dictionary* pDict, const ByteString& key); 45 46 std::ostream& operator<<(std::ostream& buf, const CPDF_Object* pObj); 47 48 #endif // CORE_FPDFAPI_PARSER_FPDF_PARSER_UTILITY_H_ 49