Skip to content

Commit

Permalink
fixing broken literal parsing.
Browse files Browse the repository at this point in the history
  • Loading branch information
Arvid Picciani committed Mar 22, 2010
1 parent e5e56ae commit 668261d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/core/qxtjson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,11 +287,13 @@ static QVariant parseLiteral (QTextStream & s,bool & error){
return QVariant();
}else if (c=='-' || c.isDigit()){
QString n;
n.append(c);
while(!s.atEnd() && !error && ( c.isDigit() || (c=='.') || (c=='E') || (c=='e') || (c=='-') || (c=='+') )){
s>>c;
while(( c.isDigit() || (c=='.') || (c=='E') || (c=='e') || (c=='-') || (c=='+') )){
n.append(c);
if(s.atEnd() || error)
break;
s>>c;
}
s.seek(s.pos()-1);
if(n.contains('.')){
return n.toDouble();
}else{
Expand Down
12 changes: 10 additions & 2 deletions tests/unit/core/json/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,21 @@ private slots:
QCOMPARE(QxtJSON::stringify(e),QString("{\"bla\":\"fish\",\"boo\":false,\"foo\":5}"));
}
void parseLiteral(){
QCOMPARE(QxtJSON::parse("0.5").toDouble(),0.5);
QCOMPARE(QxtJSON::parse("5123").toInt(),5123);
QCOMPARE(QxtJSON::parse("1.5").toDouble(),1.5);
}
void same(){
QVariantList e;
e<<"fish"<<true<<QVariant()<<"bla"<<false;
e<<"fish"<<true<<QVariant()<<"bla"<<false<<6.5;
QCOMPARE(QxtJSON::parse(QxtJSON::stringify(e)),QVariant(e));
}

void regressXenakios(){
QVariant e=QxtJSON::parse("{\"apina\":\"ripulia!\",\"doctype\":\"QtCDP WorkSpace\",\"processinghistory\":[{\"infilename\":\"H:/Samples from net/Berklee44v8/Berklee44v8/aluminum2.wav\",\"itemname\":\"aluminum2.wav\",\"itemtag\":\"inputfile\",\"tse\":5.62246,\"tss\":5.08163},{\"infilename\":\"H:/Samples from net/Berklee44v8/Berklee44v8/aluminum3.wav\",\"itemname\":\"aluminum3.wav\",\"itemtag\":\"inputfile\"},{\"infilename\":\"H:/Samples from net/Berklee44v8/Berklee44v8/asprin_crinkle_1.wav\",\"itemname\":\"asprin_crinkle_1.wav\",\"itemtag\":\"inputfile\",\"tse\":0.593006,\"tss\":0.255667},{\"infilename\":\"H:/Samples from net/Berklee44v8/Berklee44v8/asprin_crinkle_2.wav\",\"itemname\":\"asprin_crinkle_2.wav\",\"itemtag\":\"inputfile\",\"tse\":1.66739,\"tss\":1.53128}]}");
QVERIFY(!e.isNull());
}


};

QTEST_MAIN(QxtJSONTest)
Expand Down

0 comments on commit 668261d

Please sign in to comment.