Xerces-C++ 3.2.4

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>
26#include <xercesc/util/XMLString.hpp>
27
28 XERCES_CPP_NAMESPACE_BEGIN
29
42 class XMLUTIL_EXPORT XMLStringTokenizer :public XMemory
43{
44 public:
45 // -----------------------------------------------------------------------
46 // Public Constructors
47 // -----------------------------------------------------------------------
50
63 XMLStringTokenizer(const XMLCh* const srcStr,
64 MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
65
76 XMLStringTokenizer(const XMLCh* const srcStr
77 , const XMLCh* const delim
78 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
79
81
82 // -----------------------------------------------------------------------
83 // Public Destructor
84 // -----------------------------------------------------------------------
87
88 ~XMLStringTokenizer();
89
91
92 // -----------------------------------------------------------------------
93 // Management methods
94 // -----------------------------------------------------------------------
97
104 bool hasMoreTokens();
105
114 unsigned int countTokens();
115
122 XMLCh* nextToken();
123
125
126 private:
127 // -----------------------------------------------------------------------
128 // Unimplemented constructors and operators
129 // -----------------------------------------------------------------------
130 XMLStringTokenizer(const XMLStringTokenizer&);
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// ---------------------------------------------------------------------------
172 inline 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// ---------------------------------------------------------------------------
181 inline 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
211 XERCES_CPP_NAMESPACE_END
212
213#endif
214
XMLString.hpp
XERCES_CPP_NAMESPACE_BEGIN
#define XERCES_CPP_NAMESPACE_BEGIN
Definition: XercesDefs.hpp:112
XMLUTIL_EXPORT
#define XMLUTIL_EXPORT
Definition: XercesDefs.hpp:162
XERCES_CPP_NAMESPACE_END
#define XERCES_CPP_NAMESPACE_END
Definition: XercesDefs.hpp:113
XMLCh
uint16_t XMLCh
Definition: Xerces_autoconf_config.hpp:120
XMLSize_t
size_t XMLSize_t
Definition: Xerces_autoconf_config.hpp:112
MemoryManager
Configurable memory manager.
Definition: MemoryManager.hpp:40
XMLPlatformUtils::fgMemoryManager
static MemoryManager * fgMemoryManager
The configurable memory manager.
Definition: PlatformUtils.hpp:121
XMLStringTokenizer
The string tokenizer class breaks a string into tokens.
Definition: XMLStringTokenizer.hpp:43
XMLStringTokenizer::countTokens
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::XMLStringTokenizer
XMLStringTokenizer(const XMLCh *const srcStr, const XMLCh *const delim, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Constructs a string tokenizer for the specified string.
XMLStringTokenizer::nextToken
XMLCh * nextToken()
Returns the next token from this string tokenizer.
XMLStringTokenizer::~XMLStringTokenizer
~XMLStringTokenizer()
XMLStringTokenizer::XMLStringTokenizer
XMLStringTokenizer(const XMLCh *const srcStr, MemoryManager *const manager=XMLPlatformUtils::fgMemoryManager)
Constructs a string tokenizer for the specified string.
XMLStringTokenizer::hasMoreTokens
bool hasMoreTokens()
Tests if there are more tokens available from this tokenizer's string.
XMLString::indexOf
static int indexOf(const char *const toSearch, const char ch)
Provides the index of the first occurrence of a character within a string.
XMemory
This class makes it possible to override the C++ memory management by adding new/delete operators to ...
Definition: XMemory.hpp:41