Xerces-C++ 3.3.0
XMLStringTokenizer.hpp
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18/*
19 * $Id$
20 */
21
22#if !defined(XERCESC_INCLUDE_GUARD_XMLSTRINGTOKENIZER_HPP)
23#define XERCESC_INCLUDE_GUARD_XMLSTRINGTOKENIZER_HPP
24
25#include <xercesc/util/RefArrayVectorOf.hpp>
27
29
43{
44public:
45 // -----------------------------------------------------------------------
46 // Public Constructors
47 // -----------------------------------------------------------------------
50
63 XMLStringTokenizer(const XMLCh* const srcStr,
65
76 XMLStringTokenizer(const XMLCh* const srcStr
77 , const XMLCh* const delim
79
81
82 // -----------------------------------------------------------------------
83 // Public Destructor
84 // -----------------------------------------------------------------------
87
89
91
92 // -----------------------------------------------------------------------
93 // Management methods
94 // -----------------------------------------------------------------------
97
105
114 unsigned int countTokens();
115
123
125
126private:
127 // -----------------------------------------------------------------------
128 // Unimplemented constructors and operators
129 // -----------------------------------------------------------------------
131 XMLStringTokenizer& operator=(const XMLStringTokenizer&);
132
133 // -----------------------------------------------------------------------
134 // CleanUp methods
135 // -----------------------------------------------------------------------
136 void cleanUp();
137
138 // -----------------------------------------------------------------------
139 // Helper methods
140 // -----------------------------------------------------------------------
141 bool isDelimeter(const XMLCh ch);
142
143 // -----------------------------------------------------------------------
144 // Private data members
145 //
146 // fOffset
147 // The current position in the parsed string.
148 //
149 // fStringLen
150 // The length of the string parsed (for convenience).
151 //
152 // fString
153 // The string to be parsed
154 //
155 // fDelimeters
156 // A set of delimiter characters
157 //
158 // fTokens
159 // A vector of the token strings
160 // -----------------------------------------------------------------------
161 XMLSize_t fOffset;
162 XMLSize_t fStringLen;
163 XMLCh* fString;
164 const XMLCh* fDelimeters;
165 RefArrayVectorOf<XMLCh>* fTokens;
166 MemoryManager* fMemoryManager;
167};
168
169// ---------------------------------------------------------------------------
170// XMLStringTokenizer: Helper methods
171// ---------------------------------------------------------------------------
172inline bool XMLStringTokenizer::isDelimeter(const XMLCh ch) {
173
174 return XMLString::indexOf(fDelimeters, ch) == -1 ? false : true;
175}
176
177
178// ---------------------------------------------------------------------------
179// XMLStringTokenizer: Management methods
180// ---------------------------------------------------------------------------
181inline unsigned int XMLStringTokenizer::countTokens() {
182
183 if (fStringLen == 0)
184 return 0;
185
186 unsigned int tokCount = 0;
187 bool inToken = false;
188
189 for (XMLSize_t i= fOffset; i< fStringLen; i++) {
190
191 if (isDelimeter(fString[i])) {
192
193 if (inToken) {
194 inToken = false;
195 }
196
197 continue;
198 }
199
200 if (!inToken) {
201
202 tokCount++;
203 inToken = true;
204 }
205
206 } // end for
207
208 return tokCount;
209}
210
212
213#endif
214
#define XERCES_CPP_NAMESPACE_BEGIN
Definition XercesDefs.hpp:112
#define XMLUTIL_EXPORT
Definition XercesDefs.hpp:162
#define XERCES_CPP_NAMESPACE_END
Definition XercesDefs.hpp:113
size_t XMLSize_t
Definition Xerces_autoconf_config.hpp:112
char16_t XMLCh
Definition Xerces_autoconf_config.hpp:120
Configurable memory manager.
Definition MemoryManager.hpp:40
static MemoryManager * fgMemoryManager
The configurable memory manager.
Definition PlatformUtils.hpp:121
The string tokenizer class breaks a string into tokens.
Definition XMLStringTokenizer.hpp:43
unsigned int countTokens()
Calculates the number of times that this tokenizer's nextToken method can be called to return a valid...
Definition XMLStringTokenizer.hpp:181
XMLStringTokenizer(const XMLCh *const srcStr, const XMLCh *const delim, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Constructs a string tokenizer for the specified string.
XMLCh * nextToken()
Returns the next token from this string tokenizer.
XMLStringTokenizer(const XMLCh *const srcStr, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Constructs a string tokenizer for the specified string.
bool hasMoreTokens()
Tests if there are more tokens available from this tokenizer's string.
static int indexOf(const char *const toSearch, const char ch)
Provides the index of the first occurrence of a character within a string.
This class makes it possible to override the C++ memory management by adding new/delete operators to ...
Definition XMemory.hpp:41