Doomseeker
   
  • Doomseeker
  • Wadseeker
  • Download
  • Tracker
  • Git
  • Docs
  • Main Page
  • Classes
  • Files
  • File List
  • File Members

src/core/json.h

Go to the documentation of this file.
00001 /* Copyright 2011 Eeli Reilin. All rights reserved.
00002 *
00003 * Redistribution and use in source and binary forms, with or without
00004 * modification, are permitted provided that the following conditions are met:
00005 *
00006 * 1. Redistributions of source code must retain the above copyright notice,
00007 * this list of conditions and the following disclaimer.
00008 *
00009 * 2. Redistributions in binary form must reproduce the above copyright notice,
00010 * this list of conditions and the following disclaimer in the documentation
00011 * and/or other materials provided with the distribution.
00012 *
00013 * THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ''AS IS'' AND ANY EXPRESS OR
00014 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00015 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
00016 * EVENT SHALL EELI REILIN OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00017 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00018 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
00019 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00020 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00021 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
00022 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00023 *
00024 * The views and conclusions contained in the software and documentation
00025 * are those of the authors and should not be interpreted as representing
00026 * official policies, either expressed or implied, of Eeli Reilin.
00027 */
00028 
00033 #ifndef JSON_H
00034 #define JSON_H
00035 
00036 #include <QVariant>
00037 #include <QString>
00038 
00039 namespace QtJson
00040 {
00041 
00045 enum JsonToken
00046 {
00047         JsonTokenNone = 0,
00048         JsonTokenCurlyOpen = 1,
00049         JsonTokenCurlyClose = 2,
00050         JsonTokenSquaredOpen = 3,
00051         JsonTokenSquaredClose = 4,
00052         JsonTokenColon = 5,
00053         JsonTokenComma = 6,
00054         JsonTokenString = 7,
00055         JsonTokenNumber = 8,
00056         JsonTokenTrue = 9,
00057         JsonTokenFalse = 10,
00058         JsonTokenNull = 11
00059 };
00060 
00067 class Json
00068 {
00069         public:
00075                 static QVariant parse(const QString &json);
00076 
00083                 static QVariant parse(const QString &json, bool &success);
00084 
00091                 static QByteArray serialize(const QVariant &data);
00092 
00101                 static QByteArray serialize(const QVariant &data, bool &success);
00102 
00103         private:
00113                 static QVariant parseValue(const QString &json, int &index,
00114                                                                    bool &success);
00115 
00125                 static QVariant parseObject(const QString &json, int &index,
00126                                                                            bool &success);
00127 
00137                 static QVariant parseArray(const QString &json, int &index,
00138                                                                            bool &success);
00139 
00149                 static QVariant parseString(const QString &json, int &index,
00150                                                                         bool &success);
00151 
00160                 static QVariant parseNumber(const QString &json, int &index);
00161 
00170                 static int lastIndexOfNumber(const QString &json, int index);
00171 
00178                 static void eatWhitespace(const QString &json, int &index);
00179 
00188                 static int lookAhead(const QString &json, int index);
00189 
00198                 static int nextToken(const QString &json, int &index);
00199 };
00200 
00201 
00202 } //end namespace
00203 
00204 #endif //JSON_H
   
Doomseeker © 2009-2024 The Doomseeker Team