From 0094c61568bff9f9dd7bafb711f111698e683831 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Sat, 27 Oct 2012 10:13:08 +0100 Subject: [PATCH] Update bundled QJson To upstream commit 11e743c61e18e49d77c94e9568ccb6f0c2b4f0ac. --- thirdparty/qjson/.gitignore | 1 + thirdparty/qjson/CMakeLists.txt | 19 +- thirdparty/qjson/{COPYING => COPYING.lib} | 4 +- thirdparty/qjson/README | 7 +- thirdparty/qjson/json_parser.cc | 300 +++++++++++---------- thirdparty/qjson/json_parser.hh | 12 +- thirdparty/qjson/json_parser.yy | 26 +- thirdparty/qjson/json_scanner.cpp | 106 ++++++-- thirdparty/qjson/json_scanner.h | 14 +- thirdparty/qjson/parser.cpp | 21 +- thirdparty/qjson/parser.h | 24 +- thirdparty/qjson/parser_p.h | 11 +- thirdparty/qjson/parserrunnable.cpp | 12 +- thirdparty/qjson/parserrunnable.h | 10 +- thirdparty/qjson/qjson_debug.h | 10 +- thirdparty/qjson/qjson_export.h | 20 +- thirdparty/qjson/qobjecthelper.cpp | 36 +-- thirdparty/qjson/qobjecthelper.h | 11 +- thirdparty/qjson/serializer.cpp | 308 +++++++++++++++++----- thirdparty/qjson/serializer.h | 77 +++++- thirdparty/qjson/serializerrunnable.cpp | 10 +- thirdparty/qjson/serializerrunnable.h | 10 +- 22 files changed, 708 insertions(+), 341 deletions(-) create mode 100644 thirdparty/qjson/.gitignore rename thirdparty/qjson/{COPYING => COPYING.lib} (99%) diff --git a/thirdparty/qjson/.gitignore b/thirdparty/qjson/.gitignore new file mode 100644 index 0000000..b2b8eb2 --- /dev/null +++ b/thirdparty/qjson/.gitignore @@ -0,0 +1 @@ +moc_*.cxx diff --git a/thirdparty/qjson/CMakeLists.txt b/thirdparty/qjson/CMakeLists.txt index 14bda2c..567cb79 100644 --- a/thirdparty/qjson/CMakeLists.txt +++ b/thirdparty/qjson/CMakeLists.txt @@ -1,4 +1,9 @@ -add_definitions (-DQT_NO_CAST_FROM_ASCII -DQT_NO_CAST_TO_ASCII -DQT_NO_DEBUG_OUTPUT) +add_definitions ( + -DQT_NO_CAST_FROM_ASCII + -DQT_NO_CAST_TO_ASCII + -DQT_NO_DEBUG_OUTPUT + -DQJSON_EXPORT= +) set (QT_DONT_USE_QTGUI TRUE) @@ -8,11 +13,19 @@ include_directories (${CMAKE_CURRENT_BINARY_DIR}) set (qjson_MOC_HDRS parserrunnable.h - serializerrunnable.h + #serializerrunnable.h ) qt4_wrap_cpp (qjson_MOC_SRCS ${qjson_MOC_HDRS}) -set (qjson_SRCS parser.cpp qobjecthelper.cpp json_scanner.cpp json_parser.cc parserrunnable.cpp serializer.cpp serializerrunnable.cpp) +set (qjson_SRCS + parser.cpp + qobjecthelper.cpp + json_scanner.cpp + json_parser.cc + parserrunnable.cpp + #serializer.cpp + #serializerrunnable.cpp +) add_library (qjson_bundled STATIC ${qjson_SRCS} ${qjson_MOC_SRCS}) diff --git a/thirdparty/qjson/COPYING b/thirdparty/qjson/COPYING.lib similarity index 99% rename from thirdparty/qjson/COPYING rename to thirdparty/qjson/COPYING.lib index 5ab7695..08f25cd 100644 --- a/thirdparty/qjson/COPYING +++ b/thirdparty/qjson/COPYING.lib @@ -475,8 +475,8 @@ convey the exclusion of warranty; and each file should have at least the This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. + License version 2.1, as published by the Free Software Foundation. + This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of diff --git a/thirdparty/qjson/README b/thirdparty/qjson/README index 9e7b037..fe4853d 100644 --- a/thirdparty/qjson/README +++ b/thirdparty/qjson/README @@ -1,6 +1,5 @@ -QJson version 0.5.0 +QJson ------------------------------------------------- -Date: April 3rd, 2009 Website: http://qjson.sourceforge.net/ Mailing List: https://lists.sourceforge.net/mailman/listinfo/qjson-devel @@ -13,8 +12,8 @@ Install License ------- - This library is licensed under the Lesser GNU General Public License. See - the COPYING file for more information. + This library is licensed under the Lesser GNU General Public License version 2.1. + See the COPYING.lib file for more information. Description ----------- diff --git a/thirdparty/qjson/json_parser.cc b/thirdparty/qjson/json_parser.cc index a99be6c..620e135 100644 --- a/thirdparty/qjson/json_parser.cc +++ b/thirdparty/qjson/json_parser.cc @@ -42,7 +42,7 @@ #line 43 "json_parser.cc" #ifndef YY_ -# if defined YYENABLE_NLS && YYENABLE_NLS +# if YYENABLE_NLS # if ENABLE_NLS # include /* FIXME: INFRINGES ON USER NAME SPACE */ # define YY_(msgid) dgettext ("bison-runtime", msgid) @@ -384,7 +384,7 @@ namespace yy switch (yyn) { case 2: -#line 80 "json_parser.yy" +#line 84 "json_parser.yy" { driver->m_result = (yysemantic_stack_[(1) - (1)]); qjsonDebug() << "json_parser - parsing finished"; @@ -392,36 +392,31 @@ namespace yy break; case 3: -#line 85 "json_parser.yy" - {(yyval) = (yysemantic_stack_[(1) - (1)]); ;} +#line 89 "json_parser.yy" + { (yyval) = (yysemantic_stack_[(1) - (1)]); ;} break; case 4: -#line 86 "json_parser.yy" - {(yyval) = (yysemantic_stack_[(1) - (1)]); ;} - break; - - case 5: -#line 88 "json_parser.yy" +#line 91 "json_parser.yy" { qCritical()<< "json_parser - syntax error found, " - << "forcing abort"; + << "forcing abort, Line" << (yyloc).begin.line << "Column" << (yyloc).begin.column; YYABORT; ;} break; - case 7: -#line 95 "json_parser.yy" + case 6: +#line 98 "json_parser.yy" { (yyval) = (yysemantic_stack_[(3) - (2)]); ;} break; - case 8: -#line 97 "json_parser.yy" + case 7: +#line 100 "json_parser.yy" { (yyval) = QVariant (QVariantMap()); ;} break; - case 9: -#line 98 "json_parser.yy" + case 8: +#line 101 "json_parser.yy" { QVariantMap members = (yysemantic_stack_[(2) - (2)]).toMap(); (yysemantic_stack_[(2) - (2)]) = QVariant(); // Allow reuse of map @@ -429,13 +424,13 @@ namespace yy ;} break; - case 10: -#line 104 "json_parser.yy" + case 9: +#line 107 "json_parser.yy" { (yyval) = QVariant (QVariantMap()); ;} break; - case 11: -#line 105 "json_parser.yy" + case 10: +#line 108 "json_parser.yy" { QVariantMap members = (yysemantic_stack_[(3) - (3)]).toMap(); (yysemantic_stack_[(3) - (3)]) = QVariant(); // Allow reuse of map @@ -443,8 +438,8 @@ namespace yy ;} break; - case 12: -#line 111 "json_parser.yy" + case 11: +#line 114 "json_parser.yy" { QVariantMap pair; pair.insert ((yysemantic_stack_[(3) - (1)]).toString(), QVariant((yysemantic_stack_[(3) - (3)]))); @@ -452,18 +447,18 @@ namespace yy ;} break; - case 13: -#line 117 "json_parser.yy" + case 12: +#line 120 "json_parser.yy" { (yyval) = (yysemantic_stack_[(3) - (2)]); ;} break; - case 14: -#line 119 "json_parser.yy" + case 13: +#line 122 "json_parser.yy" { (yyval) = QVariant (QVariantList()); ;} break; - case 15: -#line 120 "json_parser.yy" + case 14: +#line 123 "json_parser.yy" { QVariantList members = (yysemantic_stack_[(2) - (2)]).toList(); (yysemantic_stack_[(2) - (2)]) = QVariant(); // Allow reuse of list @@ -472,13 +467,13 @@ namespace yy ;} break; - case 16: -#line 127 "json_parser.yy" + case 15: +#line 130 "json_parser.yy" { (yyval) = QVariant (QVariantList()); ;} break; - case 17: -#line 128 "json_parser.yy" + case 16: +#line 131 "json_parser.yy" { QVariantList members = (yysemantic_stack_[(3) - (3)]).toList(); (yysemantic_stack_[(3) - (3)]) = QVariant(); // Allow reuse of list @@ -487,46 +482,61 @@ namespace yy ;} break; + case 17: +#line 138 "json_parser.yy" + { (yyval) = (yysemantic_stack_[(1) - (1)]); ;} + break; + case 18: -#line 135 "json_parser.yy" +#line 139 "json_parser.yy" { (yyval) = (yysemantic_stack_[(1) - (1)]); ;} break; case 19: -#line 136 "json_parser.yy" +#line 140 "json_parser.yy" { (yyval) = (yysemantic_stack_[(1) - (1)]); ;} break; case 20: -#line 137 "json_parser.yy" +#line 141 "json_parser.yy" { (yyval) = (yysemantic_stack_[(1) - (1)]); ;} break; case 21: -#line 138 "json_parser.yy" - { (yyval) = (yysemantic_stack_[(1) - (1)]); ;} - break; - - case 22: -#line 139 "json_parser.yy" +#line 142 "json_parser.yy" { (yyval) = QVariant (true); ;} break; - case 23: -#line 140 "json_parser.yy" + case 22: +#line 143 "json_parser.yy" { (yyval) = QVariant (false); ;} break; - case 24: -#line 141 "json_parser.yy" + case 23: +#line 144 "json_parser.yy" { QVariant null_variant; (yyval) = null_variant; ;} break; + case 24: +#line 149 "json_parser.yy" + { (yyval) = QVariant(QVariant::Double); (yyval).setValue( -std::numeric_limits::infinity() ); ;} + break; + case 25: -#line 146 "json_parser.yy" +#line 150 "json_parser.yy" + { (yyval) = QVariant(QVariant::Double); (yyval).setValue( std::numeric_limits::infinity() ); ;} + break; + + case 26: +#line 151 "json_parser.yy" + { (yyval) = QVariant(QVariant::Double); (yyval).setValue( std::numeric_limits::quiet_NaN() ); ;} + break; + + case 28: +#line 154 "json_parser.yy" { if ((yysemantic_stack_[(1) - (1)]).toByteArray().startsWith('-')) { (yyval) = QVariant (QVariant::LongLong); @@ -539,8 +549,8 @@ namespace yy ;} break; - case 26: -#line 156 "json_parser.yy" + case 29: +#line 164 "json_parser.yy" { const QByteArray value = (yysemantic_stack_[(2) - (1)]).toByteArray() + (yysemantic_stack_[(2) - (2)]).toByteArray(); (yyval) = QVariant(QVariant::Double); @@ -548,65 +558,65 @@ namespace yy ;} break; - case 27: -#line 161 "json_parser.yy" + case 30: +#line 169 "json_parser.yy" { (yyval) = QVariant ((yysemantic_stack_[(2) - (1)]).toByteArray() + (yysemantic_stack_[(2) - (2)]).toByteArray()); ;} break; - case 28: -#line 162 "json_parser.yy" + case 31: +#line 170 "json_parser.yy" { const QByteArray value = (yysemantic_stack_[(3) - (1)]).toByteArray() + (yysemantic_stack_[(3) - (2)]).toByteArray() + (yysemantic_stack_[(3) - (3)]).toByteArray(); (yyval) = QVariant (value); ;} break; - case 29: -#line 167 "json_parser.yy" + case 32: +#line 175 "json_parser.yy" { (yyval) = QVariant ((yysemantic_stack_[(2) - (1)]).toByteArray() + (yysemantic_stack_[(2) - (2)]).toByteArray()); ;} break; - case 30: -#line 168 "json_parser.yy" + case 33: +#line 176 "json_parser.yy" { (yyval) = QVariant (QByteArray("-") + (yysemantic_stack_[(3) - (2)]).toByteArray() + (yysemantic_stack_[(3) - (3)]).toByteArray()); ;} break; - case 31: -#line 170 "json_parser.yy" + case 34: +#line 178 "json_parser.yy" { (yyval) = QVariant (QByteArray("")); ;} break; - case 32: -#line 171 "json_parser.yy" + case 35: +#line 179 "json_parser.yy" { (yyval) = QVariant((yysemantic_stack_[(2) - (1)]).toByteArray() + (yysemantic_stack_[(2) - (2)]).toByteArray()); ;} break; - case 33: -#line 175 "json_parser.yy" + case 36: +#line 183 "json_parser.yy" { (yyval) = QVariant(QByteArray(".") + (yysemantic_stack_[(2) - (2)]).toByteArray()); ;} break; - case 34: -#line 179 "json_parser.yy" + case 37: +#line 187 "json_parser.yy" { (yyval) = QVariant((yysemantic_stack_[(2) - (1)]).toByteArray() + (yysemantic_stack_[(2) - (2)]).toByteArray()); ;} break; - case 35: -#line 181 "json_parser.yy" + case 38: +#line 189 "json_parser.yy" { (yyval) = (yysemantic_stack_[(3) - (2)]); ;} break; - case 36: -#line 183 "json_parser.yy" + case 39: +#line 191 "json_parser.yy" { (yyval) = QVariant (QString(QLatin1String(""))); ;} break; - case 37: -#line 184 "json_parser.yy" + case 40: +#line 192 "json_parser.yy" { (yyval) = (yysemantic_stack_[(1) - (1)]); ;} @@ -614,7 +624,7 @@ namespace yy /* Line 675 of lalr1.cc. */ -#line 618 "json_parser.cc" +#line 628 "json_parser.cc" default: break; } YY_SYMBOL_PRINT ("-> $$ =", yyr1_[yyn], &yyval, &yyloc); @@ -821,16 +831,16 @@ namespace yy /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing STATE-NUM. */ - const signed char json_parser::yypact_ninf_ = -18; + const signed char json_parser::yypact_ninf_ = -21; const signed char json_parser::yypact_[] = { - 5, -18, -18, 1, -2, 19, -18, -18, -18, 2, - 20, 17, 21, 16, 18, -18, -18, -18, -18, -18, - 24, 23, -18, -8, -18, -18, -18, 15, -18, 1, - -18, -2, 18, 18, -18, -18, -2, -18, 18, 18, - 22, -18, -18, 17, -18, -18, -18, 23, -18, -18, - -18, -18, -18 + 3, -21, -21, -6, 31, -10, 0, -21, -21, -21, + 6, -21, -21, 25, -21, -21, -21, -21, -21, -21, + -5, -21, 22, 19, 21, 23, 24, 0, -21, 0, + -21, -21, 13, -21, 0, 0, 29, -21, -21, -6, + -21, 31, -21, 31, -21, -21, -21, -21, -21, -21, + -21, 19, -21, 24, -21, -21 }; /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE @@ -839,28 +849,28 @@ namespace yy const unsigned char json_parser::yydefact_[] = { - 0, 6, 5, 8, 14, 0, 2, 3, 4, 36, - 0, 10, 0, 0, 31, 22, 23, 24, 20, 21, - 0, 16, 19, 25, 18, 1, 37, 0, 7, 0, - 9, 0, 31, 31, 29, 13, 0, 15, 31, 31, - 26, 27, 35, 10, 12, 30, 32, 16, 33, 34, - 28, 11, 17 + 0, 5, 4, 7, 13, 0, 34, 21, 22, 23, + 39, 25, 26, 0, 2, 19, 20, 3, 18, 27, + 28, 17, 0, 9, 0, 0, 15, 34, 24, 34, + 32, 40, 0, 1, 34, 34, 29, 30, 6, 0, + 8, 0, 12, 0, 14, 33, 35, 38, 36, 37, + 31, 9, 11, 15, 10, 16 }; /* YYPGOTO[NTERM-NUM]. */ const signed char json_parser::yypgoto_[] = { - -18, -18, -18, 33, -18, -7, 6, 37, -18, -9, - -13, -18, -18, -17, -18, -1, -3, -18 + -21, -21, -21, -21, -21, -20, 4, -21, -21, -18, + -4, -21, -21, -21, -14, -21, -3, -1, -21 }; /* YYDEFGOTO[NTERM-NUM]. */ const signed char json_parser::yydefgoto_[] = { - -1, 5, 6, 18, 10, 30, 11, 19, 20, 37, - 21, 22, 23, 34, 40, 41, 24, 27 + -1, 13, 14, 15, 22, 40, 23, 16, 25, 44, + 17, 18, 19, 20, 30, 36, 37, 21, 32 }; /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If @@ -870,20 +880,24 @@ namespace yy const unsigned char json_parser::yytable_[] = { - 12, 3, 38, 4, 39, 1, 2, 13, 3, 14, - 4, 15, 16, 17, 9, 45, 46, 9, 44, 25, - 26, 48, 49, 47, 28, 29, 12, 32, 31, 33, - 35, 36, 42, 7, 39, 43, 51, 8, 52, 50 + 26, 27, 24, 1, 2, 34, 3, 35, 4, 28, + 10, 29, 5, 45, 6, 46, 7, 8, 9, 10, + 48, 49, 11, 12, 31, 33, 38, 39, 41, 42, + 47, 54, 43, 50, 3, 55, 4, 52, 24, 53, + 5, 35, 6, 51, 7, 8, 9, 10, 0, 0, + 11, 12 }; /* YYCHECK. */ - const unsigned char + const signed char json_parser::yycheck_[] = { - 3, 3, 10, 5, 12, 0, 1, 9, 3, 11, - 5, 13, 14, 15, 16, 32, 33, 16, 31, 0, - 18, 38, 39, 36, 4, 8, 29, 11, 7, 11, - 6, 8, 17, 0, 12, 29, 43, 0, 47, 40 + 4, 11, 3, 0, 1, 10, 3, 12, 5, 19, + 16, 11, 9, 27, 11, 29, 13, 14, 15, 16, + 34, 35, 19, 20, 18, 0, 4, 8, 7, 6, + 17, 51, 8, 36, 3, 53, 5, 41, 39, 43, + 9, 12, 11, 39, 13, 14, 15, 16, -1, -1, + 19, 20 }; /* STOS_[STATE-NUM] -- The (internal number of the) accessing @@ -891,12 +905,12 @@ namespace yy const unsigned char json_parser::yystos_[] = { - 0, 0, 1, 3, 5, 20, 21, 22, 26, 16, - 23, 25, 35, 9, 11, 13, 14, 15, 22, 26, - 27, 29, 30, 31, 35, 0, 18, 36, 4, 8, - 24, 7, 11, 11, 32, 6, 8, 28, 10, 12, - 33, 34, 17, 25, 29, 32, 32, 29, 32, 32, - 34, 24, 28 + 0, 0, 1, 3, 5, 9, 11, 13, 14, 15, + 16, 19, 20, 22, 23, 24, 28, 31, 32, 33, + 34, 38, 25, 27, 38, 29, 31, 11, 19, 11, + 35, 18, 39, 0, 10, 12, 36, 37, 4, 8, + 26, 7, 6, 8, 30, 35, 35, 17, 35, 35, + 37, 27, 31, 31, 26, 30 }; #if YYDEBUG @@ -906,7 +920,8 @@ namespace yy json_parser::yytoken_number_[] = { 0, 256, 257, 1, 2, 3, 4, 5, 6, 7, - 8, 9, 10, 11, 12, 13, 14, 15, 16 + 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, + 18 }; #endif @@ -914,20 +929,22 @@ namespace yy const unsigned char json_parser::yyr1_[] = { - 0, 19, 20, 21, 21, 21, 21, 22, 23, 23, - 24, 24, 25, 26, 27, 27, 28, 28, 29, 29, - 29, 29, 29, 29, 29, 30, 30, 30, 30, 31, - 31, 32, 32, 33, 34, 35, 36, 36 + 0, 21, 22, 23, 23, 23, 24, 25, 25, 26, + 26, 27, 28, 29, 29, 30, 30, 31, 31, 31, + 31, 31, 31, 31, 32, 32, 32, 32, 33, 33, + 33, 33, 34, 34, 35, 35, 36, 37, 38, 39, + 39 }; /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ const unsigned char json_parser::yyr2_[] = { - 0, 2, 1, 1, 1, 1, 1, 3, 0, 2, - 0, 3, 3, 3, 0, 2, 0, 3, 1, 1, - 1, 1, 1, 1, 1, 1, 2, 2, 3, 2, - 3, 0, 2, 2, 2, 3, 0, 1 + 0, 2, 1, 1, 1, 1, 3, 0, 2, 0, + 3, 3, 3, 0, 2, 0, 3, 1, 1, 1, + 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, + 2, 3, 2, 3, 0, 2, 2, 2, 3, 0, + 1 }; #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE @@ -940,9 +957,10 @@ namespace yy "\"]\"", "\":\"", "\",\"", "\"-\"", "\".\"", "\"digit\"", "\"exponential\"", "\"true\"", "\"false\"", "\"null\"", "\"open quotation mark\"", "\"close quotation mark\"", "\"string\"", - "$accept", "start", "data", "object", "members", "r_members", "pair", - "array", "values", "r_values", "value", "number", "int", "digits", - "fract", "exp", "string", "string_arg", 0 + "\"Infinity\"", "\"NaN\"", "$accept", "start", "data", "object", + "members", "r_members", "pair", "array", "values", "r_values", "value", + "special_or_number", "number", "int", "digits", "fract", "exp", "string", + "string_arg", 0 }; #endif @@ -951,16 +969,16 @@ namespace yy const json_parser::rhs_number_type json_parser::yyrhs_[] = { - 20, 0, -1, 21, -1, 22, -1, 26, -1, 1, - -1, 0, -1, 3, 23, 4, -1, -1, 25, 24, - -1, -1, 8, 25, 24, -1, 35, 7, 29, -1, - 5, 27, 6, -1, -1, 29, 28, -1, -1, 8, - 29, 28, -1, 35, -1, 30, -1, 22, -1, 26, - -1, 13, -1, 14, -1, 15, -1, 31, -1, 31, - 33, -1, 31, 34, -1, 31, 33, 34, -1, 11, - 32, -1, 9, 11, 32, -1, -1, 11, 32, -1, - 10, 32, -1, 12, 32, -1, 16, 36, 17, -1, - -1, 18, -1 + 22, 0, -1, 23, -1, 31, -1, 1, -1, 0, + -1, 3, 25, 4, -1, -1, 27, 26, -1, -1, + 8, 27, 26, -1, 38, 7, 31, -1, 5, 29, + 6, -1, -1, 31, 30, -1, -1, 8, 31, 30, + -1, 38, -1, 32, -1, 24, -1, 28, -1, 13, + -1, 14, -1, 15, -1, 9, 19, -1, 19, -1, + 20, -1, 33, -1, 34, -1, 34, 36, -1, 34, + 37, -1, 34, 36, 37, -1, 11, 35, -1, 9, + 11, 35, -1, -1, 11, 35, -1, 10, 35, -1, + 12, 35, -1, 16, 39, 17, -1, -1, 18, -1 }; /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in @@ -968,20 +986,22 @@ namespace yy const unsigned char json_parser::yyprhs_[] = { - 0, 0, 3, 5, 7, 9, 11, 13, 17, 18, - 21, 22, 26, 30, 34, 35, 38, 39, 43, 45, - 47, 49, 51, 53, 55, 57, 59, 62, 65, 69, - 72, 76, 77, 80, 83, 86, 90, 91 + 0, 0, 3, 5, 7, 9, 11, 15, 16, 19, + 20, 24, 28, 32, 33, 36, 37, 41, 43, 45, + 47, 49, 51, 53, 55, 58, 60, 62, 64, 66, + 69, 72, 76, 79, 83, 84, 87, 90, 93, 97, + 98 }; /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ const unsigned char json_parser::yyrline_[] = { - 0, 80, 80, 85, 86, 87, 93, 95, 97, 98, - 104, 105, 111, 117, 119, 120, 127, 128, 135, 136, - 137, 138, 139, 140, 141, 146, 156, 161, 162, 167, - 168, 170, 171, 175, 179, 181, 183, 184 + 0, 84, 84, 89, 90, 96, 98, 100, 101, 107, + 108, 114, 120, 122, 123, 130, 131, 138, 139, 140, + 141, 142, 143, 144, 149, 150, 151, 152, 154, 164, + 169, 170, 175, 176, 178, 179, 183, 187, 189, 191, + 192 }; // Print the state stack on the debug stream. @@ -1022,7 +1042,7 @@ namespace yy translate_table[] = { 0, 3, 4, 5, 6, 7, 8, 9, 10, 11, - 12, 13, 14, 15, 16, 17, 18, 2, 2, 2, + 12, 13, 14, 15, 16, 17, 18, 19, 20, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, @@ -1055,20 +1075,20 @@ namespace yy } const int json_parser::yyeof_ = 0; - const int json_parser::yylast_ = 39; - const int json_parser::yynnts_ = 18; + const int json_parser::yylast_ = 51; + const int json_parser::yynnts_ = 19; const int json_parser::yyempty_ = -2; - const int json_parser::yyfinal_ = 25; + const int json_parser::yyfinal_ = 33; const int json_parser::yyterror_ = 1; const int json_parser::yyerrcode_ = 256; - const int json_parser::yyntokens_ = 19; + const int json_parser::yyntokens_ = 21; const unsigned int json_parser::yyuser_token_number_max_ = 257; const json_parser::token_number_type json_parser::yyundef_token_ = 2; } // namespace yy -#line 188 "json_parser.yy" +#line 196 "json_parser.yy" int yy::yylex(YYSTYPE *yylval, yy::location *yylloc, QJson::ParserPrivate* driver) diff --git a/thirdparty/qjson/json_parser.hh b/thirdparty/qjson/json_parser.hh index 673923d..e61ca7c 100644 --- a/thirdparty/qjson/json_parser.hh +++ b/thirdparty/qjson/json_parser.hh @@ -59,6 +59,8 @@ namespace yy #include #include + #include + class JSonScanner; namespace QJson { @@ -68,8 +70,8 @@ namespace yy #define YYERROR_VERBOSE 1 -/* Line 303 of lalr1.cc. */ -#line 73 "json_parser.hh" +/* Line 35 of lalr1.cc. */ +#line 75 "json_parser.hh" #include "location.hh" @@ -146,7 +148,9 @@ namespace yy NULL_VAL = 13, QUOTMARKOPEN = 14, QUOTMARKCLOSE = 15, - STRING = 16 + STRING = 16, + INFINITY_VAL = 17, + NAN_VAL = 18 }; }; @@ -241,7 +245,7 @@ namespace yy static const unsigned char yytable_[]; static const signed char yytable_ninf_; - static const unsigned char yycheck_[]; + static const signed char yycheck_[]; /// For a state, its accessing symbol. static const unsigned char yystos_[]; diff --git a/thirdparty/qjson/json_parser.yy b/thirdparty/qjson/json_parser.yy index ad8e105..2540889 100644 --- a/thirdparty/qjson/json_parser.yy +++ b/thirdparty/qjson/json_parser.yy @@ -3,16 +3,16 @@ * 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. + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * * * 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. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License + * You should have received a copy of the GNU Lesser 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. @@ -32,6 +32,8 @@ #include #include + #include + class JSonScanner; namespace QJson { @@ -69,6 +71,8 @@ %token QUOTMARKCLOSE 15 "close quotation mark" %token STRING 16 "string" +%token INFINITY_VAL 17 "Infinity" +%token NAN_VAL 18 "NaN" // define the initial token %start start @@ -82,12 +86,11 @@ start: data { qjsonDebug() << "json_parser - parsing finished"; }; -data: object {$$ = $1; } - | array {$$ = $1; } +data: value { $$ = $1; } | error { qCritical()<< "json_parser - syntax error found, " - << "forcing abort"; + << "forcing abort, Line" << @$.begin.line << "Column" << @$.begin.column; YYABORT; } | END; @@ -133,7 +136,7 @@ r_values: /* empty */ { $$ = QVariant (QVariantList()); } }; value: string { $$ = $1; } - | number { $$ = $1; } + | special_or_number { $$ = $1; } | object { $$ = $1; } | array { $$ = $1; } | TRUE_VAL { $$ = QVariant (true); } @@ -143,6 +146,11 @@ value: string { $$ = $1; } $$ = null_variant; }; +special_or_number: MINUS INFINITY_VAL { $$ = QVariant(QVariant::Double); $$.setValue( -std::numeric_limits::infinity() ); } + | INFINITY_VAL { $$ = QVariant(QVariant::Double); $$.setValue( std::numeric_limits::infinity() ); } + | NAN_VAL { $$ = QVariant(QVariant::Double); $$.setValue( std::numeric_limits::quiet_NaN() ); } + | number; + number: int { if ($1.toByteArray().startsWith('-')) { $$ = QVariant (QVariant::LongLong); diff --git a/thirdparty/qjson/json_scanner.cpp b/thirdparty/qjson/json_scanner.cpp index 7f7b88f..de0ddc2 100644 --- a/thirdparty/qjson/json_scanner.cpp +++ b/thirdparty/qjson/json_scanner.cpp @@ -3,16 +3,16 @@ * 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. + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * * * 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. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License + * You should have received a copy of the GNU Lesser 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. @@ -38,12 +38,17 @@ bool ishexnstring(const QString& string) { } JSonScanner::JSonScanner(QIODevice* io) - : m_io (io) + : m_allowSpecialNumbers(false), + m_io (io) { m_quotmarkClosed = true; m_quotmarkCount = 0; } +void JSonScanner::allowSpecialNumbers(bool allow) { + m_allowSpecialNumbers = allow; +} + static QString unescape( const QByteArray& ba, bool* ok ) { assert( ok ); *ok = false; @@ -125,7 +130,7 @@ static QString unescape( const QByteArray& ba, bool* ok ) { int JSonScanner::yylex(YYSTYPE* yylval, yy::location *yylloc) { char ch; - + if (!m_io->isOpen()) { qCritical() << "JSonScanner::yylex - io device is not open"; return -1; @@ -148,32 +153,34 @@ int JSonScanner::yylex(YYSTYPE* yylval, yy::location *yylloc) } qjsonDebug() << "JSonScanner::yylex - got |" << ch << "|"; - yylloc->columns(); - + if (ch == '\n' || ch == '\r') yylloc->lines(); - } while (m_quotmarkClosed && (isspace(ch) != 0)); - if (m_quotmarkClosed && ((ch == 't') || (ch == 'T') - || (ch == 'n') || (ch == 'N'))) { - // check true & null value + if (m_quotmarkClosed && ((ch == 't') || (ch == 'T'))) { const QByteArray buf = m_io->peek(3).toLower(); + if (buf == "rue") { + m_io->read (3); + yylloc->columns(3); + qjsonDebug() << "JSonScanner::yylex - TRUE_VAL"; + return yy::json_parser::token::TRUE_VAL; + } + } + else if (m_quotmarkClosed && ((ch == 'n') || (ch == 'N'))) { + const QByteArray buf = m_io->peek(3).toLower(); + if (buf == "ull") { + m_io->read (3); + yylloc->columns(3); + qjsonDebug() << "JSonScanner::yylex - NULL_VAL"; + return yy::json_parser::token::NULL_VAL; + } else if (buf.startsWith("an") && m_allowSpecialNumbers) { + m_io->read(2); + yylloc->columns(2); + qjsonDebug() << "JSonScanner::yylex - NAN_VAL"; + return yy::json_parser::token::NAN_VAL; - if (buf.length() == 3) { - if (buf == "rue") { - m_io->read (3); - yylloc->columns(3); - qjsonDebug() << "JSonScanner::yylex - TRUE_VAL"; - return yy::json_parser::token::TRUE_VAL; - } - else if (buf == "ull") { - m_io->read (3); - yylloc->columns(3); - qjsonDebug() << "JSonScanner::yylex - NULL_VAL"; - return yy::json_parser::token::NULL_VAL; - } } } else if (m_quotmarkClosed && ((ch == 'f') || (ch == 'F'))) { @@ -193,14 +200,24 @@ int JSonScanner::yylex(YYSTYPE* yylval, yy::location *yylloc) const QByteArray buf = m_io->peek(1); if (!buf.isEmpty()) { if ((buf[0] == '+' ) || (buf[0] == '-' )) { - ret += m_io->read (1); + ret += m_io->read (1); yylloc->columns(); } } *yylval = QVariant(QString::fromUtf8(ret)); return yy::json_parser::token::E; } - + else if (m_allowSpecialNumbers && m_quotmarkClosed && ((ch == 'I') || (ch == 'i'))) { + QByteArray ret(1, ch); + const QByteArray buf = m_io->peek(7); + if (buf == "nfinity") { + m_io->read(7); + yylloc->columns(7); + qjsonDebug() << "JSonScanner::yylex - INFINITY_VAL"; + return yy::json_parser::token::INFINITY_VAL; + } + } + if (ch != '"' && !m_quotmarkClosed) { // we're inside a " " block QByteArray raw; @@ -259,7 +276,38 @@ int JSonScanner::yylex(YYSTYPE* yylval, yy::location *yylloc) } } else if (isdigit(ch) != 0 && m_quotmarkClosed) { - *yylval = QVariant(QString::fromLatin1(QByteArray(&ch,1))); + bool ok; + QByteArray numArray = QByteArray::fromRawData( &ch, 1 * sizeof(char) ); + qulonglong number = numArray.toULongLong(&ok); + if (!ok) { + //This shouldn't happen + qCritical() << "JSonScanner::yylex - error while converting char to ulonglong, returning -1"; + return -1; + } + if (number == 0) { + // we have to return immediately otherwise numbers like + // 2.04 will be converted to 2.4 + *yylval = QVariant(number); + qjsonDebug() << "JSonScanner::yylex - yy::json_parser::token::DIGIT"; + return yy::json_parser::token::DIGIT; + } + + char nextCh; + qint64 ret = m_io->peek(&nextCh, 1); + while (ret == 1 && isdigit(nextCh)) { + m_io->read(1); //consume + yylloc->columns(1); + numArray = QByteArray::fromRawData( &nextCh, 1 * sizeof(char) ); + number = number * 10 + numArray.toULongLong(&ok); + if (!ok) { + //This shouldn't happen + qCritical() << "JSonScanner::yylex - error while converting char to ulonglong, returning -1"; + return -1; + } + ret = m_io->peek(&nextCh, 1); + } + + *yylval = QVariant(number); qjsonDebug() << "JSonScanner::yylex - yy::json_parser::token::DIGIT"; return yy::json_parser::token::DIGIT; } diff --git a/thirdparty/qjson/json_scanner.h b/thirdparty/qjson/json_scanner.h index 593426b..f13e565 100644 --- a/thirdparty/qjson/json_scanner.h +++ b/thirdparty/qjson/json_scanner.h @@ -3,16 +3,16 @@ * 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. + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * * * 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. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License + * You should have received a copy of the GNU Lesser 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. @@ -41,9 +41,11 @@ class JSonScanner public: explicit JSonScanner(QIODevice* io); int yylex(YYSTYPE* yylval, yy::location *yylloc); - + void allowSpecialNumbers(bool allow); + protected: bool m_quotmarkClosed; + bool m_allowSpecialNumbers; unsigned int m_quotmarkCount; QIODevice* m_io; }; diff --git a/thirdparty/qjson/parser.cpp b/thirdparty/qjson/parser.cpp index 3096d17..e203b87 100644 --- a/thirdparty/qjson/parser.cpp +++ b/thirdparty/qjson/parser.cpp @@ -3,16 +3,16 @@ * 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. + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * * * 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. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License + * You should have received a copy of the GNU Lesser 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. @@ -34,6 +34,8 @@ ParserPrivate::ParserPrivate() : m_scanner(0) , m_negate(false) , m_error(false) + , m_errorLine(0) + , m_specialNumbersAllowed(false) { } @@ -82,6 +84,7 @@ QVariant Parser::parse (QIODevice* io, bool* ok) } d->m_scanner = new JSonScanner (io); + d->m_scanner->allowSpecialNumbers(d->m_specialNumbersAllowed); yy::json_parser parser(d); parser.parse(); @@ -112,3 +115,11 @@ 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; +} diff --git a/thirdparty/qjson/parser.h b/thirdparty/qjson/parser.h index 8d323cd..6fb58d8 100644 --- a/thirdparty/qjson/parser.h +++ b/thirdparty/qjson/parser.h @@ -3,16 +3,16 @@ * 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. + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * * * 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. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License + * You should have received a copy of the GNU Lesser 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. @@ -71,6 +71,20 @@ namespace QJson { */ int errorLine() const; + /** + * Sets whether special numbers (Infinity, -Infinity, NaN) are allowed as an extension to + * the standard + * @param allowSpecialNumbers new value of whether special numbers are allowed + * @sa specialNumbersAllowed + */ + void allowSpecialNumbers(bool allowSpecialNumbers); + + /** + * @returns whether special numbers (Infinity, -Infinity, NaN) are allowed + * @sa allowSpecialNumbers + */ + bool specialNumbersAllowed() const; + private: Q_DISABLE_COPY(Parser) ParserPrivate* const d; diff --git a/thirdparty/qjson/parser_p.h b/thirdparty/qjson/parser_p.h index e12b565..aae86a1 100644 --- a/thirdparty/qjson/parser_p.h +++ b/thirdparty/qjson/parser_p.h @@ -4,16 +4,16 @@ * Copyright (C) 2009 Michael Leupold * * 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. + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * * * 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. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License + * You should have received a copy of the GNU Lesser 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. @@ -49,6 +49,7 @@ namespace QJson { int m_errorLine; QString m_errorMsg; QVariant m_result; + bool m_specialNumbersAllowed; }; } diff --git a/thirdparty/qjson/parserrunnable.cpp b/thirdparty/qjson/parserrunnable.cpp index d09423e..88baf4c 100644 --- a/thirdparty/qjson/parserrunnable.cpp +++ b/thirdparty/qjson/parserrunnable.cpp @@ -3,16 +3,16 @@ * Copyright (C) 2009 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. + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * * * 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. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License + * You should have received a copy of the GNU Lesser 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. @@ -61,7 +61,7 @@ void ParserRunnable::run() qDebug() << "successfully converted json item to QVariant object"; emit parsingFinished(result, true, QString()); } else { - const QString errorText = tr("An error occured while parsing json: %1").arg(parser.errorString()); + const QString errorText = tr("An error occurred while parsing json: %1").arg(parser.errorString()); qCritical() << errorText; emit parsingFinished(QVariant(), false, errorText); } diff --git a/thirdparty/qjson/parserrunnable.h b/thirdparty/qjson/parserrunnable.h index 822e1fd..2badeb6 100644 --- a/thirdparty/qjson/parserrunnable.h +++ b/thirdparty/qjson/parserrunnable.h @@ -3,16 +3,16 @@ * Copyright (C) 2009 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. + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * * * 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. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License + * You should have received a copy of the GNU Lesser 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. diff --git a/thirdparty/qjson/qjson_debug.h b/thirdparty/qjson/qjson_debug.h index 5ae1da3..0a511ae 100644 --- a/thirdparty/qjson/qjson_debug.h +++ b/thirdparty/qjson/qjson_debug.h @@ -3,16 +3,16 @@ * Copyright (C) 2009 Michael Leupold * * 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. + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * * * 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. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License + * You should have received a copy of the GNU Lesser 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. diff --git a/thirdparty/qjson/qjson_export.h b/thirdparty/qjson/qjson_export.h index 67355f5..9a807b9 100644 --- a/thirdparty/qjson/qjson_export.h +++ b/thirdparty/qjson/qjson_export.h @@ -2,16 +2,16 @@ Copyright (C) 2009 Pino Toscano 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. + modify it under the terms of the GNU Lesser General Public + License version 2.1, as published by the Free Software Foundation. + 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. + Lesser General Public License for more details. - You should have received a copy of the GNU Library General Public License + You should have received a copy of the GNU Lesser 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. @@ -22,6 +22,14 @@ #include -#define QJSON_EXPORT +#ifndef QJSON_EXPORT +# if defined(QJSON_MAKEDLL) + /* We are building this library */ +# define QJSON_EXPORT Q_DECL_EXPORT +# else + /* We are using this library */ +# define QJSON_EXPORT Q_DECL_IMPORT +# endif +#endif #endif diff --git a/thirdparty/qjson/qobjecthelper.cpp b/thirdparty/qjson/qobjecthelper.cpp index 8bba181..b756488 100644 --- a/thirdparty/qjson/qobjecthelper.cpp +++ b/thirdparty/qjson/qobjecthelper.cpp @@ -4,16 +4,16 @@ * Copyright (C) 2009 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. + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * * * 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. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License + * You should have received a copy of the GNU Lesser 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. @@ -62,20 +62,24 @@ QVariantMap QObjectHelper::qobject2qvariant( const QObject* object, void QObjectHelper::qvariant2qobject(const QVariantMap& variant, QObject* object) { - QStringList properies; const QMetaObject *metaobject = object->metaObject(); - int count = metaobject->propertyCount(); - for (int i=0; iproperty(i); - if (metaproperty.isWritable()) { - properies << QLatin1String( metaproperty.name()); - } - } QVariantMap::const_iterator iter; - for (iter = variant.constBegin(); iter != variant.end(); iter++) { - if (properies.contains(iter.key())) { - object->setProperty(iter.key().toAscii(), iter.value()); + for (iter = variant.constBegin(); iter != variant.constEnd(); ++iter) { + int pIdx = metaobject->indexOfProperty( iter.key().toAscii() ); + + if ( pIdx < 0 ) { + continue; + } + + QMetaProperty metaproperty = metaobject->property( pIdx ); + QVariant::Type type = metaproperty.type(); + QVariant v( iter.value() ); + if ( v.canConvert( type ) ) { + v.convert( type ); + metaproperty.write( object, v ); + } else if (QString(QLatin1String("QVariant")).compare(QLatin1String(metaproperty.typeName())) == 0) { + metaproperty.write( object, v ); } } } diff --git a/thirdparty/qjson/qobjecthelper.h b/thirdparty/qjson/qobjecthelper.h index 7bf6b03..514ca1f 100644 --- a/thirdparty/qjson/qobjecthelper.h +++ b/thirdparty/qjson/qobjecthelper.h @@ -3,16 +3,16 @@ * Copyright (C) 2009 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. + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * * * 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. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License + * You should have received a copy of the GNU Lesser 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. @@ -34,6 +34,7 @@ namespace QJson { * @brief Class used to convert QObject into QVariant and vivce-versa. * During these operations only the class attributes defined as properties will * be considered. + * Properties marked as 'non-stored' will be ignored. * * Suppose the declaration of the Person class looks like this: * \code diff --git a/thirdparty/qjson/serializer.cpp b/thirdparty/qjson/serializer.cpp index f012246..41407c2 100644 --- a/thirdparty/qjson/serializer.cpp +++ b/thirdparty/qjson/serializer.cpp @@ -4,16 +4,16 @@ * Copyright (C) 2009 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. + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * * * 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. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License + * You should have received a copy of the GNU Lesser 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. @@ -25,61 +25,31 @@ #include #include +#include + +#ifdef _MSC_VER // using MSVC compiler +#include +#endif + using namespace QJson; class Serializer::SerializerPrivate { + public: + SerializerPrivate() : + specialNumbersAllowed(false), + indentMode(QJson::IndentNone), + doublePrecision(6) { + } + bool specialNumbersAllowed; + IndentMode indentMode; + int doublePrecision; + QByteArray buildIndent(int spaces); + QByteArray serialize( const QVariant &v, int reserved = 0); + QString sanitizeString( QString str ); + QByteArray join( const QList& list, const QByteArray& sep ); }; -Serializer::Serializer() : d( new SerializerPrivate ) { -} - -Serializer::~Serializer() { - delete d; -} - -void Serializer::serialize( const QVariant& v, QIODevice* io, bool* ok ) -{ - Q_ASSERT( io ); - if (!io->isOpen()) { - if (!io->open(QIODevice::WriteOnly)) { - if ( ok != 0 ) - *ok = false; - qCritical ("Error opening device"); - return; - } - } - - if (!io->isWritable()) { - if (ok != 0) - *ok = false; - qCritical ("Device is not readable"); - io->close(); - return; - } - - const QByteArray str = serialize( v ); - if ( !str.isNull() ) { - QDataStream stream( io ); - stream << str; - } else { - if ( ok ) - *ok = false; - } -} - -static QString sanitizeString( QString str ) -{ - str.replace( QLatin1String( "\\" ), QLatin1String( "\\\\" ) ); - str.replace( QLatin1String( "\"" ), QLatin1String( "\\\"" ) ); - str.replace( QLatin1String( "\b" ), QLatin1String( "\\b" ) ); - str.replace( QLatin1String( "\f" ), QLatin1String( "\\f" ) ); - str.replace( QLatin1String( "\n" ), QLatin1String( "\\n" ) ); - str.replace( QLatin1String( "\r" ), QLatin1String( "\\r" ) ); - str.replace( QLatin1String( "\t" ), QLatin1String( "\\t" ) ); - return QString( QLatin1String( "\"%1\"" ) ).arg( str ); -} - -static QByteArray join( const QList& list, const QByteArray& sep ) { +QByteArray Serializer::SerializerPrivate::join( const QList& list, const QByteArray& sep ) { QByteArray res; Q_FOREACH( const QByteArray& i, list ) { if ( !res.isEmpty() ) @@ -89,48 +59,141 @@ static QByteArray join( const QList& list, const QByteArray& sep ) { return res; } -QByteArray Serializer::serialize( const QVariant &v ) +QByteArray Serializer::SerializerPrivate::serialize( const QVariant &v, int reserved ) { QByteArray str; bool error = false; + QByteArray indent; if ( ! v.isValid() ) { // invalid or null? str = "null"; - } else if ( v.type() == QVariant::List ) { // variant is a list? + } else if (( v.type() == QVariant::List ) || ( v.type() == QVariant::StringList )){ // an array or a stringlist? const QVariantList list = v.toList(); QList values; - Q_FOREACH( const QVariant& v, list ) + Q_FOREACH( const QVariant& var, list ) { - QByteArray serializedValue = serialize( v ); + reserved++; + QByteArray serializedValue = serialize( var,reserved ); + reserved--; if ( serializedValue.isNull() ) { error = true; break; } values << serializedValue; } - str = "[ " + join( values, ", " ) + " ]"; + + if (indentMode == QJson::IndentMinimum) { + QByteArray indent = buildIndent(reserved - 1); + str = "[\n" + join( values, ",\n" ) + "\n" + indent + "]"; + } + else if (indentMode == QJson::IndentMedium || indentMode == QJson::IndentFull) { + QByteArray indent = buildIndent(reserved); + str = "[\n" + join( values, ",\n" ) + "\n" + indent + "]"; + } + else if (indentMode == QJson::IndentCompact) { + str = "[" + join( values, "," ) + "]"; + } + else { + str = "[ " + join( values, ", " ) + " ]"; + } + } else if ( v.type() == QVariant::Map ) { // variant is a map? const QVariantMap vmap = v.toMap(); QMapIterator it( vmap ); - str = "{ "; + + if (indentMode == QJson::IndentMinimum) { + QByteArray indent = buildIndent(reserved); + str = indent + "{ "; + } + else if (indentMode == QJson::IndentMedium || indentMode == QJson::IndentFull) { + QByteArray indent = buildIndent(reserved); + QByteArray nextindent = buildIndent(reserved + 1); + str = indent + "{\n" + nextindent; + } + else if (indentMode == QJson::IndentCompact) { + str = "{"; + } + else { + str = "{ "; + } + QList pairs; while ( it.hasNext() ) { it.next(); - QByteArray serializedValue = serialize( it.value() ); + reserved++; + QByteArray serializedValue = serialize( it.value() , reserved); + reserved--; if ( serializedValue.isNull() ) { error = true; break; } - pairs << sanitizeString( it.key() ).toUtf8() + " : " + serializedValue; + QByteArray key = sanitizeString( it.key() ).toUtf8(); + QByteArray value = serializedValue; + if (indentMode == QJson::IndentCompact) { + pairs << key + ":" + value; + } else { + pairs << key + " : " + value; + } + } + + if (indentMode == QJson::IndentFull) { + QByteArray indent = buildIndent(reserved + 1); + str += join( pairs, ",\n" + indent); + } + else if (indentMode == QJson::IndentCompact) { + str += join( pairs, "," ); } - str += join( pairs, ", " ); - str += " }"; + else { + str += join( pairs, ", " ); + } + + if (indentMode == QJson::IndentMedium || indentMode == QJson::IndentFull) { + QByteArray indent = buildIndent(reserved); + str += "\n" + indent + "}"; + } + else if (indentMode == QJson::IndentCompact) { + str += "}"; + } + else { + str += " }"; + } + } else if (( v.type() == QVariant::String ) || ( v.type() == QVariant::ByteArray )) { // a string or a byte array? str = sanitizeString( v.toString() ).toUtf8(); - } else if ( v.type() == QVariant::Double ) { // a double? - str = QByteArray::number( v.toDouble() ); - if( ! str.contains( "." ) && ! str.contains( "e" ) ) { - str += ".0"; + } else if (( v.type() == QVariant::Double) || ((QMetaType::Type)v.type() == QMetaType::Float)) { // a double or a float? + const double value = v.toDouble(); +#if defined _WIN32 && !defined(Q_OS_SYMBIAN) + const bool special = _isnan(value) || !_finite(value); +#elif defined(Q_OS_SYMBIAN) || defined(Q_OS_ANDROID) + const bool special = isnan(value) || isinf(value); +#else + const bool special = std::isnan(value) || std::isinf(value); +#endif + if (special) { + if (specialNumbersAllowed) { +#if defined _WIN32 && !defined(Q_OS_SYMBIAN) + if (_isnan(value)) { +#elif defined(Q_OS_SYMBIAN) || defined(Q_OS_ANDROID) + if (isnan(value)) { +#else + if (std::isnan(value)) { +#endif + str += "NaN"; + } else { + if (value<0) { + str += '-'; + } + str += "Infinity"; + } + } else { + qCritical("Attempt to write NaN or infinity, which is not supported by json"); + error = true; + } + } else { + str = QByteArray::number( value , 'g', doublePrecision); + if( ! str.contains( "." ) && ! str.contains( "e" ) ) { + str += ".0"; + } } } else if ( v.type() == QVariant::Bool ) { // boolean value? str = ( v.toBool() ? "true" : "false" ); @@ -146,7 +209,114 @@ QByteArray Serializer::serialize( const QVariant &v ) error = true; } if ( !error ) + { return str; + } else return QByteArray(); } + +QByteArray Serializer::SerializerPrivate::buildIndent(int spaces) +{ + QByteArray indent; + if (spaces < 0) { + spaces = 0; + } + for (int i = 0; i < spaces; i++ ) { + indent += " "; + } + return indent; +} + +QString Serializer::SerializerPrivate::sanitizeString( QString str ) +{ + str.replace( QLatin1String( "\\" ), QLatin1String( "\\\\" ) ); + + // escape unicode chars + QString result; + const ushort* unicode = str.utf16(); + unsigned int i = 0; + + while ( unicode[ i ] ) { + if ( unicode[ i ] < 128 ) { + result.append( QChar( unicode[ i ] ) ); + } + else { + QString hexCode = QString::number( unicode[ i ], 16 ).rightJustified( 4, + QLatin1Char('0') ); + + result.append( QLatin1String ("\\u") ).append( hexCode ); + } + ++i; + } + str = result; + + str.replace( QLatin1String( "\"" ), QLatin1String( "\\\"" ) ); + str.replace( QLatin1String( "\b" ), QLatin1String( "\\b" ) ); + str.replace( QLatin1String( "\f" ), QLatin1String( "\\f" ) ); + str.replace( QLatin1String( "\n" ), QLatin1String( "\\n" ) ); + str.replace( QLatin1String( "\r" ), QLatin1String( "\\r" ) ); + str.replace( QLatin1String( "\t" ), QLatin1String( "\\t" ) ); + + return QString( QLatin1String( "\"%1\"" ) ).arg( str ); +} + +Serializer::Serializer() + : d( new SerializerPrivate ) +{ +} + +Serializer::~Serializer() { + delete d; +} + +void Serializer::serialize( const QVariant& v, QIODevice* io, bool* ok) +{ + Q_ASSERT( io ); + if (ok) + *ok = false; + + if (!io->isOpen()) { + if (!io->open(QIODevice::WriteOnly)) { + qCritical ("Error opening device"); + return; + } + } + + if (!io->isWritable()) { + qCritical ("Device is not readable"); + io->close(); + return; + } + + const QByteArray str = serialize( v ); + if (io->write(str) == str.count()) { + if (ok) + *ok = true; + } +} + +QByteArray Serializer::serialize( const QVariant &v) +{ + return d->serialize(v); +} + +void QJson::Serializer::allowSpecialNumbers(bool allow) { + d->specialNumbersAllowed = allow; +} + +bool QJson::Serializer::specialNumbersAllowed() const { + return d->specialNumbersAllowed; +} + +void QJson::Serializer::setIndentMode(IndentMode mode) { + d->indentMode = mode; +} + +void QJson::Serializer::setDoublePrecision(int precision) { + d->doublePrecision = precision; +} + +IndentMode QJson::Serializer::indentMode() const { + return d->indentMode; +} diff --git a/thirdparty/qjson/serializer.h b/thirdparty/qjson/serializer.h index fd301b2..66b349c 100644 --- a/thirdparty/qjson/serializer.h +++ b/thirdparty/qjson/serializer.h @@ -3,16 +3,16 @@ * Copyright (C) 2009 Till Adam * * 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. + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * * * 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. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License + * You should have received a copy of the GNU Lesser 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. @@ -28,6 +28,42 @@ class QString; class QVariant; namespace QJson { + /** + * @brief How the indentation should work. + * + * none (default) : { "foo" : 0, "foo1" : 1, "foo2" : [ { "foo3" : 3, "foo4" : 4 } ] } + * + * compact : {"foo":0,"foo1":1,"foo2":[{"foo3":3,"foo4":4}]} + * + * minimum : { "foo" : 0, "foo1" : 1, "foo2" : [ + * { "foo3" : 3, "foo4" : 4 } + * ] } + * + * medium : { + * "foo" : 0, "foo1" : 1, "foo2" : [ + * { + * "foo3" : 3, "foo4" : 4 + * } + * ] + * } + * full : { + * "foo" : 0, + * "foo1" : 1, + * "foo2" : [ + * { + * "foo3" : 3, + * "foo4" : 4 + * } + * ] + * } + */ + enum IndentMode { + IndentNone, + IndentCompact, + IndentMinimum, + IndentMedium, + IndentFull + }; /** * @brief Main class used to convert QVariant objects to JSON data. * @@ -47,7 +83,7 @@ namespace QJson { * @param out Input output device * @param ok if a conversion error occurs, *ok is set to false; otherwise *ok is set to true */ - void serialize( const QVariant& variant, QIODevice* out, bool* ok = 0 ); + void serialize( const QVariant& variant, QIODevice* out, bool* ok = 0); /** * This is a method provided for convenience. It turns the passed in in-memory @@ -59,7 +95,34 @@ namespace QJson { * parser. */ - QByteArray serialize( const QVariant& variant ); + QByteArray serialize( const QVariant& variant); + + /** + * Allow or disallow writing of NaN and/or Infinity (as an extension to QJson) + */ + void allowSpecialNumbers(bool allow); + + /** + * Is Nan and/or Infinity allowed? + */ + bool specialNumbersAllowed() const; + + /** + * set output indentation mode as defined in QJson::IndentMode + */ + void setIndentMode(IndentMode mode = QJson::IndentNone); + + + /** + * set double precision used while converting Double + * \sa QByteArray::number + */ + void setDoublePrecision(int precision); + + /** + * Returns one of the indentation modes defined in QJson::IndentMode + */ + IndentMode indentMode() const; private: Q_DISABLE_COPY(Serializer) diff --git a/thirdparty/qjson/serializerrunnable.cpp b/thirdparty/qjson/serializerrunnable.cpp index 2e57c45..9ebf68b 100644 --- a/thirdparty/qjson/serializerrunnable.cpp +++ b/thirdparty/qjson/serializerrunnable.cpp @@ -6,16 +6,16 @@ * 2009 Frank Osterfeld * * 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. + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * * * 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. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License + * You should have received a copy of the GNU Lesser 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. diff --git a/thirdparty/qjson/serializerrunnable.h b/thirdparty/qjson/serializerrunnable.h index c6b5fe1..d665fc5 100644 --- a/thirdparty/qjson/serializerrunnable.h +++ b/thirdparty/qjson/serializerrunnable.h @@ -3,16 +3,16 @@ * Copyright (C) 2009 Frank Osterfeld * * 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. + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * * * 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. + * Lesser General Public License for more details. * - * You should have received a copy of the GNU Library General Public License + * You should have received a copy of the GNU Lesser 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. -- 2.43.0