source: icXML/icXML-devel/src/icxercesc/util/XMLString.hpp

Last change on this file was 3564, checked in by cameron, 6 years ago

Changes to icxercesc files

File size: 58.5 KB
Line 
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements.  See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License.  You may obtain a copy of the License at
8 *
9 *      http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18/*
19 * $Id: XMLString.hpp 932887 2010-04-11 13:04:59Z borisk $
20 */
21
22#if !defined(XERCESC_INCLUDE_GUARD_XMLSTRING_HPP)
23#define XERCESC_INCLUDE_GUARD_XMLSTRING_HPP
24
25#include <icxercesc/util/BaseRefVectorOf.hpp>
26#include <xercesc/framework/MemoryManager.hpp>
27#include <xercesc/util/XMLUniDefs.hpp>
28#include <simd-lib/bitblock.hpp>
29#include <icxmlc/clog2.h>
30#include <xercesc/util/ValueVectorOf.hpp>
31#include <string.h>
32#include <assert.h>
33
34XERCES_CPP_NAMESPACE_BEGIN
35
36class XMLBuffer;
37class XMLLCPTranscoder;
38/**
39  * Class for representing native character strings and handling common string
40  * operations
41  *
42  * This class is Unicode compliant. This class is designed primarily
43  * for internal use, but due to popular demand, it is being made
44  * publicly available. Users of this class must understand that this
45  * is not an officially supported class. All public methods of this
46  * class are <i>static functions</i>.
47  *
48  */
49class XMLUTIL_EXPORT XMLString
50{
51public:
52        /* Static methods for native character mode string manipulation */
53
54
55        /** @name String concatenation functions */
56        //@{
57        /** Concatenates two strings.
58          *
59          * <code>catString</code> appends <code>src</code> to <code>target</code> and
60          * terminates the resulting string with a null character. The initial character
61          * of <code>src</code> overwrites the terminating character of <code>target
62          * </code>.
63          *
64          * No overflow checking is performed when strings are copied or appended.
65          * The behavior of <code>catString</code> is undefined if source and
66          * destination strings overlap.
67          *
68          * @param target Null-terminated destination string
69          * @param src Null-terminated source string
70          */
71        static void catString
72        (
73                                char* const     target
74                , const char* const     src
75        );
76
77        /** Concatenates two strings.
78          *
79          * <code>catString</code> appends <code>src</code> to <code>target</code> and
80          * terminates the resulting string with a null character. The initial character of
81          * <code>src</code> overwrites the terminating character of <code>target</code>.
82          * No overflow checking is performed when strings are copied or appended.
83          * The behavior of <code>catString</code> is undefined if source and destination
84          * strings overlap.
85          *
86          * @param target Null-terminated destination string
87          * @param src Null-terminated source string
88          */
89        static void catString
90        (
91                                XMLCh* const    target
92                , const XMLCh* const    src
93        );
94        //@}
95
96        /** @name String comparison functions */
97        //@{
98        /** Lexicographically compares lowercase versions of <code>str1</code> and
99          * <code>str2</code> and returns a value indicating their relationship.
100          * @param str1 Null-terminated string to compare
101          * @param str2 Null-terminated string to compare
102          *
103          * @return The return value indicates the relation of <code>str1</code> to
104          * <code>str2</code> as follows
105          *  Less than 0 means <code>str1</code> is less than <code>str2</code>
106          *  Equal to 0 means <code>str1</code> is identical to <code>str2</code>
107          *  Greater than 0 means <code>str1</code> is more than <code>str2</code>
108          */
109        static int compareIString
110        (
111                const   char* const     str1
112                , const char* const     str2
113        );
114
115        /** Lexicographically compares lowercase versions of <code>str1</code> and
116          * <code>str2</code> and returns a value indicating their relationship.
117          * @param str1 Null-terminated string to compare
118          * @param str2 Null-terminated string to compare
119          * @return The return value indicates the relation of <code>str1</code> to
120          * <code>str2</code> as follows
121          *  Less than 0 means <code>str1</code> is less than <code>str2</code>
122          *  Equal to 0 means <code>str1</code> is identical to <code>str2</code>
123          *  Greater than 0 means <code>str1</code> is more than <code>str2</code>
124          */
125        static int compareIString
126        (
127                const   XMLCh* const    str1
128                , const XMLCh* const    str2
129        );
130
131        /** Lexicographically compares lowercase versions of <code>str1</code> and
132          * <code>str2</code> and returns a value indicating their relationship.
133          * The routine only lowercases A to Z.
134          * @param str1 Null-terminated ASCII string to compare
135          * @param str2 Null-terminated ASCII string to compare
136          * @return The return value indicates the relation of <code>str1</code> to
137          * <code>str2</code> as follows
138          *  Less than 0 means <code>str1</code> is less than <code>str2</code>
139          *  Equal to 0 means <code>str1</code> is identical to <code>str2</code>
140          *  Greater than 0 means <code>str1</code> is more than <code>str2</code>
141          */
142        static int compareIStringASCII
143        (
144                const   XMLCh* const    str1
145                , const XMLCh* const    str2
146        );
147
148
149
150        /** Lexicographically compares, at most, the first count characters in
151          * <code>str1</code> and <code>str2</code> and returns a value indicating the
152          * relationship between the substrings.
153          * @param str1 Null-terminated string to compare
154          * @param str2 Null-terminated string to compare
155          * @param count The number of characters to compare
156          *
157          * @return The return value indicates the relation of <code>str1</code> to
158          * <code>str2</code> as follows
159          *  Less than 0 means <code>str1</code> is less than <code>str2</code>
160          *  Equal to 0 means <code>str1</code> is identical to <code>str2</code>
161          *  Greater than 0 means <code>str1</code> is more than <code>str2</code>
162          */
163        static int compareNString
164        (
165                const   char* const     str1
166                , const char* const     str2
167                , const XMLSize_t       count
168        );
169
170        /** Lexicographically compares, at most, the first count characters in
171          * <code>str1</code> and <code>str2</code> and returns a value indicating
172          * the relationship between the substrings.
173          * @param str1 Null-terminated string to compare
174          * @param str2 Null-terminated string to compare
175          * @param count The number of characters to compare
176          *
177          * @return The return value indicates the relation of <code>str1</code> to
178          * <code>str2</code> as follows
179          *  Less than 0 means <code>str1</code> is less than <code>str2</code>
180          *  Equal to 0 means <code>str1</code> is identical to <code>str2</code>
181          *  Greater than 0 means <code>str1</code> is more than <code>str2</code>
182          */
183        static int compareNString
184        (
185                const   XMLCh* const    str1
186                , const XMLCh* const    str2
187                , const XMLSize_t       count
188        );
189
190
191        /** Lexicographically compares, at most, the first count characters in
192          * <code>str1</code> and <code>str2</code> without regard to case and
193          * returns a value indicating the relationship between the substrings.
194          *
195          * @param str1 Null-terminated string to compare
196          * @param str2 Null-terminated string to compare
197          * @param count The number of characters to compare
198          * @return The return value indicates the relation of <code>str1</code> to
199          * <code>str2</code> as follows
200          *  Less than 0 means <code>str1</code> is less than <code>str2</code>
201          *  Equal to 0 means <code>str1</code> is identical to <code>str2</code>
202          *  Greater than 0 means <code>str1</code> is more than <code>str2</code>
203          */
204        static int compareNIString
205        (
206                const   char* const     str1
207                , const char* const     str2
208                , const XMLSize_t       count
209        );
210
211        /** Lexicographically compares, at most, the first count characters in
212          * <code>str1</code> and <code>str2</code> without regard to case and
213          * returns a value indicating the relationship between the substrings.
214          *
215          * @param str1 Null-terminated string to compare
216          * @param str2 Null-terminated string to compare
217          * @param count The number of characters to compare
218          *
219          * @return The return value indicates the relation of <code>str1</code> to
220          * <code>str2</code> as follows
221          *  Less than 0 means <code>str1</code> is less than <code>str2</code>
222          *  Equal to 0 means <code>str1</code> is identical to <code>str2</code>
223          *  Greater than 0 means <code>str1</code> is more than <code>str2</code>
224          */
225        static int compareNIString
226        (
227                const   XMLCh* const    str1
228                , const XMLCh* const    str2
229                , const XMLSize_t       count
230        );
231
232        /** Lexicographically compares <code>str1</code> and <code>str2</code> and
233          * returns a value indicating their relationship.
234          *
235          * @param str1 Null-terminated string to compare
236          * @param str2 Null-terminated string to compare
237          *
238          * @return The return value indicates the relation of <code>str1</code> to
239          * <code>str2</code> as follows
240          *  Less than 0 means <code>str1</code> is less than <code>str2</code>
241          *  Equal to 0 means <code>str1</code> is identical to <code>str2</code>
242          *  Greater than 0 means <code>str1</code> is more than <code>str2</code>
243          */
244        static int compareString
245        (
246                const   char* const     str1
247                , const char* const     str2
248        );
249
250        /** Lexicographically compares <code>str1</code> and <code>str2</code> and
251          * returns a value indicating their relationship.
252          *
253          * @param str1 Null-terminated string to compare
254          * @param str2 Null-terminated string to compare
255          * @return The return value indicates the relation of <code>str1</code> to
256          * <code>str2</code> as follows
257          *  Less than 0 means <code>str1</code> is less than <code>str2</code>
258          *  Equal to 0 means <code>str1</code> is identical to <code>str2</code>
259          *  Greater than 0 means <code>str1</code> is more than <code>str2</code>
260          */
261        static int compareString
262        (
263                const   XMLCh* const    str1
264                , const XMLCh* const    str2
265        );
266
267        /** compares <code>str1</code> and <code>str2</code>
268          *
269          * @param str1 Null-terminated string to compare
270          * @param str2 Null-terminated string to compare
271          * @return true if two strings are equal, false if not
272          *  If one string is null, while the other is zero-length string,
273          *  it is considered as equal.
274          */
275        static bool equals
276        (
277                  const XMLCh* str1
278                , const XMLCh* str2
279        );
280
281        /** compares <code>str1</code> and <code>str2</code>
282          *
283          * @param str1 string to compare
284          * @param str2 string to compare
285          * @param n number of characters to compare
286          * @return true if two strings are equal, false if not
287          *  If one string is null, while the other is zero-length string,
288          *  it is considered as equal.
289          */
290        static bool equalsN
291        (
292                  const XMLCh* str1
293                , const XMLCh* str2
294                , XMLSize_t n
295        );
296
297        template<typename Char>
298        static bool equalsU
299        (
300                  const Char * const str1
301                , const Char * const str2
302                , const XMLSize_t n
303        );
304
305        static bool equals
306        (
307                  const char* str1
308                , const char* str2
309        );
310
311        /** compares <code>str1</code> and <code>str2</code>
312          *
313          * @param str1 string to compare
314          * @param str2 string to compare
315          * @param n number of characters to compare
316          * @return true if two strings are equal, false if not
317          *  If one string is null, while the other is zero-length string,
318          *  it is considered as equal.
319          */
320        static bool equalsN
321        (
322                  const char* str1
323                , const char* str2
324                , XMLSize_t n
325        );
326
327        /** Lexicographically compares <code>str1</code> and <code>str2</code>
328                  * regions and returns true if they are equal, otherwise false.
329                  *
330          * A substring of <code>str1</code> is compared to a substring of
331                  * <code>str2</code>. The result is true if these substrings represent
332                  * identical character sequences. The substring of <code>str1</code>
333          * to be compared begins at offset1 and has length charCount. The
334                  * substring of <code>str2</code> to be compared begins at offset2 and
335                  * has length charCount. The result is false if and only if at least
336          * one of the following is true:
337          *   offset1 is negative.
338          *   offset2 is negative.
339          *   offset1+charCount is greater than the length of str1.
340          *   offset2+charCount is greater than the length of str2.
341          *   There is some nonnegative integer k less than charCount such that:
342          *   str1.charAt(offset1+k) != str2.charAt(offset2+k)
343          *
344          * @param str1 Null-terminated string to compare
345                  * @param offset1 Starting offset of str1
346          * @param str2 Null-terminated string to compare
347                  * @param offset2 Starting offset of str2
348                  * @param charCount The number of characters to compare
349          * @return true if the specified subregion of <code>str1</code> exactly
350                  *  matches the specified subregion of <code>str2></code>; false
351                  *  otherwise.
352          */
353        static bool regionMatches
354        (
355                const   XMLCh* const    str1
356                                , const int                             offset1
357                , const XMLCh* const    str2
358                                , const int                             offset2
359                                , const XMLSize_t       charCount
360        );
361
362                /** Lexicographically compares <code>str1</code> and <code>str2</code>
363                  * regions without regard to case and returns true if they are equal,
364                  * otherwise false.
365                  *
366          * A substring of <code>str1</code> is compared to a substring of
367                  * <code>str2</code>. The result is true if these substrings represent
368                  * identical character sequences. The substring of <code>str1</code>
369          * to be compared begins at offset1 and has length charCount. The
370                  * substring of <code>str2</code> to be compared begins at offset2 and
371                  * has length charCount. The result is false if and only if at least
372          * one of the following is true:
373          *   offset1 is negative.
374          *   offset2 is negative.
375          *   offset1+charCount is greater than the length of str1.
376          *   offset2+charCount is greater than the length of str2.
377          *   There is some nonnegative integer k less than charCount such that:
378          *   str1.charAt(offset1+k) != str2.charAt(offset2+k)
379          *
380          * @param str1 Null-terminated string to compare
381                  * @param offset1 Starting offset of str1
382          * @param str2 Null-terminated string to compare
383                  * @param offset2 Starting offset of str2
384                  * @param charCount The number of characters to compare
385          * @return true if the specified subregion of <code>str1</code> exactly
386                  *  matches the specified subregion of <code>str2></code>; false
387                  *  otherwise.
388          */
389        static bool regionIMatches
390        (
391                const   XMLCh* const    str1
392                                , const int                             offset1
393                , const XMLCh* const    str2
394                                , const int                             offset2
395                                , const XMLSize_t       charCount
396        );
397        //@}
398
399        /** @name String copy functions */
400        //@{
401        /** Copies <code>src</code>, including the terminating null character, to the
402          * location specified by <code>target</code>.
403          *
404          * No overflow checking is performed when strings are copied or appended.
405          * The behavior of strcpy is undefined if the source and destination strings
406          * overlap.
407          *
408          * @param target Destination string
409          * @param src Null-terminated source string
410          */
411        static void copyString
412        (
413                                char* const     target
414                , const char* const     src
415        );
416
417        /** Copies <code>src</code>, including the terminating null character, to
418          *   the location specified by <code>target</code>.
419          *
420          * No overflow checking is performed when strings are copied or appended.
421          * The behavior of <code>copyString</code> is undefined if the source and
422          * destination strings overlap.
423          *
424          * @param target Destination string
425          * @param src Null-terminated source string
426          */
427        static void copyString
428        (
429                                XMLCh* const    target
430                , const XMLCh* const    src
431        );
432
433        /** Copies <code>src</code>, upto a fixed number of characters, to the
434          * location specified by <code>target</code>.
435          *
436          * No overflow checking is performed when strings are copied or appended.
437          * The behavior of <code>copyNString</code> is undefined if the source and
438          * destination strings overlap.
439          *
440          * @param target Destination string. The size of the buffer should
441          *        atleast be 'maxChars + 1'.
442          * @param src Null-terminated source string
443          * @param maxChars The maximum number of characters to copy
444          */
445        static bool copyNString
446        (
447                                XMLCh* const   target
448                , const XMLCh* const   src
449                , const XMLSize_t      maxChars
450        );
451        //@}
452
453        /** @name Hash functions */
454        //@{
455        /** Hashes a string given a modulus
456          *
457          * @param toHash The string to hash
458          * @param hashModulus The divisor to be used for hashing
459          * @return Returns the hash value
460          */
461        static XMLSize_t hash
462        (
463                const   char* const     toHash
464                , const XMLSize_t       hashModulus
465        );
466
467        /** Hashes a string given a modulus
468          *
469          * @param toHash The string to hash
470          * @param hashModulus The divisor to be used for hashing
471          * @return Returns the hash value
472          */
473        static XMLSize_t hash
474        (
475                const   XMLCh* const    toHash
476                , const XMLSize_t       hashModulus
477        );
478
479        /** Hashes a string given a modulus taking a maximum number of characters
480          * as the limit
481          *
482          * @param toHash The string to hash
483          * @param numChars The maximum number of characters to consider for hashing
484          * @param hashModulus The divisor to be used for hashing
485          * @return Returns the hash value
486          */
487        static XMLSize_t hashN
488        (
489                const   XMLCh* const    toHash
490                , const XMLSize_t       numChars
491                , const XMLSize_t       hashModulus
492        );
493
494        //@}
495
496        /** @name Search functions */
497        //@{
498        /**
499          * Provides the index of the first occurrence of a character within a string
500          *
501          * @param toSearch The string to search
502          * @param ch The character to search within the string
503          * @return If found, returns the index of the character within the string,
504          * else returns -1.
505          */
506        static int indexOf(const char* const toSearch, const char ch);
507
508        /**
509          * Provides the index of the first occurrence of a character within a string
510          *
511          * @param toSearch The string to search
512          * @param ch The character to search within the string
513          * @return If found, returns the index of the character within the string,
514          * else returns -1.
515          */
516        static int indexOf(const XMLCh* const toSearch, const XMLCh ch);
517
518                        /**
519          * Provides the index of the first occurrence of a character within a string
520          * starting from a given index
521          *
522          * @param toSearch The string to search
523          * @param chToFind The character to search within the string
524          * @param fromIndex The index to start searching from
525          * @param manager The MemoryManager to use to allocate objects
526          * @return If found, returns the index of the character within the string,
527          * else returns -1.
528          */
529        static int indexOf
530        (
531                const   char* const     toSearch
532                , const char            chToFind
533                , const XMLSize_t       fromIndex
534                , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
535        );
536
537        /**
538          * Provides the index of the first occurrence of a character within a string
539          * starting from a given index
540          *
541          * @param toSearch The string to search
542          * @param chToFind The character to search within the string
543          * @param fromIndex The index to start searching from
544          * @param manager The MemoryManager to use to allocate objects
545          * @return If found, returns the index of the character within the string,
546          * else returns -1.
547          */
548        static int indexOf
549        (
550                const   XMLCh* const    toSearch
551                , const XMLCh           chToFind
552                , const XMLSize_t       fromIndex
553                , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
554        );
555
556        template<typename Char, Char character>
557        static int indexOfUC
558        (
559                const   Char * const    string
560                , const XMLSize_t       length
561        );
562
563        /**
564          * Provides the index of the last occurrence of a character within a string
565          *
566          * @param toSearch The string to search
567          * @param ch The character to search within the string
568          * @return If found, returns the index of the character within the string,
569          * else returns -1.
570          */
571        static int lastIndexOf(const char* const toSearch, const char ch);
572
573        /**
574          * Provides the index of the last occurrence of a character within a string
575          *
576          * @param toSearch The string to search
577          * @param ch The character to search within the string
578          * @return If found, returns the index of the character within the string,
579          * else returns -1.
580          */
581        static int lastIndexOf(const XMLCh* const toSearch, const XMLCh ch);
582
583        /**
584          * Provides the index of the last occurrence of a character within a string
585          *
586          * @param ch The character to search within the string
587          * @param toSearch The string to search
588          * @param toSearchLen The length of the string to search
589          * @return If found, returns the index of the character within the string,
590          * else returns -1.
591          */
592        static int lastIndexOf
593        (
594                const XMLCh ch
595                , const XMLCh* const toSearch
596                , const XMLSize_t    toSearchLen
597        );
598
599        /**
600          * Provides the index of the last occurrence of a character within a string
601          * starting backward from a given index
602          *
603          * @param toSearch The string to search
604          * @param chToFind The character to search within the string
605          * @param fromIndex The index to start backward search from
606          * @param manager The MemoryManager to use to allocate objects
607          * @return If found, returns the index of the character within the string,
608          * else returns -1.
609          */
610        static int lastIndexOf
611        (
612                const   char* const     toSearch
613                , const char            chToFind
614                , const XMLSize_t       fromIndex
615                , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
616        );
617
618        /**
619          * Provides the index of the last occurrence of a character within a string
620          * starting backward from a given index
621          *
622          * @param toSearch The string to search
623          * @param ch       The character to search within the string
624          * @param fromIndex The index to start backward search from
625          * @param manager The MemoryManager to use to allocate objects
626          * @return If found, returns the index of the character within the string,
627          * else returns -1.
628          */
629        static int lastIndexOf
630        (
631                const   XMLCh* const    toSearch
632                , const XMLCh           ch
633                , const XMLSize_t       fromIndex
634                , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
635        );
636        //@}
637
638        /** @name Fixed size string movement */
639        //@{
640        /** Moves X number of chars
641          * @param targetStr The string to copy the chars to
642          * @param srcStr The string to copy the chars from
643          * @param count The number of chars to move
644          */
645        static void moveChars
646        (
647                                XMLCh* const    targetStr
648                , const XMLCh* const    srcStr
649                , const XMLSize_t       count
650        );
651
652        /** @name Fixed size string movement */
653        //@{
654        /** Moves X number of chars
655          * @param targetStr The string to copy the chars to
656          * @param srcStr The string to copy the chars from
657          * @param count The number of chars to move
658          */
659        static void moveChars
660        (
661                                XMLByte* const    targetStr
662                , const XMLByte* const    srcStr
663                , const XMLSize_t       count
664        );
665
666        //@}
667
668        /** @name Substring function */
669        //@{
670        /** Create a substring of a given string. The substring begins at the
671          * specified beginIndex and extends to the character at index
672          * endIndex - 1.
673          * @param targetStr The string to copy the chars to
674          * @param srcStr The string to copy the chars from
675          * @param startIndex beginning index, inclusive.
676          * @param endIndex the ending index, exclusive.
677          * @param manager The MemoryManager to use to allocate objects
678          */
679        static void subString
680        (
681                                char* const    targetStr
682                , const char* const    srcStr
683                , const XMLSize_t      startIndex
684                , const XMLSize_t      endIndex
685                , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
686        );
687
688        /** Create a substring of a given string. The substring begins at the
689          * specified beginIndex and extends to the character at index
690          * endIndex - 1.
691          * @param targetStr The string to copy the chars to
692          * @param srcStr The string to copy the chars from
693          * @param startIndex beginning index, inclusive.
694          * @param endIndex the ending index, exclusive.
695          * @param manager The MemoryManager to use to allocate objects
696          */
697        static void subString
698        (
699                                XMLCh* const    targetStr
700                , const XMLCh* const    srcStr
701                , const XMLSize_t       startIndex
702                , const XMLSize_t       endIndex
703                , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
704        );
705
706        /** Create a substring of a given string. The substring begins at the
707          * specified beginIndex and extends to the character at index
708          * endIndex - 1.
709          * @param targetStr The string to copy the chars to
710          * @param srcStr The string to copy the chars from
711          * @param startIndex beginning index, inclusive.
712          * @param endIndex the ending index, exclusive.
713          * @param srcStrLength the length of srcStr
714          * @param manager The MemoryManager to use to allocate objects
715          */
716        static void subString
717        (
718                                XMLCh* const    targetStr
719                , const XMLCh* const    srcStr
720                , const XMLSize_t       startIndex
721                , const XMLSize_t       endIndex
722                , const XMLSize_t       srcStrLength
723                , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
724        );
725
726        //@}
727
728        /** @name Replication function */
729        //@{
730        /** Replicates a string
731          * NOTE: The returned buffer is allocated with the MemoryManager. It is the
732          * responsibility of the caller to delete it when not longer needed.
733          * You can call XMLString::release to release this returned buffer.
734          *
735          * @param toRep The string to replicate
736          * @param manager The MemoryManager to use to allocate the string
737          * @return Returns a pointer to the replicated string
738          * @see   XMLString::release(char**, MemoryManager*)
739          */
740        static char* replicate(const char* const toRep,
741                                                   MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
742
743        /** Replicates a string
744          * NOTE: The returned buffer is allocated with the MemoryManager. It is the
745          * responsibility of the caller to delete it when not longer needed.
746          * You can call XMLString::release to release this returned buffer.
747          *
748          * @param toRep The string to replicate
749          * @param manager The MemoryManager to use to allocate the string
750          * @return Returns a pointer to the replicated string
751          * @see   XMLString::release(XMLCh**, MemoryManager*)
752          */
753        static XMLCh* replicate(const XMLCh* const toRep,
754                                                        MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
755
756        static XMLCh* replicate(const XMLCh* const   toRep,
757                                                        const XMLSize_t      len,
758                                                        MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
759
760
761        //@}
762
763        /** @name String query function */
764        //@{
765        /** Tells if the sub-string appears within a string at the beginning
766          * @param toTest The string to test
767          * @param prefix The sub-string that needs to be checked
768          * @return Returns true if the sub-string was found at the beginning of
769          * <code>toTest</code>, else false
770          */
771        static bool startsWith
772        (
773                const   char* const     toTest
774                , const char* const     prefix
775        );
776
777        /** Tells if the sub-string appears within a string at the beginning
778          * @param toTest The string to test
779          * @param prefix The sub-string that needs to be checked
780          * @return Returns true if the sub-string was found at the beginning of
781          * <code>toTest</code>, else false
782          */
783        static bool startsWith
784        (
785                const   XMLCh* const    toTest
786                , const XMLCh* const    prefix
787        );
788
789        /** Tells if the sub-string appears within a string at the beginning
790          * without regard to case
791          *
792          * @param toTest The string to test
793          * @param prefix The sub-string that needs to be checked
794          * @return Returns true if the sub-string was found at the beginning of
795          * <code>toTest</code>, else false
796          */
797        static bool startsWithI
798        (
799                const   char* const     toTest
800                , const char* const     prefix
801        );
802
803        /** Tells if the sub-string appears within a string at the beginning
804          * without regard to case
805          *
806          * @param toTest The string to test
807          * @param prefix The sub-string that needs to be checked
808          *
809          * @return Returns true if the sub-string was found at the beginning
810          * of <code>toTest</code>, else false
811          */
812        static bool startsWithI
813        (
814                const   XMLCh* const    toTest
815                , const XMLCh* const    prefix
816        );
817
818        /** Tells if the sub-string appears within a string at the end.
819          * @param toTest The string to test
820          * @param suffix The sub-string that needs to be checked
821          * @return Returns true if the sub-string was found at the end of
822          * <code>toTest</code>, else false
823          */
824        static bool endsWith
825        (
826                const   XMLCh* const    toTest
827                , const XMLCh* const    suffix
828        );
829
830
831        /** Tells if a string has any occurrence of any character of another
832          * string within itself
833          * @param toSearch The string to be searched
834          * @param searchList The string from which characters to be searched for are drawn
835          * @return Returns the pointer to the location where the first occurrence of any
836          * character from searchList is found,
837          * else returns 0
838          */
839        static const XMLCh* findAny
840        (
841                const   XMLCh* const    toSearch
842                , const XMLCh* const    searchList
843        );
844
845        /** Tells if a string has any occurrence of any character of another
846          * string within itself
847          * @param toSearch The string to be searched
848          * @param searchList The string from which characters to be searched for are drawn
849          * @return Returns the pointer to the location where the first occurrence of any
850          * character from searchList is found,
851          * else returns 0
852          */
853        static XMLCh* findAny
854        (
855                                XMLCh* const    toSearch
856                , const XMLCh* const    searchList
857        );
858
859        /** Tells if a string has pattern within itself
860          * @param toSearch The string to be searched
861          * @param pattern The pattern to be located within the string
862          * @return Returns index to the location where the pattern was
863          * found, else returns -1
864          */
865        static int patternMatch
866        (
867                  const XMLCh* const    toSearch
868                , const XMLCh* const    pattern
869        );
870
871        /** Get the length of the string
872          * @param src The string whose length is to be determined
873          * @return Returns the length of the string
874          */
875        static XMLSize_t stringLen(const char* const src);
876
877        /** Get the length of the string
878          * @param src The string whose length is to be determined
879          * @return Returns the length of the string
880          */
881        static XMLSize_t stringLen(const XMLCh* const src);
882
883
884        /** Does the following string contain all spaces?
885          * @param src The string whose length is to be determined
886          * @return Returns whether this string contains only chSpace's
887          */
888        static bool isAllSpaces( const XMLCh*    const toCheck
889                                                   , const XMLSize_t       count);
890
891        /**
892          *
893          * Checks whether an name is a valid NOTATION according to XML 1.0
894          * @param name    The string to check its NOTATION validity
895          * @param manager The memory manager
896          * @return Returns true if name is NOTATION valid, otherwise false
897          */
898        static bool isValidNOTATION(const XMLCh*         const name
899                                                          ,       MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
900
901        /**
902          * Checks whether an name is a valid EncName.
903          * @param name The string to check its EncName validity
904          * @return Returns true if name is EncName valid, otherwise false
905          */
906        static bool isValidEncName(const XMLCh* const name);
907
908        /**
909          * Checks whether a character is within [a-zA-Z].
910          * @param theChar the character to check
911          * @return Returns true if within the range, otherwise false
912          */
913
914        static bool isAlpha(XMLCh const theChar);
915
916        /**
917          * Checks whether a character is within [0-9].
918          * @param theChar the character to check
919          * @return Returns true if within the range, otherwise false
920          */
921        static bool isDigit(XMLCh const theChar);
922
923        /**
924          * Checks whether a character is within [0-9a-zA-Z].
925          * @param theChar the character to check
926          * @return Returns true if within the range, otherwise false
927          */
928        static bool isAlphaNum(XMLCh const theChar);
929
930        /**
931          * Checks whether a character is within [0-9a-fA-F].
932          * @param theChar the character to check
933          * @return Returns true if within the range, otherwise false
934          */
935        static bool isHex(XMLCh const theChar);
936
937        /** Find is the string appears in the enum list
938          * @param toFind the string to be found
939          * @param enumList the list
940          * return true if found
941          */
942        static bool isInList(const XMLCh* const toFind, const XMLCh* const enumList);
943
944        //@}
945
946        /** @name Conversion functions */
947        //@{
948
949          /** Converts size to a text string based a given radix
950          *
951          * @param toFormat The size to convert
952          * @param toFill The buffer that will hold the output on return. The
953          *        size of this buffer should at least be 'maxChars + 1'.
954          * @param maxChars The maximum number of output characters that can be
955          *         accepted. If the result will not fit, it is an error.
956          * @param radix The radix of the input data, based on which the conversion
957          * @param manager The MemoryManager to use to allocate objects
958          * will be done
959          */
960        static void sizeToText
961        (
962                const   XMLSize_t           toFormat
963                ,       char* const         toFill
964                , const XMLSize_t           maxChars
965                , const unsigned int        radix
966                , MemoryManager* const      manager = XMLPlatformUtils::fgMemoryManager
967        );
968
969        /** Converts size to a text string based a given radix
970          *
971          * @param toFormat The size to convert
972          * @param toFill The buffer that will hold the output on return. The
973          *        size of this buffer should at least be 'maxChars + 1'.
974          * @param maxChars The maximum number of output characters that can be
975          *         accepted. If the result will not fit, it is an error.
976          * @param radix The radix of the input data, based on which the conversion
977          * @param manager The MemoryManager to use to allocate objects
978          * will be done
979          */
980        static void sizeToText
981        (
982                const   XMLSize_t           toFormat
983                ,       XMLCh* const        toFill
984                , const XMLSize_t           maxChars
985                , const unsigned int        radix
986                , MemoryManager* const      manager = XMLPlatformUtils::fgMemoryManager
987        );
988
989        /** Converts binary data to a text string based a given radix
990          *
991          * @param toFormat The number to convert
992          * @param toFill The buffer that will hold the output on return. The
993          *        size of this buffer should at least be 'maxChars + 1'.
994          * @param maxChars The maximum number of output characters that can be
995          *         accepted. If the result will not fit, it is an error.
996          * @param radix The radix of the input data, based on which the conversion
997          * @param manager The MemoryManager to use to allocate objects
998          * will be done
999          */
1000        static void binToText
1001        (
1002                const   unsigned int    toFormat
1003                ,       char* const     toFill
1004                , const XMLSize_t       maxChars
1005                , const unsigned int    radix
1006                , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
1007        );
1008
1009        /** Converts binary data to a text string based a given radix
1010          *
1011          * @param toFormat The number to convert
1012          * @param toFill The buffer that will hold the output on return. The
1013          *        size of this buffer should at least be 'maxChars + 1'.
1014          * @param maxChars The maximum number of output characters that can be
1015          *         accepted. If the result will not fit, it is an error.
1016          * @param radix The radix of the input data, based on which the conversion
1017          * @param manager The MemoryManager to use to allocate objects
1018          * will be done
1019          */
1020        static void binToText
1021        (
1022                const   unsigned int    toFormat
1023                ,       XMLCh* const    toFill
1024                , const XMLSize_t       maxChars
1025                , const unsigned int    radix
1026                , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
1027        );
1028
1029        /** Converts binary data to a text string based a given radix
1030          *
1031          * @param toFormat The number to convert
1032          * @param toFill The buffer that will hold the output on return. The
1033          *        size of this buffer should at least be 'maxChars + 1'.
1034          * @param maxChars The maximum number of output characters that can be
1035          *         accepted. If the result will not fit, it is an error.
1036          * @param radix The radix of the input data, based on which the conversion
1037          * @param manager The MemoryManager to use to allocate objects
1038          * will be done
1039          */
1040        static void binToText
1041        (
1042                const   unsigned long   toFormat
1043                ,       char* const     toFill
1044                , const XMLSize_t       maxChars
1045                , const unsigned int    radix
1046                , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
1047        );
1048
1049        /** Converts binary data to a text string based a given radix
1050          *
1051          * @param toFormat The number to convert
1052          * @param toFill The buffer that will hold the output on return. The
1053          *        size of this buffer should at least be 'maxChars + 1'.
1054          * @param maxChars The maximum number of output characters that can be
1055          *         accepted. If the result will not fit, it is an error.
1056          * @param radix The radix of the input data, based on which the conversion
1057          * @param manager The MemoryManager to use to allocate objects
1058          * will be done
1059          */
1060        static void binToText
1061        (
1062                const   unsigned long   toFormat
1063                ,       XMLCh* const    toFill
1064                , const XMLSize_t       maxChars
1065                , const unsigned int    radix
1066                , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
1067        );
1068
1069        /** Converts binary data to a text string based a given radix
1070          *
1071          * @param toFormat The number to convert
1072          * @param toFill The buffer that will hold the output on return. The
1073          *        size of this buffer should at least be 'maxChars + 1'.
1074          * @param maxChars The maximum number of output characters that can be
1075          *         accepted. If the result will not fit, it is an error.
1076          * @param radix The radix of the input data, based on which the conversion
1077          * @param manager The MemoryManager to use to allocate objects
1078          * will be done
1079          */
1080        static void binToText
1081        (
1082                const   int             toFormat
1083                ,       char* const     toFill
1084                , const XMLSize_t       maxChars
1085                , const unsigned int    radix
1086                , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
1087        );
1088
1089        /** Converts binary data to a text string based a given radix
1090          *
1091          * @param toFormat The number to convert
1092          * @param toFill The buffer that will hold the output on return. The
1093          *        size of this buffer should at least be 'maxChars + 1'.
1094          * @param maxChars The maximum number of output characters that can be
1095          *         accepted. If the result will not fit, it is an error.
1096          * @param radix The radix of the input data, based on which the conversion
1097          * @param manager The MemoryManager to use to allocate objects
1098          * will be done
1099          */
1100        static void binToText
1101        (
1102                const   int             toFormat
1103                ,       XMLCh* const    toFill
1104                , const XMLSize_t       maxChars
1105                , const unsigned int    radix
1106                , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
1107        );
1108
1109        /** Converts binary data to a text string based a given radix
1110          *
1111          * @param toFormat The number to convert
1112          * @param toFill The buffer that will hold the output on return. The
1113          *        size of this buffer should at least be 'maxChars + 1'.
1114          * @param maxChars The maximum number of output characters that can be
1115          *         accepted. If the result will not fit, it is an error.
1116          * @param radix The radix of the input data, based on which the conversion
1117          * @param manager The MemoryManager to use to allocate objects
1118          * will be done
1119          */
1120        static void binToText
1121        (
1122                const   long            toFormat
1123                ,       char* const     toFill
1124                , const XMLSize_t       maxChars
1125                , const unsigned int    radix
1126                , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
1127        );
1128
1129        /** Converts binary data to a text string based a given radix
1130          *
1131          * @param toFormat The number to convert
1132          * @param toFill The buffer that will hold the output on return. The
1133          *        size of this buffer should at least be 'maxChars + 1'.
1134          * @param maxChars The maximum number of output characters that can be
1135          *         accepted. If the result will not fit, it is an error.
1136          * @param radix The radix of the input data, based on which the conversion
1137          * @param manager The MemoryManager to use to allocate objects
1138          * will be done
1139          */
1140        static void binToText
1141        (
1142                const   long            toFormat
1143                ,       XMLCh* const    toFill
1144                , const XMLSize_t       maxChars
1145                , const unsigned int    radix
1146                , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
1147        );
1148
1149        /**
1150          * Converts a string of decimal chars to a binary value
1151          *
1152          * Note that leading and trailing whitespace is legal and will be ignored
1153          * but the remainder must be all decimal digits.
1154          *
1155          * @param toConvert The string of digits to convert
1156          * @param toFill    The unsigned int value to fill with the converted
1157          *                  value.
1158          * @param manager The MemoryManager to use to allocate objects
1159          */
1160        static bool textToBin
1161        (
1162                const   XMLCh* const    toConvert
1163                ,       unsigned int&   toFill
1164                ,       MemoryManager*  const manager = XMLPlatformUtils::fgMemoryManager
1165        );
1166
1167        /**
1168          * Converts a string of decimal chars to a binary value
1169          *
1170          * Note that leading and trailing whitespace is legal and will be ignored,
1171          *
1172          * Only one and either of (+,-) after the leading whitespace, before
1173          * any other characters are allowed.
1174          *
1175          * but the remainder must be all decimal digits.
1176          *
1177          * @param toConvert The string of digits to convert
1178          * @param manager The MemoryManager to use to allocate objects
1179          */
1180        static int parseInt
1181        (
1182                const   XMLCh* const    toConvert
1183          , MemoryManager* const    manager = XMLPlatformUtils::fgMemoryManager
1184        );
1185
1186        /** Cut leading chars from a string
1187          *
1188          * @param toCutFrom The string to cut chars from
1189          * @param count     The count of leading chars to cut
1190          */
1191        static void cut
1192        (
1193                                XMLCh* const    toCutFrom
1194                , const XMLSize_t       count
1195        );
1196
1197        /** Transcodes a string to native code-page
1198          *
1199          * NOTE: The returned buffer is dynamically allocated and is the
1200          * responsibility of the caller to delete it when not longer needed.
1201          * You can call XMLString::release to release this returned buffer.
1202          *
1203          * @param toTranscode The string to be transcoded
1204          * @param manager The MemoryManager to use to allocate objects
1205          * @return Returns the transcoded string
1206          * @see   XMLString::release(XMLCh**, MemoryManager*)
1207          */
1208        static char* transcode
1209        (
1210                const   XMLCh* const         toTranscode
1211                ,       MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
1212        );
1213
1214        /** Transcodes a string to native code-page (DEPRECATED)
1215          *
1216          * Be aware that when transcoding to an external encoding, that each
1217          * Unicode char can create multiple output bytes. So you cannot assume
1218          * a one to one correspondence of input chars to output bytes.
1219          *
1220          * @param toTranscode The string tobe transcoded
1221          * @param toFill The buffer that is filled with the transcoded value.
1222          *        The size of this buffer should atleast be 'maxChars + 1'.
1223          * @param maxChars The maximum number of bytes that the output
1224          *         buffer can hold (not including the null, which is why
1225          *         toFill should be at least maxChars+1.).
1226          * @param manager The MemoryManager to use to allocate objects
1227          * @return Returns true if successful, false if there was an error
1228          */
1229        static bool transcode
1230        (
1231                const   XMLCh* const    toTranscode
1232                ,       char* const     toFill
1233                , const XMLSize_t       maxChars
1234                , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
1235        );
1236
1237        /** Transcodes a string to native code-page
1238          *
1239          * NOTE: The returned buffer is dynamically allocated and is the
1240          * responsibility of the caller to delete it when not longer needed.
1241          * You can call XMLString::release to release this returned buffer.
1242          *
1243          * @param toTranscode The string to be transcoded
1244          * @param manager The MemoryManager to use to allocate objects
1245          * @return Returns the transcoded string
1246          * @see   XMLString::release(char**, MemoryManager*)
1247          */
1248        static XMLCh* transcode
1249        (
1250                const   char* const          toTranscode
1251                ,       MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
1252        );
1253
1254        /** Transcodes a string to native code-page (DEPRECATED)
1255          * @param toTranscode The string tobe transcoded
1256          * @param toFill The buffer that is filled with the transcoded value.
1257          *        The size of this buffer should atleast be 'maxChars + 1'.
1258          * @param maxChars The maximum number of characters that the output
1259          *         buffer can hold (not including the null, which is why
1260          *         toFill should be at least maxChars+1.).
1261          * @param manager The MemoryManager to use to allocate objects
1262          * @return Returns true if successful, false if there was an error
1263          */
1264        static bool transcode
1265        (
1266                const   char* const     toTranscode
1267                ,       XMLCh* const    toFill
1268                , const XMLSize_t       maxChars
1269                , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
1270        );
1271
1272        /** Trims off extra space characters from the start and end of the string,
1273          * moving the non-space string content back to the start.
1274          * @param toTrim The string to be trimmed. On return this contains the
1275          * trimmed string
1276          */
1277        static void trim(char* const toTrim);
1278
1279        /** Trims off extra space characters from the start and end of the string,
1280          * moving the non-space string content back to the start.
1281          * @param toTrim The string to be trimmed. On return this contains
1282          * the trimmed string
1283          */
1284        static void trim(XMLCh* const toTrim);
1285
1286        /** Break a string into tokens with space as delimiter, and
1287          * stored in a string vector.  The caller owns the string vector
1288          * that is returned, and is responsible for deleting it.
1289          * @param tokenizeSrc String to be tokenized
1290          * @param manager The MemoryManager to use to allocate objects
1291          * @return a vector of all the tokenized string
1292          */
1293    static BaseRefVectorOf<XMLCh>* tokenizeString(const XMLCh* const tokenizeSrc, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
1294
1295    /** Break a string into tokens with the given character as delimiter, and
1296    * stored in a string vector.  The caller owns the string vector
1297    * that is returned, and is responsible for deleting it.
1298    * @param tokenizeSrc String to be tokenized
1299    * @param delimiter Delimiter character
1300    * @param manager The MemoryManager to use to allocate objects
1301    * @return a vector of all the tokenized string
1302    */
1303    static BaseRefVectorOf<XMLCh>* tokenizeString(const XMLCh* const tokenizeSrc, XMLCh delimiter, MemoryManager * const manager = XMLPlatformUtils::fgMemoryManager);
1304
1305        //@}
1306
1307        /** @name Formatting functions */
1308        //@{
1309        /** Creates a UName from a URI and base name. It is in the form
1310          * {url}name, and is commonly used internally to represent fully
1311          * qualified names when namespaces are enabled.
1312          *
1313          * @param pszURI The URI part of the name
1314          * @param pszName The base part of the name
1315          * @return Returns the complete formatted UName
1316          */
1317        static XMLCh* makeUName
1318        (
1319                const   XMLCh* const    pszURI
1320                , const XMLCh* const    pszName
1321        );
1322
1323        /**
1324          * Internal function to perform token replacement for strings.
1325          *
1326          * @param errText The text (NULL terminated) where the replacement
1327          *        is to be done. The size of this buffer should be
1328          *        'maxChars + 1' to account for the final NULL.
1329          * @param maxChars The size of the output buffer, i.e. the maximum
1330          *         number of characters that it will hold. If the result is
1331          *         larger, it will be truncated.
1332          * @param text1 Replacement text-one
1333          * @param text2 Replacement text-two
1334          * @param text3 Replacement text-three
1335          * @param text4 Replacement text-four
1336          * @param manager The MemoryManager to use to allocate objects
1337          * @return Returns the count of characters that are outputted
1338          */
1339        static XMLSize_t replaceTokens
1340        (
1341                                XMLCh* const    errText
1342                , const XMLSize_t       maxChars
1343                , const XMLCh* const    text1
1344                , const XMLCh* const    text2
1345                , const XMLCh* const    text3
1346                , const XMLCh* const    text4
1347                , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
1348        );
1349
1350        /** Converts a string to uppercase
1351          * @param toUpperCase The string which needs to be converted to uppercase.
1352          *        On return, this buffer also holds the converted uppercase string
1353          */
1354        static void upperCase(XMLCh* const toUpperCase);
1355
1356        /** Converts a string to uppercase
1357          * The routine only uppercases A to Z (other characters not changed).
1358          * @param toUpperCase The string which needs to be converted to uppercase.
1359          *        On return, this buffer also holds the converted uppercase string
1360          */
1361        static void upperCaseASCII(XMLCh* const toUpperCase);
1362
1363                /** Converts a string to lowercase
1364          * @param toLowerCase The string which needs to be converted to lowercase.
1365          *        On return, this buffer also holds the converted lowercase string
1366          */
1367        static void lowerCase(XMLCh* const toLowerCase);
1368
1369        /** Converts a string to lowercase
1370          * The routine only lowercases a to z (other characters not changed).
1371          * @param toLowerCase The string which needs to be converted to lowercase.
1372          *        On return, this buffer also holds the converted lowercase string
1373          */
1374        static void lowerCaseASCII(XMLCh* const toLowerCase);
1375
1376                /** Check if string is WhiteSpace:replace
1377          * @param toCheck The string which needs to be checked.
1378          */
1379        static bool isWSReplaced(const XMLCh* const toCheck);
1380
1381                /** Check if string is WhiteSpace:collapse
1382          * @param toCheck The string which needs to be checked.
1383          */
1384        static bool isWSCollapsed(const XMLCh* const toCheck);
1385
1386                /** Replace whitespace
1387          * @param toConvert The string which needs to be whitespace replaced.
1388          *        On return , this buffer also holds the converted string
1389          * @param manager The MemoryManager to use to allocate objects
1390          */
1391        static void replaceWS(XMLCh* toConvert
1392                , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager);
1393
1394                /** Collapse whitespace
1395          * @param toConvert The string which needs to be whitespace collapsed.
1396          *        On return , this buffer also holds the converted string
1397          * @param manager The MemoryManager to use to allocate objects
1398          */
1399        static void collapseWS(XMLCh* toConvert
1400                , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager);
1401
1402        /** Remove whitespace
1403          * @param toConvert The string which needs to be whitespace removed.
1404          *        On return , this buffer also holds the converted string
1405          * @param manager The MemoryManager to use to allocate objects
1406          */
1407        static void removeWS(XMLCh* toConvert
1408        , MemoryManager*       const manager = XMLPlatformUtils::fgMemoryManager);
1409
1410
1411        /** Remove character
1412          * @param srcString The string
1413          * @param toRemove  The character needs to be removed from the string
1414          * @param dstBuffer The buffer containing the result
1415          */
1416        static void removeChar(const XMLCh*     const srcString
1417                                                 , const XMLCh&           toRemove
1418                                                 ,       XMLBuffer&       dstBuffer);
1419
1420        /**
1421         * Fixes a platform dependent absolute path filename to standard URI form.
1422         * 1. Windows: fix 'x:' to 'file:///x:' and convert any backslash to forward slash
1423         * 2. UNIX: fix '/blah/blahblah' to 'file:///blah/blahblah'
1424         * @param str    The string that has the absolute path filename
1425         * @param target The target string pre-allocated to store the fixed uri
1426         */
1427        static void fixURI(const XMLCh* const str, XMLCh* const target);
1428
1429
1430        //@}
1431        /** @name String Memory Management functions */
1432        //@{
1433        /**
1434         * Release the parameter string that was allocated by XMLString::transcode and XMLString::replicate.
1435         * The implementation will call MemoryManager::deallocate and then turn the string to a null pointer.
1436         *
1437         * @param buf  The string to be deleted and become a null pointer.
1438         * @param manager The MemoryManager used to allocate the string
1439         */
1440        static void release
1441        (
1442                char**  buf
1443                ,       MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
1444        );
1445
1446        /**
1447         * Release the parameter string that was allocated by XMLString::transcode and XMLString::replicate.
1448         * The implementation will call MemoryManager::deallocate and then turn the string to a null pointer.
1449         *
1450         * @param buf  The string to be deleted and become a null pointer.
1451         * @param manager The MemoryManager used to allocate the string
1452         */
1453        static void release
1454        (
1455                XMLCh**  buf
1456                ,       MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
1457        );
1458        //@}
1459
1460        static inline
1461        bool isXML(const XMLCh * string);
1462
1463        static inline
1464        bool isXMLNS(const XMLCh * string);
1465
1466
1467
1468private:
1469
1470        /** @name Constructors and Destructor */
1471        //@{
1472        /** Unimplemented default constructor */
1473        XMLString();
1474        /** Unimplemented destructor */
1475        ~XMLString();
1476        //@}
1477
1478
1479        /** @name Initialization */
1480        //@{
1481        /** Init/Term methods called from XMLPlatformUtils class */
1482        static void initString(XMLLCPTranscoder* const defToUse,
1483                                                   MemoryManager* const manager);
1484        static void termString();
1485        //@}
1486
1487                /**
1488                  * Called by regionMatches/regionIMatches to validate that we
1489                  * have a valid input
1490                  */
1491                static bool validateRegion(const XMLCh* const str1, const int offset1,
1492                                                                                                const XMLCh* const str2, const int offset2,
1493                                                                                                const XMLSize_t charCount);
1494
1495        static MemoryManager* fgMemoryManager;
1496
1497        friend class XMLPlatformUtils;
1498};
1499
1500// ---------------------------------------------------------------------------
1501//  Inline some methods that are either just passthroughs to other string
1502//  methods, or which are key for performance.
1503// ---------------------------------------------------------------------------
1504inline void XMLString::moveChars(       XMLCh* const targetStr
1505                                                                , const XMLCh* const srcStr
1506                                                                , const XMLSize_t    count)
1507{
1508        memcpy(targetStr, srcStr, count << CONST_LOG_2(sizeof(XMLCh)));
1509}
1510
1511inline void XMLString::moveChars(       XMLByte * const targetStr
1512                                                                , const XMLByte * const srcStr
1513                                                                , const XMLSize_t       count)
1514{
1515        memcpy(targetStr, srcStr, count << CONST_LOG_2(sizeof(XMLByte)));
1516}
1517
1518inline XMLSize_t XMLString::stringLen(const XMLCh* const src)
1519{
1520        if (src == 0)
1521                return 0;
1522
1523        const XMLCh* pszTmp = src;
1524
1525        while (*pszTmp++);
1526
1527        return (pszTmp - src - 1);
1528}
1529
1530inline XMLCh* XMLString::replicate( const XMLCh* const toRep
1531                                                                  , MemoryManager* const manager)
1532{
1533        // If a null string, return a null string!
1534        XMLCh* ret = 0;
1535        if (toRep)
1536        {
1537                const XMLSize_t len = stringLen(toRep);
1538                ret = (XMLCh*) manager->allocate((len+1) * sizeof(XMLCh)); //new XMLCh[len + 1];
1539                XMLString::moveChars(ret, toRep, (len + 1));
1540        }
1541        return ret;
1542}
1543
1544inline XMLCh* XMLString::replicate( const XMLCh* const toRep
1545                                                                  , const XMLSize_t len
1546                                                                  , MemoryManager* const manager)
1547{
1548        // If a null string, return a null string!
1549        XMLCh* ret = 0;
1550        if (len)
1551        {
1552                ret = (XMLCh *)manager->allocate((len + 1) * sizeof(XMLCh));
1553                XMLString::moveChars(ret, toRep, (len + 1));
1554        }
1555        return ret;
1556}
1557
1558inline bool XMLString::startsWith(  const   XMLCh* const    toTest
1559                                                                        , const XMLCh* const    prefix)
1560{
1561        return (compareNString(toTest, prefix, stringLen(prefix)) == 0);
1562}
1563
1564inline bool XMLString::startsWithI( const   XMLCh* const    toTest
1565                                                                        , const XMLCh* const    prefix)
1566{
1567        return (compareNIString(toTest, prefix, stringLen(prefix)) == 0);
1568}
1569
1570inline bool XMLString::endsWith(const XMLCh* const toTest,
1571                                                                const XMLCh* const suffix)
1572{
1573
1574        XMLSize_t suffixLen = XMLString::stringLen(suffix);
1575
1576        return regionMatches(toTest, (int)(XMLString::stringLen(toTest) - suffixLen),
1577                                                 suffix, 0, suffixLen);
1578}
1579
1580inline bool XMLString::validateRegion(const XMLCh* const str1,
1581                                                                                                                                                  const int offset1,
1582                                                                                                                                                  const XMLCh* const str2,
1583                                                                                                                                                  const int offset2,
1584                                                                                                                                                  const XMLSize_t charCount)
1585{
1586
1587                if (offset1 < 0 || offset2 < 0 ||
1588                                (offset1 + charCount) > XMLString::stringLen(str1) ||
1589                                (offset2 + charCount) > XMLString::stringLen(str2) )
1590                                return false;
1591
1592                return true;
1593}
1594
1595inline bool XMLString::equals(   const XMLCh* str1
1596                                                           , const XMLCh* str2)
1597{
1598        if (str1 == str2)
1599                return true;
1600
1601        if (str1 == 0 || str2 == 0)
1602                return ((!str1 || !*str1) && (!str2 || !*str2));
1603
1604        while (*str1)
1605                if(*str1++ != *str2++)  // they are different (or str2 is shorter and we hit the NULL)
1606                        return false;
1607
1608        // either both ended (and *str2 is 0 too), or str2 is longer
1609        return (*str2==0);
1610}
1611
1612inline bool XMLString::equalsN(const XMLCh* str1,
1613                                                           const XMLCh*  str2,
1614                                                           XMLSize_t n)
1615{
1616        if (str1 == str2 || n == 0)
1617          return true;
1618
1619        if (str1 == 0 || str2 == 0)
1620                return ((!str1 || !*str1) && (!str2 || !*str2));
1621
1622        for (; n != 0 && *str1 && *str2; --n, ++str1, ++str2)
1623          if(*str1 != *str2)
1624                break;
1625
1626        return n == 0 || *str1 == *str2; // either equal or both ended premat.
1627}
1628
1629inline bool XMLString::equals(   const char* str1
1630                                                           , const char* str2)
1631{
1632        if (str1 == str2)
1633                return true;
1634
1635        if (str1 == 0 || str2 == 0)
1636                return ((!str1 || !*str1) && (!str2 || !*str2));
1637
1638        while (*str1)
1639                if(*str1++ != *str2++)  // they are different (or str2 is shorter and we hit the NULL)
1640                        return false;
1641
1642        // either both ended (and *str2 is 0 too), or str2 is longer
1643        return (*str2==0);
1644}
1645
1646inline bool XMLString::isAllSpaces( const XMLCh*    const toCheck
1647                                                                  , const XMLSize_t       count)
1648{
1649
1650        for (XMLSize_t pos = 0; pos < count; pos++)
1651        {
1652                if (toCheck[pos] != chSpace && toCheck[pos] != chLF && toCheck[pos] != chHTab)
1653                {
1654                        return 0;
1655                }
1656        }
1657        return 1;
1658}
1659
1660inline bool XMLString::equalsN(const char* str1,
1661                                                           const char* str2,
1662                                                           XMLSize_t n)
1663{
1664        if (str1 == str2 || n == 0)
1665          return true;
1666
1667        if (str1 == 0 || str2 == 0)
1668                return ((!str1 || !*str1) && (!str2 || !*str2));
1669
1670        for (; n != 0 && *str1 && *str2; --n, ++str1, ++str2)
1671          if(*str1 != *str2)
1672                break;
1673
1674        return n == 0 || *str1 == *str2; // either equal or both ended premat.
1675}
1676
1677inline int XMLString::lastIndexOf(const XMLCh* const toSearch, const XMLCh ch)
1678{
1679        return XMLString::lastIndexOf(ch, toSearch, stringLen(toSearch));
1680}
1681
1682inline XMLSize_t XMLString::hash( const XMLCh* const   tohash
1683                                                                , const XMLSize_t       hashModulus)
1684{
1685#ifdef USE_MURMUR_HASH_3
1686        const XMLSize_t n = XMLString::stringLenU<XMLCh>(tohash);
1687        XMLSize_t hashVal = getMurmur3HashVal<XMLCh, 0x5bd1e995>(tohash, n);
1688#else
1689        if (tohash == 0 || *tohash == 0)
1690                return 0;
1691
1692        const XMLCh* curCh = tohash;
1693        XMLSize_t hashVal = (XMLSize_t)(*curCh++);
1694
1695        while (*curCh)
1696                hashVal = (hashVal * 38) + (hashVal >> 24) + (XMLSize_t)(*curCh++);
1697#endif
1698        // Divide by modulus
1699        return hashVal % hashModulus;
1700}
1701
1702inline XMLSize_t XMLString::hashN( const   XMLCh* const   tohash
1703                                                                 , const XMLSize_t      n
1704                                                                 , const XMLSize_t      hashModulus)
1705{
1706#ifdef USE_MURMUR_HASH_3
1707        XMLSize_t hashVal = getMurmur3HashVal<XMLCh, 0x5bd1e995>(tohash, n);
1708#else
1709        if (tohash == 0 || n == 0)
1710                return 0;
1711
1712        const XMLCh* curCh = tohash;
1713        XMLSize_t hashVal = (XMLSize_t)(*curCh++);
1714
1715        for(XMLSize_t i = 0; i < n; i++)
1716                hashVal = (hashVal * 38) + (hashVal >> 24) + (XMLSize_t)(*curCh++);
1717#endif
1718  // Divide by modulus
1719  return hashVal % hashModulus;
1720}
1721
1722template<typename Char, Char character>
1723inline int XMLString::indexOfUC
1724(
1725        const   Char * const       string
1726        , const XMLSize_t          length
1727)
1728{
1729        const BytePack mask = mvmd<sizeof(Char) * 8>::fill(character);
1730
1731        // if we have a simd block worth of characters, check them in parallel
1732        for (unsigned int pos = 0; pos < length; pos += (sizeof(BytePack) / sizeof(Char)))
1733        {
1734                const BytePack data =
1735                        bitblock::load_unaligned((const BytePack *)&string[pos]);
1736        const size_t temp =
1737                        hsimd<8>::signmask(simd_not(simd<sizeof(Char) * 8>::eq(data, mask)));
1738                if (temp)
1739                {
1740                        pos += (scan_forward_zeroes(temp) >> CONST_LOG_2(sizeof(Char)));
1741                        return (likely(pos < length)) ? ((int)pos) : -1;
1742                }
1743        }
1744
1745        return -1;
1746}
1747
1748inline bool XMLString::isXML( const XMLCh * string )
1749{
1750        const XMLCh XML[] = { chLatin_x, chLatin_m, chLatin_l };
1751
1752        return (XMLString::equalsN(string, XML, 3)) && ((string[3] == chColon) || (string[3] == chNull));
1753}
1754
1755inline bool XMLString::isXMLNS( const XMLCh * string )
1756{
1757        const XMLCh XMLNS[] = { chLatin_x, chLatin_m, chLatin_l, chLatin_n, chLatin_s };
1758
1759        return (XMLString::equalsN(string, XMLNS, 5)) && ((string[5] == chColon) || (string[5] == chNull));
1760}
1761
1762XERCES_CPP_NAMESPACE_END
1763
1764#endif
Note: See TracBrowser for help on using the repository browser.