Xalan-C++ API Documentation

The Xalan C++ XSLT Processor Version 1.10

XalanDOMString.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #if !defined(XALANDOMSTRING_HEADER_GUARD_1357924680)
17 #define XALANDOMSTRING_HEADER_GUARD_1357924680
18 
19 
20 
22 
23 
24 
25 #include <cassert>
26 
27 
28 
31 
32 
33 
35 
36 
37 
38 XALAN_CPP_NAMESPACE_BEGIN
39 
40 
41 
43 {
44 public:
48 
49  typedef XalanDOMChar value_type;
50  typedef XalanDOMChar& reference;
51  typedef const XalanDOMChar& const_reference;
52 
53  typedef unsigned int size_type;
54 
59 
60 #if defined(XALAN_INLINE_INITIALIZATION)
61  static const size_type npos = ~0u;
62 #else
63  enum { npos = -1 };
64 #endif
65 
67 
68  explicit
70  const char* theString,
72  size_type theCount = size_type(npos));
73 
75  const XalanDOMString& theSource,
77  size_type theStartPosition = 0,
78  size_type theCount = size_type(npos));
79 
80  explicit
82  const XalanDOMChar* theString,
83  MemoryManagerType& theManager XALAN_DEFAULT_MEMMGR,
84  size_type theCount = size_type(npos));
85 
87  size_type theCount,
88  XalanDOMChar theChar,
89  MemoryManagerType& theManager XALAN_DEFAULT_MEMMGR);
90 
92  clone(MemoryManagerType& 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
225  resize(
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  void
269  erase(
270  size_type theStartPosition = 0,
271  size_type theCount = size_type(npos));
272 
273  bool
274  empty() const
275  {
276  invariants();
277 
278  return m_size == 0 ? true : false;
279  }
280 
281  const_reference
282  operator[](size_type theIndex) const
283  {
284  invariants();
285 
286  return m_data[theIndex];
287  }
288 
289  reference
291  {
292  invariants();
293 
294  return m_data[theIndex];
295  }
296 
297  const_reference
298  at(size_type theIndex) const
299  {
300  invariants();
301 
302  return m_data.at(theIndex);
303  }
304 
305  reference
306  at(size_type theIndex)
307  {
308  invariants();
309 
310  return m_data.at(theIndex);
311  }
312 
313  const XalanDOMChar*
314  c_str() const
315  {
316  invariants();
317 
318  return m_data.empty() == true ? &s_empty : &m_data[0];
319  }
320 
321  const XalanDOMChar*
322  data() const
323  {
324  invariants();
325 
326  return c_str();
327  }
328 
329  void
330  swap(XalanDOMString& theOther)
331  {
332  invariants();
333 
334  m_data.swap(theOther.m_data);
335 
336 #if defined(XALAN_NO_STD_NAMESPACE)
337  ::swap(m_size, theOther.m_size);
338 #else
339  std::swap(m_size, theOther.m_size);
340 #endif
341  }
342 
344  operator+=(const XalanDOMString& theSource)
345  {
346  return append(theSource);
347  }
348 
350  operator+=(const XalanDOMChar* theString)
351  {
352  return append(theString);
353  }
354 
356  operator+=(XalanDOMChar theChar)
357  {
358  append(1, theChar);
359 
360  return *this;
361  }
362 
364  assign(const XalanDOMChar* theSource)
365  {
366  invariants();
367 
368  erase();
369 
370  invariants();
371 
372  return append(theSource);
373  }
374 
377  const XalanDOMChar* theSource,
378  size_type theCount)
379  {
380  invariants();
381 
382  erase();
383 
384  invariants();
385 
386  return append(theSource, theCount);
387  }
388 
390  assign(const char* theSource)
391  {
392  invariants();
393 
394  erase();
395 
396  invariants();
397 
398  return append(theSource);
399  }
400 
403  const char* theSource,
404  size_type theCount)
405  {
406  invariants();
407 
408  erase();
409 
410  invariants();
411 
412  return append(theSource, theCount);
413  }
414 
416  assign(
417  const XalanDOMString& theSource,
418  size_type thePosition,
419  size_type theCount);
420 
422  assign(const XalanDOMString& theSource)
423  {
424  invariants();
425 
426  if (&theSource != this)
427  {
428  m_data = theSource.m_data;
429 
430  m_size = theSource.m_size;
431  }
432 
433  invariants();
434 
435  return *this;
436  }
437 
440  size_type theCount,
441  XalanDOMChar theChar)
442  {
443  invariants();
444 
445  erase();
446 
447  invariants();
448 
449  return append(theCount, theChar);
450  }
451 
453  assign(
454  iterator theFirstPosition,
455  iterator theLastPosition);
456 
458  append(const XalanDOMString& theSource)
459  {
460  return append(theSource.c_str(), theSource.length());
461  }
462 
465  const XalanDOMString& theSource,
466  size_type thePosition,
467  size_type theCount)
468  {
469  assert(thePosition < theSource.length() &&
470  (theCount == size_type(npos) || thePosition + theCount <= theSource.length()));
471 
472  return append(theSource.c_str() + thePosition, theCount);
473  }
474 
476  append(
477  const XalanDOMChar* theString,
478  size_type theCount);
479 
481  append(const XalanDOMChar* theString)
482  {
483  return append(theString, length(theString));
484  }
485 
487  append(
488  const char* theString,
489  size_type theCount);
490 
492  append(const char* theString)
493  {
494  return append(theString, length(theString));
495  }
496 
498  append(
499  size_type theCount,
500  XalanDOMChar theChar);
501 
502  void
503  push_back(XalanDOMChar theChar)
504  {
505  invariants();
506 
507  append(1, theChar);
508 
509  invariants();
510  }
511 
514  size_type thePosition,
515  const XalanDOMString& theString)
516  {
517  return insert(thePosition, theString.c_str(), theString.length());
518  }
519 
522  size_type thePosition1,
523  const XalanDOMString& theString,
524  size_type thePosition2,
525  size_type theCount)
526  {
527  return insert(thePosition1, theString.c_str() + thePosition2, theCount);
528  }
529 
531  insert(
532  size_type thePosition,
533  const XalanDOMChar* theString,
534  size_type theCount);
535 
538  size_type thePosition,
539  const XalanDOMChar* theString)
540  {
541  return insert(thePosition, theString, length(theString));
542  }
543 
545  insert(
546  size_type thePosition,
547  size_type theCount,
548  XalanDOMChar theChar);
549 
550  iterator
551  insert(
552  iterator thePosition,
553  XalanDOMChar theChar);
554 
555  void
556  insert(
557  iterator thePosition,
558  size_type theCount,
559  XalanDOMChar theChar);
560 
561  void
562  insert(
563  iterator theInsertPosition,
564  iterator theFirstPosition,
565  iterator theLastPosition);
566 
567 
570  XalanDOMString& theSubstring,
571  size_type thePosition = 0,
572  size_type theCount = size_type(npos)) const
573  {
574  assert(theCount == size_type(npos) && thePosition < length() ||
575  thePosition + theCount <= length());
576 
577  invariants();
578 
579  return theSubstring.assign(*this, thePosition, theCount);
580  }
581 
582  int
583  compare(const XalanDOMString& theString) const
584  {
585  invariants();
586 
587  return compare(theString.c_str());
588  }
589 
590  int
592  size_type thePosition1,
593  size_type theCount1,
594  const XalanDOMString& theString) const
595  {
596  invariants();
597 
598  return compare(thePosition1, theCount1, theString.c_str(), theString.length());
599  }
600 
601  int
603  size_type thePosition1,
604  size_type theCount1,
605  const XalanDOMString& theString,
606  size_type thePosition2,
607  size_type theCount2) const
608  {
609  invariants();
610 
611  return compare(thePosition1, theCount1, theString.c_str() + thePosition2, theCount2);
612  }
613 
614  int
615  compare(const XalanDOMChar* theString) const;
616 
617  int
618  compare(
619  size_type thePosition1,
620  size_type theCount1,
621  const XalanDOMChar* theString,
622  size_type theCount2 = size_type(npos)) const;
623 
624 
625  void
626  reset(MemoryManagerType& theManager, const char* theString);
627 
628  void
629  reset(MemoryManagerType& theManager, const XalanDOMChar* theString);
630 
632  {
633  public:
634 
636  XalanDOMException(TRANSCODING_ERR)
637  {
638  }
639 
640  virtual
642  {
643  }
644  };
645 
646 
647 
655  void
656  transcode(CharVectorType& theResult) const;
657 
660  {
661  return m_data.getMemoryManager();
662  }
663 
664  size_type
665  hash() const
666  {
667  return hash(c_str(), size());
668  }
669 
670  static bool
671  equals(
672  const XalanDOMChar* theLHS,
673  size_type theLHSLength,
674  const XalanDOMChar* theRHS,
675  size_type theRHSLength);
676 
677  static bool
679  const XalanDOMChar* theLHS,
680  const XalanDOMChar* theRHS)
681  {
682  return equals(theLHS, length(theLHS), theRHS, length(theRHS));
683  }
684 
685  static bool
686  equals(
687  const XalanDOMString& theLHS,
688  const XalanDOMString& theRHS);
689 
690  static bool
692  const XalanDOMString& theLHS,
693  const XalanDOMChar* theRHS)
694  {
695  return equals(theLHS.c_str(), theRHS);
696  }
697 
698  static bool
700  const XalanDOMChar* theLHS,
701  const XalanDOMString& theRHS)
702  {
703  return equals(theLHS, theRHS.c_str());
704  }
705 
706  /*
707  * Helper function to determine the length of a null-
708  * terminated string.
709  *
710  * @theString The string
711  * @return the length
712  */
713  static size_type
714  length(const XalanDOMChar* theString);
715 
716  /*
717  * Helper function to determine the length of a null-
718  * terminated string.
719  *
720  * @theString The string
721  * @return the length
722  */
723  static size_type
724  length(const char* theString);
725 
726  static size_type
727  hash(
728  const XalanDOMChar* theString,
729  size_type theLength);
730 
731 protected:
732 
733  /*
734  * Function to assert invariant conditions for the class.
735  *
736  * @return the iterator
737  */
738  void
739  invariants() const
740  {
741 #if !defined(NDEBUG)
742  assert((m_data.empty() == true && m_size == 0) || m_size == m_data.size() - 1);
743  assert(m_data.empty() == true || m_data.back() == 0);
744 #endif
745  }
746 
747  /*
748  * Get an iterator to the position of the terminating null.
749  *
750  * @return the iterator
751  */
752  iterator
754  {
755  invariants();
756 
757  return m_data.empty() == true ? m_data.end() : m_data.end() - 1;
758  }
759 
760  const_iterator
762  {
763  invariants();
764 
765  return m_data.empty() == true ? m_data.end() : m_data.end() - 1;
766  }
767 
768  iterator
770  {
771  invariants();
772 
773  return m_data.begin() + thePosition;
774  }
775 
776  const_iterator
778  {
779  invariants();
780 
781  return m_data.begin() + thePosition;
782  }
783 
784 #if defined (XALAN_DEVELOPMENT)
785  // not defined
786  XalanDOMString();
788 #endif
789 
790 private:
791 
792 
793  XalanDOMCharVectorType m_data;
794 
795  size_type m_size;
796 
797  static const XalanDOMChar s_empty;
798 };
799 
800 
801 
802 inline bool
804  const XalanDOMString& theLHS,
805  const XalanDOMString& theRHS)
806 {
807  return XalanDOMString::equals(theLHS, theRHS);
808 }
809 
810 
811 
812 inline bool
814  const XalanDOMString& theLHS,
815  const XalanDOMChar* theRHS)
816 {
817  return XalanDOMString::equals(theLHS, theRHS);
818 }
819 
820 
821 
822 inline bool
824  const XalanDOMChar* theLHS,
825  const XalanDOMString& theRHS)
826 {
827  // Note reversing of operands...
828  return XalanDOMString::equals(theLHS, theRHS);
829 }
830 
831 
832 
833 inline bool
835  const XalanDOMString& theLHS,
836  const XalanDOMString& theRHS)
837 {
838  return !(theLHS == theRHS);
839 }
840 
841 
842 
843 inline bool
845  const XalanDOMChar* theLHS,
846  const XalanDOMString& theRHS)
847 {
848  return !(theLHS == theRHS);
849 }
850 
851 
852 
853 inline bool
855  const XalanDOMString& theLHS,
856  const XalanDOMChar* theRHS)
857 {
858  return !(theRHS == theLHS);
859 }
860 
861 
862 
863 inline XalanDOMString&
865  const XalanDOMString& theLHS,
866  const XalanDOMString& theRHS,
867  XalanDOMString& result)
868 {
869  result.assign(theLHS);
870 
871  return result += theRHS;
872 }
873 
874 
875 
876 inline XalanDOMString&
878  const XalanDOMString& theLHS,
879  const XalanDOMChar* theRHS,
880  XalanDOMString& result)
881 {
882  result.assign(theLHS);
883 
884  return result += theRHS;
885 }
886 
887 
888 
889 inline XalanDOMString&
891  const XalanDOMChar* theLHS,
892  const XalanDOMString& theRHS,
893  XalanDOMString& result)
894 {
895  result.assign(theLHS);
896 
897  return result += theRHS;
898 }
899 
900 
901 
902 inline const XalanDOMString&
904  const char* theLHS,
905  const XalanDOMString& theRHS,
906  XalanDOMString& result)
907 {
908  result.assign(theLHS);
909 
910  result.append(theRHS);
911 
912  return result;
913 }
914 
915 
916 
917 inline const XalanDOMString&
919  const XalanDOMString& theLHS,
920  const char* theRHS,
921  XalanDOMString& result)
922 {
923  result.assign(theLHS);
924 
925  result.append(theRHS);
926 
927  return result;
928 }
929 
930 
931 
932 // Standard vector of XalanDOMChars and chars
934 
936 
937 
938 
939 
940 
954  const XalanDOMChar* theSourceString,
955  XalanDOMString::size_type theSourceStringLength,
956  CharVectorType& targetVector,
957  bool terminate = false);
958 
974  const XalanDOMChar* theSourceString,
975  XalanDOMString::size_type theSourceStringLength,
976  CharVectorType& targetVector,
977  bool terminate,
978  char theSubstitutionChar);
979 
988 #if !defined(XALAN_DEVELOPMENT)
989 inline const XalanDOMString
991  const char* theSourceString,
992  XalanDOMString::size_type theSourceStringLength = XalanDOMString::npos)
993 {
994  return XalanDOMString(theSourceString,XalanMemMgrs::getDefaultXercesMemMgr(), theSourceStringLength);
995 }
996 #endif
997 
998 
1011  const XalanDOMChar* theSourceString,
1012  CharVectorType& targetVector,
1013  bool terminate = false);
1014 
1026  const XalanDOMChar* theSourceString,
1027  CharVectorType& targetVector,
1028  bool terminate,
1029  char theSubstitutionChar);
1030 
1039 #if !defined(XALAN_DEVELOPMENT)
1040 inline const CharVectorType
1041 TranscodeToLocalCodePage(const XalanDOMChar* theSourceString)
1042 {
1043  CharVectorType theResult;
1044 
1045  TranscodeToLocalCodePage(theSourceString, theResult, true, '?');
1046 
1047  return theResult;
1048 }
1049 #endif
1050 
1051 
1061 inline bool
1063  const XalanDOMString& theSourceString,
1064  CharVectorType& targetVector,
1065  bool terminate = false)
1066 {
1067  return TranscodeToLocalCodePage(theSourceString.c_str(), targetVector, terminate);
1068 }
1069 
1080 inline void
1082  const XalanDOMString& theSourceString,
1083  CharVectorType& targetVector,
1084  bool terminate ,
1085  char theSubstitutionChar)
1086 {
1087  TranscodeToLocalCodePage(theSourceString.c_str(), targetVector, terminate, theSubstitutionChar);
1088 }
1089 
1098 #if !defined(XALAN_DEVELOPMENT)
1099 inline const CharVectorType
1101 {
1102  CharVectorType theResult;
1103 
1104  TranscodeToLocalCodePage(theSourceString.c_str(), theResult, true, '?');
1105 
1106  return theResult;
1107 }
1108 #endif
1109 
1110 
1119 inline const XalanDOMString&
1121  const char* theSourceString,
1122  XalanDOMString& result,
1123  XalanDOMString::size_type theSourceStringLength = XalanDOMString::npos)
1124 {
1125  result.assign(theSourceString, theSourceStringLength);
1126 
1127  return result;
1128 }
1129 
1130 
1131 
1145  const char* theSourceString,
1146  XalanDOMString::size_type theSourceStringLength,
1147  XalanDOMCharVectorType& theTargetVector,
1148  bool terminate = false);
1149 
1162  const char* theSourceString,
1163  XalanDOMCharVectorType& theTargetVector,
1164  bool terminate = false);
1165 
1174 TranscodeFromLocalCodePage(const CharVectorType& theSourceString,
1175  XalanDOMString& result);
1176 
1177 
1179 
1180 
1181 
1182 XALAN_CPP_NAMESPACE_END
1183 
1184 
1185 
1186 #endif // !defined(XALANDOMSTRING_HEADER_GUARD_1357924680)

Interpreting class diagrams

Doxygen and GraphViz are used to generate this API documentation from the Xalan-C header files.

dot

Xalan-C++ XSLT Processor Version 1.10
Copyright © 1999-2004 The Apache Software Foundation. All Rights Reserved.

Apache Logo