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

superkaramba

lineparser.cpp

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2003-2004 Adam Geitgey <adam@rootnode.org>
00003  * Copyright (C) 2003 Hans Karlsson <karlsson.h@home.se>
00004  * Copyright (c) 2005 Ryan Nickell <p0z3r@earthlink.net>
00005  * Copyright (c) 2005 Petri Damsten <damu@iki.fi>
00006  *
00007  * This file is part of SuperKaramba.
00008  *
00009  *  SuperKaramba is free software; you can redistribute it and/or modify
00010  *  it under the terms of the GNU General Public License as published by
00011  *  the Free Software Foundation; either version 2 of the License, or
00012  *  (at your option) any later version.
00013  *
00014  *  SuperKaramba is distributed in the hope that it will be useful,
00015  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  *  GNU General Public License for more details.
00018  *
00019  *  You should have received a copy of the GNU General Public License
00020  *  along with SuperKaramba; if not, write to the Free Software
00021  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00022  ****************************************************************************/
00023 #include "lineparser.h"
00024 
00025 #include <QRegExp>
00026 
00027 LineParser::LineParser(const QString& line)
00028 {
00029     set(line);
00030 }
00031 
00032 LineParser::~LineParser()
00033 {}
00034 
00035 void LineParser::set(const QString& line)
00036 {
00037     QRegExp rx("^\\s*(\\S+)");
00038     m_line = line;
00039 
00040     rx.indexIn(m_line);
00041     m_meter = rx.cap(1).toUpper();
00042 }
00043 
00044 int LineParser::getInt(const QString &w, int def) const
00045 {
00046     QRegExp rx("\\W+" + w + "=([-]?\\d+)", Qt::CaseInsensitive);
00047     if (rx.indexIn(m_line) != -1)
00048         return rx.cap(1).toInt();
00049     else
00050         return def;
00051 }
00052 
00053 QColor LineParser::getColor(const QString &w, const QColor &def) const
00054 {
00055     QRegExp rx("\\W+" + w + "=([-]?\\d+),([-]?\\d+),([-]?\\d+)(,([-]?\\d+))?", Qt::CaseInsensitive);
00056     if (rx.indexIn(m_line) != -1) {
00057         int alpha = 255;
00058         QString alphaString = rx.cap(4).remove(0, 1);
00059         if (!alphaString.isEmpty()) {
00060             alpha = alphaString.toInt();
00061         }
00062         return QColor(rx.cap(1).toInt(), rx.cap(2).toInt(), rx.cap(3).toInt(), alpha);
00063     } else {
00064         return def;
00065     }
00066 }
00067 
00068 QString LineParser::getString(const QString &w, const QString &def) const
00069 {
00070     QString result;
00071     QRegExp rx("\\W+" + w + "=\"([^\"]*)\"", Qt::CaseInsensitive);
00072 
00073     bool found = (rx.indexIn(m_line) == -1) ? false : true;
00074     if (rx.cap(1).isEmpty()) {
00075         rx = QRegExp(w + "=(\\S+)", Qt::CaseInsensitive);
00076         found = (rx.indexIn(m_line) == -1) ? false : true;
00077         result = rx.cap(1);
00078     } else {
00079         result = rx.cap(1);
00080     }
00081 
00082     result.replace("%quote", "\"");
00083 
00084     if (found)
00085         return result;
00086     else
00087         return def;
00088 }
00089 
00090 bool LineParser::getBoolean(const QString &w, bool def) const
00091 {
00092     QString boolean = getString(w, "-").toLower();
00093     if (boolean == "-")
00094         return def;
00095     else if (boolean == "true") // true / false
00096         return true;
00097     else if (boolean == "1") // 1 / 0
00098         return true;
00099     else if (boolean == "on") // on / off
00100         return true;
00101     return false;
00102 }

superkaramba

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

kdeutils

Skip menu "kdeutils"
  • ark
  • kcalc
  • kcharselect
  • kdelirc
  • kdessh
  • kdf
  • kfloppy
  • kgpg
  • kjots
  • klaptopdaemon
  • kmilo
  • ksim
  • ktimer
  • kwallet
  • superkaramba
Generated for kdeutils by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal