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 #if !defined(XMLSTRINGTOKENIZER_HPP)
00062 #define XMLSTRINGTOKENIZER_HPP
00063
00064 #include <xercesc/util/RefArrayVectorOf.hpp>
00065 #include <xercesc/util/XMLString.hpp>
00066
00067 XERCES_CPP_NAMESPACE_BEGIN
00068
00081 class XMLStringTokenizer :public XMemory
00082 {
00083 public:
00084
00085
00086
00089
00102 XMLStringTokenizer(const XMLCh* const srcStr,
00103 MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00104
00115 XMLStringTokenizer(const XMLCh* const srcStr
00116 , const XMLCh* const delim
00117 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00118
00120
00121
00122
00123
00126
00127 ~XMLStringTokenizer();
00128
00130
00131
00132
00133
00136
00143 bool hasMoreTokens();
00144
00153 int countTokens();
00154
00161 XMLCh* nextToken();
00162
00164
00165 private:
00166
00167
00168
00169 XMLStringTokenizer(const XMLStringTokenizer&);
00170 XMLStringTokenizer& operator=(const XMLStringTokenizer&);
00171
00172
00173
00174
00175 void cleanUp();
00176
00177
00178
00179
00180 bool isDelimeter(const XMLCh ch);
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200 int fOffset;
00201 int fStringLen;
00202 XMLCh* fString;
00203 XMLCh* fDelimeters;
00204 RefArrayVectorOf<XMLCh>* fTokens;
00205 MemoryManager* fMemoryManager;
00206 };
00207
00208
00209
00210
00211
00212 inline void XMLStringTokenizer::cleanUp() {
00213
00214 fMemoryManager->deallocate(fString);
00215 fMemoryManager->deallocate(fDelimeters);
00216 delete fTokens;
00217 }
00218
00219
00220
00221
00222 inline bool XMLStringTokenizer::isDelimeter(const XMLCh ch) {
00223
00224 return XMLString::indexOf(fDelimeters, ch) == -1 ? false : true;
00225 }
00226
00227
00228
00229
00230
00231 inline int XMLStringTokenizer::countTokens() {
00232
00233 if (fStringLen == 0)
00234 return 0;
00235
00236 int tokCount = 0;
00237 bool inToken = false;
00238
00239 for (int i= fOffset; i< fStringLen; i++) {
00240
00241 if (isDelimeter(fString[i])) {
00242
00243 if (inToken) {
00244 inToken = false;
00245 }
00246
00247 continue;
00248 }
00249
00250 if (!inToken) {
00251
00252 tokCount++;
00253 inToken = true;
00254 }
00255
00256 }
00257
00258 return tokCount;
00259 }
00260
00261 XERCES_CPP_NAMESPACE_END
00262
00263 #endif
00264