• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeutils API Reference
  • KDE Home
  • Contact Us
 

superkaramba

  • sources
  • kde-4.12
  • kdeutils
  • superkaramba
  • src
lineparser.cpp
Go to the documentation of this file.
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 
25 #include <QRegExp>
26 
27 LineParser::LineParser(const QString& line)
28 {
29  set(line);
30 }
31 
32 LineParser::~LineParser()
33 {}
34 
35 void LineParser::set(const QString& line)
36 {
37  QRegExp rx("^\\s*(\\S+)");
38  m_line = line;
39 
40  rx.indexIn(m_line);
41  m_meter = rx.cap(1).toUpper();
42 }
43 
44 int LineParser::getInt(const QString &w, int def) const
45 {
46  QRegExp rx("\\W+" + w + "=([-]?\\d+)", Qt::CaseInsensitive);
47  if (rx.indexIn(m_line) != -1)
48  return rx.cap(1).toInt();
49  else
50  return def;
51 }
52 
53 QColor LineParser::getColor(const QString &w, const QColor &def) const
54 {
55  QRegExp rx("\\W+" + w + "=([-]?\\d+),([-]?\\d+),([-]?\\d+)(,([-]?\\d+))?", Qt::CaseInsensitive);
56  if (rx.indexIn(m_line) != -1) {
57  int alpha = 255;
58  QString alphaString = rx.cap(4).remove(0, 1);
59  if (!alphaString.isEmpty()) {
60  alpha = alphaString.toInt();
61  }
62  return QColor(rx.cap(1).toInt(), rx.cap(2).toInt(), rx.cap(3).toInt(), alpha);
63  } else {
64  return def;
65  }
66 }
67 
68 QString LineParser::getString(const QString &w, const QString &def) const
69 {
70  QString result;
71  QRegExp rx("\\W+" + w + "=\"([^\"]*)\"", Qt::CaseInsensitive);
72 
73  bool found = (rx.indexIn(m_line) == -1) ? false : true;
74  if (rx.cap(1).isEmpty()) {
75  rx = QRegExp(w + "=(\\S+)", Qt::CaseInsensitive);
76  found = (rx.indexIn(m_line) == -1) ? false : true;
77  result = rx.cap(1);
78  } else {
79  result = rx.cap(1);
80  }
81 
82  result.replace("%quote", "\"");
83 
84  if (found)
85  return result;
86  else
87  return def;
88 }
89 
90 bool LineParser::getBoolean(const QString &w, bool def) const
91 {
92  QString boolean = getString(w, "-").toLower();
93  if (boolean == "-")
94  return def;
95  else if (boolean == "true") // true / false
96  return true;
97  else if (boolean == "1") // 1 / 0
98  return true;
99  else if (boolean == "on") // on / off
100  return true;
101  return false;
102 }
LineParser::LineParser
LineParser(const QString &line=QString())
Definition: lineparser.cpp:27
LineParser::set
void set(const QString &line)
Definition: lineparser.cpp:35
LineParser::getColor
QColor getColor(const QString &w, const QColor &def=QColor()) const
Definition: lineparser.cpp:53
LineParser::getString
QString getString(const QString &w, const QString &def=QString()) const
Definition: lineparser.cpp:68
LineParser::~LineParser
~LineParser()
Definition: lineparser.cpp:32
LineParser::getBoolean
bool getBoolean(const QString &w, bool def=false) const
Definition: lineparser.cpp:90
lineparser.h
LineParser::getInt
int getInt(const QString &w, int def=0) const
Definition: lineparser.cpp:44
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:07:20 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

superkaramba

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

kdeutils API Reference

Skip menu "kdeutils API Reference"
  • ark
  • filelight
  • kcalc
  • kcharselect
  • kdf
  • kfloppy
  • kgpg
  • kremotecontrol
  • ktimer
  • kwallet
  • superkaramba
  • sweeper

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal