• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • superkaramba
 

superkaramba

  • superkaramba
  • src
lineparser.cpp
1/*
2 * Copyright (C) 2003-2004 Adam Geitgey <adam@rootnode.org>
3 * Copyright (C) 2003 Hans Karlsson <karlsson.h@home.se>
4 * Copyright (c) 2005 Ryan Nickell <p0z3r@earthlink.net>
5 * Copyright (c) 2005 Petri Damsten <damu@iki.fi>
6 *
7 * This file is part of SuperKaramba.
8 *
9 * SuperKaramba is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * SuperKaramba is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with SuperKaramba; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 ****************************************************************************/
23#include "lineparser.h"
24#include <tqregexp.h>
25
26LineParser::LineParser(const TQString& line)
27{
28 set(line);
29}
30
31LineParser::~LineParser()
32{
33}
34
35void LineParser::set(const TQString& line)
36{
37 TQRegExp rx("^\\s*(\\S+)");
38 m_line = line;
39
40 rx.search(m_line);
41 m_meter = rx.cap(1).upper();
42}
43
44int LineParser::getInt(TQString w, int def) const
45{
46 TQRegExp rx( "\\W+" + w +"=([-]?\\d+)", false );
47 if (rx.search(m_line) != -1)
48 return rx.cap(1).toInt();
49 else
50 return def;
51}
52
53TQColor LineParser::getColor(TQString w, TQColor def) const
54{
55 TQRegExp rx( "\\W+" + w + "=([-]?\\d+),([-]?\\d+),([-]?\\d+)", false );
56 if (rx.search(m_line) != -1)
57 return TQColor(rx.cap(1).toInt(), rx.cap(2).toInt(), rx.cap(3).toInt());
58 else
59 return def;
60}
61
62TQString LineParser::getString(TQString w, TQString def) const
63{
64 TQString result;
65 TQRegExp rx( "\\W+" + w + "=\"([^\"]*)\"", false );
66
67 bool found = (rx.search(m_line)==-1)?false:true;
68 if (rx.cap(1).isEmpty())
69 {
70 rx = TQRegExp(w + "=(\\S+)", false);
71 found = (rx.search(m_line)==-1)?false:true;
72 result = rx.cap(1);
73 }
74 else
75 {
76 result = rx.cap(1);
77 }
78 if(found)
79 return result;
80 else
81 return def;
82}
83
84bool LineParser::getBoolean(TQString w, bool def) const
85{
86 TQString boolean = getString(w, "-").lower();
87 if(boolean == "-")
88 return def;
89 else if (boolean == "true") // true / false
90 return true;
91 else if (boolean == "1") // 1 / 0
92 return true;
93 else if (boolean == "on") // on / off
94 return true;
95 return false;
96}

superkaramba

Skip menu "superkaramba"
  • Main Page
  • Alphabetical List
  • Class List
  • File List
  • Class Members

superkaramba

Skip menu "superkaramba"
  • kcalc
  •   knumber
  • superkaramba
Generated for superkaramba by doxygen 1.9.4
This website is maintained by Timothy Pearson.