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 #include "core/fpdfapi/parser/cpdf_string.h" 8 9 #include <utility> 10 11 #include "core/fpdfapi/parser/fpdf_parser_decode.h" 12 #include "third_party/base/ptr_util.h" 13 CPDF_String()14CPDF_String::CPDF_String() : m_bHex(false) {} 15 CPDF_String(CFX_WeakPtr<CFX_ByteStringPool> pPool,const CFX_ByteString & str,bool bHex)16CPDF_String::CPDF_String(CFX_WeakPtr<CFX_ByteStringPool> pPool, 17 const CFX_ByteString& str, 18 bool bHex) 19 : m_String(str), m_bHex(bHex) { 20 if (pPool) 21 m_String = pPool->Intern(m_String); 22 } 23 CPDF_String(CFX_WeakPtr<CFX_ByteStringPool> pPool,const CFX_WideString & str)24CPDF_String::CPDF_String(CFX_WeakPtr<CFX_ByteStringPool> pPool, 25 const CFX_WideString& str) 26 : m_String(PDF_EncodeText(str)), m_bHex(false) { 27 if (pPool) 28 m_String = pPool->Intern(m_String); 29 } 30 ~CPDF_String()31CPDF_String::~CPDF_String() {} 32 GetType() const33CPDF_Object::Type CPDF_String::GetType() const { 34 return STRING; 35 } 36 Clone() const37std::unique_ptr<CPDF_Object> CPDF_String::Clone() const { 38 auto pRet = pdfium::MakeUnique<CPDF_String>(); 39 pRet->m_String = m_String; 40 pRet->m_bHex = m_bHex; 41 return std::move(pRet); 42 } 43 GetString() const44CFX_ByteString CPDF_String::GetString() const { 45 return m_String; 46 } 47 SetString(const CFX_ByteString & str)48void CPDF_String::SetString(const CFX_ByteString& str) { 49 m_String = str; 50 } 51 IsString() const52bool CPDF_String::IsString() const { 53 return true; 54 } 55 AsString()56CPDF_String* CPDF_String::AsString() { 57 return this; 58 } 59 AsString() const60const CPDF_String* CPDF_String::AsString() const { 61 return this; 62 } 63 GetUnicodeText() const64CFX_WideString CPDF_String::GetUnicodeText() const { 65 return PDF_DecodeText(m_String); 66 } 67