1 #ifndef __DOMSTRING_H__
2 #define __DOMSTRING_H__
3 /**
4 * Phoebe DOM Implementation.
5 *
6 * This is a C++ approximation of the W3C DOM model, which follows
7 * fairly closely the specifications in the various .idl files, copies of
8 * which are provided for reference. Most important is this one:
9 *
10 * http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/idl-definitions.html
11 *
12 * Authors:
13 * Bob Jamison
14 *
15 * Copyright (C) 2005 Bob Jamison
16 *
17 * This library is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU Lesser General Public
19 * License as published by the Free Software Foundation; either
20 * version 2.1 of the License, or (at your option) any later version.
21 *
22 * This library is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25 * Lesser General Public License for more details.
26 *
27 * You should have received a copy of the GNU Lesser General Public
28 * License along with this library; if not, write to the Free Software
29 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30 */
33 #include <vector>
34 #include <string>
36 namespace org
37 {
38 namespace w3c
39 {
40 namespace dom
41 {
43 /**
44 *
45 */
46 typedef unsigned short XMLCh;
48 class DOMString
49 {
50 public:
52 //###############################
53 //# C O N S T R U C T O R S
54 //###############################
56 /**
57 *
58 */
59 DOMString();
61 /**
62 *
63 */
64 DOMString(const char *str);
67 /**
68 *
69 */
70 DOMString(const DOMString &str);
73 /**
74 *
75 */
76 DOMString(const std::string &str);
78 /**
79 *
80 */
81 virtual ~DOMString();
84 //###############################
85 //# M O D I F Y
86 //###############################
90 /**
91 *
92 */
93 virtual DOMString &append(const DOMString &str);
94 virtual DOMString &operator +(const DOMString &str)
95 { return append(str); }
96 virtual DOMString &operator +=(const DOMString &str)
97 { return append(str); }
99 /**
100 *
101 */
102 virtual DOMString &append(const char *str);
104 /**
105 *
106 */
107 virtual DOMString &append(const std::string &str);
110 /**
111 *
112 */
113 virtual DOMString &assign(const DOMString &str);
115 /**
116 *
117 */
118 virtual DOMString &assign(const char *str);
120 /**
121 *
122 */
123 virtual DOMString &assign(const std::string &str);
125 /**
126 *
127 */
128 virtual void erase(unsigned long pos, unsigned long count);
130 /**
131 *
132 */
133 virtual DOMString &insert(unsigned long pos, const DOMString &str);
135 /**
136 *
137 */
138 virtual DOMString &insert(unsigned long pos, const char *str);
140 /**
141 *
142 */
143 virtual DOMString &insert(unsigned long pos, const std::string &str);
146 /**
147 *
148 */
149 virtual DOMString &prepend(const DOMString &str);
151 /**
152 *
153 */
154 virtual DOMString &prepend(const char *str);
156 /**
157 *
158 */
159 virtual DOMString &prepend(const std::string &str);
162 /**
163 *
164 */
165 virtual DOMString &replace(unsigned long pos, unsigned long count,
166 const DOMString &str);
168 /**
169 *
170 */
171 virtual DOMString &replace(unsigned long pos, unsigned long count,
172 const char *str);
174 /**
175 *
176 */
177 virtual DOMString &replace(unsigned long pos, unsigned long count,
178 const std::string &str);
180 /**
181 *
182 */
183 virtual DOMString &push_back(XMLCh ch);
185 /**
186 *
187 */
188 virtual void clear();
190 //###############################
191 //# Q U E R Y
192 //###############################
194 /**
195 *
196 */
197 virtual DOMString substr(unsigned long start, unsigned long end) const;
199 /**
200 *
201 */
202 virtual XMLCh charAt(unsigned long index) const;
204 /**
205 *
206 */
207 virtual XMLCh operator[](unsigned long index) const;
209 /**
210 *
211 */
212 virtual unsigned long size() const;
214 /**
215 *
216 */
217 virtual const char *c_str();
219 //###############################
220 //# C O M P A R I S O N
221 //###############################
223 /**
224 *
225 */
226 virtual int compare(const DOMString &str) const;
227 virtual bool operator <(const DOMString &str) const
228 { return (compare(str)<0) ; }
229 virtual bool operator <=(const DOMString &str) const
230 { return (compare(str)<=0) ; }
231 virtual bool operator >(const DOMString &str) const
232 { return (compare(str)>0) ; }
233 virtual bool operator >=(const DOMString &str) const
234 { return (compare(str)>=0) ; }
235 virtual bool operator !=(const DOMString &str) const
236 { return (compare(str)!=0) ; }
237 virtual bool operator ==(const DOMString &str) const
238 { return (compare(str)==0) ; }
240 /**
241 *
242 */
243 virtual int compare(const char *str) const;
244 virtual bool operator <(const char *str) const
245 { return (compare(str)<0) ; }
246 virtual bool operator <=(const char *str) const
247 { return (compare(str)<=0) ; }
248 virtual bool operator >(const char *str) const
249 { return (compare(str)>0) ; }
250 virtual bool operator >=(const char *str) const
251 { return (compare(str)>=0) ; }
252 virtual bool operator !=(const char *str) const
253 { return (compare(str)!=0) ; }
254 virtual bool operator ==(const char *str) const
255 { return (compare(str)==0) ; }
257 /**
258 *
259 */
260 virtual int compare(const std::string &str) const;
261 virtual bool operator <(const std::string &str) const
262 { return (compare(str)<0) ; }
263 virtual bool operator <=(const std::string &str) const
264 { return (compare(str)<=0) ; }
265 virtual bool operator >(const std::string &str) const
266 { return (compare(str)>0) ; }
267 virtual bool operator >=(const std::string &str) const
268 { return (compare(str)>=0) ; }
269 virtual bool operator !=(const std::string &str) const
270 { return (compare(str)!=0) ; }
271 virtual bool operator ==(const std::string &str) const
272 { return (compare(str)==0) ; }
277 protected:
279 void init();
281 char *cstring;
283 std::vector<XMLCh> chars;
285 }; // class DOMString
290 //###############################
291 //# O P E R A T O R S
292 //###############################
294 DOMString &operator +(DOMString &a, const char *b);
296 DOMString &operator +(const char *b, DOMString &a);
300 } //namespace dom
301 } //namespace w3c
302 } //namespace org
304 #endif // __DOMSTRING_H__
305 //#########################################################################
306 //## E N D O F F I L E
307 //#########################################################################