QJson home page
json_scanner.cpp
1 /* This file is part of QJson
2  *
3  * Copyright (C) 2008 Flavio Castelli <flavio.castelli@gmail.com>
4  * Copyright (C) 2013 Silvio Moioli <silvio@moioli.net>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License version 2.1, as published by the Free Software Foundation.
9  *
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library; see the file COPYING.LIB. If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21 #include "json_scanner.cc"
22 
23 #include "qjson_debug.h"
24 #include "json_scanner.h"
25 #include "json_parser.hh"
26 
27 #include <ctype.h>
28 
29 #include <QtCore/QDebug>
30 #include <QtCore/QRegExp>
31 
32 #include <cassert>
33 
34 
35 JSonScanner::JSonScanner(QIODevice* io)
36  : m_allowSpecialNumbers(false),
37  m_io (io),
38  m_criticalError(false),
39  m_C_locale(QLocale::C)
40 {
41 
42 }
43 
44 JSonScanner::~JSonScanner()
45 {
46 }
47 
48 void JSonScanner::allowSpecialNumbers(bool allow) {
49  m_allowSpecialNumbers = allow;
50 }
51 
52 int JSonScanner::yylex(YYSTYPE* yylval, yy::location *yylloc) {
53  m_yylval = yylval;
54  m_yylloc = yylloc;
55  m_yylloc->step();
56  int result = yylex();
57 
58  if (m_criticalError) {
59  return -1;
60  }
61 
62  return result;
63 }
64 
65 int JSonScanner::LexerInput(char* buf, int max_size) {
66  if (!m_io->isOpen()) {
67  qCritical() << "JSonScanner::yylex - io device is not open";
68  m_criticalError = true;
69  return 0;
70  }
71 
72  int readBytes = m_io->read(buf, max_size);
73  if(readBytes < 0) {
74  qCritical() << "JSonScanner::yylex - error while reading from io device";
75  m_criticalError = true;
76  return 0;
77  }
78 
79  return readBytes;
80 }
81 
82 
void step()
Reset initial location to final location.
Definition: location.hh:90
Abstract a location.
Definition: location.hh:49

SourceForge Logo hosts this site. Send comments to:
QJson Developers