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_boolean.h" 8 9 #include "core/fxcrt/fx_stream.h" 10 #include "third_party/base/ptr_util.h" 11 12 CPDF_Boolean::CPDF_Boolean() = default; 13 CPDF_Boolean(bool value)14CPDF_Boolean::CPDF_Boolean(bool value) : m_bValue(value) {} 15 16 CPDF_Boolean::~CPDF_Boolean() = default; 17 GetType() const18CPDF_Object::Type CPDF_Boolean::GetType() const { 19 return kBoolean; 20 } 21 Clone() const22RetainPtr<CPDF_Object> CPDF_Boolean::Clone() const { 23 return pdfium::MakeRetain<CPDF_Boolean>(m_bValue); 24 } 25 GetString() const26ByteString CPDF_Boolean::GetString() const { 27 return m_bValue ? "true" : "false"; 28 } 29 GetInteger() const30int CPDF_Boolean::GetInteger() const { 31 return m_bValue; 32 } 33 SetString(const ByteString & str)34void CPDF_Boolean::SetString(const ByteString& str) { 35 m_bValue = (str == "true"); 36 } 37 IsBoolean() const38bool CPDF_Boolean::IsBoolean() const { 39 return true; 40 } 41 AsBoolean()42CPDF_Boolean* CPDF_Boolean::AsBoolean() { 43 return this; 44 } 45 AsBoolean() const46const CPDF_Boolean* CPDF_Boolean::AsBoolean() const { 47 return this; 48 } 49 WriteTo(IFX_ArchiveStream * archive,const CPDF_Encryptor * encryptor) const50bool CPDF_Boolean::WriteTo(IFX_ArchiveStream* archive, 51 const CPDF_Encryptor* encryptor) const { 52 return archive->WriteString(" ") && 53 archive->WriteString(GetString().AsStringView()); 54 } 55