From 855fc17d10393d72e647219abf44d445c90752e8 Mon Sep 17 00:00:00 2001 From: konrad Date: Mon, 15 Nov 2010 07:54:46 +0000 Subject: [PATCH] fix literal int parser to be more strict git-svn-id: https://silmor.de/svn/softmagic/elam/trunk@630 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- src/elamintengine.cpp | 42 +++++++++++------------------------------- tests/parser/parser.cpp | 17 +++++++++++++++++ 2 files changed, 28 insertions(+), 31 deletions(-) diff --git a/src/elamintengine.cpp b/src/elamintengine.cpp index 1504a16..849c8a4 100644 --- a/src/elamintengine.cpp +++ b/src/elamintengine.cpp @@ -16,41 +16,21 @@ IntEngine::IntEngine() // decimal: [1-9][0-9]* // octal: 0[0-7]* // hex: 0x[0-9a-fA-F]+ +// end of expression: anything not a nameClass.second QPair IntLiteralParser(const QString&expr,Engine&engine,int start) { QString ls; - //shortcut: single char? - if(start==(expr.size()-1)){ - ls=expr.mid(start,1); - return QPair(ls,ls.toInt()); + //parse to end of expression + QString nc=engine.characterClasses().nameClass().second; + for(int i=start;i'0' && expr[start]<='9'){ - //decimal - for(int i=start;i'9')break; - ls+=expr[i]; - } - }else //oct or hex - if(expr[start+1]=='x'){ - //hex - ls="0x"; - for(int i=start+2;i='0' && expr[i]<='9')&& - (expr[i]>='a' && expr[i]<='f')&& - (expr[i]>='A' && expr[i]<='F')) - ls+=expr[i]; - else - break; - } - }else{ - //oct - for(int i=start;i'7')break; - ls+=expr[i]; - } - } - return QPair(ls,ls.toLongLong(0,0)); + //is it integer? + bool ok; + qlonglong r=ls.toLongLong(&ok,0); + if(ok)return QPair(ls,r); + else QPair(); } void IntEngine::configureIntEngine(ELAM::Engine& eng) diff --git a/tests/parser/parser.cpp b/tests/parser/parser.cpp index 857f639..84c7771 100644 --- a/tests/parser/parser.cpp +++ b/tests/parser/parser.cpp @@ -76,6 +76,23 @@ void ElamTest::tokenizer() for(int i=0;i