00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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;
00030 const uint MAX_LINES = 500;
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;
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