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/cfx_string_pool_template.h" 14 #include "core/fxcrt/cfx_weak_ptr.h" 15 #include "core/fxcrt/fx_string.h" 16 #include "core/fxcrt/fx_system.h" 17 18 class CPDF_String : public CPDF_Object { 19 public: 20 CPDF_String(); 21 CPDF_String(CFX_WeakPtr<CFX_ByteStringPool> pPool, 22 const CFX_ByteString& str, 23 bool bHex); 24 CPDF_String(CFX_WeakPtr<CFX_ByteStringPool> pPool, const CFX_WideString& str); 25 ~CPDF_String() override; 26 27 // CPDF_Object: 28 Type GetType() const override; 29 std::unique_ptr<CPDF_Object> Clone() const override; 30 CFX_ByteString GetString() const override; 31 CFX_WideString GetUnicodeText() const override; 32 void SetString(const CFX_ByteString& str) override; 33 bool IsString() const override; 34 CPDF_String* AsString() override; 35 const CPDF_String* AsString() const override; 36 IsHex()37 bool IsHex() const { return m_bHex; } 38 39 protected: 40 CFX_ByteString m_String; 41 bool m_bHex; 42 }; 43 ToString(CPDF_Object * obj)44inline CPDF_String* ToString(CPDF_Object* obj) { 45 return obj ? obj->AsString() : nullptr; 46 } 47 ToString(const CPDF_Object * obj)48inline const CPDF_String* ToString(const CPDF_Object* obj) { 49 return obj ? obj->AsString() : nullptr; 50 } 51 52 #endif // CORE_FPDFAPI_PARSER_CPDF_STRING_H_ 53