X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=qjson%2Fsrc%2Fparser.cpp;fp=qjson%2Fsrc%2Fparser.cpp;h=0000000000000000000000000000000000000000;hb=54cb1857146acd8ada989ccbc85540793f654d69;hp=061e063e91e0cbd09e47b5b1c903c2a3c0cd81c1;hpb=ffe49fc9cc4e16f1f300e7e2468036d9dd6529b7;p=buliscores diff --git a/qjson/src/parser.cpp b/qjson/src/parser.cpp deleted file mode 100644 index 061e063..0000000 --- a/qjson/src/parser.cpp +++ /dev/null @@ -1,124 +0,0 @@ -/* This file is part of QJson - * - * Copyright (C) 2008 Flavio Castelli - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "parser.h" -#include "parser_p.h" -#include "json_parser.hh" -#include "json_scanner.h" - -#include -#include -#include -#include - -using namespace QJson; - -ParserPrivate::ParserPrivate() : - m_scanner(0) - , m_negate(false) - , m_error(false) - , m_specialNumbersAllowed(false) -{ -} - -ParserPrivate::~ParserPrivate() -{ - delete m_scanner; -} - -void ParserPrivate::setError(QString errorMsg, int errorLine) { - m_error = true; - m_errorMsg = errorMsg; - m_errorLine = errorLine; -} - -Parser::Parser() : - d(new ParserPrivate) -{ -} - -Parser::~Parser() -{ - delete d; -} - -QVariant Parser::parse (QIODevice* io, bool* ok) -{ - d->m_errorMsg.clear(); - delete d->m_scanner; - d->m_scanner = 0; - - if (!io->isOpen()) { - if (!io->open(QIODevice::ReadOnly)) { - if (ok != 0) - *ok = false; - qCritical ("Error opening device"); - return QVariant(); - } - } - - if (!io->isReadable()) { - if (ok != 0) - *ok = false; - qCritical ("Device is not readable"); - io->close(); - return QVariant(); - } - - d->m_scanner = new JSonScanner (io); - d->m_scanner->allowSpecialNumbers(d->m_specialNumbersAllowed); - yy::json_parser parser(d); - parser.parse(); - - delete d->m_scanner; - d->m_scanner = 0; - - if (ok != 0) - *ok = !d->m_error; - - io->close(); - return d->m_result; -} - -QVariant Parser::parse(const QByteArray& jsonString, bool* ok) { - QBuffer buffer; - buffer.open(QBuffer::ReadWrite); - buffer.write(jsonString); - buffer.seek(0); - return parse (&buffer, ok); -} - -QString Parser::errorString() const -{ - return d->m_errorMsg; -} - -int Parser::errorLine() const -{ - return d->m_errorLine; -} - -void QJson::Parser::allowSpecialNumbers(bool allowSpecialNumbers) { - d->m_specialNumbersAllowed = allowSpecialNumbers; -} - -bool Parser::specialNumbersAllowed() const { - return d->m_specialNumbersAllowed; -}