00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00036 
00037 
00038 
00039 
00040 
00041 
00042 
00043 
00044 
00045 
00046 
00047 
00048 
00049 
00050 
00051 
00052 
00053 
00054 
00055 
00056 
00057 
00058 
00059 
00060 
00061 
00062 
00063 
00064 
00065 
00066 
00067 
00068 
00069 
00070 
00071 
00072 
00073 
00074 
00075 
00076 
00077 
00078 
00079 
00080 
00081 
00082 
00083 
00084 
00085 
00086 
00087 
00088 
00089 
00090 
00091 
00092 
00093 
00094 
00095 
00096 
00097 
00098 
00099 
00100 
00101 
00102 
00103 
00104 
00105 
00106 
00107 
00108 
00109 
00110 
00111 
00112 
00113 
00114 
00115 
00116 
00117 
00118 
00119 
00120 
00121 
00122 
00123 
00124 
00125 
00126 
00127 
00128 
00129 
00130 
00131 
00132 
00133 
00134 
00135 
00136 
00137 
00138 
00139 
00140 
00141 
00142 
00143 
00144 
00145 
00146 
00147 
00148 
00149 
00150 
00151 
00152 
00153 
00154 
00155 
00156 
00157 
00158 
00159 
00160 
00161 
00162 
00163 
00164 
00165 
00166 
00167 
00168 
00169 
00170 
00171 
00172 
00173 
00174 
00175 
00176 
00177 
00178 
00179 
00180 
00181 
00182 
00183 
00184 
00185 
00186 
00187 
00188 
00189 
00190 
00191 
00192 
00193 
00194 
00195 
00196 
00197 
00198 
00199 
00200 
00201 
00202 
00203 
00204 
00205 
00206 
00207 
00208 
00209 
00210 
00211 
00212 
00213 
00214 
00215 
00216 
00217 
00218 
00219 
00220 
00221 
00222 
00223 
00224 
00225 
00226 
00227 
00228 
00229 
00230 
00231 
00232 
00233 
00234 
00235 
00236 
00237 
00238 
00239 
00240 
00241 
00242 
00243 
00244 
00245 
00246 #if !defined(XMLSTRING_HPP)
00247 #define XMLSTRING_HPP
00248 
00249 #include <xercesc/util/BaseRefVectorOf.hpp>
00250 #include <xercesc/framework/XMLBuffer.hpp>
00251 #include <xercesc/framework/MemoryManager.hpp>
00252 #include <string.h>
00253 #include <assert.h>
00254 
00255 XERCES_CPP_NAMESPACE_BEGIN
00256 
00257 class XMLLCPTranscoder;
00269 class  XMLString
00270 {
00271 public:
00272     
00273 
00274 
00291     static void catString
00292     (
00293                 char* const     target
00294         , const char* const     src
00295     );
00296 
00309     static void catString
00310     (
00311                 XMLCh* const    target
00312         , const XMLCh* const    src
00313     );
00315 
00329     static int compareIString
00330     (
00331         const   char* const     str1
00332         , const char* const     str2
00333     );
00334 
00345     static int compareIString
00346     (
00347         const   XMLCh* const    str1
00348         , const XMLCh* const    str2
00349     );
00350 
00362     static int compareIStringASCII
00363     (
00364         const   XMLCh* const    str1
00365         , const XMLCh* const    str2
00366     );
00367 
00368 
00369 
00383     static int compareNString
00384     (
00385         const   char* const     str1
00386         , const char* const     str2
00387         , const unsigned int    count
00388     );
00389 
00403     static int compareNString
00404     (
00405         const   XMLCh* const    str1
00406         , const XMLCh* const    str2
00407         , const unsigned int    count
00408     );
00409 
00410 
00424     static int compareNIString
00425     (
00426         const   char* const     str1
00427         , const char* const     str2
00428         , const unsigned int    count
00429     );
00430 
00445     static int compareNIString
00446     (
00447         const   XMLCh* const    str1
00448         , const XMLCh* const    str2
00449         , const unsigned int    count
00450     );
00451 
00464     static int compareString
00465     (
00466         const   char* const     str1
00467         , const char* const     str2
00468     );
00469 
00481     static int compareString
00482     (
00483         const   XMLCh* const    str1
00484         , const XMLCh* const    str2
00485     );
00486 
00495     static bool equals
00496     (
00497           const XMLCh* const    str1
00498         , const XMLCh* const    str2
00499     );
00500 
00501     static bool equals
00502     (
00503           const char* const    str1
00504         , const char* const    str2
00505     );
00506 
00533     static bool regionMatches
00534     (
00535         const   XMLCh* const    str1
00536         , const int             offset1
00537         , const XMLCh* const    str2
00538         , const int             offset2
00539         , const unsigned int    charCount
00540     );
00541 
00569     static bool regionIMatches
00570     (
00571         const   XMLCh* const    str1
00572         , const int             offset1
00573         , const XMLCh* const    str2
00574         , const int             offset2
00575         , const unsigned int    charCount
00576     );
00578 
00591     static void copyString
00592     (
00593                 char* const     target
00594         , const char* const     src
00595     );
00596 
00607     static void copyString
00608     (
00609                 XMLCh* const    target
00610         , const XMLCh* const    src
00611     );
00612 
00625     static bool copyNString
00626     (
00627                 XMLCh* const    target
00628         , const XMLCh* const    src
00629         , const unsigned int    maxChars
00630     );
00632 
00642     static unsigned int hash
00643     (
00644         const   char* const     toHash
00645         , const unsigned int    hashModulus
00646         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
00647     );
00648 
00656     static unsigned int hash
00657     (
00658         const   XMLCh* const    toHash
00659         , const unsigned int    hashModulus
00660         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
00661     );
00662 
00672     static unsigned int hashN
00673     (
00674         const   XMLCh* const    toHash
00675         , const unsigned int    numChars
00676         , const unsigned int    hashModulus
00677         , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00678     );
00679 
00681 
00692     static int indexOf(const char* const toSearch, const char ch);
00693 
00702     static int indexOf(const XMLCh* const toSearch, const XMLCh ch);
00703 
00715     static int indexOf
00716     (
00717         const   char* const     toSearch
00718         , const char            chToFind
00719         , const unsigned int    fromIndex
00720         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
00721     );
00722 
00734     static int indexOf
00735     (
00736         const   XMLCh* const    toSearch
00737         , const XMLCh           chToFind
00738         , const unsigned int    fromIndex
00739         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
00740     );
00741 
00750     static int lastIndexOf(const char* const toSearch, const char ch);
00751 
00760     static int lastIndexOf(const XMLCh* const toSearch, const XMLCh ch);
00761 
00771     static int lastIndexOf
00772     (
00773         const XMLCh ch
00774         , const XMLCh* const toSearch
00775         , const unsigned int toSearchLen
00776     );
00777 
00789     static int lastIndexOf
00790     (
00791         const   char* const     toSearch
00792         , const char            chToFind
00793         , const unsigned int    fromIndex
00794         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
00795     );
00796 
00808     static int lastIndexOf
00809     (
00810         const   XMLCh* const    toSearch
00811         , const XMLCh           ch
00812         , const unsigned int    fromIndex
00813         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
00814     );
00816 
00824     static void moveChars
00825     (
00826                 XMLCh* const    targetStr
00827         , const XMLCh* const    srcStr
00828         , const unsigned int    count
00829     );
00830 
00832 
00844     static void subString
00845     (
00846                 char* const    targetStr
00847         , const char* const    srcStr
00848         , const int            startIndex
00849         , const int            endIndex
00850         , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00851     );
00852 
00862     static void subString
00863     (
00864                 XMLCh* const    targetStr
00865         , const XMLCh* const    srcStr
00866         , const int             startIndex
00867         , const int             endIndex
00868         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
00869     );
00870 
00881     static void subString
00882     (
00883                 XMLCh* const    targetStr
00884         , const XMLCh* const    srcStr
00885         , const int             startIndex
00886         , const int             endIndex
00887         , const int             srcStrLength
00888         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
00889     );
00890 
00892 
00904     static char* replicate(const char* const toRep);
00905 
00914     static char* replicate(const char* const toRep,
00915                            MemoryManager* const manager);
00916 
00926     static XMLCh* replicate(const XMLCh* const toRep);
00927 
00936     static XMLCh* replicate(const XMLCh* const toRep,
00937                             MemoryManager* const manager);
00938 
00940 
00949     static bool startsWith
00950     (
00951         const   char* const     toTest
00952         , const char* const     prefix
00953     );
00954 
00961     static bool startsWith
00962     (
00963         const   XMLCh* const    toTest
00964         , const XMLCh* const    prefix
00965     );
00966 
00975     static bool startsWithI
00976     (
00977         const   char* const     toTest
00978         , const char* const     prefix
00979     );
00980 
00990     static bool startsWithI
00991     (
00992         const   XMLCh* const    toTest
00993         , const XMLCh* const    prefix
00994     );
00995 
01002     static bool endsWith
01003     (
01004         const   XMLCh* const    toTest
01005         , const XMLCh* const    suffix
01006     );
01007 
01008 
01017     static const XMLCh* findAny
01018     (
01019         const   XMLCh* const    toSearch
01020         , const XMLCh* const    searchList
01021     );
01022 
01031     static XMLCh* findAny
01032     (
01033                 XMLCh* const    toSearch
01034         , const XMLCh* const    searchList
01035     );
01036 
01043     static int patternMatch
01044     (
01045           const XMLCh* const    toSearch
01046         , const XMLCh* const    pattern
01047     );
01048 
01053     static unsigned int stringLen(const char* const src);
01054 
01059     static unsigned int stringLen(const XMLCh* const src);
01060 
01068     static bool isValidNOTATION(const XMLCh*         const name
01069                               ,       MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
01070 
01078     static bool isValidNCName(const XMLCh* const name);
01079 
01087     static bool isValidName(const XMLCh* const name);
01088 
01094     static bool isValidEncName(const XMLCh* const name);
01095 
01103     static bool isValidQName(const XMLCh* const name);
01104 
01111     static bool isAlpha(XMLCh const theChar);
01112 
01118     static bool isDigit(XMLCh const theChar);
01119 
01125     static bool isAlphaNum(XMLCh const theChar);
01126 
01132     static bool isHex(XMLCh const theChar);
01133 
01141     static bool isAllWhiteSpace(const XMLCh* const toCheck);
01142 
01148     static bool isInList(const XMLCh* const toFind, const XMLCh* const enumList);
01149 
01151 
01154 
01166     static void binToText
01167     (
01168         const   unsigned int    toFormat
01169         ,       char* const     toFill
01170         , const unsigned int    maxChars
01171         , const unsigned int    radix
01172         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
01173     );
01174 
01186     static void binToText
01187     (
01188         const   unsigned int    toFormat
01189         ,       XMLCh* const    toFill
01190         , const unsigned int    maxChars
01191         , const unsigned int    radix
01192         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
01193     );
01194 
01206     static void binToText
01207     (
01208         const   unsigned long   toFormat
01209         ,       char* const     toFill
01210         , const unsigned int    maxChars
01211         , const unsigned int    radix
01212         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
01213     );
01214 
01226     static void binToText
01227     (
01228         const   unsigned long   toFormat
01229         ,       XMLCh* const    toFill
01230         , const unsigned int    maxChars
01231         , const unsigned int    radix
01232         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
01233     );
01234 
01246     static void binToText
01247     (
01248         const   long            toFormat
01249         ,       char* const     toFill
01250         , const unsigned int    maxChars
01251         , const unsigned int    radix
01252         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
01253     );
01254 
01266     static void binToText
01267     (
01268         const   long            toFormat
01269         ,       XMLCh* const    toFill
01270         , const unsigned int    maxChars
01271         , const unsigned int    radix
01272         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
01273     );
01274 
01286     static void binToText
01287     (
01288         const   int             toFormat
01289         ,       char* const     toFill
01290         , const unsigned int    maxChars
01291         , const unsigned int    radix
01292         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
01293     );
01294 
01306     static void binToText
01307     (
01308         const   int             toFormat
01309         ,       XMLCh* const    toFill
01310         , const unsigned int    maxChars
01311         , const unsigned int    radix
01312         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
01313     );
01314 
01326     static bool textToBin
01327     (
01328         const   XMLCh* const    toConvert
01329         ,       unsigned int&   toFill
01330         ,       MemoryManager*  const manager = XMLPlatformUtils::fgMemoryManager
01331     );
01332 
01346     static int parseInt
01347     (
01348         const   XMLCh* const    toConvert
01349       , MemoryManager* const    manager = XMLPlatformUtils::fgMemoryManager
01350     );
01351 
01357     static void cut
01358     (
01359                 XMLCh* const    toCutFrom
01360         , const unsigned int    count
01361     );
01362 
01373     static char* transcode
01374     (
01375         const   XMLCh* const    toTranscode
01376     );
01377     static char* transcode
01378     (
01379         const   XMLCh* const         toTranscode
01380         ,       MemoryManager* const manager
01381     );
01382 
01398     static bool transcode
01399     (
01400         const   XMLCh* const    toTranscode
01401         ,       char* const     toFill
01402         , const unsigned int    maxChars
01403         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
01404     );
01405 
01416     static XMLCh* transcode
01417     (
01418         const   char* const     toTranscode
01419     );
01420     static XMLCh* transcode
01421     (
01422         const   char* const          toTranscode
01423         ,       MemoryManager* const manager
01424     );
01425 
01436     static bool transcode
01437     (
01438         const   char* const     toTranscode
01439         ,       XMLCh* const    toFill
01440         , const unsigned int    maxChars
01441         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
01442     );
01443 
01449     static void trim(char* const toTrim);
01450 
01456     static void trim(XMLCh* const toTrim);
01457 
01465     static BaseRefVectorOf<XMLCh>* tokenizeString(const XMLCh* const tokenizeSrc
01466                                         , MemoryManager*       const manager = XMLPlatformUtils::fgMemoryManager);
01467 
01469 
01480     static XMLCh* makeUName
01481     (
01482         const   XMLCh* const    pszURI
01483         , const XMLCh* const    pszName      
01484     );
01485 
01502     static unsigned int replaceTokens
01503     (
01504                 XMLCh* const    errText
01505         , const unsigned int    maxChars
01506         , const XMLCh* const    text1
01507         , const XMLCh* const    text2
01508         , const XMLCh* const    text3
01509         , const XMLCh* const    text4
01510         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
01511     );
01512 
01517     static void upperCase(XMLCh* const toUpperCase);
01518 
01524     static void upperCaseASCII(XMLCh* const toUpperCase);
01525 
01530     static void lowerCase(XMLCh* const toLowerCase);
01531 
01537     static void lowerCaseASCII(XMLCh* const toLowerCase);
01538 
01542     static bool isWSReplaced(const XMLCh* const toCheck);
01543 
01547     static bool isWSCollapsed(const XMLCh* const toCheck);
01548 
01554     static void replaceWS(XMLCh* const toConvert
01555         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager);
01556 
01562     static void collapseWS(XMLCh* const toConvert
01563         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager);
01564 
01570     static void removeWS(XMLCh* const toConvert
01571     , MemoryManager*       const manager = XMLPlatformUtils::fgMemoryManager);
01572 
01573 
01579     static void removeChar(const XMLCh*     const srcString
01580                          , const XMLCh&           toRemove
01581                          ,       XMLBuffer&       dstBuffer);
01582 
01590     static void fixURI(const XMLCh* const str, XMLCh* const target);
01591 
01593 
01601     static void release(char** buf);
01602 
01609     static void release(XMLCh** buf);
01610 
01617     static void release(XMLByte** buf);
01618 
01627     static void release
01628     (
01629         void**  buf
01630         ,       MemoryManager* const manager
01631     );
01632 
01634 
01635 
01636 private :
01637 
01641     XMLString();
01643     ~XMLString();
01645 
01646 
01650     static void initString(XMLLCPTranscoder* const defToUse,
01651                            MemoryManager* const manager);
01652     static void termString();
01654 
01659     static bool validateRegion(const XMLCh* const str1, const int offset1,
01660                         const XMLCh* const str2, const int offset2,
01661                         const unsigned int charCount);
01662 
01663     static MemoryManager* fgMemoryManager;
01664 
01665     friend class XMLPlatformUtils;
01666 };
01667 
01668 
01669 
01670 
01671 
01672 
01673 inline void XMLString::moveChars(       XMLCh* const targetStr
01674                                 , const XMLCh* const srcStr
01675                                 , const unsigned int count)
01676 {
01677     memcpy(targetStr, srcStr, count * sizeof(XMLCh));
01678 }
01679 
01680 inline unsigned int XMLString::stringLen(const XMLCh* const src)
01681 {
01682     if (src == 0 || *src == 0)
01683     {
01684         return 0;
01685    }
01686     else
01687    {
01688         const XMLCh* pszTmp = src + 1;
01689 
01690         while (*pszTmp)
01691             ++pszTmp;
01692 
01693         return (unsigned int)(pszTmp - src);
01694     }
01695 }
01696 
01697 inline XMLCh* XMLString::replicate(const XMLCh* const toRep,
01698                                    MemoryManager* const manager)
01699 {
01700     
01701     XMLCh* ret = 0;
01702     if (toRep)
01703     {
01704         const unsigned int len = stringLen(toRep);
01705         ret = (XMLCh*) manager->allocate((len+1) * sizeof(XMLCh)); 
01706         memcpy(ret, toRep, (len + 1) * sizeof(XMLCh));
01707     }
01708     return ret;
01709 }
01710 
01711 inline bool XMLString::startsWith(  const   XMLCh* const    toTest
01712                                     , const XMLCh* const    prefix)
01713 {
01714     return (compareNString(toTest, prefix, stringLen(prefix)) == 0);
01715 }
01716 
01717 inline bool XMLString::startsWithI( const   XMLCh* const    toTest
01718                                     , const XMLCh* const    prefix)
01719 {
01720     return (compareNIString(toTest, prefix, stringLen(prefix)) == 0);
01721 }
01722 
01723 inline bool XMLString::endsWith(const XMLCh* const toTest,
01724                                 const XMLCh* const suffix)
01725 {
01726 
01727     unsigned int suffixLen = XMLString::stringLen(suffix);
01728 
01729     return regionMatches(toTest, XMLString::stringLen(toTest) - suffixLen,
01730                          suffix, 0, suffixLen);
01731 }
01732 
01733 inline bool XMLString::validateRegion(const XMLCh* const str1,
01734                                       const int offset1,
01735                                       const XMLCh* const str2,
01736                                       const int offset2,
01737                                       const unsigned int charCount)
01738 {
01739 
01740     if (offset1 < 0 || offset2 < 0 ||
01741         (offset1 + charCount) > XMLString::stringLen(str1) ||
01742         (offset2 + charCount) > XMLString::stringLen(str2) )
01743         return false;
01744 
01745     return true;
01746 }
01747 
01748 inline bool XMLString::equals(   const XMLCh* const    str1
01749                                , const XMLCh* const    str2)
01750 {
01751     const XMLCh* psz1 = str1;
01752     const XMLCh* psz2 = str2;
01753 
01754     if (psz1 == 0 || psz2 == 0) {
01755         if ((psz1 != 0 && *psz1) || (psz2 != 0 && *psz2))
01756             return false;
01757         else
01758             return true;
01759     }
01760 
01761     while (*psz1 == *psz2)
01762     {
01763         
01764         if (!*psz1)
01765             return true;
01766 
01767         
01768         psz1++;
01769         psz2++;
01770     }
01771     return false;
01772 }
01773 
01774 inline bool XMLString::equals(   const char* const    str1
01775                                , const char* const    str2)
01776 {
01777     const char* psz1 = str1;
01778     const char* psz2 = str2;
01779 
01780     if (psz1 == 0 || psz2 == 0) {
01781         if ((psz1 != 0 && *psz1) || (psz2 != 0 && *psz2))
01782             return false;
01783         else
01784             return true;
01785     }
01786 
01787     while (*psz1 == *psz2)
01788     {
01789         
01790         if (!*psz1)
01791             return true;
01792 
01793         
01794         psz1++;
01795         psz2++;
01796     }
01797     return false;
01798 }
01799 
01800 inline int XMLString::lastIndexOf(const XMLCh* const toSearch, const XMLCh ch)
01801 {
01802     return XMLString::lastIndexOf(ch, toSearch, stringLen(toSearch));
01803 }
01804 
01805 inline unsigned int XMLString::hash(   const   XMLCh* const    tohash
01806                                 , const unsigned int    hashModulus
01807                                 , MemoryManager* const)
01808 {  
01809     assert(hashModulus);
01810 
01811     if (tohash == 0 || *tohash == 0)
01812         return 0;
01813 
01814     const XMLCh* curCh = tohash;
01815     unsigned int hashVal = (unsigned int)(*curCh);
01816     curCh++;
01817 
01818     while (*curCh)
01819     {
01820         hashVal = (hashVal * 38) + (hashVal >> 24) + (unsigned int)(*curCh);
01821         curCh++;
01822     }
01823 
01824     
01825     return hashVal % hashModulus;
01826 }
01827 
01828 XERCES_CPP_NAMESPACE_END
01829 
01830 #endif