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_CPDF_STRING_H_ 8 #define CORE_FPDFAPI_PARSER_CPDF_STRING_H_ 9 10 #include <memory> 11 12 #include "core/fpdfapi/parser/cpdf_object.h" 13 #include "core/fxcrt/fx_string.h" 14 #include "core/fxcrt/fx_system.h" 15 #include "core/fxcrt/string_pool_template.h" 16 #include "core/fxcrt/weak_ptr.h" 17 18 class CPDF_String : public CPDF_Object { 19 public: 20 CPDF_String(); 21 CPDF_String(WeakPtr<ByteStringPool> pPool, const ByteString& str, bool bHex); 22 CPDF_String(WeakPtr<ByteStringPool> pPool, const WideString& str); 23 ~CPDF_String() override; 24 25 // CPDF_Object: 26 Type GetType() const override; 27 std::unique_ptr<CPDF_Object> Clone() const override; 28 ByteString GetString() const override; 29 WideString GetUnicodeText() const override; 30 void SetString(const ByteString& str) override; 31 bool IsString() const override; 32 CPDF_String* AsString() override; 33 const CPDF_String* AsString() const override; 34 bool WriteTo(IFX_ArchiveStream* archive) const override; 35 IsHex()36 bool IsHex() const { return m_bHex; } 37 38 protected: 39 ByteString m_String; 40 bool m_bHex; 41 }; 42 ToString(CPDF_Object * obj)43inline CPDF_String* ToString(CPDF_Object* obj) { 44 return obj ? obj->AsString() : nullptr; 45 } 46 ToString(const CPDF_Object * obj)47inline const CPDF_String* ToString(const CPDF_Object* obj) { 48 return obj ? obj->AsString() : nullptr; 49 } 50 51 #endif // CORE_FPDFAPI_PARSER_CPDF_STRING_H_ 52