• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 The PDFium Authors
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 #ifndef CORE_FXCRT_XML_CFX_XMLTEXT_H_
8 #define CORE_FXCRT_XML_CFX_XMLTEXT_H_
9 
10 #include "core/fxcrt/widestring.h"
11 #include "core/fxcrt/xml/cfx_xmlnode.h"
12 
13 class CFX_XMLDocument;
14 
15 class CFX_XMLText : public CFX_XMLNode {
16  public:
17   explicit CFX_XMLText(const WideString& wsText);
18   ~CFX_XMLText() override;
19 
20   // CFX_XMLNode
21   Type GetType() const override;
22   CFX_XMLNode* Clone(CFX_XMLDocument* doc) override;
23   void Save(const RetainPtr<IFX_RetainableWriteStream>& pXMLStream) override;
24 
GetText()25   const WideString& GetText() const { return text_; }
SetText(const WideString & wsText)26   void SetText(const WideString& wsText) { text_ = wsText; }
27 
28  private:
29   WideString text_;
30 };
31 
IsXMLText(const CFX_XMLNode * pNode)32 inline bool IsXMLText(const CFX_XMLNode* pNode) {
33   CFX_XMLNode::Type type = pNode->GetType();
34   return type == CFX_XMLNode::Type::kText ||
35          type == CFX_XMLNode::Type::kCharData;
36 }
37 
ToXMLText(CFX_XMLNode * pNode)38 inline CFX_XMLText* ToXMLText(CFX_XMLNode* pNode) {
39   return pNode && IsXMLText(pNode) ? static_cast<CFX_XMLText*>(pNode) : nullptr;
40 }
41 
ToXMLText(const CFX_XMLNode * pNode)42 inline const CFX_XMLText* ToXMLText(const CFX_XMLNode* pNode) {
43   return pNode && IsXMLText(pNode) ? static_cast<const CFX_XMLText*>(pNode)
44                                    : nullptr;
45 }
46 
47 #endif  // CORE_FXCRT_XML_CFX_XMLTEXT_H_
48