1//
2// CharacterData.cpp
3//
4// Library: XML
5// Package: DOM
6// Module: DOM
7//
8// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
9// and Contributors.
10//
11// SPDX-License-Identifier: BSL-1.0
12//
13
14
15#include "Poco/DOM/CharacterData.h"
16#include "Poco/DOM/DOMException.h"
17#include "Poco/String.h"
18
19
20namespace Poco {
21namespace XML {
22
23
24CharacterData::CharacterData(Document* pOwnerDocument, const XMLString& data):
25 AbstractNode(pOwnerDocument),
26 _data(data)
27{
28}
29
30
31CharacterData::CharacterData(Document* pOwnerDocument, const CharacterData& data):
32 AbstractNode(pOwnerDocument, data),
33 _data(data._data)
34{
35}
36
37
38CharacterData::~CharacterData()
39{
40}
41
42
43void CharacterData::setData(const XMLString& data)
44{
45 if (events())
46 {
47 XMLString oldData = _data;
48 _data = data;
49 dispatchCharacterDataModified(oldData, _data);
50 }
51 else
52 {
53 _data = data;
54 }
55}
56
57
58XMLString CharacterData::substringData(unsigned long offset, unsigned long count) const
59{
60 if (offset >= _data.length())
61 throw DOMException(DOMException::INDEX_SIZE_ERR);
62
63 return _data.substr(offset, count);
64}
65
66
67void CharacterData::appendData(const XMLString& arg)
68{
69 if (events())
70 {
71 XMLString oldData = _data;
72 _data.append(arg);
73 dispatchCharacterDataModified(oldData, _data);
74 }
75 else
76 {
77 _data.append(arg);
78 }
79}
80
81
82void CharacterData::insertData(unsigned long offset, const XMLString& arg)
83{
84 if (offset > _data.length())
85 throw DOMException(DOMException::INDEX_SIZE_ERR);
86
87 if (events())
88 {
89 XMLString oldData = _data;
90 _data.insert(offset, arg);
91 dispatchCharacterDataModified(oldData, _data);
92 }
93 else
94 {
95 _data.insert(offset, arg);
96 }
97}
98
99
100void CharacterData::deleteData(unsigned long offset, unsigned long count)
101{
102 if (offset >= _data.length())
103 throw DOMException(DOMException::INDEX_SIZE_ERR);
104
105 if (events())
106 {
107 XMLString oldData = _data;
108 _data.replace(offset, count, EMPTY_STRING);
109 dispatchCharacterDataModified(oldData, _data);
110 }
111 else
112 _data.replace(offset, count, EMPTY_STRING);
113}
114
115
116void CharacterData::replaceData(unsigned long offset, unsigned long count, const XMLString& arg)
117{
118 if (offset >= _data.length())
119 throw DOMException(DOMException::INDEX_SIZE_ERR);
120
121 if (events())
122 {
123 XMLString oldData = _data;
124 _data.replace(offset, count, arg);
125 dispatchCharacterDataModified(oldData, _data);
126 }
127 else
128 {
129 _data.replace(offset, count, arg);
130 }
131}
132
133
134const XMLString& CharacterData::getNodeValue() const
135{
136 return _data;
137}
138
139
140void CharacterData::setNodeValue(const XMLString& value)
141{
142 setData(value);
143}
144
145
146XMLString CharacterData::trimmedData() const
147{
148 return Poco::trim(_data);
149}
150
151
152} } // namespace Poco::XML
153