filters

ailexer.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2002, Dirk Schönberger <dirk.schoenberger@sz-online.de>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #ifndef AILEXER_H
00021 #define AILEXER_H
00022 
00023 #include <qiodevice.h>
00024 #include <qstring.h>
00025 
00029 typedef enum {
00030   State_Comment=0,
00031   State_Integer,
00032   State_Float,
00033   State_String,
00034   State_Token,
00035   State_Reference,
00036   State_Start,
00037   State_BlockStart,
00038   State_BlockEnd,
00039   State_ArrayStart,
00040   State_ArrayEnd,
00041   State_Byte,
00042   State_ByteArray,
00043   State_StringEncodedChar,
00044   State_CommentEncodedChar,
00045   State_ByteArray2
00046 } State;
00047 
00048 typedef enum {
00049   Action_Copy=1,
00050   Action_CopyOutput,
00051   Action_Output,
00052   Action_Ignore,
00053   Action_Abort,
00054   Action_OutputUnget,
00055   Action_InitTemp,
00056   Action_CopyTemp,
00057   Action_DecodeUnget,
00058   Action_ByteArraySpecial
00059 } Action;
00060 
00061 class StringBuffer {
00062 public:
00063   StringBuffer ();
00064   virtual ~StringBuffer ();
00065 
00066   void append (char c);
00067   void clear();
00068   QString toString() const;
00069   uint length();
00070   double toFloat();
00071   int toInt();
00072   const char *latin1();
00073   QString mid( uint index, uint len=0xffffffff) const;
00074 private:
00075   char *m_buffer;
00076   uint m_length;
00077   int m_capacity;
00078 
00079   void ensureCapacity (int p_capacity);
00080 };
00081 
00082 class AILexer {
00083 public: 
00084     AILexer();
00085     virtual ~AILexer();
00086 
00087   virtual bool parse (QIODevice& fin);
00088 private:
00089   State m_curState;
00090   StringBuffer m_buffer;
00091   StringBuffer m_temp;
00092 
00093 /*  State nextState (char c);
00094   Action nextAction (char c);  */
00095 
00096   void nextStep (char c, State* newState, Action* newAction);
00097 
00098   void doOutput ();
00099   void doHandleByteArray ();
00100   uchar getByte();
00101   uchar decode();
00102 
00103 protected:
00104   virtual void parsingStarted();
00105   virtual void parsingFinished();
00106   virtual void parsingAborted();
00107 
00108   virtual void gotComment (const char *value);
00109   virtual void gotIntValue (int value);
00110   virtual void gotDoubleValue (double value);
00111   virtual void gotStringValue (const char *value);
00112   virtual void gotToken (const char *value);
00113   virtual void gotReference (const char *value);
00114   virtual void gotBlockStart ();
00115   virtual void gotBlockEnd ();
00116   virtual void gotArrayStart ();
00117   virtual void gotArrayEnd ();
00118   virtual void gotByte (uchar value);
00119   virtual void gotByteArray (const QByteArray &data);
00120 };
00121 
00122 #endif
00123 
KDE Home | KDE Accessibility Home | Description of Access Keys