• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

spl/text/StringTokenizer.h

00001 /* Ported to SPL, original attribution below. */
00002 /*
00003  * Copyright 1999-2004 The Apache Software Foundation.
00004  *
00005  * Licensed under the Apache License, Version 2.0 (the "License");
00006  * you may not use this file except in compliance with the License.
00007  * 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 #if !defined(STRINGTOKENIZER_HEADER_GUARD_1357924680)
00018 #define STRINGTOKENIZER_HEADER_GUARD_1357924680
00019 
00020 #include <spl/String.h>
00021 #include <spl/RefCountPtr.h>
00022 #include <spl/WeakReference.h>
00023 
00029 class StringTokenizer;
00030 typedef RefCountPtr<StringTokenizer> StringTokenizerPtr;
00031 typedef WeakReference<StringTokenizer, StringTokenizerPtr> StringTokenizerRef;
00032 
00033 REGISTER_TYPEOF( 492, StringTokenizerPtr );
00034 REGISTER_TYPEOF( 494, StringTokenizerRef );
00035 
00039 class StringTokenizer : public IMemoryValidate
00040 {
00041 private:
00042         static const char s_defaultTokens[];
00043 
00044     // Data members...
00045     String m_string;
00046 
00047         String m_tokens;
00048 
00049         bool m_returnTokens;
00050 
00051         int m_currentIndex;
00052 
00053 public:
00054 
00065         StringTokenizer(const String&   theString,
00066                                         const String&   theTokens = " \t\n\r",
00067                                         bool fReturnTokens = false);
00068 
00069         StringTokenizer(const StringTokenizer&);
00070 
00071     StringTokenizer& operator =(const StringTokenizer&);
00072 
00073         virtual ~StringTokenizer();
00074 
00080         bool HasMoreTokens() const;
00081 
00088         void NextToken(String&  theToken);
00089 
00095         int     CountTokens() const;
00096 
00097         inline void Reset()
00098         {
00099                 m_currentIndex = 0;
00100         }
00101 
00102 #if defined(DEBUG) || defined(_DEBUG)
00103         void CheckMem() const;
00104         void ValidateMem() const;
00105 #endif
00106 
00107 protected:
00108 
00109         int FindNextDelimiterIndex(int theStartIndex) const;
00110 
00111 private:
00112 
00113     // These are not implemented...
00114         inline bool     operator ==(const StringTokenizer&) const { return false; }
00115 };
00116 
00117 REGISTER_TYPEOF( 496, StringTokenizer );
00118 
00121 #endif  // STRINGTOKENIZER_HEADER_GUARD_1357924680