superkaramba
lineparser.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "lineparser.h"
00024 #include <tqregexp.h>
00025
00026 LineParser::LineParser(const TQString& line)
00027 {
00028 set(line);
00029 }
00030
00031 LineParser::~LineParser()
00032 {
00033 }
00034
00035 void LineParser::set(const TQString& line)
00036 {
00037 TQRegExp rx("^\\s*(\\S+)");
00038 m_line = line;
00039
00040 rx.search(m_line);
00041 m_meter = rx.cap(1).upper();
00042 }
00043
00044 int LineParser::getInt(TQString w, int def) const
00045 {
00046 TQRegExp rx( "\\W+" + w +"=([-]?\\d+)", false );
00047 if (rx.search(m_line) != -1)
00048 return rx.cap(1).toInt();
00049 else
00050 return def;
00051 }
00052
00053 TQColor LineParser::getColor(TQString w, TQColor def) const
00054 {
00055 TQRegExp rx( "\\W+" + w + "=([-]?\\d+),([-]?\\d+),([-]?\\d+)", false );
00056 if (rx.search(m_line) != -1)
00057 return TQColor(rx.cap(1).toInt(), rx.cap(2).toInt(), rx.cap(3).toInt());
00058 else
00059 return def;
00060 }
00061
00062 TQString LineParser::getString(TQString w, TQString def) const
00063 {
00064 TQString result;
00065 TQRegExp rx( "\\W+" + w + "=\"([^\"]*)\"", false );
00066
00067 bool found = (rx.search(m_line)==-1)?false:true;
00068 if (rx.cap(1).isEmpty())
00069 {
00070 rx = TQRegExp(w + "=(\\S+)", false);
00071 found = (rx.search(m_line)==-1)?false:true;
00072 result = rx.cap(1);
00073 }
00074 else
00075 {
00076 result = rx.cap(1);
00077 }
00078 if(found)
00079 return result;
00080 else
00081 return def;
00082 }
00083
00084 bool LineParser::getBoolean(TQString w, bool def) const
00085 {
00086 TQString boolean = getString(w, "-").lower();
00087 if(boolean == "-")
00088 return def;
00089 else if (boolean == "true")
00090 return true;
00091 else if (boolean == "1")
00092 return true;
00093 else if (boolean == "on")
00094 return true;
00095 return false;
00096 }