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$
*/
#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
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
XMLSize_t
size_t XMLSize_t
Definition Xerces_autoconf_config.hpp:112
XMLCh
char16_t XMLCh
Definition Xerces_autoconf_config.hpp:120
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