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
00247
00248
00249
00250
00251
00252
00253 #if !defined(XMLSTRING_HPP)
00254 #define XMLSTRING_HPP
00255
00256 #include <xercesc/util/BaseRefVectorOf.hpp>
00257 #include <xercesc/framework/MemoryManager.hpp>
00258 #include <string.h>
00259
00260 XERCES_CPP_NAMESPACE_BEGIN
00261
00262 class XMLLCPTranscoder;
00274 class XMLString
00275 {
00276 public:
00277
00278
00279
00296 static void catString
00297 (
00298 char* const target
00299 , const char* const src
00300 );
00301
00314 static void catString
00315 (
00316 XMLCh* const target
00317 , const XMLCh* const src
00318 );
00320
00334 static int compareIString
00335 (
00336 const char* const str1
00337 , const char* const str2
00338 );
00339
00350 static int compareIString
00351 (
00352 const XMLCh* const str1
00353 , const XMLCh* const str2
00354 );
00355
00356
00370 static int compareNString
00371 (
00372 const char* const str1
00373 , const char* const str2
00374 , const unsigned int count
00375 );
00376
00390 static int compareNString
00391 (
00392 const XMLCh* const str1
00393 , const XMLCh* const str2
00394 , const unsigned int count
00395 );
00396
00397
00411 static int compareNIString
00412 (
00413 const char* const str1
00414 , const char* const str2
00415 , const unsigned int count
00416 );
00417
00432 static int compareNIString
00433 (
00434 const XMLCh* const str1
00435 , const XMLCh* const str2
00436 , const unsigned int count
00437 );
00438
00451 static int compareString
00452 (
00453 const char* const str1
00454 , const char* const str2
00455 );
00456
00468 static int compareString
00469 (
00470 const XMLCh* const str1
00471 , const XMLCh* const str2
00472 );
00473
00482 static bool equals
00483 (
00484 const XMLCh* const str1
00485 , const XMLCh* const str2
00486 );
00487
00488 static bool equals
00489 (
00490 const char* const str1
00491 , const char* const str2
00492 );
00493
00520 static bool regionMatches
00521 (
00522 const XMLCh* const str1
00523 , const int offset1
00524 , const XMLCh* const str2
00525 , const int offset2
00526 , const unsigned int charCount
00527 );
00528
00556 static bool regionIMatches
00557 (
00558 const XMLCh* const str1
00559 , const int offset1
00560 , const XMLCh* const str2
00561 , const int offset2
00562 , const unsigned int charCount
00563 );
00565
00578 static void copyString
00579 (
00580 char* const target
00581 , const char* const src
00582 );
00583
00594 static void copyString
00595 (
00596 XMLCh* const target
00597 , const XMLCh* const src
00598 );
00599
00612 static bool copyNString
00613 (
00614 XMLCh* const target
00615 , const XMLCh* const src
00616 , const unsigned int maxChars
00617 );
00619
00628 static unsigned int hash
00629 (
00630 const char* const toHash
00631 , const unsigned int hashModulus
00632 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00633 );
00634
00641 static unsigned int hash
00642 (
00643 const XMLCh* const toHash
00644 , const unsigned int hashModulus
00645 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00646 );
00647
00657 static unsigned int hashN
00658 (
00659 const XMLCh* const toHash
00660 , const unsigned int numChars
00661 , const unsigned int hashModulus
00662 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00663 );
00664
00666
00677 static int indexOf(const char* const toSearch, const char ch);
00678
00687 static int indexOf(const XMLCh* const toSearch, const XMLCh ch);
00688
00699 static int indexOf
00700 (
00701 const char* const toSearch
00702 , const char chToFind
00703 , const unsigned int fromIndex
00704 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00705 );
00706
00717 static int indexOf
00718 (
00719 const XMLCh* const toSearch
00720 , const XMLCh chToFind
00721 , const unsigned int fromIndex
00722 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00723 );
00724
00733 static int lastIndexOf(const char* const toSearch, const char ch);
00734
00743 static int lastIndexOf(const XMLCh* const toSearch, const XMLCh ch);
00744
00754 static int lastIndexOf
00755 (
00756 const XMLCh ch
00757 , const XMLCh* const toSearch
00758 , const unsigned int toSearchLen
00759 );
00760
00771 static int lastIndexOf
00772 (
00773 const char* const toSearch
00774 , const char chToFind
00775 , const unsigned int fromIndex
00776 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00777 );
00778
00789 static int lastIndexOf
00790 (
00791 const XMLCh* const toSearch
00792 , const XMLCh ch
00793 , const unsigned int fromIndex
00794 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00795 );
00797
00805 static void moveChars
00806 (
00807 XMLCh* const targetStr
00808 , const XMLCh* const srcStr
00809 , const unsigned int count
00810 );
00811
00813
00824 static void subString
00825 (
00826 char* const targetStr
00827 , const char* const srcStr
00828 , const int startIndex
00829 , const int endIndex
00830 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00831 );
00832
00841 static void subString
00842 (
00843 XMLCh* const targetStr
00844 , const XMLCh* const srcStr
00845 , const int startIndex
00846 , const int endIndex
00847 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00848 );
00849
00851
00863 static char* replicate(const char* const toRep);
00864
00873 static char* replicate(const char* const toRep,
00874 MemoryManager* const manager);
00875
00885 static XMLCh* replicate(const XMLCh* const toRep);
00886
00895 static XMLCh* replicate(const XMLCh* const toRep,
00896 MemoryManager* const manager);
00897
00899
00908 static bool startsWith
00909 (
00910 const char* const toTest
00911 , const char* const prefix
00912 );
00913
00920 static bool startsWith
00921 (
00922 const XMLCh* const toTest
00923 , const XMLCh* const prefix
00924 );
00925
00934 static bool startsWithI
00935 (
00936 const char* const toTest
00937 , const char* const prefix
00938 );
00939
00949 static bool startsWithI
00950 (
00951 const XMLCh* const toTest
00952 , const XMLCh* const prefix
00953 );
00954
00961 static bool endsWith
00962 (
00963 const XMLCh* const toTest
00964 , const XMLCh* const suffix
00965 );
00966
00967
00976 static const XMLCh* findAny
00977 (
00978 const XMLCh* const toSearch
00979 , const XMLCh* const searchList
00980 );
00981
00990 static XMLCh* findAny
00991 (
00992 XMLCh* const toSearch
00993 , const XMLCh* const searchList
00994 );
00995
01002 static int patternMatch
01003 (
01004 const XMLCh* const toSearch
01005 , const XMLCh* const pattern
01006 );
01007
01012 static unsigned int stringLen(const char* const src);
01013
01018 static unsigned int stringLen(const XMLCh* const src);
01019
01027 static bool isValidNCName(const XMLCh* const name);
01028
01036 static bool isValidName(const XMLCh* const name);
01037
01043 static bool isValidEncName(const XMLCh* const name);
01044
01052 static bool isValidQName(const XMLCh* const name);
01053
01060 static bool isAlpha(XMLCh const theChar);
01061
01067 static bool isDigit(XMLCh const theChar);
01068
01074 static bool isAlphaNum(XMLCh const theChar);
01075
01081 static bool isHex(XMLCh const theChar);
01082
01090 static bool isAllWhiteSpace(const XMLCh* const toCheck);
01091
01097 static bool isInList(const XMLCh* const toFind, const XMLCh* const enumList);
01098
01100
01103
01114 static void binToText
01115 (
01116 const unsigned int toFormat
01117 , char* const toFill
01118 , const unsigned int maxChars
01119 , const unsigned int radix
01120 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
01121 );
01122
01133 static void binToText
01134 (
01135 const unsigned int toFormat
01136 , XMLCh* const toFill
01137 , const unsigned int maxChars
01138 , const unsigned int radix
01139 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
01140 );
01141
01152 static void binToText
01153 (
01154 const unsigned long toFormat
01155 , char* const toFill
01156 , const unsigned int maxChars
01157 , const unsigned int radix
01158 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
01159 );
01160
01171 static void binToText
01172 (
01173 const unsigned long toFormat
01174 , XMLCh* const toFill
01175 , const unsigned int maxChars
01176 , const unsigned int radix
01177 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
01178 );
01179
01190 static void binToText
01191 (
01192 const long toFormat
01193 , char* const toFill
01194 , const unsigned int maxChars
01195 , const unsigned int radix
01196 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
01197 );
01198
01209 static void binToText
01210 (
01211 const long toFormat
01212 , XMLCh* const toFill
01213 , const unsigned int maxChars
01214 , const unsigned int radix
01215 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
01216 );
01217
01228 static void binToText
01229 (
01230 const int toFormat
01231 , char* const toFill
01232 , const unsigned int maxChars
01233 , const unsigned int radix
01234 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
01235 );
01236
01247 static void binToText
01248 (
01249 const int toFormat
01250 , XMLCh* const toFill
01251 , const unsigned int maxChars
01252 , const unsigned int radix
01253 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
01254 );
01255
01266 static bool textToBin
01267 (
01268 const XMLCh* const toConvert
01269 , unsigned int& toFill
01270 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
01271 );
01272
01285 static int parseInt
01286 (
01287 const XMLCh* const toConvert
01288 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
01289 );
01290
01296 static void cut
01297 (
01298 XMLCh* const toCutFrom
01299 , const unsigned int count
01300 );
01301
01312 static char* transcode
01313 (
01314 const XMLCh* const toTranscode
01315 );
01316 static char* transcode
01317 (
01318 const XMLCh* const toTranscode
01319 , MemoryManager* const manager
01320 );
01321
01336 static bool transcode
01337 (
01338 const XMLCh* const toTranscode
01339 , char* const toFill
01340 , const unsigned int maxChars
01341 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
01342 );
01343
01354 static XMLCh* transcode
01355 (
01356 const char* const toTranscode
01357 );
01358 static XMLCh* transcode
01359 (
01360 const char* const toTranscode
01361 , MemoryManager* const manager
01362 );
01363
01373 static bool transcode
01374 (
01375 const char* const toTranscode
01376 , XMLCh* const toFill
01377 , const unsigned int maxChars
01378 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
01379 );
01380
01386 static void trim(char* const toTrim);
01387
01393 static void trim(XMLCh* const toTrim);
01394
01401 static BaseRefVectorOf<XMLCh>* tokenizeString(const XMLCh* const tokenizeSrc
01402 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
01403
01405
01416 static XMLCh* makeUName
01417 (
01418 const XMLCh* const pszURI
01419 , const XMLCh* const pszName
01420 );
01421
01437 static unsigned int replaceTokens
01438 (
01439 XMLCh* const errText
01440 , const unsigned int maxChars
01441 , const XMLCh* const text1
01442 , const XMLCh* const text2
01443 , const XMLCh* const text3
01444 , const XMLCh* const text4
01445 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
01446 );
01447
01452 static void upperCase(XMLCh* const toUpperCase);
01453
01458 static void lowerCase(XMLCh* const toLowerCase);
01459
01463 static bool isWSReplaced(const XMLCh* const toCheck);
01464
01468 static bool isWSCollapsed(const XMLCh* const toCheck);
01469
01474 static void replaceWS(XMLCh* const toConvert
01475 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
01476
01481 static void collapseWS(XMLCh* const toConvert
01482 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
01483
01488 static void removeWS(XMLCh* const toConvert
01489 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
01490
01498 static void fixURI(const XMLCh* const str, XMLCh* const target);
01499
01501
01509 static void release(char** buf);
01510
01517 static void release(XMLCh** buf);
01518
01525 static void release(XMLByte** buf);
01526
01528
01529
01530 private :
01531
01535 XMLString();
01537 ~XMLString();
01539
01540
01544 static void initString(XMLLCPTranscoder* const defToUse,
01545 MemoryManager* const manager);
01546 static void termString();
01548
01553 static bool validateRegion(const XMLCh* const str1, const int offset1,
01554 const XMLCh* const str2, const int offset2,
01555 const unsigned int charCount);
01556
01557 static MemoryManager* fgMemoryManager;
01558
01559 friend class XMLPlatformUtils;
01560 };
01561
01562
01563
01564
01565
01566
01567 inline void XMLString::moveChars( XMLCh* const targetStr
01568 , const XMLCh* const srcStr
01569 , const unsigned int count)
01570 {
01571 memcpy(targetStr, srcStr, count * sizeof(XMLCh));
01572 }
01573
01574 inline unsigned int XMLString::stringLen(const XMLCh* const src)
01575 {
01576 if (src == 0 || *src == 0)
01577 {
01578 return 0;
01579 }
01580 else
01581 {
01582 const XMLCh* pszTmp = src + 1;
01583
01584 while (*pszTmp)
01585 ++pszTmp;
01586
01587 return (unsigned int)(pszTmp - src);
01588 }
01589 }
01590
01591 inline XMLCh* XMLString::replicate(const XMLCh* const toRep,
01592 MemoryManager* const manager)
01593 {
01594
01595 XMLCh* ret = 0;
01596 if (toRep)
01597 {
01598 const unsigned int len = stringLen(toRep);
01599 ret = (XMLCh*) manager->allocate((len+1) * sizeof(XMLCh));
01600 memcpy(ret, toRep, (len + 1) * sizeof(XMLCh));
01601 }
01602 return ret;
01603 }
01604
01605 inline bool XMLString::startsWith( const XMLCh* const toTest
01606 , const XMLCh* const prefix)
01607 {
01608 return (compareNString(toTest, prefix, stringLen(prefix)) == 0);
01609 }
01610
01611 inline bool XMLString::startsWithI( const XMLCh* const toTest
01612 , const XMLCh* const prefix)
01613 {
01614 return (compareNIString(toTest, prefix, stringLen(prefix)) == 0);
01615 }
01616
01617 inline bool XMLString::endsWith(const XMLCh* const toTest,
01618 const XMLCh* const suffix)
01619 {
01620
01621 unsigned int suffixLen = XMLString::stringLen(suffix);
01622
01623 return regionMatches(toTest, XMLString::stringLen(toTest) - suffixLen,
01624 suffix, 0, suffixLen);
01625 }
01626
01627 inline bool XMLString::validateRegion(const XMLCh* const str1,
01628 const int offset1,
01629 const XMLCh* const str2,
01630 const int offset2,
01631 const unsigned int charCount)
01632 {
01633
01634 if (offset1 < 0 || offset2 < 0 ||
01635 (offset1 + charCount) > XMLString::stringLen(str1) ||
01636 (offset2 + charCount) > XMLString::stringLen(str2) )
01637 return false;
01638
01639 return true;
01640 }
01641
01642 inline bool XMLString::equals( const XMLCh* const str1
01643 , const XMLCh* const str2)
01644 {
01645 const XMLCh* psz1 = str1;
01646 const XMLCh* psz2 = str2;
01647
01648 if (psz1 == 0 || psz2 == 0) {
01649 if ((psz1 != 0 && *psz1) || (psz2 != 0 && *psz2))
01650 return false;
01651 else
01652 return true;
01653 }
01654
01655 while (*psz1 == *psz2)
01656 {
01657
01658 if (!*psz1)
01659 return true;
01660
01661
01662 psz1++;
01663 psz2++;
01664 }
01665 return false;
01666 }
01667
01668 inline bool XMLString::equals( const char* const str1
01669 , const char* const str2)
01670 {
01671 const char* psz1 = str1;
01672 const char* psz2 = str2;
01673
01674 if (psz1 == 0 || psz2 == 0) {
01675 if ((psz1 != 0 && *psz1) || (psz2 != 0 && *psz2))
01676 return false;
01677 else
01678 return true;
01679 }
01680
01681 while (*psz1 == *psz2)
01682 {
01683
01684 if (!*psz1)
01685 return true;
01686
01687
01688 psz1++;
01689 psz2++;
01690 }
01691 return false;
01692 }
01693
01694 inline int XMLString::lastIndexOf(const XMLCh* const toSearch, const XMLCh ch)
01695 {
01696 return XMLString::lastIndexOf(ch, toSearch, stringLen(toSearch));
01697 }
01698
01699 XERCES_CPP_NAMESPACE_END
01700
01701 #endif