Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:15:15

0001 /*
0002  * Licensed to the Apache Software Foundation (ASF) under one or more
0003  * contributor license agreements.  See the NOTICE file distributed with
0004  * this work for additional information regarding copyright ownership.
0005  * The ASF licenses this file to You under the Apache License, Version 2.0
0006  * (the "License"); you may not use this file except in compliance with
0007  * the License.  You may obtain a copy of the License at
0008  *
0009  *      http://www.apache.org/licenses/LICENSE-2.0
0010  *
0011  * Unless required by applicable law or agreed to in writing, software
0012  * distributed under the License is distributed on an "AS IS" BASIS,
0013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014  * See the License for the specific language governing permissions and
0015  * limitations under the License.
0016  */
0017 
0018 /*
0019  * $Id$
0020  */
0021 
0022 #if !defined(XERCESC_INCLUDE_GUARD_XMLSTRING_HPP)
0023 #define XERCESC_INCLUDE_GUARD_XMLSTRING_HPP
0024 
0025 #include <xercesc/util/BaseRefVectorOf.hpp>
0026 #include <xercesc/framework/XMLBuffer.hpp>
0027 #include <xercesc/framework/MemoryManager.hpp>
0028 #include <string.h>
0029 #include <assert.h>
0030 
0031 XERCES_CPP_NAMESPACE_BEGIN
0032 
0033 class XMLLCPTranscoder;
0034 /**
0035   * Class for representing native character strings and handling common string
0036   * operations
0037   *
0038   * This class is Unicode compliant. This class is designed primarily
0039   * for internal use, but due to popular demand, it is being made
0040   * publicly available. Users of this class must understand that this
0041   * is not an officially supported class. All public methods of this
0042   * class are <i>static functions</i>.
0043   *
0044   */
0045 class XMLUTIL_EXPORT XMLString
0046 {
0047 public:
0048     /* Static methods for native character mode string manipulation */
0049 
0050 
0051     /** @name String concatenation functions */
0052     //@{
0053     /** Concatenates two strings.
0054       *
0055       * <code>catString</code> appends <code>src</code> to <code>target</code> and
0056       * terminates the resulting string with a null character. The initial character
0057       * of <code>src</code> overwrites the terminating character of <code>target
0058       * </code>.
0059       *
0060       * No overflow checking is performed when strings are copied or appended.
0061       * The behavior of <code>catString</code> is undefined if source and
0062       * destination strings overlap.
0063       *
0064       * @param target Null-terminated destination string
0065       * @param src Null-terminated source string
0066       */
0067     static void catString
0068     (
0069                 char* const     target
0070         , const char* const     src
0071     );
0072 
0073     /** Concatenates two strings.
0074       *
0075       * <code>catString</code> appends <code>src</code> to <code>target</code> and
0076       * terminates the resulting string with a null character. The initial character of
0077       * <code>src</code> overwrites the terminating character of <code>target</code>.
0078       * No overflow checking is performed when strings are copied or appended.
0079       * The behavior of <code>catString</code> is undefined if source and destination
0080       * strings overlap.
0081       *
0082       * @param target Null-terminated destination string
0083       * @param src Null-terminated source string
0084       */
0085     static void catString
0086     (
0087                 XMLCh* const    target
0088         , const XMLCh* const    src
0089     );
0090     //@}
0091 
0092     /** @name String comparison functions */
0093     //@{
0094     /** Lexicographically compares lowercase versions of <code>str1</code> and
0095       * <code>str2</code> and returns a value indicating their relationship.
0096       * @param str1 Null-terminated string to compare
0097       * @param str2 Null-terminated string to compare
0098       *
0099       * @return The return value indicates the relation of <code>str1</code> to
0100       * <code>str2</code> as follows
0101       *  Less than 0 means <code>str1</code> is less than <code>str2</code>
0102       *  Equal to 0 means <code>str1</code> is identical to <code>str2</code>
0103       *  Greater than 0 means <code>str1</code> is more than <code>str2</code>
0104       */
0105     static int compareIString
0106     (
0107         const   char* const     str1
0108         , const char* const     str2
0109     );
0110 
0111     /** Lexicographically compares lowercase versions of <code>str1</code> and
0112       * <code>str2</code> and returns a value indicating their relationship.
0113       * @param str1 Null-terminated string to compare
0114       * @param str2 Null-terminated string to compare
0115       * @return The return value indicates the relation of <code>str1</code> to
0116       * <code>str2</code> as follows
0117       *  Less than 0 means <code>str1</code> is less than <code>str2</code>
0118       *  Equal to 0 means <code>str1</code> is identical to <code>str2</code>
0119       *  Greater than 0 means <code>str1</code> is more than <code>str2</code>
0120       */
0121     static int compareIString
0122     (
0123         const   XMLCh* const    str1
0124         , const XMLCh* const    str2
0125     );
0126 
0127     /** Lexicographically compares lowercase versions of <code>str1</code> and
0128       * <code>str2</code> and returns a value indicating their relationship.
0129       * The routine only lowercases A to Z.
0130       * @param str1 Null-terminated ASCII string to compare
0131       * @param str2 Null-terminated ASCII string to compare
0132       * @return The return value indicates the relation of <code>str1</code> to
0133       * <code>str2</code> as follows
0134       *  Less than 0 means <code>str1</code> is less than <code>str2</code>
0135       *  Equal to 0 means <code>str1</code> is identical to <code>str2</code>
0136       *  Greater than 0 means <code>str1</code> is more than <code>str2</code>
0137       */
0138     static int compareIStringASCII
0139     (
0140         const   XMLCh* const    str1
0141         , const XMLCh* const    str2
0142     );
0143 
0144 
0145 
0146     /** Lexicographically compares, at most, the first count characters in
0147       * <code>str1</code> and <code>str2</code> and returns a value indicating the
0148       * relationship between the substrings.
0149       * @param str1 Null-terminated string to compare
0150       * @param str2 Null-terminated string to compare
0151       * @param count The number of characters to compare
0152       *
0153       * @return The return value indicates the relation of <code>str1</code> to
0154       * <code>str2</code> as follows
0155       *  Less than 0 means <code>str1</code> is less than <code>str2</code>
0156       *  Equal to 0 means <code>str1</code> is identical to <code>str2</code>
0157       *  Greater than 0 means <code>str1</code> is more than <code>str2</code>
0158       */
0159     static int compareNString
0160     (
0161         const   char* const     str1
0162         , const char* const     str2
0163         , const XMLSize_t       count
0164     );
0165 
0166     /** Lexicographically compares, at most, the first count characters in
0167       * <code>str1</code> and <code>str2</code> and returns a value indicating
0168       * the relationship between the substrings.
0169       * @param str1 Null-terminated string to compare
0170       * @param str2 Null-terminated string to compare
0171       * @param count The number of characters to compare
0172       *
0173       * @return The return value indicates the relation of <code>str1</code> to
0174       * <code>str2</code> as follows
0175       *  Less than 0 means <code>str1</code> is less than <code>str2</code>
0176       *  Equal to 0 means <code>str1</code> is identical to <code>str2</code>
0177       *  Greater than 0 means <code>str1</code> is more than <code>str2</code>
0178       */
0179     static int compareNString
0180     (
0181         const   XMLCh* const    str1
0182         , const XMLCh* const    str2
0183         , const XMLSize_t       count
0184     );
0185 
0186 
0187     /** Lexicographically compares, at most, the first count characters in
0188       * <code>str1</code> and <code>str2</code> without regard to case and
0189       * returns a value indicating the relationship between the substrings.
0190       *
0191       * @param str1 Null-terminated string to compare
0192       * @param str2 Null-terminated string to compare
0193       * @param count The number of characters to compare
0194       * @return The return value indicates the relation of <code>str1</code> to
0195       * <code>str2</code> as follows
0196       *  Less than 0 means <code>str1</code> is less than <code>str2</code>
0197       *  Equal to 0 means <code>str1</code> is identical to <code>str2</code>
0198       *  Greater than 0 means <code>str1</code> is more than <code>str2</code>
0199       */
0200     static int compareNIString
0201     (
0202         const   char* const     str1
0203         , const char* const     str2
0204         , const XMLSize_t       count
0205     );
0206 
0207     /** Lexicographically compares, at most, the first count characters in
0208       * <code>str1</code> and <code>str2</code> without regard to case and
0209       * returns a value indicating the relationship between the substrings.
0210       *
0211       * @param str1 Null-terminated string to compare
0212       * @param str2 Null-terminated string to compare
0213       * @param count The number of characters to compare
0214       *
0215       * @return The return value indicates the relation of <code>str1</code> to
0216       * <code>str2</code> as follows
0217       *  Less than 0 means <code>str1</code> is less than <code>str2</code>
0218       *  Equal to 0 means <code>str1</code> is identical to <code>str2</code>
0219       *  Greater than 0 means <code>str1</code> is more than <code>str2</code>
0220       */
0221     static int compareNIString
0222     (
0223         const   XMLCh* const    str1
0224         , const XMLCh* const    str2
0225         , const XMLSize_t       count
0226     );
0227 
0228     /** Lexicographically compares <code>str1</code> and <code>str2</code> and
0229       * returns a value indicating their relationship.
0230       *
0231       * @param str1 Null-terminated string to compare
0232       * @param str2 Null-terminated string to compare
0233       *
0234       * @return The return value indicates the relation of <code>str1</code> to
0235       * <code>str2</code> as follows
0236       *  Less than 0 means <code>str1</code> is less than <code>str2</code>
0237       *  Equal to 0 means <code>str1</code> is identical to <code>str2</code>
0238       *  Greater than 0 means <code>str1</code> is more than <code>str2</code>
0239       */
0240     static int compareString
0241     (
0242         const   char* const     str1
0243         , const char* const     str2
0244     );
0245 
0246     /** Lexicographically compares <code>str1</code> and <code>str2</code> and
0247       * returns a value indicating their relationship.
0248       *
0249       * @param str1 Null-terminated string to compare
0250       * @param str2 Null-terminated string to compare
0251       * @return The return value indicates the relation of <code>str1</code> to
0252       * <code>str2</code> as follows
0253       *  Less than 0 means <code>str1</code> is less than <code>str2</code>
0254       *  Equal to 0 means <code>str1</code> is identical to <code>str2</code>
0255       *  Greater than 0 means <code>str1</code> is more than <code>str2</code>
0256       */
0257     static int compareString
0258     (
0259         const   XMLCh* const    str1
0260         , const XMLCh* const    str2
0261     );
0262 
0263     /** compares <code>str1</code> and <code>str2</code>
0264       *
0265       * @param str1 Null-terminated string to compare
0266       * @param str2 Null-terminated string to compare
0267       * @return true if two strings are equal, false if not
0268       *  If one string is null, while the other is zero-length string,
0269       *  it is considered as equal.
0270       */
0271     static bool equals
0272     (
0273           const XMLCh* str1
0274         , const XMLCh* str2
0275     );
0276 
0277     /** compares <code>str1</code> and <code>str2</code>
0278       *
0279       * @param str1 string to compare
0280       * @param str2 string to compare
0281       * @param n number of characters to compare
0282       * @return true if two strings are equal, false if not
0283       *  If one string is null, while the other is zero-length string,
0284       *  it is considered as equal.
0285       */
0286     static bool equalsN
0287     (
0288           const XMLCh* str1
0289         , const XMLCh* str2
0290         , XMLSize_t n
0291     );
0292 
0293     static bool equals
0294     (
0295           const char* str1
0296         , const char* str2
0297     );
0298 
0299     /** compares <code>str1</code> and <code>str2</code>
0300       *
0301       * @param str1 string to compare
0302       * @param str2 string to compare
0303       * @param n number of characters to compare
0304       * @return true if two strings are equal, false if not
0305       *  If one string is null, while the other is zero-length string,
0306       *  it is considered as equal.
0307       */
0308     static bool equalsN
0309     (
0310           const char* str1
0311         , const char* str2
0312         , XMLSize_t n
0313     );
0314 
0315     /** Lexicographically compares <code>str1</code> and <code>str2</code>
0316       * regions and returns true if they are equal, otherwise false.
0317       *
0318       * A substring of <code>str1</code> is compared to a substring of
0319       * <code>str2</code>. The result is true if these substrings represent
0320       * identical character sequences. The substring of <code>str1</code>
0321       * to be compared begins at offset1 and has length charCount. The
0322       * substring of <code>str2</code> to be compared begins at offset2 and
0323       * has length charCount. The result is false if and only if at least
0324       * one of the following is true:
0325       *   offset1 is negative.
0326       *   offset2 is negative.
0327       *   offset1+charCount is greater than the length of str1.
0328       *   offset2+charCount is greater than the length of str2.
0329       *   There is some nonnegative integer k less than charCount such that:
0330       *   str1.charAt(offset1+k) != str2.charAt(offset2+k)
0331       *
0332       * @param str1 Null-terminated string to compare
0333       * @param offset1 Starting offset of str1
0334       * @param str2 Null-terminated string to compare
0335       * @param offset2 Starting offset of str2
0336       * @param charCount The number of characters to compare
0337       * @return true if the specified subregion of <code>str1</code> exactly
0338       *  matches the specified subregion of <code>str2></code>; false
0339       *  otherwise.
0340       */
0341     static bool regionMatches
0342     (
0343         const   XMLCh* const    str1
0344         , const int             offset1
0345         , const XMLCh* const    str2
0346         , const int             offset2
0347         , const XMLSize_t       charCount
0348     );
0349 
0350     /** Lexicographically compares <code>str1</code> and <code>str2</code>
0351       * regions without regard to case and returns true if they are equal,
0352       * otherwise false.
0353       *
0354       * A substring of <code>str1</code> is compared to a substring of
0355       * <code>str2</code>. The result is true if these substrings represent
0356       * identical character sequences. The substring of <code>str1</code>
0357       * to be compared begins at offset1 and has length charCount. The
0358       * substring of <code>str2</code> to be compared begins at offset2 and
0359       * has length charCount. The result is false if and only if at least
0360       * one of the following is true:
0361       *   offset1 is negative.
0362       *   offset2 is negative.
0363       *   offset1+charCount is greater than the length of str1.
0364       *   offset2+charCount is greater than the length of str2.
0365       *   There is some nonnegative integer k less than charCount such that:
0366       *   str1.charAt(offset1+k) != str2.charAt(offset2+k)
0367       *
0368       * @param str1 Null-terminated string to compare
0369       * @param offset1 Starting offset of str1
0370       * @param str2 Null-terminated string to compare
0371       * @param offset2 Starting offset of str2
0372       * @param charCount The number of characters to compare
0373       * @return true if the specified subregion of <code>str1</code> exactly
0374       *  matches the specified subregion of <code>str2></code>; false
0375       *  otherwise.
0376       */
0377     static bool regionIMatches
0378     (
0379         const   XMLCh* const    str1
0380         , const int             offset1
0381         , const XMLCh* const    str2
0382         , const int             offset2
0383         , const XMLSize_t       charCount
0384     );
0385     //@}
0386 
0387     /** @name String copy functions */
0388     //@{
0389     /** Copies <code>src</code>, including the terminating null character, to the
0390       * location specified by <code>target</code>.
0391       *
0392       * No overflow checking is performed when strings are copied or appended.
0393       * The behavior of strcpy is undefined if the source and destination strings
0394       * overlap.
0395       *
0396       * @param target Destination string
0397       * @param src Null-terminated source string
0398       */
0399     static void copyString
0400     (
0401                 char* const     target
0402         , const char* const     src
0403     );
0404 
0405     /** Copies <code>src</code>, including the terminating null character, to
0406       *   the location specified by <code>target</code>.
0407       *
0408       * No overflow checking is performed when strings are copied or appended.
0409       * The behavior of <code>copyString</code> is undefined if the source and
0410       * destination strings overlap.
0411       *
0412       * @param target Destination string
0413       * @param src Null-terminated source string
0414       */
0415     static void copyString
0416     (
0417                 XMLCh* const    target
0418         , const XMLCh* const    src
0419     );
0420 
0421     /** Copies <code>src</code>, upto a fixed number of characters, to the
0422       * location specified by <code>target</code>.
0423       *
0424       * No overflow checking is performed when strings are copied or appended.
0425       * The behavior of <code>copyNString</code> is undefined if the source and
0426       * destination strings overlap.
0427       *
0428       * @param target Destination string. The size of the buffer should
0429       *        atleast be 'maxChars + 1'.
0430       * @param src Null-terminated source string
0431       * @param maxChars The maximum number of characters to copy
0432       */
0433     static bool copyNString
0434     (
0435                 XMLCh* const   target
0436         , const XMLCh* const   src
0437         , const XMLSize_t      maxChars
0438     );
0439     //@}
0440 
0441     /** @name Hash functions */
0442     //@{
0443     /** Hashes a string given a modulus
0444       *
0445       * @param toHash The string to hash
0446       * @param hashModulus The divisor to be used for hashing
0447       * @return Returns the hash value
0448       */
0449     static XMLSize_t hash
0450     (
0451         const   char* const     toHash
0452         , const XMLSize_t       hashModulus
0453     );
0454 
0455     /** Hashes a string given a modulus
0456       *
0457       * @param toHash The string to hash
0458       * @param hashModulus The divisor to be used for hashing
0459       * @return Returns the hash value
0460       */
0461     static XMLSize_t hash
0462     (
0463         const   XMLCh* const    toHash
0464         , const XMLSize_t       hashModulus
0465     );
0466 
0467     /** Hashes a string given a modulus taking a maximum number of characters
0468       * as the limit
0469       *
0470       * @param toHash The string to hash
0471       * @param numChars The maximum number of characters to consider for hashing
0472       * @param hashModulus The divisor to be used for hashing
0473       * @return Returns the hash value
0474       */
0475     static XMLSize_t hashN
0476     (
0477         const   XMLCh* const    toHash
0478         , const XMLSize_t       numChars
0479         , const XMLSize_t       hashModulus
0480     );
0481 
0482     //@}
0483 
0484     /** @name Search functions */
0485     //@{
0486     /**
0487       * Provides the index of the first occurrence of a character within a string
0488       *
0489       * @param toSearch The string to search
0490       * @param ch The character to search within the string
0491       * @return If found, returns the index of the character within the string,
0492       * else returns -1.
0493       */
0494     static int indexOf(const char* const toSearch, const char ch);
0495 
0496     /**
0497       * Provides the index of the first occurrence of a character within a string
0498       *
0499       * @param toSearch The string to search
0500       * @param ch The character to search within the string
0501       * @return If found, returns the index of the character within the string,
0502       * else returns -1.
0503       */
0504     static int indexOf(const XMLCh* const toSearch, const XMLCh ch);
0505 
0506         /**
0507       * Provides the index of the first occurrence of a character within a string
0508       * starting from a given index
0509       *
0510       * @param toSearch The string to search
0511       * @param chToFind The character to search within the string
0512       * @param fromIndex The index to start searching from
0513       * @param manager The MemoryManager to use to allocate objects
0514       * @return If found, returns the index of the character within the string,
0515       * else returns -1.
0516       */
0517     static int indexOf
0518     (
0519         const   char* const     toSearch
0520         , const char            chToFind
0521         , const XMLSize_t       fromIndex
0522         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
0523     );
0524 
0525     /**
0526       * Provides the index of the first occurrence of a character within a string
0527       * starting from a given index
0528       *
0529       * @param toSearch The string to search
0530       * @param chToFind The character to search within the string
0531       * @param fromIndex The index to start searching from
0532       * @param manager The MemoryManager to use to allocate objects
0533       * @return If found, returns the index of the character within the string,
0534       * else returns -1.
0535       */
0536     static int indexOf
0537     (
0538         const   XMLCh* const    toSearch
0539         , const XMLCh           chToFind
0540         , const XMLSize_t       fromIndex
0541         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
0542     );
0543 
0544     /**
0545       * Provides the index of the last occurrence of a character within a string
0546       *
0547       * @param toSearch The string to search
0548       * @param ch The character to search within the string
0549       * @return If found, returns the index of the character within the string,
0550       * else returns -1.
0551       */
0552     static int lastIndexOf(const char* const toSearch, const char ch);
0553 
0554     /**
0555       * Provides the index of the last occurrence of a character within a string
0556       *
0557       * @param toSearch The string to search
0558       * @param ch The character to search within the string
0559       * @return If found, returns the index of the character within the string,
0560       * else returns -1.
0561       */
0562     static int lastIndexOf(const XMLCh* const toSearch, const XMLCh ch);
0563 
0564     /**
0565       * Provides the index of the last occurrence of a character within a string
0566       *
0567       * @param ch The character to search within the string
0568       * @param toSearch The string to search
0569       * @param toSearchLen The length of the string to search
0570       * @return If found, returns the index of the character within the string,
0571       * else returns -1.
0572       */
0573     static int lastIndexOf
0574     (
0575         const XMLCh ch
0576         , const XMLCh* const toSearch
0577         , const XMLSize_t    toSearchLen
0578     );
0579 
0580     /**
0581       * Provides the index of the last occurrence of a character within a string
0582       * starting backward from a given index
0583       *
0584       * @param toSearch The string to search
0585       * @param chToFind The character to search within the string
0586       * @param fromIndex The index to start backward search from
0587       * @param manager The MemoryManager to use to allocate objects
0588       * @return If found, returns the index of the character within the string,
0589       * else returns -1.
0590       */
0591     static int lastIndexOf
0592     (
0593         const   char* const     toSearch
0594         , const char            chToFind
0595         , const XMLSize_t       fromIndex
0596         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
0597     );
0598 
0599     /**
0600       * Provides the index of the last occurrence of a character within a string
0601       * starting backward from a given index
0602       *
0603       * @param toSearch The string to search
0604       * @param ch       The character to search within the string
0605       * @param fromIndex The index to start backward search from
0606       * @param manager The MemoryManager to use to allocate objects
0607       * @return If found, returns the index of the character within the string,
0608       * else returns -1.
0609       */
0610     static int lastIndexOf
0611     (
0612         const   XMLCh* const    toSearch
0613         , const XMLCh           ch
0614         , const XMLSize_t       fromIndex
0615         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
0616     );
0617     //@}
0618 
0619     /** @name Fixed size string movement */
0620     //@{
0621     /** Moves X number of chars
0622       * @param targetStr The string to copy the chars to
0623       * @param srcStr The string to copy the chars from
0624       * @param count The number of chars to move
0625       */
0626     static void moveChars
0627     (
0628                 XMLCh* const    targetStr
0629         , const XMLCh* const    srcStr
0630         , const XMLSize_t       count
0631     );
0632 
0633     //@}
0634 
0635     /** @name Substring function */
0636     //@{
0637     /** Create a substring of a given string. The substring begins at the
0638       * specified beginIndex and extends to the character at index
0639       * endIndex - 1.
0640       * @param targetStr The string to copy the chars to
0641       * @param srcStr The string to copy the chars from
0642       * @param startIndex beginning index, inclusive.
0643       * @param endIndex the ending index, exclusive.
0644       * @param manager The MemoryManager to use to allocate objects
0645       */
0646     static void subString
0647     (
0648                 char* const    targetStr
0649         , const char* const    srcStr
0650         , const XMLSize_t      startIndex
0651         , const XMLSize_t      endIndex
0652         , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
0653     );
0654 
0655     /** Create a substring of a given string. The substring begins at the
0656       * specified beginIndex and extends to the character at index
0657       * endIndex - 1.
0658       * @param targetStr The string to copy the chars to
0659       * @param srcStr The string to copy the chars from
0660       * @param startIndex beginning index, inclusive.
0661       * @param endIndex the ending index, exclusive.
0662       * @param manager The MemoryManager to use to allocate objects
0663       */
0664     static void subString
0665     (
0666                 XMLCh* const    targetStr
0667         , const XMLCh* const    srcStr
0668         , const XMLSize_t       startIndex
0669         , const XMLSize_t       endIndex
0670         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
0671     );
0672 
0673     /** Create a substring of a given string. The substring begins at the
0674       * specified beginIndex and extends to the character at index
0675       * endIndex - 1.
0676       * @param targetStr The string to copy the chars to
0677       * @param srcStr The string to copy the chars from
0678       * @param startIndex beginning index, inclusive.
0679       * @param endIndex the ending index, exclusive.
0680       * @param srcStrLength the length of srcStr
0681       * @param manager The MemoryManager to use to allocate objects
0682       */
0683     static void subString
0684     (
0685                 XMLCh* const    targetStr
0686         , const XMLCh* const    srcStr
0687         , const XMLSize_t       startIndex
0688         , const XMLSize_t       endIndex
0689         , const XMLSize_t       srcStrLength
0690         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
0691     );
0692 
0693     //@}
0694 
0695     /** @name Replication function */
0696     //@{
0697     /** Replicates a string
0698       * NOTE: The returned buffer is allocated with the MemoryManager. It is the
0699       * responsibility of the caller to delete it when not longer needed.
0700       * You can call XMLString::release to release this returned buffer.
0701       *
0702       * @param toRep The string to replicate
0703       * @param manager The MemoryManager to use to allocate the string
0704       * @return Returns a pointer to the replicated string
0705       * @see   XMLString::release(char**, MemoryManager*)
0706       */
0707     static char* replicate(const char* const toRep,
0708                            MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
0709 
0710     /** Replicates a string
0711       * NOTE: The returned buffer is allocated with the MemoryManager. It is the
0712       * responsibility of the caller to delete it when not longer needed.
0713       * You can call XMLString::release to release this returned buffer.
0714       *
0715       * @param toRep The string to replicate
0716       * @param manager The MemoryManager to use to allocate the string
0717       * @return Returns a pointer to the replicated string
0718       * @see   XMLString::release(XMLCh**, MemoryManager*)
0719       */
0720     static XMLCh* replicate(const XMLCh* const toRep,
0721                             MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
0722 
0723     //@}
0724 
0725     /** @name String query function */
0726     //@{
0727     /** Tells if the sub-string appears within a string at the beginning
0728       * @param toTest The string to test
0729       * @param prefix The sub-string that needs to be checked
0730       * @return Returns true if the sub-string was found at the beginning of
0731       * <code>toTest</code>, else false
0732       */
0733     static bool startsWith
0734     (
0735         const   char* const     toTest
0736         , const char* const     prefix
0737     );
0738 
0739     /** Tells if the sub-string appears within a string at the beginning
0740       * @param toTest The string to test
0741       * @param prefix The sub-string that needs to be checked
0742       * @return Returns true if the sub-string was found at the beginning of
0743       * <code>toTest</code>, else false
0744       */
0745     static bool startsWith
0746     (
0747         const   XMLCh* const    toTest
0748         , const XMLCh* const    prefix
0749     );
0750 
0751     /** Tells if the sub-string appears within a string at the beginning
0752       * without regard to case
0753       *
0754       * @param toTest The string to test
0755       * @param prefix The sub-string that needs to be checked
0756       * @return Returns true if the sub-string was found at the beginning of
0757       * <code>toTest</code>, else false
0758       */
0759     static bool startsWithI
0760     (
0761         const   char* const     toTest
0762         , const char* const     prefix
0763     );
0764 
0765     /** Tells if the sub-string appears within a string at the beginning
0766       * without regard to case
0767       *
0768       * @param toTest The string to test
0769       * @param prefix The sub-string that needs to be checked
0770       *
0771       * @return Returns true if the sub-string was found at the beginning
0772       * of <code>toTest</code>, else false
0773       */
0774     static bool startsWithI
0775     (
0776         const   XMLCh* const    toTest
0777         , const XMLCh* const    prefix
0778     );
0779 
0780     /** Tells if the sub-string appears within a string at the end.
0781       * @param toTest The string to test
0782       * @param suffix The sub-string that needs to be checked
0783       * @return Returns true if the sub-string was found at the end of
0784       * <code>toTest</code>, else false
0785       */
0786     static bool endsWith
0787     (
0788         const   XMLCh* const    toTest
0789         , const XMLCh* const    suffix
0790     );
0791 
0792 
0793     /** Tells if a string has any occurrence of any character of another
0794       * string within itself
0795       * @param toSearch The string to be searched
0796       * @param searchList The string from which characters to be searched for are drawn
0797       * @return Returns the pointer to the location where the first occurrence of any
0798       * character from searchList is found,
0799       * else returns 0
0800       */
0801     static const XMLCh* findAny
0802     (
0803         const   XMLCh* const    toSearch
0804         , const XMLCh* const    searchList
0805     );
0806 
0807     /** Tells if a string has any occurrence of any character of another
0808       * string within itself
0809       * @param toSearch The string to be searched
0810       * @param searchList The string from which characters to be searched for are drawn
0811       * @return Returns the pointer to the location where the first occurrence of any
0812       * character from searchList is found,
0813       * else returns 0
0814       */
0815     static XMLCh* findAny
0816     (
0817                 XMLCh* const    toSearch
0818         , const XMLCh* const    searchList
0819     );
0820 
0821     /** Tells if a string has pattern within itself
0822       * @param toSearch The string to be searched
0823       * @param pattern The pattern to be located within the string
0824       * @return Returns index to the location where the pattern was
0825       * found, else returns -1
0826       */
0827     static int patternMatch
0828     (
0829           const XMLCh* const    toSearch
0830         , const XMLCh* const    pattern
0831     );
0832 
0833     /** Get the length of the string
0834       * @param src The string whose length is to be determined
0835       * @return Returns the length of the string
0836       */
0837     static XMLSize_t stringLen(const char* const src);
0838 
0839     /** Get the length of the string
0840       * @param src The string whose length is to be determined
0841       * @return Returns the length of the string
0842       */
0843     static XMLSize_t stringLen(const XMLCh* const src);
0844 
0845     /**
0846       *
0847       * Checks whether an name is a valid NOTATION according to XML 1.0
0848       * @param name    The string to check its NOTATION validity
0849       * @param manager The memory manager
0850       * @return Returns true if name is NOTATION valid, otherwise false
0851       */
0852     static bool isValidNOTATION(const XMLCh*         const name
0853                               ,       MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
0854 
0855     /**
0856       * Checks whether an name is a valid EncName.
0857       * @param name The string to check its EncName validity
0858       * @return Returns true if name is EncName valid, otherwise false
0859       */
0860     static bool isValidEncName(const XMLCh* const name);
0861 
0862     /**
0863       * Checks whether a character is within [a-zA-Z].
0864       * @param theChar the character to check
0865       * @return Returns true if within the range, otherwise false
0866       */
0867 
0868     static bool isAlpha(XMLCh const theChar);
0869 
0870     /**
0871       * Checks whether a character is within [0-9].
0872       * @param theChar the character to check
0873       * @return Returns true if within the range, otherwise false
0874       */
0875     static bool isDigit(XMLCh const theChar);
0876 
0877     /**
0878       * Checks whether a character is within [0-9a-zA-Z].
0879       * @param theChar the character to check
0880       * @return Returns true if within the range, otherwise false
0881       */
0882     static bool isAlphaNum(XMLCh const theChar);
0883 
0884     /**
0885       * Checks whether a character is within [0-9a-fA-F].
0886       * @param theChar the character to check
0887       * @return Returns true if within the range, otherwise false
0888       */
0889     static bool isHex(XMLCh const theChar);
0890 
0891     /** Find is the string appears in the enum list
0892       * @param toFind the string to be found
0893       * @param enumList the list
0894       * return true if found
0895       */
0896     static bool isInList(const XMLCh* const toFind, const XMLCh* const enumList);
0897 
0898     //@}
0899 
0900     /** @name Conversion functions */
0901     //@{
0902 
0903       /** Converts size to a text string based a given radix
0904       *
0905       * @param toFormat The size to convert
0906       * @param toFill The buffer that will hold the output on return. The
0907       *        size of this buffer should at least be 'maxChars + 1'.
0908       * @param maxChars The maximum number of output characters that can be
0909       *         accepted. If the result will not fit, it is an error.
0910       * @param radix The radix of the input data, based on which the conversion
0911       * @param manager The MemoryManager to use to allocate objects
0912       * will be done
0913       */
0914     static void sizeToText
0915     (
0916         const   XMLSize_t           toFormat
0917         ,       char* const         toFill
0918         , const XMLSize_t           maxChars
0919         , const unsigned int        radix
0920         , MemoryManager* const      manager = XMLPlatformUtils::fgMemoryManager
0921     );
0922 
0923     /** Converts size to a text string based a given radix
0924       *
0925       * @param toFormat The size to convert
0926       * @param toFill The buffer that will hold the output on return. The
0927       *        size of this buffer should at least be 'maxChars + 1'.
0928       * @param maxChars The maximum number of output characters that can be
0929       *         accepted. If the result will not fit, it is an error.
0930       * @param radix The radix of the input data, based on which the conversion
0931       * @param manager The MemoryManager to use to allocate objects
0932       * will be done
0933       */
0934     static void sizeToText
0935     (
0936         const   XMLSize_t           toFormat
0937         ,       XMLCh* const        toFill
0938         , const XMLSize_t           maxChars
0939         , const unsigned int        radix
0940         , MemoryManager* const      manager = XMLPlatformUtils::fgMemoryManager
0941     );
0942 
0943     /** Converts binary data to a text string based a given radix
0944       *
0945       * @param toFormat The number to convert
0946       * @param toFill The buffer that will hold the output on return. The
0947       *        size of this buffer should at least be 'maxChars + 1'.
0948       * @param maxChars The maximum number of output characters that can be
0949       *         accepted. If the result will not fit, it is an error.
0950       * @param radix The radix of the input data, based on which the conversion
0951       * @param manager The MemoryManager to use to allocate objects
0952       * will be done
0953       */
0954     static void binToText
0955     (
0956         const   unsigned int    toFormat
0957         ,       char* const     toFill
0958         , const XMLSize_t       maxChars
0959         , const unsigned int    radix
0960         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
0961     );
0962 
0963     /** Converts binary data to a text string based a given radix
0964       *
0965       * @param toFormat The number to convert
0966       * @param toFill The buffer that will hold the output on return. The
0967       *        size of this buffer should at least be 'maxChars + 1'.
0968       * @param maxChars The maximum number of output characters that can be
0969       *         accepted. If the result will not fit, it is an error.
0970       * @param radix The radix of the input data, based on which the conversion
0971       * @param manager The MemoryManager to use to allocate objects
0972       * will be done
0973       */
0974     static void binToText
0975     (
0976         const   unsigned int    toFormat
0977         ,       XMLCh* const    toFill
0978         , const XMLSize_t       maxChars
0979         , const unsigned int    radix
0980         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
0981     );
0982 
0983     /** Converts binary data to a text string based a given radix
0984       *
0985       * @param toFormat The number to convert
0986       * @param toFill The buffer that will hold the output on return. The
0987       *        size of this buffer should at least be 'maxChars + 1'.
0988       * @param maxChars The maximum number of output characters that can be
0989       *         accepted. If the result will not fit, it is an error.
0990       * @param radix The radix of the input data, based on which the conversion
0991       * @param manager The MemoryManager to use to allocate objects
0992       * will be done
0993       */
0994     static void binToText
0995     (
0996         const   unsigned long   toFormat
0997         ,       char* const     toFill
0998         , const XMLSize_t       maxChars
0999         , const unsigned int    radix
1000         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
1001     );
1002 
1003     /** Converts binary data to a text string based a given radix
1004       *
1005       * @param toFormat The number to convert
1006       * @param toFill The buffer that will hold the output on return. The
1007       *        size of this buffer should at least be 'maxChars + 1'.
1008       * @param maxChars The maximum number of output characters that can be
1009       *         accepted. If the result will not fit, it is an error.
1010       * @param radix The radix of the input data, based on which the conversion
1011       * @param manager The MemoryManager to use to allocate objects
1012       * will be done
1013       */
1014     static void binToText
1015     (
1016         const   unsigned long   toFormat
1017         ,       XMLCh* const    toFill
1018         , const XMLSize_t       maxChars
1019         , const unsigned int    radix
1020         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
1021     );
1022 
1023     /** Converts binary data to a text string based a given radix
1024       *
1025       * @param toFormat The number to convert
1026       * @param toFill The buffer that will hold the output on return. The
1027       *        size of this buffer should at least be 'maxChars + 1'.
1028       * @param maxChars The maximum number of output characters that can be
1029       *         accepted. If the result will not fit, it is an error.
1030       * @param radix The radix of the input data, based on which the conversion
1031       * @param manager The MemoryManager to use to allocate objects
1032       * will be done
1033       */
1034     static void binToText
1035     (
1036         const   int             toFormat
1037         ,       char* const     toFill
1038         , const XMLSize_t       maxChars
1039         , const unsigned int    radix
1040         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
1041     );
1042 
1043     /** Converts binary data to a text string based a given radix
1044       *
1045       * @param toFormat The number to convert
1046       * @param toFill The buffer that will hold the output on return. The
1047       *        size of this buffer should at least be 'maxChars + 1'.
1048       * @param maxChars The maximum number of output characters that can be
1049       *         accepted. If the result will not fit, it is an error.
1050       * @param radix The radix of the input data, based on which the conversion
1051       * @param manager The MemoryManager to use to allocate objects
1052       * will be done
1053       */
1054     static void binToText
1055     (
1056         const   int             toFormat
1057         ,       XMLCh* const    toFill
1058         , const XMLSize_t       maxChars
1059         , const unsigned int    radix
1060         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
1061     );
1062 
1063     /** Converts binary data to a text string based a given radix
1064       *
1065       * @param toFormat The number to convert
1066       * @param toFill The buffer that will hold the output on return. The
1067       *        size of this buffer should at least be 'maxChars + 1'.
1068       * @param maxChars The maximum number of output characters that can be
1069       *         accepted. If the result will not fit, it is an error.
1070       * @param radix The radix of the input data, based on which the conversion
1071       * @param manager The MemoryManager to use to allocate objects
1072       * will be done
1073       */
1074     static void binToText
1075     (
1076         const   long            toFormat
1077         ,       char* const     toFill
1078         , const XMLSize_t       maxChars
1079         , const unsigned int    radix
1080         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
1081     );
1082 
1083     /** Converts binary data to a text string based a given radix
1084       *
1085       * @param toFormat The number to convert
1086       * @param toFill The buffer that will hold the output on return. The
1087       *        size of this buffer should at least be 'maxChars + 1'.
1088       * @param maxChars The maximum number of output characters that can be
1089       *         accepted. If the result will not fit, it is an error.
1090       * @param radix The radix of the input data, based on which the conversion
1091       * @param manager The MemoryManager to use to allocate objects
1092       * will be done
1093       */
1094     static void binToText
1095     (
1096         const   long            toFormat
1097         ,       XMLCh* const    toFill
1098         , const XMLSize_t       maxChars
1099         , const unsigned int    radix
1100         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
1101     );
1102 
1103     /**
1104       * Converts a string of decimal chars to a binary value
1105       *
1106       * Note that leading and trailing whitespace is legal and will be ignored
1107       * but the remainder must be all decimal digits.
1108       *
1109       * @param toConvert The string of digits to convert
1110       * @param toFill    The unsigned int value to fill with the converted
1111       *                  value.
1112       * @param manager The MemoryManager to use to allocate objects
1113       */
1114     static bool textToBin
1115     (
1116         const   XMLCh* const    toConvert
1117         ,       unsigned int&   toFill
1118         ,       MemoryManager*  const manager = XMLPlatformUtils::fgMemoryManager
1119     );
1120 
1121     /**
1122       * Converts a string of decimal chars to a binary value
1123       *
1124       * Note that leading and trailing whitespace is legal and will be ignored,
1125       *
1126       * Only one and either of (+,-) after the leading whitespace, before
1127       * any other characters are allowed.
1128       *
1129       * but the remainder must be all decimal digits.
1130       *
1131       * @param toConvert The string of digits to convert
1132       * @param manager The MemoryManager to use to allocate objects
1133       */
1134     static int parseInt
1135     (
1136         const   XMLCh* const    toConvert
1137       , MemoryManager* const    manager = XMLPlatformUtils::fgMemoryManager
1138     );
1139 
1140     /** Cut leading chars from a string
1141       *
1142       * @param toCutFrom The string to cut chars from
1143       * @param count     The count of leading chars to cut
1144       */
1145     static void cut
1146     (
1147                 XMLCh* const    toCutFrom
1148         , const XMLSize_t       count
1149     );
1150 
1151     /** Transcodes a string to native code-page
1152       *
1153       * NOTE: The returned buffer is dynamically allocated and is the
1154       * responsibility of the caller to delete it when not longer needed.
1155       * You can call XMLString::release to release this returned buffer.
1156       *
1157       * @param toTranscode The string to be transcoded
1158       * @param manager The MemoryManager to use to allocate objects
1159       * @return Returns the transcoded string
1160       * @see   XMLString::release(XMLCh**, MemoryManager*)
1161       */
1162     static char* transcode
1163     (
1164         const   XMLCh* const         toTranscode
1165         ,       MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
1166     );
1167 
1168     /** Transcodes a string to native code-page (DEPRECATED)
1169       *
1170       * Be aware that when transcoding to an external encoding, that each
1171       * Unicode char can create multiple output bytes. So you cannot assume
1172       * a one to one correspondence of input chars to output bytes.
1173       *
1174       * @param toTranscode The string tobe transcoded
1175       * @param toFill The buffer that is filled with the transcoded value.
1176       *        The size of this buffer should atleast be 'maxChars + 1'.
1177       * @param maxChars The maximum number of bytes that the output
1178       *         buffer can hold (not including the null, which is why
1179       *         toFill should be at least maxChars+1.).
1180       * @param manager The MemoryManager to use to allocate objects
1181       * @return Returns true if successful, false if there was an error
1182       */
1183     static bool transcode
1184     (
1185         const   XMLCh* const    toTranscode
1186         ,       char* const     toFill
1187         , const XMLSize_t       maxChars
1188         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
1189     );
1190 
1191     /** Transcodes a string to native code-page
1192       *
1193       * NOTE: The returned buffer is dynamically allocated and is the
1194       * responsibility of the caller to delete it when not longer needed.
1195       * You can call XMLString::release to release this returned buffer.
1196       *
1197       * @param toTranscode The string to be transcoded
1198       * @param manager The MemoryManager to use to allocate objects
1199       * @return Returns the transcoded string
1200       * @see   XMLString::release(char**, MemoryManager*)
1201       */
1202     static XMLCh* transcode
1203     (
1204         const   char* const          toTranscode
1205         ,       MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
1206     );
1207 
1208     /** Transcodes a string to native code-page (DEPRECATED)
1209       * @param toTranscode The string tobe transcoded
1210       * @param toFill The buffer that is filled with the transcoded value.
1211       *        The size of this buffer should atleast be 'maxChars + 1'.
1212       * @param maxChars The maximum number of characters that the output
1213       *         buffer can hold (not including the null, which is why
1214       *         toFill should be at least maxChars+1.).
1215       * @param manager The MemoryManager to use to allocate objects
1216       * @return Returns true if successful, false if there was an error
1217       */
1218     static bool transcode
1219     (
1220         const   char* const     toTranscode
1221         ,       XMLCh* const    toFill
1222         , const XMLSize_t       maxChars
1223         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
1224     );
1225 
1226     /** Trims off extra space characters from the start and end of the string,
1227       * moving the non-space string content back to the start.
1228       * @param toTrim The string to be trimmed. On return this contains the
1229       * trimmed string
1230       */
1231     static void trim(char* const toTrim);
1232 
1233     /** Trims off extra space characters from the start and end of the string,
1234       * moving the non-space string content back to the start.
1235       * @param toTrim The string to be trimmed. On return this contains
1236       * the trimmed string
1237       */
1238     static void trim(XMLCh* const toTrim);
1239 
1240     /** Break a string into tokens with space as delimiter, and
1241       * stored in a string vector.  The caller owns the string vector
1242       * that is returned, and is responsible for deleting it.
1243       * @param tokenizeSrc String to be tokenized
1244       * @param manager The MemoryManager to use to allocate objects
1245       * @return a vector of all the tokenized string
1246       */
1247     static BaseRefVectorOf<XMLCh>* tokenizeString(const XMLCh* const tokenizeSrc
1248                                         , MemoryManager*       const manager = XMLPlatformUtils::fgMemoryManager);
1249 
1250     /** Break a string into tokens with the given character as delimiter, and
1251       * stored in a string vector.  The caller owns the string vector
1252       * that is returned, and is responsible for deleting it.
1253       * @param tokenizeSrc String to be tokenized
1254       * @param delimiter Delimiter character 
1255       * @param manager The MemoryManager to use to allocate objects
1256       * @return a vector of all the tokenized string
1257       */
1258     static BaseRefVectorOf<XMLCh>* tokenizeString(const XMLCh* const tokenizeSrc
1259                                         , XMLCh delimiter
1260                                         , MemoryManager*       const manager = XMLPlatformUtils::fgMemoryManager);
1261     //@}
1262 
1263     /** @name Formatting functions */
1264     //@{
1265     /** Creates a UName from a URI and base name. It is in the form
1266       * {url}name, and is commonly used internally to represent fully
1267       * qualified names when namespaces are enabled.
1268       *
1269       * @param pszURI The URI part of the name
1270       * @param pszName The base part of the name
1271       * @return Returns the complete formatted UName
1272       */
1273     static XMLCh* makeUName
1274     (
1275         const   XMLCh* const    pszURI
1276         , const XMLCh* const    pszName
1277     );
1278 
1279     /**
1280       * Internal function to perform token replacement for strings.
1281       *
1282       * @param errText The text (NULL terminated) where the replacement
1283       *        is to be done. The size of this buffer should be
1284       *        'maxChars + 1' to account for the final NULL.
1285       * @param maxChars The size of the output buffer, i.e. the maximum
1286       *         number of characters that it will hold. If the result is
1287       *         larger, it will be truncated.
1288       * @param text1 Replacement text-one
1289       * @param text2 Replacement text-two
1290       * @param text3 Replacement text-three
1291       * @param text4 Replacement text-four
1292       * @param manager The MemoryManager to use to allocate objects
1293       * @return Returns the count of characters that are outputted
1294       */
1295     static XMLSize_t replaceTokens
1296     (
1297                 XMLCh* const    errText
1298         , const XMLSize_t       maxChars
1299         , const XMLCh* const    text1
1300         , const XMLCh* const    text2
1301         , const XMLCh* const    text3
1302         , const XMLCh* const    text4
1303         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
1304     );
1305 
1306     /** Converts a string to uppercase
1307       * @param toUpperCase The string which needs to be converted to uppercase.
1308       *        On return, this buffer also holds the converted uppercase string
1309       */
1310     static void upperCase(XMLCh* const toUpperCase);
1311 
1312     /** Converts a string to uppercase
1313       * The routine only uppercases A to Z (other characters not changed).
1314       * @param toUpperCase The string which needs to be converted to uppercase.
1315       *        On return, this buffer also holds the converted uppercase string
1316       */
1317     static void upperCaseASCII(XMLCh* const toUpperCase);
1318 
1319     /** Converts a string to lowercase
1320       * @param toLowerCase The string which needs to be converted to lowercase.
1321       *        On return, this buffer also holds the converted lowercase string
1322       */
1323     static void lowerCase(XMLCh* const toLowerCase);
1324 
1325     /** Converts a string to lowercase
1326       * The routine only lowercases a to z (other characters not changed).
1327       * @param toLowerCase The string which needs to be converted to lowercase.
1328       *        On return, this buffer also holds the converted lowercase string
1329       */
1330     static void lowerCaseASCII(XMLCh* const toLowerCase);
1331 
1332     /** Check if string is WhiteSpace:replace
1333       * @param toCheck The string which needs to be checked.
1334       */
1335     static bool isWSReplaced(const XMLCh* const toCheck);
1336 
1337     /** Check if string is WhiteSpace:collapse
1338       * @param toCheck The string which needs to be checked.
1339       */
1340     static bool isWSCollapsed(const XMLCh* const toCheck);
1341 
1342     /** Replace whitespace
1343       * @param toConvert The string which needs to be whitespace replaced.
1344       *        On return , this buffer also holds the converted string
1345       * @param manager The MemoryManager to use to allocate objects
1346       */
1347     static void replaceWS(XMLCh* toConvert
1348         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager);
1349 
1350     /** Collapse whitespace
1351       * @param toConvert The string which needs to be whitespace collapsed.
1352       *        On return , this buffer also holds the converted string
1353       * @param manager The MemoryManager to use to allocate objects
1354       */
1355     static void collapseWS(XMLCh* toConvert
1356         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager);
1357 
1358     /** Remove whitespace
1359       * @param toConvert The string which needs to be whitespace removed.
1360       *        On return , this buffer also holds the converted string
1361       * @param manager The MemoryManager to use to allocate objects
1362       */
1363     static void removeWS(XMLCh* toConvert
1364     , MemoryManager*       const manager = XMLPlatformUtils::fgMemoryManager);
1365 
1366 
1367     /** Remove character
1368       * @param srcString The string
1369       * @param toRemove  The character needs to be removed from the string
1370       * @param dstBuffer The buffer containing the result
1371       */
1372     static void removeChar(const XMLCh*     const srcString
1373                          , const XMLCh&           toRemove
1374                          ,       XMLBuffer&       dstBuffer);
1375 
1376     /**
1377      * Fixes a platform dependent absolute path filename to standard URI form.
1378      * 1. Windows: fix 'x:' to 'file:///x:' and convert any backslash to forward slash
1379      * 2. UNIX: fix '/blah/blahblah' to 'file:///blah/blahblah'
1380      * @param str    The string that has the absolute path filename
1381      * @param target The target string pre-allocated to store the fixed uri
1382      */
1383     static void fixURI(const XMLCh* const str, XMLCh* const target);
1384 
1385     //@}
1386     /** @name String Memory Management functions */
1387     //@{
1388     /**
1389      * Release the parameter string that was allocated by XMLString::transcode and XMLString::replicate.
1390      * The implementation will call MemoryManager::deallocate and then turn the string to a null pointer.
1391      *
1392      * @param buf  The string to be deleted and become a null pointer.
1393      * @param manager The MemoryManager used to allocate the string
1394      */
1395     static void release
1396     (
1397         char**  buf
1398         ,       MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
1399     );
1400 
1401     /**
1402      * Release the parameter string that was allocated by XMLString::transcode and XMLString::replicate.
1403      * The implementation will call MemoryManager::deallocate and then turn the string to a null pointer.
1404      *
1405      * @param buf  The string to be deleted and become a null pointer.
1406      * @param manager The MemoryManager used to allocate the string
1407      */
1408     static void release
1409     (
1410         XMLCh**  buf
1411         ,       MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
1412     );
1413     //@}
1414 
1415 
1416 private :
1417 
1418     /** @name Constructors and Destructor */
1419     //@{
1420     /** Unimplemented default constructor */
1421     XMLString();
1422     /** Unimplemented destructor */
1423     ~XMLString();
1424     //@}
1425 
1426 
1427     /** @name Initialization */
1428     //@{
1429     /** Init/Term methods called from XMLPlatformUtils class */
1430     static void initString(XMLLCPTranscoder* const defToUse,
1431                            MemoryManager* const manager);
1432     static void termString();
1433     //@}
1434 
1435     /**
1436       * Called by regionMatches/regionIMatches to validate that we
1437       * have a valid input
1438       */
1439     static bool validateRegion(const XMLCh* const str1, const int offset1,
1440                         const XMLCh* const str2, const int offset2,
1441                         const XMLSize_t charCount);
1442 
1443     static MemoryManager* fgMemoryManager;
1444 
1445     friend class XMLPlatformUtils;
1446 };
1447 
1448 
1449 // ---------------------------------------------------------------------------
1450 //  Inline some methods that are either just passthroughs to other string
1451 //  methods, or which are key for performance.
1452 // ---------------------------------------------------------------------------
1453 inline void XMLString::moveChars(       XMLCh* const targetStr
1454                                 , const XMLCh* const srcStr
1455                                 , const XMLSize_t    count)
1456 {
1457     memmove(targetStr, srcStr, count * sizeof(XMLCh));
1458 }
1459 
1460 inline XMLSize_t XMLString::stringLen(const XMLCh* const src)
1461 {
1462     if (src == 0)
1463         return 0;
1464 
1465     const XMLCh* pszTmp = src;
1466 
1467     while (*pszTmp++) ;
1468 
1469     return (pszTmp - src - 1);
1470 }
1471 
1472 inline XMLCh* XMLString::replicate(const XMLCh* const toRep,
1473                                    MemoryManager* const manager)
1474 {
1475     // If a null string, return a null string!
1476     XMLCh* ret = 0;
1477     if (toRep)
1478     {
1479         const XMLSize_t len = stringLen(toRep);
1480         ret = (XMLCh*) manager->allocate((len+1) * sizeof(XMLCh)); //new XMLCh[len + 1];
1481         memcpy(ret, toRep, (len + 1) * sizeof(XMLCh));
1482     }
1483     return ret;
1484 }
1485 
1486 inline bool XMLString::startsWith(  const   XMLCh* const    toTest
1487                                     , const XMLCh* const    prefix)
1488 {
1489     return (compareNString(toTest, prefix, stringLen(prefix)) == 0);
1490 }
1491 
1492 inline bool XMLString::startsWithI( const   XMLCh* const    toTest
1493                                     , const XMLCh* const    prefix)
1494 {
1495     return (compareNIString(toTest, prefix, stringLen(prefix)) == 0);
1496 }
1497 
1498 inline bool XMLString::endsWith(const XMLCh* const toTest,
1499                                 const XMLCh* const suffix)
1500 {
1501 
1502     XMLSize_t suffixLen = XMLString::stringLen(suffix);
1503 
1504     return regionMatches(toTest, (int)(XMLString::stringLen(toTest) - suffixLen),
1505                          suffix, 0, suffixLen);
1506 }
1507 
1508 inline bool XMLString::validateRegion(const XMLCh* const str1,
1509                                       const int offset1,
1510                                       const XMLCh* const str2,
1511                                       const int offset2,
1512                                       const XMLSize_t charCount)
1513 {
1514 
1515     if (offset1 < 0 || offset2 < 0 ||
1516         (offset1 + charCount) > XMLString::stringLen(str1) ||
1517         (offset2 + charCount) > XMLString::stringLen(str2) )
1518         return false;
1519 
1520     return true;
1521 }
1522 
1523 inline bool XMLString::equals(   const XMLCh* str1
1524                                , const XMLCh* str2)
1525 {
1526     if (str1 == str2)
1527         return true;
1528 
1529     if (str1 == 0 || str2 == 0)
1530         return ((!str1 || !*str1) && (!str2 || !*str2));
1531 
1532     while (*str1)
1533         if(*str1++ != *str2++)  // they are different (or str2 is shorter and we hit the NULL)
1534             return false;
1535 
1536     // either both ended (and *str2 is 0 too), or str2 is longer
1537     return (*str2==0);
1538 }
1539 
1540 inline bool XMLString::equalsN(const XMLCh* str1,
1541                                const XMLCh* str2,
1542                                XMLSize_t n)
1543 {
1544     if (str1 == str2 || n == 0)
1545       return true;
1546 
1547     if (str1 == 0 || str2 == 0)
1548         return ((!str1 || !*str1) && (!str2 || !*str2));
1549 
1550     for (; n != 0 && *str1 && *str2; --n, ++str1, ++str2)
1551       if(*str1 != *str2)
1552         break;
1553 
1554     return n == 0 || *str1 == *str2; // either equal or both ended premat.
1555 }
1556 
1557 inline bool XMLString::equals(   const char* str1
1558                                , const char* str2)
1559 {
1560     if (str1 == str2)
1561         return true;
1562 
1563     if (str1 == 0 || str2 == 0)
1564         return ((!str1 || !*str1) && (!str2 || !*str2));
1565 
1566     while (*str1)
1567         if(*str1++ != *str2++)  // they are different (or str2 is shorter and we hit the NULL)
1568             return false;
1569 
1570     // either both ended (and *str2 is 0 too), or str2 is longer
1571     return (*str2==0);
1572 }
1573 
1574 inline bool XMLString::equalsN(const char* str1,
1575                                const char* str2,
1576                                XMLSize_t n)
1577 {
1578     if (str1 == str2 || n == 0)
1579       return true;
1580 
1581     if (str1 == 0 || str2 == 0)
1582         return ((!str1 || !*str1) && (!str2 || !*str2));
1583 
1584     for (; n != 0 && *str1 && *str2; --n, ++str1, ++str2)
1585       if(*str1 != *str2)
1586         break;
1587 
1588     return n == 0 || *str1 == *str2; // either equal or both ended premat.
1589 }
1590 
1591 inline int XMLString::lastIndexOf(const XMLCh* const toSearch, const XMLCh ch)
1592 {
1593     return XMLString::lastIndexOf(ch, toSearch, stringLen(toSearch));
1594 }
1595 
1596 inline XMLSize_t XMLString::hash(const   XMLCh* const   tohash
1597                                 , const XMLSize_t          hashModulus)
1598 {
1599     if (tohash == 0 || *tohash == 0)
1600         return 0;
1601 
1602     const XMLCh* curCh = tohash;
1603     XMLSize_t hashVal = (XMLSize_t)(*curCh++);
1604 
1605     while (*curCh)
1606         hashVal = (hashVal * 38) + (hashVal >> 24) + (XMLSize_t)(*curCh++);
1607 
1608     // Divide by modulus
1609     return hashVal % hashModulus;
1610 }
1611 
1612 inline XMLSize_t XMLString::hashN(const   XMLCh* const   tohash
1613                                   , const XMLSize_t       n
1614                                   , const XMLSize_t       hashModulus)
1615 {
1616   if (tohash == 0 || n == 0)
1617     return 0;
1618 
1619   const XMLCh* curCh = tohash;
1620   XMLSize_t hashVal = (XMLSize_t)(*curCh++);
1621 
1622   for(XMLSize_t i=0;i<n;i++)
1623     hashVal = (hashVal * 38) + (hashVal >> 24) + (XMLSize_t)(*curCh++);
1624 
1625   // Divide by modulus
1626   return hashVal % hashModulus;
1627 }
1628 
1629 XERCES_CPP_NAMESPACE_END
1630 
1631 #endif