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

kconf_update

  • sources
  • kde-4.14
  • kdelibs
  • kconf_update
kconfigutils.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE libraries
2  Copyright 2010 Canonical Ltd
3  Author: Aurélien Gâteau <aurelien.gateau@canonical.com>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License (LGPL) as published by the Free Software Foundation;
8  either version 2 of the License, or (at your option) any later
9  version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Library General Public License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to
18  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  Boston, MA 02110-1301, USA.
20 */
21 #include "kconfigutils.h"
22 
23 // KDE
24 #include <kconfig.h>
25 #include <kconfiggroup.h>
26 
27 namespace KConfigUtils
28 {
29 
30 bool hasGroup(KConfig *config, const QStringList &lst)
31 {
32  KConfigGroup group = openGroup(config, lst);
33  return group.exists();
34 }
35 
36 KConfigGroup openGroup(KConfig *config, const QStringList &_lst)
37 {
38  if (_lst.isEmpty()) {
39  return KConfigGroup(config, QString());
40  }
41 
42  QStringList lst = _lst;
43 
44  KConfigGroup cg;
45  for (cg = KConfigGroup(config, lst.takeFirst()); !lst.isEmpty(); cg = KConfigGroup(&cg, lst.takeFirst())) {}
46  return cg;
47 }
48 
49 QStringList parseGroupString(const QString &_str, bool *ok, QString *error)
50 {
51  QString str = unescapeString(_str.trimmed(), ok, error);
52  if (!ok) {
53  return QStringList();
54  }
55 
56  *ok = true;
57  if (str[0] != '[') {
58  // Simplified notation, no '['
59  return QStringList() << str;
60  }
61 
62  if (!str.endsWith(']')) {
63  *ok = false;
64  *error = QString("Missing closing ']' in %1").arg(_str);
65  return QStringList();
66  }
67  // trim outer brackets
68  str.chop(1);
69  str.remove(0, 1);
70 
71  return str.split("][");
72 }
73 
74 QString unescapeString(const QString &src, bool *ok, QString *error)
75 {
76  QString dst;
77  int length = src.length();
78  for (int pos = 0; pos < length; ++pos) {
79  QChar ch = src.at(pos);
80  if (ch != '\\') {
81  dst += ch;
82  } else {
83  ++pos;
84  if (pos == length) {
85  *ok = false;
86  *error = QString("Unfinished escape sequence in %1").arg(src);
87  return QString();
88  }
89  ch = src.at(pos);
90  if (ch == 's') {
91  dst += ' ';
92  } else if (ch == 't') {
93  dst += '\t';
94  } else if (ch == 'n') {
95  dst += '\n';
96  } else if (ch == 'r') {
97  dst += '\r';
98  } else if (ch == '\\') {
99  dst += '\\';
100  } else if (ch == 'x') {
101  if (pos + 2 < length) {
102  char value = src.mid(pos + 1, 2).toInt(ok, 16);
103  if (*ok) {
104  dst += QChar::fromLatin1(value);
105  pos += 2;
106  } else {
107  *error = QString("Invalid hex escape sequence at column %1 in %2").arg(pos).arg(src);
108  return QString();
109  }
110  } else {
111  *ok = false;
112  *error = QString("Unfinished hex escape sequence at column %1 in %2").arg(pos).arg(src);
113  return QString();
114  }
115  } else {
116  *ok = false;
117  *error = QString("Invalid escape sequence at column %1 in %2").arg(pos).arg(src);
118  return QString();
119  }
120  }
121  }
122 
123  *ok = true;
124  return dst;
125 }
126 
127 } // namespace
KConfigUtils::parseGroupString
QStringList parseGroupString(const QString &_str, bool *ok, QString *error)
Definition: kconfigutils.cpp:49
QChar
QString::split
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
KConfigUtils::unescapeString
QString unescapeString(const QString &src, bool *ok, QString *error)
Definition: kconfigutils.cpp:74
kconfigutils.h
KConfigUtils::hasGroup
bool hasGroup(KConfig *config, const QStringList &lst)
Definition: kconfigutils.cpp:30
QString::remove
QString & remove(int position, int n)
QString::chop
void chop(int n)
QChar::fromLatin1
QChar fromLatin1(char c)
QString::toInt
int toInt(bool *ok, int base) const
QList::isEmpty
bool isEmpty() const
QString::trimmed
QString trimmed() const
QString::endsWith
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const
QString
QStringList
QString::mid
QString mid(int position, int n) const
QList::takeFirst
T takeFirst()
QString::at
const QChar at(int position) const
QString::length
int length() const
KConfigUtils::openGroup
KConfigGroup openGroup(KConfig *config, const QStringList &_lst)
Definition: kconfigutils.cpp:36
QString::arg
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:22:06 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kconf_update

Skip menu "kconf_update"
  • Main Page
  • Namespace List
  • Namespace Members
  • File List
  • File Members
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

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