00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef FLC_TOKENIZER_H
00017 #define FLC_TOKENIZER_H
00018
00019 #include <falcon/setup.h>
00020 #include <falcon/types.h>
00021 #include <falcon/string.h>
00022 #include <falcon/sequence.h>
00023 #include <falcon/item.h>
00024
00025 namespace Falcon
00026 {
00027
00035 class FALCON_DYN_CLASS TokenizerParams: public BaseAlloc
00036 {
00037 bool m_bGroupSep;
00038 bool m_bBindSep;
00039 bool m_bTrim;
00040 int32 m_nMaxToken;
00041 bool m_bWsIsToken;
00042 bool m_bReturnSep;
00043
00044 public:
00045 TokenizerParams():
00046 m_bGroupSep( false ),
00047 m_bBindSep( false ),
00048 m_bTrim( false ),
00049 m_nMaxToken( -1 ),
00050 m_bWsIsToken( false ),
00051 m_bReturnSep( false )
00052 {}
00053
00059 TokenizerParams &groupSep( bool mode = true ) { m_bGroupSep = mode; return *this; }
00060
00066 TokenizerParams &wsIsToken( bool mode = true ) { m_bWsIsToken = mode; return *this; }
00067
00073 TokenizerParams &bindSep( bool mode = true ) { m_bBindSep = mode; return *this; }
00074
00084 TokenizerParams &returnSep( bool mode = true ) { m_bReturnSep = mode; return *this; }
00085
00086
00098 TokenizerParams &trim( bool mode = true ) { m_bTrim = mode; return *this; }
00099
00103 TokenizerParams &maxToken( int32 size ) { m_nMaxToken = size; return *this; }
00104
00105 bool isGroupSep() const { return m_bGroupSep; }
00106 bool isBindSep() const { return m_bBindSep; }
00107 bool isTrim() const { return m_bTrim; }
00108 bool isWsToken() const { return m_bWsIsToken; }
00109 int32 maxToken() const { return m_nMaxToken; }
00110 bool isReturnSep() const { return m_bReturnSep; }
00111 };
00112
00113
00135 class FALCON_DYN_CLASS Tokenizer: public Sequence
00136 {
00137 String m_separators;
00138 TokenizerParams m_params;
00139
00140 Stream *m_input;
00141 bool m_bOwnStream;
00142
00143 String m_temp;
00144 uint32 m_version;
00145
00146 uint32 m_nextToken;
00147 bool m_hasCurrent;
00148
00149 public:
00150
00155 Tokenizer( TokenizerParams ¶ms, const String &seps, const String &source );
00156 Tokenizer( TokenizerParams ¶ms, const String &seps, Stream *inp=0, bool bOwn = false );
00157 Tokenizer( const Tokenizer &other );
00158
00159
00160 virtual ~Tokenizer();
00161
00165 virtual const Item &front() const;
00166
00170 virtual const Item &back() const;
00171
00175 virtual void clear();
00176
00178 virtual bool empty() const;
00179
00183 virtual bool next();
00184
00186 const String &getToken() const { return m_temp; }
00187
00190 virtual void rewind();
00191
00192 virtual FalconData* clone() const;
00193 virtual void gcMark( uint32 mark ) { Sequence::gcMark( mark ); }
00194
00199 void parse( const String &data );
00200
00204 void parse( Stream *in, bool bOwn = false );
00205
00207 bool isReady() const { return m_input != 0; }
00208
00209 bool hasCurrent() const { return m_hasCurrent; }
00210
00211 virtual void append( const Item& itm );
00212 virtual void prepend( const Item& itm );
00213
00214
00215
00216
00217 protected:
00218
00219 virtual void getIterator( Iterator& tgt, bool tail = false ) const;
00220 virtual void copyIterator( Iterator& tgt, const Iterator& source ) const;
00221 virtual void insert( Iterator &iter, const Item &data );
00222 virtual void erase( Iterator &iter );
00223 virtual bool hasNext( const Iterator &iter ) const;
00224 virtual bool hasPrev( const Iterator &iter ) const;
00225 virtual bool hasCurrent( const Iterator &iter ) const;
00226 virtual bool next( Iterator &iter ) const;
00227 virtual bool prev( Iterator &iter ) const;
00228 virtual Item& getCurrent( const Iterator &iter );
00229 virtual Item& getCurrentKey( const Iterator &iter );
00230 virtual bool equalIterator( const Iterator &first, const Iterator &second ) const;
00231 };
00232
00233
00234
00235 }
00236
00237 #endif
00238
00239