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

KIOSlave

parsinghelpers.h

Go to the documentation of this file.
00001 /* This file is part of the KDE libraries
00002     Copyright (C) 2008 Andreas Hartmetz <ahartmetz@gmail.com>
00003 
00004     This library is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU Library General Public
00006     License as published by the Free Software Foundation; either
00007     version 2 of the License, or (at your option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012     Library General Public License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public License
00015     along with this library; see the file COPYING.LIB.  If not, write to
00016     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017     Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #ifndef PARSINGHELPERS_H
00021 #define PARSINGHELPERS_H
00022 
00023 #include <QtCore/QList>
00024 #include <QtCore/QPair>
00025 #include <QtCore/QMap>
00026 
00027 struct HeaderField {
00028     HeaderField(bool multiValued)
00029         { isMultiValued = multiValued; }
00030     // QHash requires a default constructor
00031     HeaderField()
00032         { isMultiValued = false; }
00033 
00034     bool isMultiValued;
00035     QList<QPair<int, int> > beginEnd;
00036 };
00037 
00038 class HeaderTokenizer;
00039 class TokenIterator
00040 {
00041 public:
00042     inline bool hasNext() const
00043     {
00044         return m_currentToken < m_tokens.count();
00045     }
00046 
00047     QByteArray next();
00048 
00049     QByteArray current() const;
00050 
00051     QList<QByteArray> all() const;
00052 
00053 private:
00054     friend class HeaderTokenizer;
00055     QList<QPair<int, int> > m_tokens;
00056     int m_currentToken;
00057     const char *m_buffer;
00058     TokenIterator(const QList<QPair<int, int> > &tokens, const char *buffer)
00059      : m_tokens(tokens),
00060        m_currentToken(0),
00061        m_buffer(buffer) {}
00062 };
00063 
00064 class HeaderTokenizer : public QHash<QByteArray, HeaderField>
00065 {
00066 public:
00067     HeaderTokenizer(char *buffer);
00068     // note that buffer is not const - in the parsed area CR/LF will be overwritten
00069     // with spaces if there is a line continuation.
00071     int tokenize(int begin, int end);
00072 
00073     // after tokenize() has been called use the QHash part of this class to
00074     // ask for a list of begin-end indexes in buffer for header values.
00075 
00076     TokenIterator iterator(const char *key) const;
00077 private:
00078     char *m_buffer;
00079     struct HeaderFieldTemplate {
00080         const char *name;
00081         bool isMultiValued;
00082     };
00083     QList<QPair<int, int> > m_nullTokens;   //long-lived, allows us to pass out references.
00084 };
00085 
00086 #endif //PARSINGHELPERS_H

KIOSlave

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • 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
Generated for kdelibs by doxygen 1.7.3
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