http://xml.apache.org/http://www.apache.org/http://www.w3.org/

Home

Readme
Charter
Release Info

Installation
Download
Build Instructions

FAQs
Samples
API Docs

DOM C++ Binding
Programming
Migration Guide

Feedback
Bug-Reporting
PDF Document

Source Repository
User Mail Archive
Devel Mail Archive

API Docs for SAX and DOM
 

XMLStringTokenizer.hpp

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


Copyright © 1994-2004 The Apache Software Foundation. All Rights Reserved.