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 final : public CPDF_Object {
19  public:
20   template <typename T, typename... Args>
21   friend RetainPtr<T> pdfium::MakeRetain(Args&&... args);
22 
23   // CPDF_Object:
24   Type GetType() const override;
25   RetainPtr<CPDF_Object> Clone() const override;
26   ByteString GetString() const override;
27   WideString GetUnicodeText() const override;
28   void SetString(const ByteString& str) override;
29   bool IsString() const override;
30   CPDF_String* AsString() override;
31   const CPDF_String* AsString() const override;
32   bool WriteTo(IFX_ArchiveStream* archive,
33                const CPDF_Encryptor* encryptor) const override;
34 
IsHex()35   bool IsHex() const { return m_bHex; }
36 
37  private:
38   CPDF_String();
39   CPDF_String(WeakPtr<ByteStringPool> pPool, const ByteString& str, bool bHex);
40   CPDF_String(WeakPtr<ByteStringPool> pPool, const WideString& str);
41   ~CPDF_String() override;
42 
43   ByteString m_String;
44   bool m_bHex = false;
45 };
46 
ToString(CPDF_Object * obj)47 inline CPDF_String* ToString(CPDF_Object* obj) {
48   return obj ? obj->AsString() : nullptr;
49 }
50 
ToString(const CPDF_Object * obj)51 inline const CPDF_String* ToString(const CPDF_Object* obj) {
52   return obj ? obj->AsString() : nullptr;
53 }
54 
55 #endif  // CORE_FPDFAPI_PARSER_CPDF_STRING_H_
56