a963e9850cf854cc980eb1cc49b6945da4e0e2a6
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 DOMString &operator =(const DOMString &a);
120 /**
121 *
122 */
123 virtual DOMString &assign(const char *str);
125 /**
126 *
127 */
128 virtual DOMString &assign(const std::string &str);
130 /**
131 *
132 */
133 virtual void erase(unsigned long pos, unsigned long count);
135 /**
136 *
137 */
138 virtual DOMString &insert(unsigned long pos, const DOMString &str);
140 /**
141 *
142 */
143 virtual DOMString &insert(unsigned long pos, const char *str);
145 /**
146 *
147 */
148 virtual DOMString &insert(unsigned long pos, const std::string &str);
151 /**
152 *
153 */
154 virtual DOMString &prepend(const DOMString &str);
156 /**
157 *
158 */
159 virtual DOMString &prepend(const char *str);
161 /**
162 *
163 */
164 virtual DOMString &prepend(const std::string &str);
167 /**
168 *
169 */
170 virtual DOMString &replace(unsigned long pos, unsigned long count,
171 const DOMString &str);
173 /**
174 *
175 */
176 virtual DOMString &replace(unsigned long pos, unsigned long count,
177 const char *str);
179 /**
180 *
181 */
182 virtual DOMString &replace(unsigned long pos, unsigned long count,
183 const std::string &str);
185 /**
186 *
187 */
188 virtual DOMString &push_back(XMLCh ch);
190 /**
191 *
192 */
193 virtual void clear();
195 //###############################
196 //# Q U E R Y
197 //###############################
199 /**
200 *
201 */
202 virtual DOMString substr(unsigned long start, unsigned long end) const;
204 /**
205 *
206 */
207 virtual XMLCh charAt(unsigned long index) const;
209 /**
210 *
211 */
212 virtual XMLCh operator[](unsigned long index) const;
214 /**
215 *
216 */
217 virtual unsigned long size() const;
219 /**
220 *
221 */
222 virtual const char *c_str();
224 //###############################
225 //# C O M P A R I S O N
226 //###############################
228 /**
229 *
230 */
231 virtual int compare(const DOMString &str) const;
232 virtual bool operator <(const DOMString &str) const
233 { return (compare(str)<0) ; }
234 virtual bool operator <=(const DOMString &str) const
235 { return (compare(str)<=0) ; }
236 virtual bool operator >(const DOMString &str) const
237 { return (compare(str)>0) ; }
238 virtual bool operator >=(const DOMString &str) const
239 { return (compare(str)>=0) ; }
240 virtual bool operator !=(const DOMString &str) const
241 { return (compare(str)!=0) ; }
242 virtual bool operator ==(const DOMString &str) const
243 { return (compare(str)==0) ; }
245 /**
246 *
247 */
248 virtual int compare(const char *str) const;
249 virtual bool operator <(const char *str) const
250 { return (compare(str)<0) ; }
251 virtual bool operator <=(const char *str) const
252 { return (compare(str)<=0) ; }
253 virtual bool operator >(const char *str) const
254 { return (compare(str)>0) ; }
255 virtual bool operator >=(const char *str) const
256 { return (compare(str)>=0) ; }
257 virtual bool operator !=(const char *str) const
258 { return (compare(str)!=0) ; }
259 virtual bool operator ==(const char *str) const
260 { return (compare(str)==0) ; }
262 /**
263 *
264 */
265 virtual int compare(const std::string &str) const;
266 virtual bool operator <(const std::string &str) const
267 { return (compare(str)<0) ; }
268 virtual bool operator <=(const std::string &str) const
269 { return (compare(str)<=0) ; }
270 virtual bool operator >(const std::string &str) const
271 { return (compare(str)>0) ; }
272 virtual bool operator >=(const std::string &str) const
273 { return (compare(str)>=0) ; }
274 virtual bool operator !=(const std::string &str) const
275 { return (compare(str)!=0) ; }
276 virtual bool operator ==(const std::string &str) const
277 { return (compare(str)==0) ; }
282 protected:
284 void init();
286 char *cstring;
288 std::vector<XMLCh> chars;
290 }; // class DOMString
295 //###############################
296 //# O P E R A T O R S
297 //###############################
299 DOMString &operator +(DOMString &a, const char *b);
301 DOMString &operator +(const char *b, DOMString &a);
305 } //namespace dom
306 } //namespace w3c
307 } //namespace org
309 #endif // __DOMSTRING_H__
310 //#########################################################################
311 //## E N D O F F I L E
312 //#########################################################################