Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef LINEPARSER_H
00029 #define LINEPARSER_H
00030
00031 #include "QGpCoreToolsDLLExport.h"
00032 #include "StringSection.h"
00033
00034 namespace QGpCoreTools {
00035
00036 class QGPCORETOOLS_EXPORT LineParser
00037 {
00038 public:
00039 LineParser();
00040 LineParser(const QString& str);
00041 LineParser(const StringSection& str);
00042 ~LineParser() {}
00043
00044 void setString(const QString& str);
00045 void setString(const StringSection& str);
00046
00047 void setDelimiters(const QString& d) {_delimiters=d;}
00048 const QString& delimiters() const {return _delimiters;}
00049
00050 void setSkipEmpty(bool s) {_skipEmpty=s;}
00051 bool skipEmpty() const {return _skipEmpty;}
00052
00053 int count();
00054 inline const StringSection& value(int index);
00055 inline QString toString(int index, bool& ok);
00056 QString toString(int indexBegin, int indexEnd, bool& ok);
00057 inline bool toBool(int index, bool& ok);
00058 inline int toInt(int index, bool& ok, int base=10);
00059 inline uint toUInt(int index, bool& ok, int base=10);
00060 inline qlonglong toLongLong(int index, bool& ok, int base=10);
00061 inline double toDouble(int index, bool& ok);
00062 int startsAt(int index, bool& ok);
00063 int endsAt(int index, bool& ok);
00064 private:
00065 const StringSection& parse(int index);
00066
00067 QVector<StringSection> _values;
00068 const QChar * _ptr;
00069 StringSection _strSection;
00070 QString _str;
00071 QString _delimiters;
00072 bool _skipEmpty;
00073 };
00074
00075 inline const StringSection& LineParser::value(int index)
00076 {
00077 if(index<_values.count()) return _values.at(index);
00078 return parse(index);
00079 }
00080
00081 inline QString LineParser::toString(int index, bool& ok)
00082 {
00083 const StringSection& v=value(index);
00084 if(v.isValid()) {
00085 return v.toString();
00086 } else {
00087 ok=false;
00088 return QString::null;
00089 }
00090 }
00091
00092 inline bool LineParser::toBool(int index, bool& ok)
00093 {
00094 const StringSection& v=value(index);
00095 if(v.isValid()) {
00096 return v.toBool();
00097 } else {
00098 ok=false;
00099 return true;
00100 }
00101 }
00102
00103 inline int LineParser::toInt(int index, bool& ok, int base)
00104 {
00105 if(ok) {
00106 return value(index).toInt(&ok, base);
00107 } else {
00108 return 0;
00109 }
00110 }
00111
00112 inline uint LineParser::toUInt(int index, bool& ok, int base)
00113 {
00114 if(ok) {
00115 return value(index).toUInt(&ok, base);
00116 } else {
00117 return 0;
00118 }
00119 }
00120
00121 inline qlonglong LineParser::toLongLong(int index, bool& ok, int base)
00122 {
00123 if(ok) {
00124 return value(index).toLongLong(&ok, base);
00125 } else {
00126 return 0;
00127 }
00128 }
00129
00130 inline double LineParser::toDouble(int index, bool& ok)
00131 {
00132 if(ok) {
00133 return value(index).toDouble(&ok);
00134 } else {
00135 return 0.0;
00136 }
00137 }
00138
00139 }
00140
00141 #endif // LINEPARSER_H