/src/poco/XML/include/Poco/DOM/CharacterData.h
Line | Count | Source |
1 | | // |
2 | | // CharacterData.h |
3 | | // |
4 | | // Library: XML |
5 | | // Package: DOM |
6 | | // Module: DOM |
7 | | // |
8 | | // Definition of the DOM CharacterData class. |
9 | | // |
10 | | // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. |
11 | | // and Contributors. |
12 | | // |
13 | | // SPDX-License-Identifier: BSL-1.0 |
14 | | // |
15 | | |
16 | | |
17 | | #ifndef DOM_CharacterData_INCLUDED |
18 | | #define DOM_CharacterData_INCLUDED |
19 | | |
20 | | |
21 | | #include "Poco/XML/XML.h" |
22 | | #include "Poco/DOM/AbstractNode.h" |
23 | | #include "Poco/XML/XMLString.h" |
24 | | |
25 | | |
26 | | namespace Poco::XML { |
27 | | |
28 | | |
29 | | class XML_API CharacterData: public AbstractNode |
30 | | /// The CharacterData interface extends Node with a set of attributes and methods |
31 | | /// for accessing character data in the DOM. For clarity this set is defined |
32 | | /// here rather than on each object that uses these attributes and methods. |
33 | | /// No DOM objects correspond directly to CharacterData, though Text and others |
34 | | /// do inherit the interface from it. All offsets in this interface start from 0. |
35 | | /// |
36 | | /// Text strings in the DOM are represented in either UTF-8 (if XML_UNICODE_WCHAR_T is |
37 | | /// not defined) or in UTF-16 (if XML_UNICODE_WCHAR_T is defined). |
38 | | /// Indexing on character data is done in XMLChar units. |
39 | | { |
40 | | public: |
41 | | [[nodiscard]] const XMLString& data() const; |
42 | | /// Returns the character data of the node that |
43 | | /// implements the interface. |
44 | | |
45 | | [[nodiscard]] const XMLString& getData() const; |
46 | | /// Returns the character data of the node that |
47 | | /// implements the interface. |
48 | | |
49 | | void setData(const XMLString& data); |
50 | | /// Sets the character data of the node that |
51 | | /// implements the interface. |
52 | | |
53 | | [[nodiscard]] unsigned long length() const; |
54 | | /// Returns the number of XMLChars that are available |
55 | | /// through getData and substringData. This may have the |
56 | | /// value zero. |
57 | | |
58 | | [[nodiscard]] XMLString substringData(unsigned long offset, unsigned long count) const; |
59 | | /// Extracts a range of data from the node. |
60 | | /// If offset and count exceeds the length, then all |
61 | | /// the characters to the end of the data are returned. |
62 | | |
63 | | void appendData(const XMLString& arg); |
64 | | /// Append the string to the end of the character data |
65 | | /// of the node. |
66 | | |
67 | | void insertData(unsigned long offset, const XMLString& arg); |
68 | | /// Insert a string at the specified character offset. |
69 | | |
70 | | void deleteData(unsigned long offset, unsigned long count); |
71 | | /// Remove a range of characters from the node. |
72 | | |
73 | | void replaceData(unsigned long offset, unsigned long count, const XMLString& arg); |
74 | | /// Replace the characters starting at the specified character |
75 | | /// offset with the specified string. |
76 | | |
77 | | // Non-standard extensions |
78 | | [[nodiscard]] XMLString trimmedData() const; |
79 | | /// Returns the character data of that node with |
80 | | /// all surrounding whitespace removed. |
81 | | /// |
82 | | /// This method is an extension to the W3C Document Object Model. |
83 | | |
84 | | // Node |
85 | | [[nodiscard]] const XMLString& getNodeValue() const; |
86 | | void setNodeValue(const XMLString& value); |
87 | | |
88 | | protected: |
89 | | CharacterData(Document* pOwnerDocument, const XMLString& data); |
90 | | CharacterData(Document* pOwnerDocument, const CharacterData& data); |
91 | | ~CharacterData(); |
92 | | |
93 | | private: |
94 | | XMLString _data; |
95 | | }; |
96 | | |
97 | | |
98 | | // |
99 | | // inlines |
100 | | // |
101 | | inline const XMLString& CharacterData::data() const |
102 | 0 | { |
103 | 0 | return _data; |
104 | 0 | } |
105 | | |
106 | | |
107 | | inline const XMLString& CharacterData::getData() const |
108 | 0 | { |
109 | 0 | return _data; |
110 | 0 | } |
111 | | |
112 | | |
113 | | inline unsigned long CharacterData::length() const |
114 | 0 | { |
115 | 0 | return (unsigned long) _data.length(); |
116 | 0 | } |
117 | | |
118 | | |
119 | | } // namespace Poco::XML |
120 | | |
121 | | |
122 | | #endif // DOM_CharacterData_INCLUDED |