• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_name.h"
8 
9 #include "core/fpdfapi/parser/fpdf_parser_decode.h"
10 #include "core/fxcrt/fx_stream.h"
11 #include "third_party/base/ptr_util.h"
12 
CPDF_Name(WeakPtr<ByteStringPool> pPool,const ByteString & str)13 CPDF_Name::CPDF_Name(WeakPtr<ByteStringPool> pPool, const ByteString& str)
14     : m_Name(str) {
15   if (pPool)
16     m_Name = pPool->Intern(m_Name);
17 }
18 
~CPDF_Name()19 CPDF_Name::~CPDF_Name() {}
20 
GetType() const21 CPDF_Object::Type CPDF_Name::GetType() const {
22   return NAME;
23 }
24 
Clone() const25 std::unique_ptr<CPDF_Object> CPDF_Name::Clone() const {
26   return pdfium::MakeUnique<CPDF_Name>(nullptr, m_Name);
27 }
28 
GetString() const29 ByteString CPDF_Name::GetString() const {
30   return m_Name;
31 }
32 
SetString(const ByteString & str)33 void CPDF_Name::SetString(const ByteString& str) {
34   m_Name = str;
35 }
36 
IsName() const37 bool CPDF_Name::IsName() const {
38   return true;
39 }
40 
AsName()41 CPDF_Name* CPDF_Name::AsName() {
42   return this;
43 }
44 
AsName() const45 const CPDF_Name* CPDF_Name::AsName() const {
46   return this;
47 }
48 
GetUnicodeText() const49 WideString CPDF_Name::GetUnicodeText() const {
50   return PDF_DecodeText(m_Name);
51 }
52 
WriteTo(IFX_ArchiveStream * archive) const53 bool CPDF_Name::WriteTo(IFX_ArchiveStream* archive) const {
54   return archive->WriteString("/") &&
55          archive->WriteString(PDF_NameEncode(GetString()).AsStringView());
56 }
57