secureswitools/swisistools/source/xmlparser/xerces/include/xercesc/util/XMLStringTokenizer.hpp
changeset 0 ba25891c3a9e
child 1 c42dffbd5b4f
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 /*
       
    18  * Licensed to the Apache Software Foundation (ASF) under one or more
       
    19  * contributor license agreements.  See the NOTICE file distributed with
       
    20  * this work for additional information regarding copyright ownership.
       
    21  * The ASF licenses this file to You under the Apache License, Version 2.0
       
    22  * (the "License"); you may not use this file except in compliance with
       
    23  * the License.  You may obtain a copy of the License at
       
    24  * 
       
    25  *      http://www.apache.org/licenses/LICENSE-2.0
       
    26  * 
       
    27  * Unless required by applicable law or agreed to in writing, software
       
    28  * distributed under the License is distributed on an "AS IS" BASIS,
       
    29  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       
    30  * See the License for the specific language governing permissions and
       
    31  * limitations under the License.
       
    32  */
       
    33 
       
    34 /*
       
    35  * $Id: XMLStringTokenizer.hpp 568078 2007-08-21 11:43:25Z amassari $
       
    36  */
       
    37 
       
    38 #if !defined(XMLSTRINGTOKENIZER_HPP)
       
    39 #define XMLSTRINGTOKENIZER_HPP
       
    40 
       
    41 #include <xercesc/util/RefArrayVectorOf.hpp>
       
    42 #include <xercesc/util/XMLString.hpp>
       
    43 
       
    44 XERCES_CPP_NAMESPACE_BEGIN
       
    45 
       
    46 /**
       
    47   * The string tokenizer class breaks a string into tokens.
       
    48   *
       
    49   * The XMLStringTokenizer methods do not distinguish among identifiers,
       
    50   * numbers, and quoted strings, nor do they recognize and skip comments
       
    51   *
       
    52   * A XMLStringTokenizer object internally maintains a current position within
       
    53   * the string to be tokenized. Some operations advance this current position
       
    54   * past the characters processed.
       
    55   */
       
    56 
       
    57 
       
    58   class XMLUTIL_EXPORT XMLStringTokenizer :public XMemory
       
    59 {
       
    60 public:
       
    61     // -----------------------------------------------------------------------
       
    62     //  Public Constructors
       
    63     // -----------------------------------------------------------------------
       
    64     /** @name Constructors */
       
    65     //@{
       
    66 
       
    67     /**
       
    68       * Constructs a string tokenizer for the specified string. The tokenizer
       
    69       * uses the default delimiter set, which is "\t\n\r\f": the space
       
    70       * character, the tab character, the newline character, the
       
    71       * carriage-return character, and the form-feed character. Delimiter
       
    72       * characters themselves will not be treated as tokens.
       
    73       *
       
    74       * @param  srcStr  The string to be parsed.
       
    75       * @param  manager Pointer to the memory manager to be used to
       
    76       *                 allocate objects.
       
    77       *
       
    78       */
       
    79 	XMLStringTokenizer(const XMLCh* const srcStr,
       
    80                        MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
       
    81 
       
    82     /**
       
    83       * Constructs a string tokenizer for the specified string. The characters
       
    84       * in the delim argument are the delimiters for separating tokens.
       
    85       * Delimiter characters themselves will not be treated as tokens.
       
    86       *
       
    87       * @param  srcStr  The string to be parsed.
       
    88       * @param  delim   The set of delimiters.
       
    89       * @param  manager Pointer to the memory manager to be used to
       
    90       *                 allocate objects.
       
    91       */
       
    92     XMLStringTokenizer(const XMLCh* const srcStr
       
    93                        , const XMLCh* const delim
       
    94                        , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
       
    95 
       
    96     //@}
       
    97 
       
    98 	// -----------------------------------------------------------------------
       
    99     //  Public Destructor
       
   100     // -----------------------------------------------------------------------
       
   101 	/** @name Destructor. */
       
   102     //@{
       
   103 
       
   104     ~XMLStringTokenizer();
       
   105 
       
   106     //@}
       
   107 
       
   108     // -----------------------------------------------------------------------
       
   109     // Management methods
       
   110     // -----------------------------------------------------------------------
       
   111     /** @name Management Function */
       
   112     //@{
       
   113 
       
   114      /**
       
   115        * Tests if there are more tokens available from this tokenizer's string.
       
   116        *
       
   117        * Returns true if and only if there is at least one token in the string
       
   118        * after the current position; false otherwise.
       
   119        */
       
   120 	bool hasMoreTokens();
       
   121 
       
   122     /**
       
   123       * Calculates the number of times that this tokenizer's nextToken method
       
   124       * can be called to return a valid token. The current position is not
       
   125       * advanced.
       
   126       *
       
   127       * Returns the number of tokens remaining in the string using the current
       
   128       * delimiter set.
       
   129       */
       
   130     int countTokens();
       
   131 
       
   132     /**
       
   133       * Returns the next token from this string tokenizer.
       
   134       *
       
   135       * Function allocated, function managed (fafm). The calling function
       
   136       * does not need to worry about deleting the returned pointer.
       
   137 	  */
       
   138 	XMLCh* nextToken();
       
   139 
       
   140     //@}
       
   141 
       
   142 private:
       
   143     // -----------------------------------------------------------------------
       
   144     //  Unimplemented constructors and operators
       
   145     // -----------------------------------------------------------------------
       
   146     XMLStringTokenizer(const XMLStringTokenizer&);
       
   147     XMLStringTokenizer& operator=(const XMLStringTokenizer&);
       
   148 
       
   149     // -----------------------------------------------------------------------
       
   150     //  CleanUp methods
       
   151     // -----------------------------------------------------------------------
       
   152 	void cleanUp();
       
   153 
       
   154     // -----------------------------------------------------------------------
       
   155     //  Helper methods
       
   156     // -----------------------------------------------------------------------
       
   157     bool isDelimeter(const XMLCh ch);
       
   158 
       
   159     // -----------------------------------------------------------------------
       
   160     //  Private data members
       
   161     //
       
   162     //  fOffset
       
   163     //      The current position in the parsed string.
       
   164     //
       
   165     //  fStringLen
       
   166     //      The length of the string parsed (for convenience).
       
   167     //
       
   168     //  fString
       
   169     //      The string to be parsed
       
   170 	//
       
   171     //  fDelimeters
       
   172     //      A set of delimeter characters
       
   173     //
       
   174     //  fTokens
       
   175     //      A vector of the token strings
       
   176     // -----------------------------------------------------------------------
       
   177     int                 fOffset;
       
   178     int                 fStringLen;
       
   179 	XMLCh*              fString;
       
   180     const XMLCh*        fDelimeters;
       
   181 	RefArrayVectorOf<XMLCh>* fTokens;
       
   182     MemoryManager*           fMemoryManager;
       
   183 };
       
   184 
       
   185 // ---------------------------------------------------------------------------
       
   186 //  XMLStringTokenizer: Helper methods
       
   187 // ---------------------------------------------------------------------------
       
   188 inline bool XMLStringTokenizer::isDelimeter(const XMLCh ch) {
       
   189 
       
   190     return XMLString::indexOf(fDelimeters, ch) == -1 ? false : true;
       
   191 }
       
   192 
       
   193 
       
   194 // ---------------------------------------------------------------------------
       
   195 //  XMLStringTokenizer: Management methods
       
   196 // ---------------------------------------------------------------------------
       
   197 inline int XMLStringTokenizer::countTokens() {
       
   198 
       
   199     if (fStringLen == 0)
       
   200 		return 0;
       
   201 
       
   202     int  tokCount = 0;
       
   203     bool inToken = false;
       
   204 
       
   205     for (int i= fOffset; i< fStringLen; i++) {
       
   206 
       
   207         if (isDelimeter(fString[i])) {
       
   208 
       
   209             if (inToken) {
       
   210                 inToken = false;
       
   211             }
       
   212 
       
   213             continue;
       
   214         }
       
   215 
       
   216 		if (!inToken) {
       
   217 
       
   218             tokCount++;
       
   219             inToken = true;
       
   220         }
       
   221 
       
   222     } // end for
       
   223 
       
   224     return tokCount;
       
   225 }
       
   226 
       
   227 XERCES_CPP_NAMESPACE_END
       
   228 
       
   229 #endif
       
   230 
       
   231 /**
       
   232   * End of file XMLStringTokenizer.hpp
       
   233   */
       
   234