blob: 340495995082c3d47187de9ab532239d5ce655aa [file] [log] [blame]
K. Moon832a6942022-10-31 20:11:31 +00001// Copyright 2016 The PDFium Authors
Tom Sepez5fc239a2016-03-10 14:10:38 -08002// 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
dsinclair488b7ad2016-10-04 11:55:50 -07007#include "core/fpdfapi/parser/cpdf_boolean.h"
Lei Zhangc52e3002018-10-01 17:38:38 +00008
Dan Sinclairbcd1e702017-08-31 13:19:18 -04009#include "core/fxcrt/fx_stream.h"
Tom Sepez5fc239a2016-03-10 14:10:38 -080010
Lei Zhangf3163cf2019-12-17 00:55:11 +000011CPDF_Boolean::CPDF_Boolean() = default;
Tom Sepez5fc239a2016-03-10 14:10:38 -080012
thestigded36342016-05-23 17:54:02 -070013CPDF_Boolean::CPDF_Boolean(bool value) : m_bValue(value) {}
Tom Sepez5fc239a2016-03-10 14:10:38 -080014
Lei Zhangf3163cf2019-12-17 00:55:11 +000015CPDF_Boolean::~CPDF_Boolean() = default;
Tom Sepez5fc239a2016-03-10 14:10:38 -080016
17CPDF_Object::Type CPDF_Boolean::GetType() const {
Hans Wennborg2f62d362018-10-22 19:17:02 +000018 return kBoolean;
Tom Sepez5fc239a2016-03-10 14:10:38 -080019}
20
Tom Sepeza3097da2019-05-01 16:42:36 +000021RetainPtr<CPDF_Object> CPDF_Boolean::Clone() const {
22 return pdfium::MakeRetain<CPDF_Boolean>(m_bValue);
Tom Sepez5fc239a2016-03-10 14:10:38 -080023}
24
Ryan Harrison275e2602017-09-18 14:23:18 -040025ByteString CPDF_Boolean::GetString() const {
Tom Sepez5fc239a2016-03-10 14:10:38 -080026 return m_bValue ? "true" : "false";
27}
28
29int CPDF_Boolean::GetInteger() const {
30 return m_bValue;
31}
32
Ryan Harrison275e2602017-09-18 14:23:18 -040033void CPDF_Boolean::SetString(const ByteString& str) {
Tom Sepez5fc239a2016-03-10 14:10:38 -080034 m_bValue = (str == "true");
35}
36
Tom Sepezd6daaed2022-09-02 23:58:32 +000037CPDF_Boolean* CPDF_Boolean::AsMutableBoolean() {
Tom Sepez5fc239a2016-03-10 14:10:38 -080038 return this;
39}
40
Artem Strygin2bfa7852018-07-23 19:54:34 +000041bool CPDF_Boolean::WriteTo(IFX_ArchiveStream* archive,
42 const CPDF_Encryptor* encryptor) const {
Dan Sinclair5b590332017-05-10 13:59:14 -040043 return archive->WriteString(" ") &&
Ryan Harrison275e2602017-09-18 14:23:18 -040044 archive->WriteString(GetString().AsStringView());
Dan Sinclairc68b1e72017-05-08 16:59:54 -040045}