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

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

Initial check-in of icXML 0.8 source files

File size: 58.0 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 <xercesc/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
1294                                                                                , MemoryManager*       const manager = XMLPlatformUtils::fgMemoryManager);
1295
1296        //@}
1297
1298        /** @name Formatting functions */
1299        //@{
1300        /** Creates a UName from a URI and base name. It is in the form
1301          * {url}name, and is commonly used internally to represent fully
1302          * qualified names when namespaces are enabled.
1303          *
1304          * @param pszURI The URI part of the name
1305          * @param pszName The base part of the name
1306          * @return Returns the complete formatted UName
1307          */
1308        static XMLCh* makeUName
1309        (
1310                const   XMLCh* const    pszURI
1311                , const XMLCh* const    pszName
1312        );
1313
1314        /**
1315          * Internal function to perform token replacement for strings.
1316          *
1317          * @param errText The text (NULL terminated) where the replacement
1318          *        is to be done. The size of this buffer should be
1319          *        'maxChars + 1' to account for the final NULL.
1320          * @param maxChars The size of the output buffer, i.e. the maximum
1321          *         number of characters that it will hold. If the result is
1322          *         larger, it will be truncated.
1323          * @param text1 Replacement text-one
1324          * @param text2 Replacement text-two
1325          * @param text3 Replacement text-three
1326          * @param text4 Replacement text-four
1327          * @param manager The MemoryManager to use to allocate objects
1328          * @return Returns the count of characters that are outputted
1329          */
1330        static XMLSize_t replaceTokens
1331        (
1332                                XMLCh* const    errText
1333                , const XMLSize_t       maxChars
1334                , const XMLCh* const    text1
1335                , const XMLCh* const    text2
1336                , const XMLCh* const    text3
1337                , const XMLCh* const    text4
1338                , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
1339        );
1340
1341        /** Converts a string to uppercase
1342          * @param toUpperCase The string which needs to be converted to uppercase.
1343          *        On return, this buffer also holds the converted uppercase string
1344          */
1345        static void upperCase(XMLCh* const toUpperCase);
1346
1347        /** Converts a string to uppercase
1348          * The routine only uppercases A to Z (other characters not changed).
1349          * @param toUpperCase The string which needs to be converted to uppercase.
1350          *        On return, this buffer also holds the converted uppercase string
1351          */
1352        static void upperCaseASCII(XMLCh* const toUpperCase);
1353
1354                /** Converts a string to lowercase
1355          * @param toLowerCase The string which needs to be converted to lowercase.
1356          *        On return, this buffer also holds the converted lowercase string
1357          */
1358        static void lowerCase(XMLCh* const toLowerCase);
1359
1360        /** Converts a string to lowercase
1361          * The routine only lowercases a to z (other characters not changed).
1362          * @param toLowerCase The string which needs to be converted to lowercase.
1363          *        On return, this buffer also holds the converted lowercase string
1364          */
1365        static void lowerCaseASCII(XMLCh* const toLowerCase);
1366
1367                /** Check if string is WhiteSpace:replace
1368          * @param toCheck The string which needs to be checked.
1369          */
1370        static bool isWSReplaced(const XMLCh* const toCheck);
1371
1372                /** Check if string is WhiteSpace:collapse
1373          * @param toCheck The string which needs to be checked.
1374          */
1375        static bool isWSCollapsed(const XMLCh* const toCheck);
1376
1377                /** Replace whitespace
1378          * @param toConvert The string which needs to be whitespace replaced.
1379          *        On return , this buffer also holds the converted string
1380          * @param manager The MemoryManager to use to allocate objects
1381          */
1382        static void replaceWS(XMLCh* toConvert
1383                , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager);
1384
1385                /** Collapse whitespace
1386          * @param toConvert The string which needs to be whitespace collapsed.
1387          *        On return , this buffer also holds the converted string
1388          * @param manager The MemoryManager to use to allocate objects
1389          */
1390        static void collapseWS(XMLCh* toConvert
1391                , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager);
1392
1393        /** Remove whitespace
1394          * @param toConvert The string which needs to be whitespace removed.
1395          *        On return , this buffer also holds the converted string
1396          * @param manager The MemoryManager to use to allocate objects
1397          */
1398        static void removeWS(XMLCh* toConvert
1399        , MemoryManager*       const manager = XMLPlatformUtils::fgMemoryManager);
1400
1401
1402        /** Remove character
1403          * @param srcString The string
1404          * @param toRemove  The character needs to be removed from the string
1405          * @param dstBuffer The buffer containing the result
1406          */
1407        static void removeChar(const XMLCh*     const srcString
1408                                                 , const XMLCh&           toRemove
1409                                                 ,       XMLBuffer&       dstBuffer);
1410
1411        /**
1412         * Fixes a platform dependent absolute path filename to standard URI form.
1413         * 1. Windows: fix 'x:' to 'file:///x:' and convert any backslash to forward slash
1414         * 2. UNIX: fix '/blah/blahblah' to 'file:///blah/blahblah'
1415         * @param str    The string that has the absolute path filename
1416         * @param target The target string pre-allocated to store the fixed uri
1417         */
1418        static void fixURI(const XMLCh* const str, XMLCh* const target);
1419
1420
1421        //@}
1422        /** @name String Memory Management functions */
1423        //@{
1424        /**
1425         * Release the parameter string that was allocated by XMLString::transcode and XMLString::replicate.
1426         * The implementation will call MemoryManager::deallocate and then turn the string to a null pointer.
1427         *
1428         * @param buf  The string to be deleted and become a null pointer.
1429         * @param manager The MemoryManager used to allocate the string
1430         */
1431        static void release
1432        (
1433                char**  buf
1434                ,       MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
1435        );
1436
1437        /**
1438         * Release the parameter string that was allocated by XMLString::transcode and XMLString::replicate.
1439         * The implementation will call MemoryManager::deallocate and then turn the string to a null pointer.
1440         *
1441         * @param buf  The string to be deleted and become a null pointer.
1442         * @param manager The MemoryManager used to allocate the string
1443         */
1444        static void release
1445        (
1446                XMLCh**  buf
1447                ,       MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
1448        );
1449        //@}
1450
1451        static inline
1452        bool isXML(const XMLCh * string);
1453
1454        static inline
1455        bool isXMLNS(const XMLCh * string);
1456
1457
1458
1459private:
1460
1461        /** @name Constructors and Destructor */
1462        //@{
1463        /** Unimplemented default constructor */
1464        XMLString();
1465        /** Unimplemented destructor */
1466        ~XMLString();
1467        //@}
1468
1469
1470        /** @name Initialization */
1471        //@{
1472        /** Init/Term methods called from XMLPlatformUtils class */
1473        static void initString(XMLLCPTranscoder* const defToUse,
1474                                                   MemoryManager* const manager);
1475        static void termString();
1476        //@}
1477
1478                /**
1479                  * Called by regionMatches/regionIMatches to validate that we
1480                  * have a valid input
1481                  */
1482                static bool validateRegion(const XMLCh* const str1, const int offset1,
1483                                                                                                const XMLCh* const str2, const int offset2,
1484                                                                                                const XMLSize_t charCount);
1485
1486        static MemoryManager* fgMemoryManager;
1487
1488        friend class XMLPlatformUtils;
1489};
1490
1491// ---------------------------------------------------------------------------
1492//  Inline some methods that are either just passthroughs to other string
1493//  methods, or which are key for performance.
1494// ---------------------------------------------------------------------------
1495inline void XMLString::moveChars(       XMLCh* const targetStr
1496                                                                , const XMLCh* const srcStr
1497                                                                , const XMLSize_t    count)
1498{
1499        memcpy(targetStr, srcStr, count << CONST_LOG_2(sizeof(XMLCh)));
1500}
1501
1502inline void XMLString::moveChars(       XMLByte * const targetStr
1503                                                                , const XMLByte * const srcStr
1504                                                                , const XMLSize_t       count)
1505{
1506        memcpy(targetStr, srcStr, count << CONST_LOG_2(sizeof(XMLByte)));
1507}
1508
1509inline XMLSize_t XMLString::stringLen(const XMLCh* const src)
1510{
1511        if (src == 0)
1512                return 0;
1513
1514        const XMLCh* pszTmp = src;
1515
1516        while (*pszTmp++);
1517
1518        return (pszTmp - src - 1);
1519}
1520
1521inline XMLCh* XMLString::replicate( const XMLCh* const toRep
1522                                                                  , MemoryManager* const manager)
1523{
1524        // If a null string, return a null string!
1525        XMLCh* ret = 0;
1526        if (toRep)
1527        {
1528                const XMLSize_t len = stringLen(toRep);
1529                ret = (XMLCh*) manager->allocate((len+1) * sizeof(XMLCh)); //new XMLCh[len + 1];
1530                XMLString::moveChars(ret, toRep, (len + 1));
1531        }
1532        return ret;
1533}
1534
1535inline XMLCh* XMLString::replicate( const XMLCh* const toRep
1536                                                                  , const XMLSize_t len
1537                                                                  , MemoryManager* const manager)
1538{
1539        // If a null string, return a null string!
1540        XMLCh* ret = 0;
1541        if (len)
1542        {
1543                ret = (XMLCh *)manager->allocate((len + 1) * sizeof(XMLCh));
1544                XMLString::moveChars(ret, toRep, (len + 1));
1545        }
1546        return ret;
1547}
1548
1549inline bool XMLString::startsWith(  const   XMLCh* const    toTest
1550                                                                        , const XMLCh* const    prefix)
1551{
1552        return (compareNString(toTest, prefix, stringLen(prefix)) == 0);
1553}
1554
1555inline bool XMLString::startsWithI( const   XMLCh* const    toTest
1556                                                                        , const XMLCh* const    prefix)
1557{
1558        return (compareNIString(toTest, prefix, stringLen(prefix)) == 0);
1559}
1560
1561inline bool XMLString::endsWith(const XMLCh* const toTest,
1562                                                                const XMLCh* const suffix)
1563{
1564
1565        XMLSize_t suffixLen = XMLString::stringLen(suffix);
1566
1567        return regionMatches(toTest, (int)(XMLString::stringLen(toTest) - suffixLen),
1568                                                 suffix, 0, suffixLen);
1569}
1570
1571inline bool XMLString::validateRegion(const XMLCh* const str1,
1572                                                                                                                                                  const int offset1,
1573                                                                                                                                                  const XMLCh* const str2,
1574                                                                                                                                                  const int offset2,
1575                                                                                                                                                  const XMLSize_t charCount)
1576{
1577
1578                if (offset1 < 0 || offset2 < 0 ||
1579                                (offset1 + charCount) > XMLString::stringLen(str1) ||
1580                                (offset2 + charCount) > XMLString::stringLen(str2) )
1581                                return false;
1582
1583                return true;
1584}
1585
1586inline bool XMLString::equals(   const XMLCh* str1
1587                                                           , const XMLCh* str2)
1588{
1589        if (str1 == str2)
1590                return true;
1591
1592        if (str1 == 0 || str2 == 0)
1593                return ((!str1 || !*str1) && (!str2 || !*str2));
1594
1595        while (*str1)
1596                if(*str1++ != *str2++)  // they are different (or str2 is shorter and we hit the NULL)
1597                        return false;
1598
1599        // either both ended (and *str2 is 0 too), or str2 is longer
1600        return (*str2==0);
1601}
1602
1603inline bool XMLString::equalsN(const XMLCh* str1,
1604                                                           const XMLCh*  str2,
1605                                                           XMLSize_t n)
1606{
1607        if (str1 == str2 || n == 0)
1608          return true;
1609
1610        if (str1 == 0 || str2 == 0)
1611                return ((!str1 || !*str1) && (!str2 || !*str2));
1612
1613        for (; n != 0 && *str1 && *str2; --n, ++str1, ++str2)
1614          if(*str1 != *str2)
1615                break;
1616
1617        return n == 0 || *str1 == *str2; // either equal or both ended premat.
1618}
1619
1620inline bool XMLString::equals(   const char* str1
1621                                                           , const char* str2)
1622{
1623        if (str1 == str2)
1624                return true;
1625
1626        if (str1 == 0 || str2 == 0)
1627                return ((!str1 || !*str1) && (!str2 || !*str2));
1628
1629        while (*str1)
1630                if(*str1++ != *str2++)  // they are different (or str2 is shorter and we hit the NULL)
1631                        return false;
1632
1633        // either both ended (and *str2 is 0 too), or str2 is longer
1634        return (*str2==0);
1635}
1636
1637inline bool XMLString::isAllSpaces( const XMLCh*    const toCheck
1638                                                                  , const XMLSize_t       count)
1639{
1640
1641        for (XMLSize_t pos = 0; pos < count; pos++)
1642        {
1643                if (toCheck[pos] != chSpace && toCheck[pos] != chLF && toCheck[pos] != chHTab)
1644                {
1645                        return 0;
1646                }
1647        }
1648        return 1;
1649}
1650
1651inline bool XMLString::equalsN(const char* str1,
1652                                                           const char* str2,
1653                                                           XMLSize_t n)
1654{
1655        if (str1 == str2 || n == 0)
1656          return true;
1657
1658        if (str1 == 0 || str2 == 0)
1659                return ((!str1 || !*str1) && (!str2 || !*str2));
1660
1661        for (; n != 0 && *str1 && *str2; --n, ++str1, ++str2)
1662          if(*str1 != *str2)
1663                break;
1664
1665        return n == 0 || *str1 == *str2; // either equal or both ended premat.
1666}
1667
1668inline int XMLString::lastIndexOf(const XMLCh* const toSearch, const XMLCh ch)
1669{
1670        return XMLString::lastIndexOf(ch, toSearch, stringLen(toSearch));
1671}
1672
1673inline XMLSize_t XMLString::hash( const XMLCh* const   tohash
1674                                                                , const XMLSize_t       hashModulus)
1675{
1676#ifdef USE_MURMUR_HASH_3
1677        const XMLSize_t n = XMLString::stringLenU<XMLCh>(tohash);
1678        XMLSize_t hashVal = getMurmur3HashVal<XMLCh, 0x5bd1e995>(tohash, n);
1679#else
1680        if (tohash == 0 || *tohash == 0)
1681                return 0;
1682
1683        const XMLCh* curCh = tohash;
1684        XMLSize_t hashVal = (XMLSize_t)(*curCh++);
1685
1686        while (*curCh)
1687                hashVal = (hashVal * 38) + (hashVal >> 24) + (XMLSize_t)(*curCh++);
1688#endif
1689        // Divide by modulus
1690        return hashVal % hashModulus;
1691}
1692
1693inline XMLSize_t XMLString::hashN( const   XMLCh* const   tohash
1694                                                                 , const XMLSize_t      n
1695                                                                 , const XMLSize_t      hashModulus)
1696{
1697#ifdef USE_MURMUR_HASH_3
1698        XMLSize_t hashVal = getMurmur3HashVal<XMLCh, 0x5bd1e995>(tohash, n);
1699#else
1700        if (tohash == 0 || n == 0)
1701                return 0;
1702
1703        const XMLCh* curCh = tohash;
1704        XMLSize_t hashVal = (XMLSize_t)(*curCh++);
1705
1706        for(XMLSize_t i = 0; i < n; i++)
1707                hashVal = (hashVal * 38) + (hashVal >> 24) + (XMLSize_t)(*curCh++);
1708#endif
1709  // Divide by modulus
1710  return hashVal % hashModulus;
1711}
1712
1713template<typename Char, Char character>
1714inline int XMLString::indexOfUC
1715(
1716        const   Char * const       string
1717        , const XMLSize_t          length
1718)
1719{
1720        const BytePack mask = mvmd<sizeof(Char) * 8>::fill(character);
1721
1722        // if we have a simd block worth of characters, check them in parallel
1723        for (unsigned int pos = 0; pos < length; pos += (sizeof(BytePack) / sizeof(Char)))
1724        {
1725                const BytePack data =
1726                        bitblock::load_unaligned((const BytePack *)&string[pos]);
1727        const size_t temp =
1728                        hsimd<8>::signmask(simd_not(simd<sizeof(Char) * 8>::eq(data, mask)));
1729                if (temp)
1730                {
1731                        pos += (scan_forward_zeroes(temp) >> CONST_LOG_2(sizeof(Char)));
1732                        return (likely(pos < length)) ? ((int)pos) : -1;
1733                }
1734        }
1735
1736        return -1;
1737}
1738
1739inline bool XMLString::isXML( const XMLCh * string )
1740{
1741        const XMLCh XML[] = { chLatin_x, chLatin_m, chLatin_l };
1742
1743        return (XMLString::equalsN(string, XML, 3)) && ((string[3] == chColon) || (string[3] == chNull));
1744}
1745
1746inline bool XMLString::isXMLNS( const XMLCh * string )
1747{
1748        const XMLCh XMLNS[] = { chLatin_x, chLatin_m, chLatin_l, chLatin_n, chLatin_s };
1749
1750        return (XMLString::equalsN(string, XMLNS, 5)) && ((string[5] == chColon) || (string[5] == chNull));
1751}
1752
1753XERCES_CPP_NAMESPACE_END
1754
1755#endif
Note: See TracBrowser for help on using the repository browser.