Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

textparser.h

Go to the documentation of this file.
00001 /**********************************************************************
00002 ** Copyright (C) 2001 Trolltech AS.  All rights reserved.
00003 **
00004 ** This file is part of Qt Palmtop Environment.
00005 **
00006 ** This file may be distributed and/or modified under the terms of the
00007 ** GNU General Public License version 2 as published by the Free Software
00008 ** Foundation and appearing in the file LICENSE.GPL included in the
00009 ** packaging of this file.
00010 **
00011 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 **
00014 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00015 **
00016 ** Contact info@trolltech.com if any conditions of this licensing are
00017 ** not clear to you.
00018 **
00019 **********************************************************************/
00020 #include <qobject.h>
00021 #include <qstring.h>
00022 
00023 #ifndef TEXTPARSER_H
00024 #define TEXTPARSER_H
00025 
00026 enum t_strType { Word, Number};
00027 enum t_lineType {NewLine, LastLine};
00028 
00029 const uint MAX_ELEMENTS = 200;    //Should be dynamic
00030 const uint MAX_LINES = 500;     //Should be dynamic
00031 
00032 struct t_splitElm
00033 {
00034   QChar separator;
00035   int strType;
00036   QString str;
00037 };
00038 
00039 struct t_splitLine
00040 {
00041   t_lineType lineType;
00042   QString str;          //a bit redundant...
00043   t_splitElm elm[MAX_ELEMENTS];
00044   int elmCount;
00045 };
00046 
00047 class TextParser: public QObject
00048 {
00049   Q_OBJECT
00050   
00051 public:
00052   TextParser(const QString &in, const QString &lineBreak);
00053   TextParser(const QString &in, const QString &lineBreak, const QString &sep);
00054   int find(const QString &target, QChar sep, int pos, bool upperCase);
00055   int elmCount();
00056   QChar separatorAt(int pos);
00057   QChar nextSeparator();
00058   bool hasNextSeparator();
00059   QString wordAt(int pos);
00060   QString nextWord();
00061   bool hasNextWord();
00062     QString getString(int *pos, QChar stop, bool lineEnd);
00063     QString getNextLine();
00064     bool hasNextLine();
00065     int endLinePos(int pos);
00066 
00067 private:
00068   void init();
00069   void createSeparators();
00070   t_splitLine nextLine();
00071   void split();
00072   t_splitLine splitLine(t_splitLine line);
00073   bool isSeparator(QChar chr);
00074   t_splitLine splitDone[MAX_LINES];
00075   int getLineReference(int pos, int *line, int *inLinePos);
00076   
00077   int lineCount, linePos, totalElmCount;
00078   int separatorPos, wordPos;
00079   QString data, separators, lineSep;
00080   int sepAtLine, sepAtPosElm;
00081   int wordAtLine, wordAtPosElm;
00082   int atLine, atPosElm;
00083 };
00084 
00085 #endif

Generated on Sat Nov 5 16:18:09 2005 for OPIE by  doxygen 1.4.2