XMLStringTokenizer.hpp

Go to the documentation of this file.
00001 /*
00002  * Licensed to the Apache Software Foundation (ASF) under one or more
00003  * contributor license agreements.  See the NOTICE file distributed with
00004  * this work for additional information regarding copyright ownership.
00005  * The ASF licenses this file to You under the Apache License, Version 2.0
00006  * (the "License"); you may not use this file except in compliance with
00007  * the License.  You may obtain a copy of the License at
00008  * 
00009  *      http://www.apache.org/licenses/LICENSE-2.0
00010  * 
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 
00018 /*
00019  * $Id: XMLStringTokenizer.hpp 568078 2007-08-21 11:43:25Z amassari $
00020  */
00021 
00022 #if !defined(XMLSTRINGTOKENIZER_HPP)
00023 #define XMLSTRINGTOKENIZER_HPP
00024 
00025 #include <xercesc/util/RefArrayVectorOf.hpp>
00026 #include <xercesc/util/XMLString.hpp>
00027 
00028 XERCES_CPP_NAMESPACE_BEGIN
00029 
00042   class XMLUTIL_EXPORT XMLStringTokenizer :public XMemory
00043 {
00044 public:
00045     // -----------------------------------------------------------------------
00046     //  Public Constructors
00047     // -----------------------------------------------------------------------
00050 
00063     XMLStringTokenizer(const XMLCh* const srcStr,
00064                        MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00065 
00076     XMLStringTokenizer(const XMLCh* const srcStr
00077                        , const XMLCh* const delim
00078                        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
00079 
00081 
00082     // -----------------------------------------------------------------------
00083     //  Public Destructor
00084     // -----------------------------------------------------------------------
00087 
00088     ~XMLStringTokenizer();
00089 
00091 
00092     // -----------------------------------------------------------------------
00093     // Management methods
00094     // -----------------------------------------------------------------------
00097 
00104     bool hasMoreTokens();
00105 
00114     int countTokens();
00115 
00122     XMLCh* nextToken();
00123 
00125 
00126 private:
00127     // -----------------------------------------------------------------------
00128     //  Unimplemented constructors and operators
00129     // -----------------------------------------------------------------------
00130     XMLStringTokenizer(const XMLStringTokenizer&);
00131     XMLStringTokenizer& operator=(const XMLStringTokenizer&);
00132 
00133     // -----------------------------------------------------------------------
00134     //  CleanUp methods
00135     // -----------------------------------------------------------------------
00136     void cleanUp();
00137 
00138     // -----------------------------------------------------------------------
00139     //  Helper methods
00140     // -----------------------------------------------------------------------
00141     bool isDelimeter(const XMLCh ch);
00142 
00143     // -----------------------------------------------------------------------
00144     //  Private data members
00145     //
00146     //  fOffset
00147     //      The current position in the parsed string.
00148     //
00149     //  fStringLen
00150     //      The length of the string parsed (for convenience).
00151     //
00152     //  fString
00153     //      The string to be parsed
00154     //
00155     //  fDelimeters
00156     //      A set of delimeter characters
00157     //
00158     //  fTokens
00159     //      A vector of the token strings
00160     // -----------------------------------------------------------------------
00161     int                 fOffset;
00162     int                 fStringLen;
00163     XMLCh*              fString;
00164     const XMLCh*        fDelimeters;
00165     RefArrayVectorOf<XMLCh>* fTokens;
00166     MemoryManager*           fMemoryManager;
00167 };
00168 
00169 // ---------------------------------------------------------------------------
00170 //  XMLStringTokenizer: Helper methods
00171 // ---------------------------------------------------------------------------
00172 inline bool XMLStringTokenizer::isDelimeter(const XMLCh ch) {
00173 
00174     return XMLString::indexOf(fDelimeters, ch) == -1 ? false : true;
00175 }
00176 
00177 
00178 // ---------------------------------------------------------------------------
00179 //  XMLStringTokenizer: Management methods
00180 // ---------------------------------------------------------------------------
00181 inline int XMLStringTokenizer::countTokens() {
00182 
00183     if (fStringLen == 0)
00184         return 0;
00185 
00186     int  tokCount = 0;
00187     bool inToken = false;
00188 
00189     for (int i= fOffset; i< fStringLen; i++) {
00190 
00191         if (isDelimeter(fString[i])) {
00192 
00193             if (inToken) {
00194                 inToken = false;
00195             }
00196 
00197             continue;
00198         }
00199 
00200         if (!inToken) {
00201 
00202             tokCount++;
00203             inToken = true;
00204         }
00205 
00206     } // end for
00207 
00208     return tokCount;
00209 }
00210 
00211 XERCES_CPP_NAMESPACE_END
00212 
00213 #endif
00214 

Generated on Thu Feb 19 11:35:44 2009 for Xerces-C++ by  doxygen 1.5.4