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 #if !defined(XMLSTRING_HPP)
00229 #define XMLSTRING_HPP
00230
00231 #include <xercesc/util/BaseRefVectorOf.hpp>
00232 #include <xercesc/framework/XMLBuffer.hpp>
00233 #include <xercesc/framework/MemoryManager.hpp>
00234 #include <string.h>
00235
00236 XERCES_CPP_NAMESPACE_BEGIN
00237
00238 class XMLLCPTranscoder;
00250 class XMLString
00251 {
00252 public:
00253
00254
00255
00272 static void catString
00273 (
00274 char* const target
00275 , const char* const src
00276 );
00277
00290 static void catString
00291 (
00292 XMLCh* const target
00293 , const XMLCh* const src
00294 );
00296
00310 static int compareIString
00311 (
00312 const char* const str1
00313 , const char* const str2
00314 );
00315
00326 static int compareIString
00327 (
00328 const XMLCh* const str1
00329 , const XMLCh* const str2
00330 );
00331
00332
00346 static int compareNString
00347 (
00348 const char* const str1
00349 , const char* const str2
00350 , const unsigned int count
00351 );
00352
00366 static int compareNString
00367 (
00368 const XMLCh* const str1
00369 , const XMLCh* const str2
00370 , const unsigned int count
00371 );
00372
00373
00387 static int compareNIString
00388 (
00389 const char* const str1
00390 , const char* const str2
00391 , const unsigned int count
00392 );
00393
00408 static int compareNIString
00409 (
00410 const XMLCh* const str1
00411 , const XMLCh* const str2
00412 , const unsigned int count
00413 );
00414
00427 static int compareString
00428 (
00429 const char* const str1
00430 , const char* const str2
00431 );
00432
00444 static int compareString
00445 (
00446 const XMLCh* const str1
00447 , const XMLCh* const str2
00448 );
00449
00458 static bool equals
00459 (
00460 const XMLCh* const str1
00461 , const XMLCh* const str2
00462 );
00463
00464 static bool equals
00465 (
00466 const char* const str1
00467 , const char* const str2
00468 );
00469
00496 static bool regionMatches
00497 (
00498 const XMLCh* const str1
00499 , const int offset1
00500 , const XMLCh* const str2
00501 , const int offset2
00502 , const unsigned int charCount
00503 );
00504
00532 static bool regionIMatches
00533 (
00534 const XMLCh* const str1
00535 , const int offset1
00536 , const XMLCh* const str2
00537 , const int offset2
00538 , const unsigned int charCount
00539 );
00541
00554 static void copyString
00555 (
00556 char* const target
00557 , const char* const src
00558 );
00559
00570 static void copyString
00571 (
00572 XMLCh* const target
00573 , const XMLCh* const src
00574 );
00575
00588 static bool copyNString
00589 (
00590 XMLCh* const target
00591 , const XMLCh* const src
00592 , const unsigned int maxChars
00593 );
00595
00605 static unsigned int hash
00606 (
00607 const char* const toHash
00608 , const unsigned int hashModulus
00609 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00610 );
00611
00619 static unsigned int hash
00620 (
00621 const XMLCh* const toHash
00622 , const unsigned int hashModulus
00623 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00624 );
00625
00635 static unsigned int hashN
00636 (
00637 const XMLCh* const toHash
00638 , const unsigned int numChars
00639 , const unsigned int hashModulus
00640 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00641 );
00642
00644
00655 static int indexOf(const char* const toSearch, const char ch);
00656
00665 static int indexOf(const XMLCh* const toSearch, const XMLCh ch);
00666
00678 static int indexOf
00679 (
00680 const char* const toSearch
00681 , const char chToFind
00682 , const unsigned int fromIndex
00683 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00684 );
00685
00697 static int indexOf
00698 (
00699 const XMLCh* const toSearch
00700 , const XMLCh chToFind
00701 , const unsigned int fromIndex
00702 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00703 );
00704
00713 static int lastIndexOf(const char* const toSearch, const char ch);
00714
00723 static int lastIndexOf(const XMLCh* const toSearch, const XMLCh ch);
00724
00734 static int lastIndexOf
00735 (
00736 const XMLCh ch
00737 , const XMLCh* const toSearch
00738 , const unsigned int toSearchLen
00739 );
00740
00752 static int lastIndexOf
00753 (
00754 const char* const toSearch
00755 , const char chToFind
00756 , const unsigned int fromIndex
00757 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00758 );
00759
00771 static int lastIndexOf
00772 (
00773 const XMLCh* const toSearch
00774 , const XMLCh ch
00775 , const unsigned int fromIndex
00776 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00777 );
00779
00787 static void moveChars
00788 (
00789 XMLCh* const targetStr
00790 , const XMLCh* const srcStr
00791 , const unsigned int count
00792 );
00793
00795
00807 static void subString
00808 (
00809 char* const targetStr
00810 , const char* const srcStr
00811 , const int startIndex
00812 , const int endIndex
00813 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00814 );
00815
00825 static void subString
00826 (
00827 XMLCh* const targetStr
00828 , const XMLCh* const srcStr
00829 , const int startIndex
00830 , const int endIndex
00831 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
00832 );
00833
00835
00847 static char* replicate(const char* const toRep);
00848
00857 static char* replicate(const char* const toRep,
00858 MemoryManager* const manager);
00859
00869 static XMLCh* replicate(const XMLCh* const toRep);
00870
00879 static XMLCh* replicate(const XMLCh* const toRep,
00880 MemoryManager* const manager);
00881
00883
00892 static bool startsWith
00893 (
00894 const char* const toTest
00895 , const char* const prefix
00896 );
00897
00904 static bool startsWith
00905 (
00906 const XMLCh* const toTest
00907 , const XMLCh* const prefix
00908 );
00909
00918 static bool startsWithI
00919 (
00920 const char* const toTest
00921 , const char* const prefix
00922 );
00923
00933 static bool startsWithI
00934 (
00935 const XMLCh* const toTest
00936 , const XMLCh* const prefix
00937 );
00938
00945 static bool endsWith
00946 (
00947 const XMLCh* const toTest
00948 , const XMLCh* const suffix
00949 );
00950
00951
00960 static const XMLCh* findAny
00961 (
00962 const XMLCh* const toSearch
00963 , const XMLCh* const searchList
00964 );
00965
00974 static XMLCh* findAny
00975 (
00976 XMLCh* const toSearch
00977 , const XMLCh* const searchList
00978 );
00979
00986 static int patternMatch
00987 (
00988 const XMLCh* const toSearch
00989 , const XMLCh* const pattern
00990 );
00991
00996 static unsigned int stringLen(const char* const src);
00997
01002 static unsigned int stringLen(const XMLCh* const src);
01003
01011 static bool isValidNOTATION(const XMLCh* const name
01012 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
01013
01021 static bool isValidNCName(const XMLCh* const name);
01022
01030 static bool isValidName(const XMLCh* const name);
01031
01037 static bool isValidEncName(const XMLCh* const name);
01038
01046 static bool isValidQName(const XMLCh* const name);
01047
01054 static bool isAlpha(XMLCh const theChar);
01055
01061 static bool isDigit(XMLCh const theChar);
01062
01068 static bool isAlphaNum(XMLCh const theChar);
01069
01075 static bool isHex(XMLCh const theChar);
01076
01084 static bool isAllWhiteSpace(const XMLCh* const toCheck);
01085
01091 static bool isInList(const XMLCh* const toFind, const XMLCh* const enumList);
01092
01094
01097
01109 static void binToText
01110 (
01111 const unsigned int toFormat
01112 , char* const toFill
01113 , const unsigned int maxChars
01114 , const unsigned int radix
01115 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
01116 );
01117
01129 static void binToText
01130 (
01131 const unsigned int toFormat
01132 , XMLCh* const toFill
01133 , const unsigned int maxChars
01134 , const unsigned int radix
01135 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
01136 );
01137
01149 static void binToText
01150 (
01151 const unsigned long toFormat
01152 , char* const toFill
01153 , const unsigned int maxChars
01154 , const unsigned int radix
01155 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
01156 );
01157
01169 static void binToText
01170 (
01171 const unsigned long toFormat
01172 , XMLCh* const toFill
01173 , const unsigned int maxChars
01174 , const unsigned int radix
01175 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
01176 );
01177
01189 static void binToText
01190 (
01191 const long toFormat
01192 , char* const toFill
01193 , const unsigned int maxChars
01194 , const unsigned int radix
01195 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
01196 );
01197
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
01229 static void binToText
01230 (
01231 const int toFormat
01232 , char* const toFill
01233 , const unsigned int maxChars
01234 , const unsigned int radix
01235 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
01236 );
01237
01249 static void binToText
01250 (
01251 const int toFormat
01252 , XMLCh* const toFill
01253 , const unsigned int maxChars
01254 , const unsigned int radix
01255 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
01256 );
01257
01269 static bool textToBin
01270 (
01271 const XMLCh* const toConvert
01272 , unsigned int& toFill
01273 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
01274 );
01275
01289 static int parseInt
01290 (
01291 const XMLCh* const toConvert
01292 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
01293 );
01294
01300 static void cut
01301 (
01302 XMLCh* const toCutFrom
01303 , const unsigned int count
01304 );
01305
01316 static char* transcode
01317 (
01318 const XMLCh* const toTranscode
01319 );
01320 static char* transcode
01321 (
01322 const XMLCh* const toTranscode
01323 , MemoryManager* const manager
01324 );
01325
01341 static bool transcode
01342 (
01343 const XMLCh* const toTranscode
01344 , char* const toFill
01345 , const unsigned int maxChars
01346 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
01347 );
01348
01359 static XMLCh* transcode
01360 (
01361 const char* const toTranscode
01362 );
01363 static XMLCh* transcode
01364 (
01365 const char* const toTranscode
01366 , MemoryManager* const manager
01367 );
01368
01379 static bool transcode
01380 (
01381 const char* const toTranscode
01382 , XMLCh* const toFill
01383 , const unsigned int maxChars
01384 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
01385 );
01386
01392 static void trim(char* const toTrim);
01393
01399 static void trim(XMLCh* const toTrim);
01400
01408 static BaseRefVectorOf<XMLCh>* tokenizeString(const XMLCh* const tokenizeSrc
01409 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
01410
01412
01423 static XMLCh* makeUName
01424 (
01425 const XMLCh* const pszURI
01426 , const XMLCh* const pszName
01427 );
01428
01445 static unsigned int replaceTokens
01446 (
01447 XMLCh* const errText
01448 , const unsigned int maxChars
01449 , const XMLCh* const text1
01450 , const XMLCh* const text2
01451 , const XMLCh* const text3
01452 , const XMLCh* const text4
01453 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
01454 );
01455
01460 static void upperCase(XMLCh* const toUpperCase);
01461
01466 static void lowerCase(XMLCh* const toLowerCase);
01467
01471 static bool isWSReplaced(const XMLCh* const toCheck);
01472
01476 static bool isWSCollapsed(const XMLCh* const toCheck);
01477
01483 static void replaceWS(XMLCh* const toConvert
01484 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
01485
01491 static void collapseWS(XMLCh* const toConvert
01492 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
01493
01499 static void removeWS(XMLCh* const toConvert
01500 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
01501
01502
01508 static void removeChar(const XMLCh* const srcString
01509 , const XMLCh& toRemove
01510 , XMLBuffer& dstBuffer);
01511
01519 static void fixURI(const XMLCh* const str, XMLCh* const target);
01520
01522
01530 static void release(char** buf);
01531
01538 static void release(XMLCh** buf);
01539
01546 static void release(XMLByte** buf);
01547
01549
01550
01551 private :
01552
01556 XMLString();
01558 ~XMLString();
01560
01561
01565 static void initString(XMLLCPTranscoder* const defToUse,
01566 MemoryManager* const manager);
01567 static void termString();
01569
01574 static bool validateRegion(const XMLCh* const str1, const int offset1,
01575 const XMLCh* const str2, const int offset2,
01576 const unsigned int charCount);
01577
01578 static MemoryManager* fgMemoryManager;
01579
01580 friend class XMLPlatformUtils;
01581 };
01582
01583
01584
01585
01586
01587
01588 inline void XMLString::moveChars( XMLCh* const targetStr
01589 , const XMLCh* const srcStr
01590 , const unsigned int count)
01591 {
01592 memcpy(targetStr, srcStr, count * sizeof(XMLCh));
01593 }
01594
01595 inline unsigned int XMLString::stringLen(const XMLCh* const src)
01596 {
01597 if (src == 0 || *src == 0)
01598 {
01599 return 0;
01600 }
01601 else
01602 {
01603 const XMLCh* pszTmp = src + 1;
01604
01605 while (*pszTmp)
01606 ++pszTmp;
01607
01608 return (unsigned int)(pszTmp - src);
01609 }
01610 }
01611
01612 inline XMLCh* XMLString::replicate(const XMLCh* const toRep,
01613 MemoryManager* const manager)
01614 {
01615
01616 XMLCh* ret = 0;
01617 if (toRep)
01618 {
01619 const unsigned int len = stringLen(toRep);
01620 ret = (XMLCh*) manager->allocate((len+1) * sizeof(XMLCh));
01621 memcpy(ret, toRep, (len + 1) * sizeof(XMLCh));
01622 }
01623 return ret;
01624 }
01625
01626 inline bool XMLString::startsWith( const XMLCh* const toTest
01627 , const XMLCh* const prefix)
01628 {
01629 return (compareNString(toTest, prefix, stringLen(prefix)) == 0);
01630 }
01631
01632 inline bool XMLString::startsWithI( const XMLCh* const toTest
01633 , const XMLCh* const prefix)
01634 {
01635 return (compareNIString(toTest, prefix, stringLen(prefix)) == 0);
01636 }
01637
01638 inline bool XMLString::endsWith(const XMLCh* const toTest,
01639 const XMLCh* const suffix)
01640 {
01641
01642 unsigned int suffixLen = XMLString::stringLen(suffix);
01643
01644 return regionMatches(toTest, XMLString::stringLen(toTest) - suffixLen,
01645 suffix, 0, suffixLen);
01646 }
01647
01648 inline bool XMLString::validateRegion(const XMLCh* const str1,
01649 const int offset1,
01650 const XMLCh* const str2,
01651 const int offset2,
01652 const unsigned int charCount)
01653 {
01654
01655 if (offset1 < 0 || offset2 < 0 ||
01656 (offset1 + charCount) > XMLString::stringLen(str1) ||
01657 (offset2 + charCount) > XMLString::stringLen(str2) )
01658 return false;
01659
01660 return true;
01661 }
01662
01663 inline bool XMLString::equals( const XMLCh* const str1
01664 , const XMLCh* const str2)
01665 {
01666 const XMLCh* psz1 = str1;
01667 const XMLCh* psz2 = str2;
01668
01669 if (psz1 == 0 || psz2 == 0) {
01670 if ((psz1 != 0 && *psz1) || (psz2 != 0 && *psz2))
01671 return false;
01672 else
01673 return true;
01674 }
01675
01676 while (*psz1 == *psz2)
01677 {
01678
01679 if (!*psz1)
01680 return true;
01681
01682
01683 psz1++;
01684 psz2++;
01685 }
01686 return false;
01687 }
01688
01689 inline bool XMLString::equals( const char* const str1
01690 , const char* const str2)
01691 {
01692 const char* psz1 = str1;
01693 const char* psz2 = str2;
01694
01695 if (psz1 == 0 || psz2 == 0) {
01696 if ((psz1 != 0 && *psz1) || (psz2 != 0 && *psz2))
01697 return false;
01698 else
01699 return true;
01700 }
01701
01702 while (*psz1 == *psz2)
01703 {
01704
01705 if (!*psz1)
01706 return true;
01707
01708
01709 psz1++;
01710 psz2++;
01711 }
01712 return false;
01713 }
01714
01715 inline int XMLString::lastIndexOf(const XMLCh* const toSearch, const XMLCh ch)
01716 {
01717 return XMLString::lastIndexOf(ch, toSearch, stringLen(toSearch));
01718 }
01719
01720 XERCES_CPP_NAMESPACE_END
01721
01722 #endif