KHtml

dom_text.cpp
1 
23 #include "dom_text.h"
24 #include "dom_exception.h"
25 
26 #include <xml/dom_textimpl.h>
27 
28 using namespace DOM;
29 
30 CharacterData::CharacterData() : Node()
31 {
32 }
33 
34 CharacterData::CharacterData(const CharacterData &other) : Node(other)
35 {
36 }
37 
38 CharacterData &CharacterData::operator = (const Node &other)
39 {
40  NodeImpl *ohandle = other.handle();
41  if (impl != ohandle) {
42  if (!ohandle ||
43  (ohandle->nodeType() != CDATA_SECTION_NODE &&
44  ohandle->nodeType() != TEXT_NODE &&
45  ohandle->nodeType() != COMMENT_NODE)) {
46  if (impl) {
47  impl->deref();
48  }
49  impl = nullptr;
50  } else {
51  Node::operator =(other);
52  }
53  }
54  return *this;
55 }
56 
57 CharacterData &CharacterData::operator = (const CharacterData &other)
58 {
59  Node::operator =(other);
60  return *this;
61 }
62 
63 CharacterData::~CharacterData()
64 {
65 }
66 
68 {
69  if (!impl) {
70  return DOMString();
71  }
72  return ((CharacterDataImpl *)impl)->data();
73 }
74 
76 {
77  if (!impl) {
78  return; // ### enable throw DOMException(DOMException::NOT_FOUND_ERR);
79  }
80 
81  int exceptioncode = 0;
82  ((CharacterDataImpl *)impl)->setData(str, exceptioncode);
83  if (exceptioncode) {
84  throw DOMException(exceptioncode);
85  }
86  return;
87 }
88 
89 unsigned long CharacterData::length() const
90 {
91  if (impl) {
92  return ((CharacterDataImpl *)impl)->length();
93  }
94  return 0;
95 }
96 
97 DOMString CharacterData::substringData(const unsigned long offset, const unsigned long count)
98 {
99  if (!impl) {
100  return DOMString(); // ### enable throw DOMException(DOMException::NOT_FOUND_ERR);
101  }
102 
103  int exceptioncode = 0;
104  DOMString str = ((CharacterDataImpl *)impl)->substringData(offset, count, exceptioncode);
105  if (exceptioncode) {
106  throw DOMException(exceptioncode);
107  }
108  return str;
109 }
110 
112 {
113  if (!impl) {
114  return; // ### enable throw DOMException(DOMException::NOT_FOUND_ERR);
115  }
116 
117  int exceptioncode = 0;
118  ((CharacterDataImpl *)impl)->appendData(arg, exceptioncode);
119  if (exceptioncode) {
120  throw DOMException(exceptioncode);
121  }
122 }
123 
124 void CharacterData::insertData(const unsigned long offset, const DOMString &arg)
125 {
126  if (!impl) {
127  return; // ### enable throw DOMException(DOMException::NOT_FOUND_ERR);
128  }
129 
130  int exceptioncode = 0;
131  ((CharacterDataImpl *)impl)->insertData(offset, arg, exceptioncode);
132  if (exceptioncode) {
133  throw DOMException(exceptioncode);
134  }
135 }
136 
137 void CharacterData::deleteData(const unsigned long offset, const unsigned long count)
138 {
139  if (!impl) {
140  return; // ### enable throw DOMException(DOMException::NOT_FOUND_ERR);
141  }
142 
143  int exceptioncode = 0;
144  ((CharacterDataImpl *)impl)->deleteData(offset, count, exceptioncode);
145  if (exceptioncode) {
146  throw DOMException(exceptioncode);
147  }
148 }
149 
150 void CharacterData::replaceData(const unsigned long offset, const unsigned long count, const DOMString &arg)
151 {
152  if (!impl) {
153  return; // ### enable throw DOMException(DOMException::NOT_FOUND_ERR);
154  }
155 
156  int exceptioncode = 0;
157  ((CharacterDataImpl *)impl)->replaceData(offset, count, arg, exceptioncode);
158  if (exceptioncode) {
159  throw DOMException(exceptioncode);
160  }
161 }
162 
163 CharacterData::CharacterData(CharacterDataImpl *i) : Node(i)
164 {
165 }
166 
167 // ---------------------------------------------------------------------------
168 
169 Comment::Comment() : CharacterData()
170 {
171 }
172 
173 Comment::Comment(const Comment &other) : CharacterData(other)
174 {
175 }
176 
177 Comment &Comment::operator = (const Node &other)
178 {
179  NodeImpl *ohandle = other.handle();
180  if (impl != ohandle) {
181  if (!ohandle || ohandle->nodeType() != COMMENT_NODE) {
182  if (impl) {
183  impl->deref();
184  }
185  impl = nullptr;
186  } else {
187  Node::operator =(other);
188  }
189  }
190  return *this;
191 }
192 
193 Comment &Comment::operator = (const Comment &other)
194 {
195  CharacterData::operator =(other);
196  return *this;
197 }
198 
199 Comment::~Comment()
200 {
201 }
202 
203 Comment::Comment(CommentImpl *i) : CharacterData(i)
204 {
205 }
206 
207 // ----------------------------------------------------------------------------
208 
209 Text::Text()
210 {
211 }
212 
213 Text::Text(const Text &other) : CharacterData(other)
214 {
215 }
216 
217 Text &Text::operator = (const Node &other)
218 {
219  NodeImpl *ohandle = other.handle();
220  if (impl != ohandle) {
221  if (!ohandle ||
222  (ohandle->nodeType() != TEXT_NODE &&
223  ohandle->nodeType() != CDATA_SECTION_NODE)) {
224  if (impl) {
225  impl->deref();
226  }
227  impl = nullptr;
228  } else {
229  Node::operator =(other);
230  }
231  }
232  return *this;
233 }
234 
235 Text &Text::operator = (const Text &other)
236 {
237  Node::operator =(other);
238  return *this;
239 }
240 
241 Text::~Text()
242 {
243 }
244 
245 Text Text::splitText(const unsigned long offset)
246 {
247  if (!impl) {
248  return nullptr; // ### enable throw DOMException(DOMException::NOT_FOUND_ERR);
249  }
250 
251  int exceptioncode = 0;
252  TextImpl *newText = static_cast<TextImpl *>(impl)->splitText(offset, exceptioncode);
253  if (exceptioncode) {
254  throw DOMException(exceptioncode);
255  }
256  return newText;
257 }
258 
259 Text::Text(TextImpl *i) : CharacterData(i)
260 {
261 }
The Node interface is the primary datatype for the entire Document Object Model.
Definition: dom_node.h:278
unsigned long length() const
The number of characters that are available through data and the substringData method below...
Definition: dom_text.cpp:89
void replaceData(const unsigned long offset, const unsigned long count, const DOMString &arg)
Replace the characters starting at the specified character offset with the specified string...
Definition: dom_text.cpp:150
DOM operations only raise exceptions in "exceptional" circumstances, i.e., when an operation is impos...
Definition: dom_exception.h:58
DOMString substringData(const unsigned long offset, const unsigned long count)
Extracts a range of data from the node.
Definition: dom_text.cpp:97
This represents the content of a comment, i.e., all the characters between the starting &#39; <!– &#39; and ...
Definition: dom_text.h:225
The Text interface represents the textual content (termed character data in XML) of an Element or At...
Definition: dom_text.h:273
void appendData(const DOMString &arg)
Append the string to the end of the character data of the node.
Definition: dom_text.cpp:111
This class implements the basic string we use in the DOM.
Definition: dom_string.h:44
void deleteData(const unsigned long offset, const unsigned long count)
Remove a range of characters from the node.
Definition: dom_text.cpp:137
DOMString()
default constructor.
Definition: dom_string.h:52
DOMString data() const
The character data of the node that implements this interface.
Definition: dom_text.cpp:67
void setData(const DOMString &)
see data NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
Definition: dom_text.cpp:75
This library provides a full-featured HTML parser and widget.
void insertData(const unsigned long offset, const DOMString &arg)
Insert a string at the specified character offset.
Definition: dom_text.cpp:124
Text splitText(const unsigned long offset)
Breaks this Text node into two Text nodes at the specified offset, keeping both in the tree as siblin...
Definition: dom_text.cpp:245
NodeImpl * handle() const
Definition: dom_node.h:936
The CharacterData interface extends Node with a set of attributes and methods for accessing character...
Definition: dom_text.h:50
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Thu Jul 9 2020 22:45:24 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.