Xalan-C++ API Reference  1.12.0
XalanDOMString.hpp
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 #if !defined(XALANDOMSTRING_HEADER_GUARD_1357924680)
19 #define XALANDOMSTRING_HEADER_GUARD_1357924680
20 
21 
22 
24 
25 
26 
27 #include <cassert>
28 
29 
30 
34 
35 
36 
38 
39 
40 
41 namespace XALAN_CPP_NAMESPACE {
42 
43 
44 
46 {
47 public:
48 
52 
53  typedef XalanDOMChar value_type;
54  typedef XalanDOMChar& reference;
55  typedef const XalanDOMChar& const_reference;
56 
57  typedef XalanSize_t size_type;
58 
63 
64  static const size_type npos;
65 
67 
68  explicit
70  const char* theString,
71  MemoryManager& theManager XALAN_DEFAULT_MEMMGR,
72  size_type theCount = size_type(npos));
73 
75  const XalanDOMString& theSource,
76  MemoryManager& theManager XALAN_DEFAULT_CONSTRUCTOR_MEMMGR,
77  size_type theStartPosition = 0,
78  size_type theCount = size_type(npos));
79 
80  explicit
82  const XalanDOMChar* theString,
83  MemoryManager& theManager XALAN_DEFAULT_MEMMGR,
84  size_type theCount = size_type(npos));
85 
87  size_type theCount,
88  XalanDOMChar theChar,
89  MemoryManager& theManager XALAN_DEFAULT_MEMMGR);
90 
92  clone(MemoryManager& theManager);
93 
95  {
96  }
97 
99  operator=(const XalanDOMString& theRHS)
100  {
101  return assign(theRHS);
102  }
103 
105  operator=(const XalanDOMChar* theRHS)
106  {
107  return assign(theRHS);
108  }
109 
111  operator=(const char* theRHS)
112  {
113  return assign(theRHS);
114  }
115 
117  operator=(XalanDOMChar theRHS)
118  {
119  return assign(1, theRHS);
120  }
121 
122  iterator
124  {
125  invariants();
126 
127  return m_data.begin();
128  }
129 
130  const_iterator
131  begin() const
132  {
133  invariants();
134 
135  return m_data.begin();
136  }
137 
138  iterator
139  end()
140  {
141  invariants();
142 
143  return m_data.empty() == true ? m_data.end() : m_data.end() - 1;
144  }
145 
146  const_iterator
147  end() const
148  {
149  invariants();
150 
151  return m_data.empty() == true ? m_data.end() : m_data.end() - 1;
152  }
153 
154  reverse_iterator
156  {
157  invariants();
158 
159  reverse_iterator i = m_data.rbegin();
160 
161  if (m_data.empty() == false)
162  {
163  ++i;
164  }
165 
166  return i;
167  }
168 
169  const_reverse_iterator
170  rbegin() const
171  {
172  invariants();
173 
174  const_reverse_iterator i = m_data.rbegin();
175 
176  if (m_data.empty() == false)
177  {
178  ++i;
179  }
180 
181  return i;
182  }
183 
184  reverse_iterator
186  {
187  invariants();
188 
189  return m_data.rend();
190  }
191 
192  const_reverse_iterator
193  rend() const
194  {
195  invariants();
196 
197  return m_data.rend();
198  }
199 
200  size_type
201  size() const
202  {
203  invariants();
204 
205  return m_size;
206  }
207 
208  size_type
209  length() const
210  {
211  invariants();
212 
213  return size();
214  }
215 
216  size_type
217  max_size() const
218  {
219  invariants();
220 
221  return ~size_type(0);
222  }
223 
224  void
226  size_type theCount,
227  XalanDOMChar theChar);
228 
229  void
230  resize(size_type theCount)
231  {
232  invariants();
233 
234  resize(theCount, XalanDOMChar(0));
235  }
236 
237  size_type
238  capacity() const
239  {
240  invariants();
241 
242  const XalanDOMCharVectorType::size_type theCapacity =
243  m_data.capacity();
244 
245  return theCapacity == 0 ? 0 : size_type(theCapacity - 1);
246  }
247 
248  void
249  reserve(size_type theCount = 0)
250  {
251  invariants();
252 
253  m_data.reserve(theCount + 1);
254  }
255 
256  void
258  {
259  invariants();
260 
261  m_data.erase(m_data.begin(), m_data.end());
262 
263  m_size = 0;
264 
265  invariants();
266  }
267 
268  iterator
269  erase(iterator thePosition)
270  {
271  invariants();
272 
273  m_data.erase(thePosition);
274 
275  --m_size;
276 
277  invariants();
278 
279  return thePosition;
280  }
281 
282  iterator
284  iterator theFirst,
285  iterator theLast)
286  {
287  invariants();
288 
289  m_data.erase(theFirst, theLast);
290 
291  m_size = m_data.size() - 1;
292 
293  invariants();
294 
295  return theFirst;
296  }
297 
300  size_type theStartPosition = 0,
301  size_type theCount = size_type(npos));
302 
303  bool
304  empty() const
305  {
306  invariants();
307 
308  return m_size == 0 ? true : false;
309  }
310 
311  const_reference
312  operator[](size_type theIndex) const
313  {
314  invariants();
315 
316  return m_data[theIndex];
317  }
318 
319  reference
321  {
322  invariants();
323 
324  return m_data[theIndex];
325  }
326 
327  const_reference
328  at(size_type theIndex) const
329  {
330  invariants();
331 
332  return m_data.at(theIndex);
333  }
334 
335  reference
336  at(size_type theIndex)
337  {
338  invariants();
339 
340  return m_data.at(theIndex);
341  }
342 
343  const XalanDOMChar*
344  c_str() const
345  {
346  invariants();
347 
348  return m_data.empty() == true ? &s_empty : &m_data[0];
349  }
350 
351  const XalanDOMChar*
352  data() const
353  {
354  invariants();
355 
356  return c_str();
357  }
358 
359  void
360  swap(XalanDOMString& theOther)
361  {
362  invariants();
363 
364  m_data.swap(theOther.m_data);
365 
366  std::swap(m_size, theOther.m_size);
367  }
368 
370  operator+=(const XalanDOMString& theSource)
371  {
372  return append(theSource);
373  }
374 
376  operator+=(const XalanDOMChar* theString)
377  {
378  return append(theString);
379  }
380 
382  operator+=(XalanDOMChar theChar)
383  {
384  append(1, theChar);
385 
386  return *this;
387  }
388 
390  assign(const XalanDOMChar* theSource)
391  {
392  invariants();
393 
394  erase();
395 
396  invariants();
397 
398  return append(theSource);
399  }
400 
403  const XalanDOMChar* theSource,
404  size_type theCount)
405  {
406  invariants();
407 
408  erase();
409 
410  invariants();
411 
412  return append(theSource, theCount);
413  }
414 
416  assign(const char* theSource)
417  {
418  invariants();
419 
420  erase();
421 
422  invariants();
423 
424  return append(theSource);
425  }
426 
429  const char* theSource,
430  size_type theCount)
431  {
432  invariants();
433 
434  erase();
435 
436  invariants();
437 
438  return append(theSource, theCount);
439  }
440 
443  const XalanDOMString& theSource,
444  size_type thePosition,
445  size_type theCount);
446 
448  assign(const XalanDOMString& theSource)
449  {
450  invariants();
451 
452  if (&theSource != this)
453  {
454  m_data = theSource.m_data;
455 
456  m_size = theSource.m_size;
457  }
458 
459  invariants();
460 
461  return *this;
462  }
463 
466  size_type theCount,
467  XalanDOMChar theChar)
468  {
469  invariants();
470 
471  erase();
472 
473  invariants();
474 
475  return append(theCount, theChar);
476  }
477 
480  iterator theFirstPosition,
481  iterator theLastPosition);
482 
484  append(const XalanDOMString& theSource)
485  {
486  return append(theSource.c_str(), theSource.length());
487  }
488 
491  const XalanDOMString& theSource,
492  size_type thePosition,
493  size_type theCount)
494  {
495  assert(thePosition < theSource.length() &&
496  (theCount == size_type(npos) || thePosition + theCount <= theSource.length()));
497 
498  return append(theSource.c_str() + thePosition, theCount);
499  }
500 
503  const XalanDOMChar* theString,
504  size_type theCount);
505 
507  append(const XalanDOMChar* theString)
508  {
509  return append(theString, length(theString));
510  }
511 
514  const char* theString,
515  size_type theCount);
516 
518  append(const char* theString)
519  {
520  return append(theString, length(theString));
521  }
522 
525  size_type theCount,
526  XalanDOMChar theChar);
527 
528  void
529  push_back(XalanDOMChar theChar)
530  {
531  invariants();
532 
533  append(1, theChar);
534 
535  invariants();
536  }
537 
540  size_type thePosition,
541  const XalanDOMString& theString)
542  {
543  return insert(thePosition, theString.c_str(), theString.length());
544  }
545 
548  size_type thePosition1,
549  const XalanDOMString& theString,
550  size_type thePosition2,
551  size_type theCount)
552  {
553  return insert(thePosition1, theString.c_str() + thePosition2, theCount);
554  }
555 
558