source: NonGTP/Xerces/xerces-c_2_8_0/include/xercesc/util/XMLString.hpp @ 2674

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