00001 /* This file is part of QJson 00002 * 00003 * Copyright (C) 2008 Flavio Castelli <flavio.castelli@gmail.com> 00004 * Copyright (C) 2013 Silvio Moioli <silvio@moioli.net> 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License version 2.1, as published by the Free Software Foundation. 00009 * 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public License 00017 * along with this library; see the file COPYING.LIB. If not, write to 00018 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 * Boston, MA 02110-1301, USA. 00020 */ 00021 #include "json_scanner.cc" 00022 00023 #include "qjson_debug.h" 00024 #include "json_scanner.h" 00025 #include "json_parser.hh" 00026 00027 #include <ctype.h> 00028 00029 #include <QtCore/QDebug> 00030 #include <QtCore/QRegExp> 00031 00032 #include <cassert> 00033 00034 00035 JSonScanner::JSonScanner(QIODevice* io) 00036 : m_allowSpecialNumbers(false), 00037 m_io (io), 00038 m_criticalError(false), 00039 m_C_locale(QLocale::C) 00040 { 00041 00042 } 00043 00044 JSonScanner::~JSonScanner() 00045 { 00046 } 00047 00048 void JSonScanner::allowSpecialNumbers(bool allow) { 00049 m_allowSpecialNumbers = allow; 00050 } 00051 00052 int JSonScanner::yylex(YYSTYPE* yylval, yy::location *yylloc) { 00053 m_yylval = yylval; 00054 m_yylloc = yylloc; 00055 m_yylloc->step(); 00056 int result = yylex(); 00057 00058 if (m_criticalError) { 00059 return -1; 00060 } 00061 00062 return result; 00063 } 00064 00065 int JSonScanner::LexerInput(char* buf, int max_size) { 00066 if (!m_io->isOpen()) { 00067 qCritical() << "JSonScanner::yylex - io device is not open"; 00068 m_criticalError = true; 00069 return 0; 00070 } 00071 00072 int readBytes = m_io->read(buf, max_size); 00073 if(readBytes < 0) { 00074 qCritical() << "JSonScanner::yylex - error while reading from io device"; 00075 m_criticalError = true; 00076 return 0; 00077 } 00078 00079 return readBytes; 00080 } 00081 00082
|
hosts this site. |
Send comments to: QJson Developers |