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

KIO

ksslx509map.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE project
00002  *
00003  * Copyright (C) 2000 George Staikos <staikos@kde.org>
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Library General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2 of the License, or (at your option) any later version.
00009  *
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Library General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Library General Public License
00016  * along with this library; see the file COPYING.LIB.  If not, write to
00017  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019  */
00020 
00021 #include "ksslx509map.h"
00022 #include <QtCore/QStringList>
00023 #include <QtCore/QRegExp>
00024 
00025 KSSLX509Map::KSSLX509Map(const QString& name) {
00026   parse(name);
00027 }
00028 
00029 
00030 KSSLX509Map::~KSSLX509Map() {
00031 
00032 }
00033 
00034 
00035 void KSSLX509Map::setValue(const QString& key, const QString& value) {
00036     m_pairs.insert(key, value);
00037 }
00038 
00039 
00040 QString KSSLX509Map::getValue(const QString& key) const {
00041     if (!m_pairs.contains(key)) {
00042         return QString();
00043     }
00044 
00045     return m_pairs[key];
00046 }
00047 
00048 static QStringList tokenizeBy(const QString& str, const QRegExp& tok, bool keepEmpties = false) {
00049 QStringList tokens;
00050 unsigned int head, tail;
00051 QByteArray bastr = str.toAscii();
00052 const char *chstr = bastr.constData();
00053 unsigned int length = str.length();
00054  
00055     if (length < 1) {
00056         return tokens;
00057     }
00058 
00059     if (length == 1) {
00060         tokens.append(str);
00061         return tokens;
00062     }
00063 
00064     for(head = 0, tail = 0; tail < length-1; head = tail+1) {
00065         QString thisline;
00066 
00067         tail = str.indexOf(tok, head);
00068 
00069         if (tail > length)           // last token - none at end
00070             tail = length;
00071 
00072         if (tail-head > 0 || keepEmpties) {    // it has to be at least 1 long!
00073             thisline = &(chstr[head]);
00074             thisline.truncate(tail-head);
00075             tokens.append(thisline);
00076         }
00077     }
00078     return tokens;
00079 }
00080 
00081 
00082 void KSSLX509Map::parse(const QString& name) {
00083 const QStringList vl = tokenizeBy(name, QRegExp("/[A-Za-z]+="), false);
00084 
00085     m_pairs.clear();
00086 
00087     for (QStringList::ConstIterator j = vl.begin(); j != vl.end(); ++j) {
00088         const QStringList apair = tokenizeBy(*j, QRegExp("="), false);
00089         if( apair.count() >0 ) {
00090         if (m_pairs.contains(apair[0])) {
00091             QString oldValue = m_pairs[apair[0]];
00092             oldValue += '\n';
00093             oldValue += (apair.count()>1) ? apair[1]:"";
00094             m_pairs.insert(apair[0], oldValue);
00095         } else {
00096             m_pairs.insert(apair[0], (apair.count()>1) ? apair[1]: "" );
00097         }
00098         }
00099     }
00100 }
00101 
00102 
00103 void KSSLX509Map::reset(const QString& name) {
00104     parse(name);
00105 }
00106 

KIO

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
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