XMLString.hpp

Go to the documentation of this file.
00001 /*
00002  * Licensed to the Apache Software Foundation (ASF) under one or more
00003  * contributor license agreements.  See the NOTICE file distributed with
00004  * this work for additional information regarding copyright ownership.
00005  * The ASF licenses this file to You under the Apache License, Version 2.0
00006  * (the "License"); you may not use this file except in compliance with
00007  * the License.  You may obtain a copy of the License at
00008  *
00009  *      http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 
00018 /*
00019  * $Id: XMLString.hpp 698579 2008-09-24 14:13:08Z borisk $
00020  */
00021 
00022 #if !defined(XERCESC_INCLUDE_GUARD_XMLSTRING_HPP)
00023 #define XERCESC_INCLUDE_GUARD_XMLSTRING_HPP
00024 
00025 #include <xercesc/util/BaseRefVectorOf.hpp>
00026 #include <xercesc/framework/XMLBuffer.hpp>
00027 #include <xercesc/framework/MemoryManager.hpp>
00028 #include <string.h>
00029 #include <assert.h>
00030 
00031 XERCES_CPP_NAMESPACE_BEGIN
00032 
00033 class XMLLCPTranscoder;
00045 class XMLUTIL_EXPORT XMLString
00046 {
00047 public:
00048     /* Static methods for native character mode string manipulation */
00049 
00050 
00067     static void catString
00068     (
00069                 char* const     target
00070         , const char* const     src
00071     );
00072 
00085     static void catString
00086     (
00087                 XMLCh* const    target
00088         , const XMLCh* const    src
00089     );
00091 
00105     static int compareIString
00106     (
00107         const   char* const     str1
00108         , const char* const     str2
00109     );
00110 
00121     static int compareIString
00122     (
00123         const   XMLCh* const    str1
00124         , const XMLCh* const    str2
00125     );
00126 
00138     static int compareIStringASCII
00139     (
00140         const   XMLCh* const    str1
00141         , const XMLCh* const    str2
00142     );
00143 
00144 
00145 
00159     static int compareNString
00160     (
00161         const   char* const     str1
00162         , const char* const     str2
00163         , const XMLSize_t       count
00164     );
00165 
00179     static int compareNString
00180     (
00181         const   XMLCh* const    str1
00182         , const XMLCh* const    str2
00183         , const XMLSize_t       count
00184     );
00185 
00186 
00200     static int compareNIString
00201     (
00202         const   char* const     str1
00203         , const char* const     str2
00204         , const XMLSize_t       count
00205     );
00206 
00221     static int compareNIString
00222     (
00223         const   XMLCh* const    str1
00224         , const XMLCh* const    str2
00225         , const XMLSize_t       count
00226     );
00227 
00240     static int compareString
00241     (
00242         const   char* const     str1
00243         , const char* const     str2
00244     );
00245 
00257     static int compareString
00258     (
00259         const   XMLCh* const    str1
00260         , const XMLCh* const    str2
00261     );
00262 
00271     static bool equals
00272     (
00273           const XMLCh* str1
00274         , const XMLCh* str2
00275     );
00276 
00286     static bool equalsN
00287     (
00288           const XMLCh* str1
00289         , const XMLCh* str2
00290         , XMLSize_t n
00291     );
00292 
00293     static bool equals
00294     (
00295           const char* str1
00296         , const char* str2
00297     );
00298 
00308     static bool equalsN
00309     (
00310           const char* str1
00311         , const char* str2
00312         , XMLSize_t n
00313     );
00314 
00341     static bool regionMatches
00342     (
00343         const   XMLCh* const    str1
00344         , const int             offset1
00345         , const XMLCh* const    str2
00346         , const int             offset2
00347         , const XMLSize_t       charCount
00348     );
00349 
00377     static bool regionIMatches
00378     (
00379         const   XMLCh* const    str1
00380         , const int             offset1
00381         , const XMLCh* const    str2
00382         , const int             offset2
00383         , const XMLSize_t       charCount
00384     );
00386 
00399     static void copyString
00400     (
00401                 char* const     target
00402         , const char* const     src
00403     );
00404 
00415     static void copyString
00416     (
00417                 XMLCh* const    target
00418         , const XMLCh* const    src
00419     );
00420 
00433     static bool copyNString
00434     (
00435                 XMLCh* const    target
00436         , const XMLCh* const    src
00437         , const XMLSize_t       maxChars
00438     );
00440 
00449     static XMLSize_t hash
00450     (
00451         const   char* const     toHash
00452         , const XMLSize_t       hashModulus
00453     );
00454 
00461     static XMLSize_t hash
00462     (
00463         const   XMLCh* const    toHash
00464         , const XMLSize_t       hashModulus
00465     );
00466 
00475     static XMLSize_t hashN
00476     (
00477         const   XMLCh* const    toHash
00478         , const XMLSize_t       numChars
00479         , const XMLSize_t       hashModulus
00480     );
00481 
00483 
00494     static int indexOf(const char* const toSearch, const char ch);
00495 
00504     static int indexOf(const XMLCh* const toSearch, const XMLCh ch);
00505 
00517     static int indexOf
00518     (
00519         const   char* const     toSearch
00520         , const char            chToFind
00521         , const XMLSize_t       fromIndex
00522         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
00523     );
00524 
00536     static int indexOf
00537     (
00538         const   XMLCh* const    toSearch
00539         , const XMLCh           chToFind
00540         , const XMLSize_t       fromIndex
00541         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
00542     );
00543 
00552     static int lastIndexOf(const char* const toSearch, const char ch);
00553 
00562     static int lastIndexOf(const XMLCh* const toSearch, const XMLCh ch);
00563 
00573     static int lastIndexOf
00574     (
00575         const XMLCh ch
00576         , const XMLCh* const toSearch
00577         , const XMLSize_t    toSearchLen
00578     );
00579 
00591     static int lastIndexOf
00592     (
00593         const   char* const     toSearch
00594         , const char            chToFind
00595         , const XMLSize_t       fromIndex
00596         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
00597     );
00598 
00610     static int lastIndexOf
00611     (
00612         const   XMLCh* const    toSearch
00613         , const XMLCh           ch
00614         , const XMLSize_t       fromIndex
00615         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
00616     );
00618 
00626     static void moveChars
00627     (
00628                 XMLCh* const    targetStr
00629         , const XMLCh* const    srcStr
00630         , const XMLSize_t       count
00631     );
00632 
00634 
00646     static void subString
00647     (
00648                 char* const    targetStr
00649         , const char* const    srcStr
00650         , const XMLSize_t      startIndex
00651         , const XMLSize_t      endIndex
00652         , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00653     );
00654 
00664     static void subString
00665     (
00666                 XMLCh* const    targetStr
00667         , const XMLCh* const    srcStr
00668         , const XMLSize_t       startIndex
00669         , const XMLSize_t       endIndex
00670         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
00671     );
00672 
00683     static void subString
00684     (
00685                 XMLCh* const    targetStr
00686         , const XMLCh* const    srcStr
00687         , const XMLSize_t       startIndex
00688         , const XMLSize_t       endIndex
00689         , const XMLSize_t       srcStrLength
00690         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
00691     );
00692 
00694 
00707     static char* replicate(const char* const toRep,
00708                            MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00709 
00720     static XMLCh* replicate(const XMLCh* const toRep,
00721                             MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00722 
00724 
00733     static bool startsWith
00734     (
00735         const   char* const     toTest
00736         , const char* const     prefix
00737     );
00738 
00745     static bool startsWith
00746     (
00747         const   XMLCh* const    toTest
00748         , const XMLCh* const    prefix
00749     );
00750 
00759     static bool startsWithI
00760     (
00761         const   char* const     toTest
00762         , const char* const     prefix
00763     );
00764 
00774     static bool startsWithI
00775     (
00776         const   XMLCh* const    toTest
00777         , const XMLCh* const    prefix
00778     );
00779 
00786     static bool endsWith
00787     (
00788         const   XMLCh* const    toTest
00789         , const XMLCh* const    suffix
00790     );
00791 
00792 
00801     static const XMLCh* findAny
00802     (
00803         const   XMLCh* const    toSearch
00804         , const XMLCh* const    searchList
00805     );
00806 
00815     static XMLCh* findAny
00816     (
00817                 XMLCh* const    toSearch
00818         , const XMLCh* const    searchList
00819     );
00820 
00827     static int patternMatch
00828     (
00829           const XMLCh* const    toSearch
00830         , const XMLCh* const    pattern
00831     );
00832 
00837     static XMLSize_t stringLen(const char* const src);
00838 
00843     static XMLSize_t stringLen(const XMLCh* const src);
00844 
00852     static bool isValidNOTATION(const XMLCh*         const name
00853                               ,       MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00854 
00860     static bool isValidEncName(const XMLCh* const name);
00861 
00868     static bool isAlpha(XMLCh const theChar);
00869 
00875     static bool isDigit(XMLCh const theChar);
00876 
00882     static bool isAlphaNum(XMLCh const theChar);
00883 
00889     static bool isHex(XMLCh const theChar);
00890 
00896     static bool isInList(const XMLCh* const toFind, const XMLCh* const enumList);
00897 
00899 
00902 
00914     static void sizeToText
00915     (
00916         const   XMLSize_t           toFormat
00917         ,       char* const         toFill
00918         , const XMLSize_t           maxChars
00919         , const unsigned int        radix
00920         , MemoryManager* const      manager = XMLPlatformUtils::fgMemoryManager
00921     );
00922 
00934     static void sizeToText
00935     (
00936         const   XMLSize_t           toFormat
00937         ,       XMLCh* const        toFill
00938         , const XMLSize_t           maxChars
00939         , const unsigned int        radix
00940         , MemoryManager* const      manager = XMLPlatformUtils::fgMemoryManager
00941     );
00942 
00954     static void binToText
00955     (
00956         const   unsigned int    toFormat
00957         ,       char* const     toFill
00958         , const XMLSize_t       maxChars
00959         , const unsigned int    radix
00960         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
00961     );
00962 
00974     static void binToText
00975     (
00976         const   unsigned int    toFormat
00977         ,       XMLCh* const    toFill
00978         , const XMLSize_t       maxChars
00979         , const unsigned int    radix
00980         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
00981     );
00982 
00994     static void binToText
00995     (
00996         const   unsigned long   toFormat
00997         ,       char* const     toFill
00998         , const XMLSize_t       maxChars
00999         , const unsigned int    radix
01000         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
01001     );
01002 
01014     static void binToText
01015     (
01016         const   unsigned long   toFormat
01017         ,       XMLCh* const    toFill
01018         , const XMLSize_t       maxChars
01019         , const unsigned int    radix
01020         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
01021     );
01022 
01023 #if XERCES_SIZEOF_INT != 8 && XERCES_SIZEOF_LONG != 8 && XERCES_SIZEOF_INT64 != 4
01024 
01035     static void binToText
01036     (
01037         const   XMLUInt64           toFormat
01038         ,       char* const         toFill
01039         , const XMLSize_t           maxChars
01040         , const unsigned int        radix
01041         , MemoryManager* const      manager = XMLPlatformUtils::fgMemoryManager
01042     );
01043 
01055     static void binToText
01056     (
01057         const   XMLUInt64           toFormat
01058         ,       XMLCh* const        toFill
01059         , const XMLSize_t           maxChars
01060         , const unsigned int        radix
01061         , MemoryManager* const      manager = XMLPlatformUtils::fgMemoryManager
01062     );
01063 #endif // XERCES_SIZEOF_INT != 8 && XERCES_SIZEOF_LONG != 8 && XERCES_SIZEOF_INT64 != 4
01064 
01076     static void binToText
01077     (
01078         const   int             toFormat
01079         ,       char* const     toFill
01080         , const XMLSize_t       maxChars
01081         , const unsigned int    radix
01082         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
01083     );
01084 
01096     static void binToText
01097     (
01098         const   int             toFormat
01099         ,       XMLCh* const    toFill
01100         , const XMLSize_t       maxChars
01101         , const unsigned int    radix
01102         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
01103     );
01104 
01116     static void binToText
01117     (
01118         const   long            toFormat
01119         ,       char* const     toFill
01120         , const XMLSize_t       maxChars
01121         , const unsigned int    radix
01122         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
01123     );
01124 
01136     static void binToText
01137     (
01138         const   long            toFormat
01139         ,       XMLCh* const    toFill
01140         , const XMLSize_t       maxChars
01141         , const unsigned int    radix
01142         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
01143     );
01144 
01145 #if XERCES_SIZEOF_INT != 8 && XERCES_SIZEOF_LONG != 8 && XERCES_SIZEOF_INT64 != 4
01146 
01157     static void binToText
01158     (
01159         const   XMLInt64        toFormat
01160         ,       char* const     toFill
01161         , const XMLSize_t       maxChars
01162         , const unsigned int    radix
01163         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
01164     );
01165 
01177     static void binToText
01178     (
01179         const   XMLInt64        toFormat
01180         ,       XMLCh* const    toFill
01181         , const XMLSize_t       maxChars
01182         , const unsigned int    radix
01183         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
01184     );
01185 #endif // XERCES_SIZEOF_INT != 8 && XERCES_SIZEOF_LONG != 8 && XERCES_SIZEOF_INT64 != 4
01186 
01198     static bool textToBin
01199     (
01200         const   XMLCh* const    toConvert
01201         ,       unsigned int&   toFill
01202         ,       MemoryManager*  const manager = XMLPlatformUtils::fgMemoryManager
01203     );
01204 
01218     static int parseInt
01219     (
01220         const   XMLCh* const    toConvert
01221       , MemoryManager* const    manager = XMLPlatformUtils::fgMemoryManager
01222     );
01223 
01229     static void cut
01230     (
01231                 XMLCh* const    toCutFrom
01232         , const XMLSize_t       count
01233     );
01234 
01246     static char* transcode
01247     (
01248         const   XMLCh* const         toTranscode
01249         ,       MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
01250     );
01251 
01267     static bool transcode
01268     (
01269         const   XMLCh* const    toTranscode
01270         ,       char* const     toFill
01271         , const XMLSize_t       maxChars
01272         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
01273     );
01274 
01286     static XMLCh* transcode
01287     (
01288         const   char* const          toTranscode
01289         ,       MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
01290     );
01291 
01302     static bool transcode
01303     (
01304         const   char* const     toTranscode
01305         ,       XMLCh* const    toFill
01306         , const XMLSize_t       maxChars
01307         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
01308     );
01309 
01315     static void trim(char* const toTrim);
01316 
01322     static void trim(XMLCh* const toTrim);
01323 
01331     static BaseRefVectorOf<XMLCh>* tokenizeString(const XMLCh* const tokenizeSrc
01332                                         , MemoryManager*       const manager = XMLPlatformUtils::fgMemoryManager);
01333 
01335 
01346     static XMLCh* makeUName
01347     (
01348         const   XMLCh* const    pszURI
01349         , const XMLCh* const    pszName
01350     );
01351 
01368     static XMLSize_t replaceTokens
01369     (
01370                 XMLCh* const    errText
01371         , const XMLSize_t       maxChars
01372         , const XMLCh* const    text1
01373         , const XMLCh* const    text2
01374         , const XMLCh* const    text3
01375         , const XMLCh* const    text4
01376         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
01377     );
01378 
01383     static void upperCase(XMLCh* const toUpperCase);
01384 
01390     static void upperCaseASCII(XMLCh* const toUpperCase);
01391 
01396     static void lowerCase(XMLCh* const toLowerCase);
01397 
01403     static void lowerCaseASCII(XMLCh* const toLowerCase);
01404 
01408     static bool isWSReplaced(const XMLCh* const toCheck);
01409 
01413     static bool isWSCollapsed(const XMLCh* const toCheck);
01414 
01420     static void replaceWS(XMLCh* const toConvert
01421         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager);
01422 
01428     static void collapseWS(XMLCh* const toConvert
01429         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager);
01430 
01436     static void removeWS(XMLCh* const toConvert
01437     , MemoryManager*       const manager = XMLPlatformUtils::fgMemoryManager);
01438 
01439 
01445     static void removeChar(const XMLCh*     const srcString
01446                          , const XMLCh&           toRemove
01447                          ,       XMLBuffer&       dstBuffer);
01448 
01456     static void fixURI(const XMLCh* const str, XMLCh* const target);
01457 
01459 
01468     static void release
01469     (
01470         char**  buf
01471         ,       MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
01472     );
01473 
01481     static void release
01482     (
01483         XMLCh**  buf
01484         ,       MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
01485     );
01487 
01488 
01489 private :
01490 
01494     XMLString();
01496     ~XMLString();
01498 
01499 
01503     static void initString(XMLLCPTranscoder* const defToUse,
01504                            MemoryManager* const manager);
01505     static void termString();
01507 
01512     static bool validateRegion(const XMLCh* const str1, const int offset1,
01513                         const XMLCh* const str2, const int offset2,
01514                         const XMLSize_t charCount);
01515 
01516     static MemoryManager* fgMemoryManager;
01517 
01518     friend class XMLPlatformUtils;
01519 };
01520 
01521 
01522 // ---------------------------------------------------------------------------
01523 //  Inline some methods that are either just passthroughs to other string
01524 //  methods, or which are key for performance.
01525 // ---------------------------------------------------------------------------
01526 inline void XMLString::moveChars(       XMLCh* const targetStr
01527                                 , const XMLCh* const srcStr
01528                                 , const XMLSize_t    count)
01529 {
01530     memcpy(targetStr, srcStr, count * sizeof(XMLCh));
01531 }
01532 
01533 inline XMLSize_t XMLString::stringLen(const XMLCh* const src)
01534 {
01535     if (src == 0 || *src == 0)
01536     {
01537         return 0;
01538     }
01539     else
01540     {
01541         const XMLCh* pszTmp = src + 1;
01542 
01543         while (*pszTmp)
01544             ++pszTmp;
01545 
01546         return (pszTmp - src);
01547     }
01548 }
01549 
01550 inline XMLCh* XMLString::replicate(const XMLCh* const toRep,
01551                                    MemoryManager* const manager)
01552 {
01553     // If a null string, return a null string!
01554     XMLCh* ret = 0;
01555     if (toRep)
01556     {
01557         const XMLSize_t len = stringLen(toRep);
01558         ret = (XMLCh*) manager->allocate((len+1) * sizeof(XMLCh)); //new XMLCh[len + 1];
01559         memcpy(ret, toRep, (len + 1) * sizeof(XMLCh));
01560     }
01561     return ret;
01562 }
01563 
01564 inline bool XMLString::startsWith(  const   XMLCh* const    toTest
01565                                     , const XMLCh* const    prefix)
01566 {
01567     return (compareNString(toTest, prefix, stringLen(prefix)) == 0);
01568 }
01569 
01570 inline bool XMLString::startsWithI( const   XMLCh* const    toTest
01571                                     , const XMLCh* const    prefix)
01572 {
01573     return (compareNIString(toTest, prefix, stringLen(prefix)) == 0);
01574 }
01575 
01576 inline bool XMLString::endsWith(const XMLCh* const toTest,
01577                                 const XMLCh* const suffix)
01578 {
01579 
01580     XMLSize_t suffixLen = XMLString::stringLen(suffix);
01581 
01582     return regionMatches(toTest, (int)(XMLString::stringLen(toTest) - suffixLen),
01583                          suffix, 0, suffixLen);
01584 }
01585 
01586 inline bool XMLString::validateRegion(const XMLCh* const str1,
01587                                       const int offset1,
01588                                       const XMLCh* const str2,
01589                                       const int offset2,
01590                                       const XMLSize_t charCount)
01591 {
01592 
01593     if (offset1 < 0 || offset2 < 0 ||
01594         (offset1 + charCount) > XMLString::stringLen(str1) ||
01595         (offset2 + charCount) > XMLString::stringLen(str2) )
01596         return false;
01597 
01598     return true;
01599 }
01600 
01601 inline bool XMLString::equals(   const XMLCh* str1
01602                                , const XMLCh* str2)
01603 {
01604     if (str1 == str2)
01605         return true;
01606 
01607     if (str1 == 0 || str2 == 0)
01608         return ((!str1 || !*str1) && (!str2 || !*str2));
01609 
01610     while (*str1)
01611         if(*str1++ != *str2++)  // they are different (or str2 is shorter and we hit the NULL)
01612             return false;
01613 
01614     // either both ended (and *str2 is 0 too), or str2 is longer
01615     return (*str2==0);
01616 }
01617 
01618 inline bool XMLString::equalsN(const XMLCh* str1,
01619                                const XMLCh* str2,
01620                                XMLSize_t n)
01621 {
01622     if (str1 == str2 || n == 0)
01623       return true;
01624 
01625     if (str1 == 0 || str2 == 0)
01626         return ((!str1 || !*str1) && (!str2 || !*str2));
01627 
01628     for (; n != 0 && *str1 && *str2; --n, ++str1, ++str2)
01629       if(*str1 != *str2)
01630         break;
01631 
01632     return n == 0 || *str1 == *str2; // either equal or both ended premat.
01633 }
01634 
01635 inline bool XMLString::equals(   const char* str1
01636                                , const char* str2)
01637 {
01638     if (str1 == str2)
01639         return true;
01640 
01641     if (str1 == 0 || str2 == 0)
01642         return ((!str1 || !*str1) && (!str2 || !*str2));
01643 
01644     while (*str1)
01645         if(*str1++ != *str2++)  // they are different (or str2 is shorter and we hit the NULL)
01646             return false;
01647 
01648     // either both ended (and *str2 is 0 too), or str2 is longer
01649     return (*str2==0);
01650 }
01651 
01652 inline bool XMLString::equalsN(const char* str1,
01653                                const char* str2,
01654                                XMLSize_t n)
01655 {
01656     if (str1 == str2 || n == 0)
01657       return true;
01658 
01659     if (str1 == 0 || str2 == 0)
01660         return ((!str1 || !*str1) && (!str2 || !*str2));
01661 
01662     for (; n != 0 && *str1 && *str2; --n, ++str1, ++str2)
01663       if(*str1 != *str2)
01664         break;
01665 
01666     return n == 0 || *str1 == *str2; // either equal or both ended premat.
01667 }
01668 
01669 inline int XMLString::lastIndexOf(const XMLCh* const toSearch, const XMLCh ch)
01670 {
01671     return XMLString::lastIndexOf(ch, toSearch, stringLen(toSearch));
01672 }
01673 
01674 inline XMLSize_t XMLString::hash(const   XMLCh* const   tohash
01675                                 , const XMLSize_t          hashModulus)
01676 {
01677     if (tohash == 0 || *tohash == 0)
01678         return 0;
01679 
01680     const XMLCh* curCh = tohash;
01681     XMLSize_t hashVal = (XMLSize_t)(*curCh++);
01682 
01683     while (*curCh)
01684         hashVal = (hashVal * 38) + (hashVal >> 24) + (XMLSize_t)(*curCh++);
01685 
01686     // Divide by modulus
01687     return hashVal % hashModulus;
01688 }
01689 
01690 inline XMLSize_t XMLString::hashN(const   XMLCh* const   tohash
01691                                   , const XMLSize_t       n
01692                                   , const XMLSize_t       hashModulus)
01693 {
01694   if (tohash == 0 || n == 0)
01695     return 0;
01696 
01697   const XMLCh* curCh = tohash;
01698   XMLSize_t hashVal = (XMLSize_t)(*curCh++);
01699 
01700   for(XMLSize_t i=0;i<n;i++)
01701     hashVal = (hashVal * 38) + (hashVal >> 24) + (XMLSize_t)(*curCh++);
01702 
01703   // Divide by modulus
01704   return hashVal % hashModulus;
01705 }
01706 
01707 XERCES_CPP_NAMESPACE_END
01708 
01709 #endif

Generated on Wed Sep 24 16:36:33 2008 for Xerces-C++ by  doxygen 1.5.4