Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:15:15

0001 /*
0002  * Licensed to the Apache Software Foundation (ASF) under one or more
0003  * contributor license agreements.  See the NOTICE file distributed with
0004  * this work for additional information regarding copyright ownership.
0005  * The ASF licenses this file to You under the Apache License, Version 2.0
0006  * (the "License"); you may not use this file except in compliance with
0007  * the License.  You may obtain a copy of the License at
0008  * 
0009  *      http://www.apache.org/licenses/LICENSE-2.0
0010  * 
0011  * Unless required by applicable law or agreed to in writing, software
0012  * distributed under the License is distributed on an "AS IS" BASIS,
0013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014  * See the License for the specific language governing permissions and
0015  * limitations under the License.
0016  */
0017 
0018 /*
0019  * $Id$
0020  */
0021 
0022 #if !defined(XERCESC_INCLUDE_GUARD_XMLSTRINGTOKENIZER_HPP)
0023 #define XERCESC_INCLUDE_GUARD_XMLSTRINGTOKENIZER_HPP
0024 
0025 #include <xercesc/util/RefArrayVectorOf.hpp>
0026 #include <xercesc/util/XMLString.hpp>
0027 
0028 XERCES_CPP_NAMESPACE_BEGIN
0029 
0030 /**
0031   * The string tokenizer class breaks a string into tokens.
0032   *
0033   * The XMLStringTokenizer methods do not distinguish among identifiers,
0034   * numbers, and quoted strings, nor do they recognize and skip comments
0035   *
0036   * A XMLStringTokenizer object internally maintains a current position within
0037   * the string to be tokenized. Some operations advance this current position
0038   * past the characters processed.
0039   */
0040 
0041 
0042   class XMLUTIL_EXPORT XMLStringTokenizer :public XMemory
0043 {
0044 public:
0045     // -----------------------------------------------------------------------
0046     //  Public Constructors
0047     // -----------------------------------------------------------------------
0048     /** @name Constructors */
0049     //@{
0050 
0051     /**
0052       * Constructs a string tokenizer for the specified string. The tokenizer
0053       * uses the default delimiter set, which is "\t\n\r\f": the space
0054       * character, the tab character, the newline character, the
0055       * carriage-return character, and the form-feed character. Delimiter
0056       * characters themselves will not be treated as tokens.
0057       *
0058       * @param  srcStr  The string to be parsed.
0059       * @param  manager Pointer to the memory manager to be used to
0060       *                 allocate objects.
0061       *
0062       */
0063     XMLStringTokenizer(const XMLCh* const srcStr,
0064                        MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
0065 
0066     /**
0067       * Constructs a string tokenizer for the specified string. The characters
0068       * in the delim argument are the delimiters for separating tokens.
0069       * Delimiter characters themselves will not be treated as tokens.
0070       *
0071       * @param  srcStr  The string to be parsed.
0072       * @param  delim   The set of delimiters.
0073       * @param  manager Pointer to the memory manager to be used to
0074       *                 allocate objects.
0075       */
0076     XMLStringTokenizer(const XMLCh* const srcStr
0077                        , const XMLCh* const delim
0078                        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
0079 
0080     //@}
0081 
0082     // -----------------------------------------------------------------------
0083     //  Public Destructor
0084     // -----------------------------------------------------------------------
0085     /** @name Destructor. */
0086     //@{
0087 
0088     ~XMLStringTokenizer();
0089 
0090     //@}
0091 
0092     // -----------------------------------------------------------------------
0093     // Management methods
0094     // -----------------------------------------------------------------------
0095     /** @name Management Function */
0096     //@{
0097 
0098      /**
0099        * Tests if there are more tokens available from this tokenizer's string.
0100        *
0101        * Returns true if and only if there is at least one token in the string
0102        * after the current position; false otherwise.
0103        */
0104     bool hasMoreTokens();
0105 
0106     /**
0107       * Calculates the number of times that this tokenizer's nextToken method
0108       * can be called to return a valid token. The current position is not
0109       * advanced.
0110       *
0111       * Returns the number of tokens remaining in the string using the current
0112       * delimiter set.
0113       */
0114     unsigned int countTokens();
0115 
0116     /**
0117       * Returns the next token from this string tokenizer.
0118       *
0119       * Function allocated, function managed (fafm). The calling function
0120       * does not need to worry about deleting the returned pointer.
0121       */
0122     XMLCh* nextToken();
0123 
0124     //@}
0125 
0126 private:
0127     // -----------------------------------------------------------------------
0128     //  Unimplemented constructors and operators
0129     // -----------------------------------------------------------------------
0130     XMLStringTokenizer(const XMLStringTokenizer&);
0131     XMLStringTokenizer& operator=(const XMLStringTokenizer&);
0132 
0133     // -----------------------------------------------------------------------
0134     //  CleanUp methods
0135     // -----------------------------------------------------------------------
0136     void cleanUp();
0137 
0138     // -----------------------------------------------------------------------
0139     //  Helper methods
0140     // -----------------------------------------------------------------------
0141     bool isDelimeter(const XMLCh ch);
0142 
0143     // -----------------------------------------------------------------------
0144     //  Private data members
0145     //
0146     //  fOffset
0147     //      The current position in the parsed string.
0148     //
0149     //  fStringLen
0150     //      The length of the string parsed (for convenience).
0151     //
0152     //  fString
0153     //      The string to be parsed
0154     //
0155     //  fDelimeters
0156     //      A set of delimiter characters
0157     //
0158     //  fTokens
0159     //      A vector of the token strings
0160     // -----------------------------------------------------------------------
0161     XMLSize_t           fOffset;
0162     XMLSize_t           fStringLen;
0163     XMLCh*              fString;
0164     const XMLCh*        fDelimeters;
0165     RefArrayVectorOf<XMLCh>* fTokens;
0166     MemoryManager*           fMemoryManager;
0167 };
0168 
0169 // ---------------------------------------------------------------------------
0170 //  XMLStringTokenizer: Helper methods
0171 // ---------------------------------------------------------------------------
0172 inline bool XMLStringTokenizer::isDelimeter(const XMLCh ch) {
0173 
0174     return XMLString::indexOf(fDelimeters, ch) == -1 ? false : true;
0175 }
0176 
0177 
0178 // ---------------------------------------------------------------------------
0179 //  XMLStringTokenizer: Management methods
0180 // ---------------------------------------------------------------------------
0181 inline unsigned int XMLStringTokenizer::countTokens() {
0182 
0183     if (fStringLen == 0)
0184         return 0;
0185 
0186     unsigned int tokCount = 0;
0187     bool inToken = false;
0188 
0189     for (XMLSize_t i= fOffset; i< fStringLen; i++) {
0190 
0191         if (isDelimeter(fString[i])) {
0192 
0193             if (inToken) {
0194                 inToken = false;
0195             }
0196 
0197             continue;
0198         }
0199 
0200         if (!inToken) {
0201 
0202             tokCount++;
0203             inToken = true;
0204         }
0205 
0206     } // end for
0207 
0208     return tokCount;
0209 }
0210 
0211 XERCES_CPP_NAMESPACE_END
0212 
0213 #endif
0214 
0215 /**
0216   * End of file XMLStringTokenizer.hpp
0217   */
0218