XMLStringTokenizer.hpp
Go to the documentation of this file.
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: XMLStringTokenizer.hpp 932889 2010-04-11 13:10:10Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_XMLSTRINGTOKENIZER_HPP)
#define XERCESC_INCLUDE_GUARD_XMLSTRINGTOKENIZER_HPP
#include <xercesc/util/RefArrayVectorOf.hpp>
#include <xercesc/util/XMLString.hpp>
XERCES_CPP_NAMESPACE_BEGIN
class XMLUTIL_EXPORT XMLStringTokenizer :public XMemory
{
public:
// -----------------------------------------------------------------------
// Public Constructors
// -----------------------------------------------------------------------
XMLStringTokenizer(const XMLCh* const srcStr,
MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
XMLStringTokenizer(const XMLCh* const srcStr
, const XMLCh* const delim
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
// -----------------------------------------------------------------------
// Public Destructor
// -----------------------------------------------------------------------
~XMLStringTokenizer();
// -----------------------------------------------------------------------
// Management methods
// -----------------------------------------------------------------------
bool hasMoreTokens();
unsigned int countTokens();
XMLCh* nextToken();
private:
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
XMLStringTokenizer(const XMLStringTokenizer&);
XMLStringTokenizer& operator=(const XMLStringTokenizer&);
// -----------------------------------------------------------------------
// CleanUp methods
// -----------------------------------------------------------------------
void cleanUp();
// -----------------------------------------------------------------------
// Helper methods
// -----------------------------------------------------------------------
bool isDelimeter(const XMLCh ch);
// -----------------------------------------------------------------------
// Private data members
//
// fOffset
// The current position in the parsed string.
//
// fStringLen
// The length of the string parsed (for convenience).
//
// fString
// The string to be parsed
//
// fDelimeters
// A set of delimiter characters
//
// fTokens
// A vector of the token strings
// -----------------------------------------------------------------------
XMLSize_t fOffset;
XMLSize_t fStringLen;
XMLCh* fString;
const XMLCh* fDelimeters;
RefArrayVectorOf<XMLCh>* fTokens;
MemoryManager* fMemoryManager;
};
// ---------------------------------------------------------------------------
// XMLStringTokenizer: Helper methods
// ---------------------------------------------------------------------------
inline bool XMLStringTokenizer::isDelimeter(const XMLCh ch) {
return XMLString::indexOf(fDelimeters, ch) == -1 ? false : true;
}
// ---------------------------------------------------------------------------
// XMLStringTokenizer: Management methods
// ---------------------------------------------------------------------------
inline unsigned int XMLStringTokenizer::countTokens() {
if (fStringLen == 0)
return 0;
unsigned int tokCount = 0;
bool inToken = false;
for (XMLSize_t i= fOffset; i< fStringLen; i++) {
if (isDelimeter(fString[i])) {
if (inToken) {
inToken = false;
}
continue;
}
if (!inToken) {
tokCount++;
inToken = true;
}
} // end for
return tokCount;
}
XERCES_CPP_NAMESPACE_END
#endif
XMemory
This class makes it possible to override the C++ memory management by adding new/delete operators to ...
Definition: XMemory.hpp:40
XERCES_CPP_NAMESPACE_BEGIN
#define XERCES_CPP_NAMESPACE_BEGIN
Definition: XercesDefs.hpp:112
XMLCh
char16_t XMLCh
Definition: Xerces_autoconf_config.hpp:120
XERCES_CPP_NAMESPACE_END
#define XERCES_CPP_NAMESPACE_END
Definition: XercesDefs.hpp:113
XMLUTIL_EXPORT
#define XMLUTIL_EXPORT
Definition: XercesDefs.hpp:162
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.
XMLPlatformUtils::fgMemoryManager
static MemoryManager * fgMemoryManager
The configurable memory manager.
Definition: PlatformUtils.hpp:121
XMLString.hpp
XMLSize_t
size_t XMLSize_t
Definition: Xerces_autoconf_config.hpp:112
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
MemoryManager
Configurable memory manager.
Definition: MemoryManager.hpp:39
XMLStringTokenizer
The string tokenizer class breaks a string into tokens.
Definition: XMLStringTokenizer.hpp:42