Home | History | Annotate | Download | only in parser
      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 
     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 
     19 CPDF_Name::~CPDF_Name() {}
     20 
     21 CPDF_Object::Type CPDF_Name::GetType() const {
     22   return NAME;
     23 }
     24 
     25 std::unique_ptr<CPDF_Object> CPDF_Name::Clone() const {
     26   return pdfium::MakeUnique<CPDF_Name>(nullptr, m_Name);
     27 }
     28 
     29 ByteString CPDF_Name::GetString() const {
     30   return m_Name;
     31 }
     32 
     33 void CPDF_Name::SetString(const ByteString& str) {
     34   m_Name = str;
     35 }
     36 
     37 bool CPDF_Name::IsName() const {
     38   return true;
     39 }
     40 
     41 CPDF_Name* CPDF_Name::AsName() {
     42   return this;
     43 }
     44 
     45 const CPDF_Name* CPDF_Name::AsName() const {
     46   return this;
     47 }
     48 
     49 WideString CPDF_Name::GetUnicodeText() const {
     50   return PDF_DecodeText(m_Name);
     51 }
     52 
     53 bool CPDF_Name::WriteTo(IFX_ArchiveStream* archive) const {
     54   return archive->WriteString("/") &&
     55          archive->WriteString(PDF_NameEncode(GetString()).AsStringView());
     56 }
     57