Xerces-C++  3.1.2
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: XMLStringTokenizer.hpp 932887 2010-04-11 13:04:59Z borisk $
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 {
44 public:
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 
104  bool hasMoreTokens();
105 
114  unsigned int countTokens();
115 
122  XMLCh* nextToken();
123 
125 
126 private:
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 // ---------------------------------------------------------------------------
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 
212 
213 #endif
214 
This class makes it possible to override the C++ memory management by adding new/delete operators to ...
Definition: XMemory.hpp:40
static MemoryManager * fgMemoryManager
The configurable memory manager.
Definition: PlatformUtils.hpp:121
Configurable memory manager.
Definition: MemoryManager.hpp:39
SIZE_T XMLSize_t
Definition: Xerces_autoconf_config.borland.hpp:86
#define XERCES_CPP_NAMESPACE_BEGIN
Definition: XercesDefs.hpp:112
wchar_t XMLCh
Definition: Xerces_autoconf_config.borland.hpp:92
The string tokenizer class breaks a string into tokens.
Definition: XMLStringTokenizer.hpp:42
#define XMLUTIL_EXPORT
Definition: XercesDefs.hpp:162
#define XERCES_CPP_NAMESPACE_END
Definition: XercesDefs.hpp:113
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
static int indexOf(const char *const toSearch, const char ch)
Provides the index of the first occurrence of a character within a string.