Skip to content

Commit

Permalink
fix interpretation of numeric constants in scientic notation (fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Oct 22, 2014
1 parent 99c5c10 commit d833c22
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/core/qgsexpressionlexer.ll
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ column_ref_quoted "\""{col_str_char}*"\""
dig [0-9]
num_int {dig}+
num_float {dig}*\.{dig}+([eE][-+]?{dig}+)?
num_float {dig}*(\.{dig}+([eE][-+]?{dig}+)?|[eE][-+]?{dig}+)
str_char ('')|(\\.)|[^'\\]
string "'"{str_char}*"'"
Expand Down Expand Up @@ -159,14 +159,14 @@ string "'"{str_char}*"'"
"," { return COMMA; }
{num_float} { yylval->numberFloat = cLocale.toDouble( QString::fromAscii(yytext) ); return NUMBER_FLOAT; }
{num_float} { yylval->numberFloat = cLocale.toDouble( QString::fromAscii(yytext) ); return NUMBER_FLOAT; }
{num_int} {
bool ok;
yylval->numberInt = cLocale.toInt( QString::fromAscii(yytext), &ok, 10 );
yylval->numberInt = cLocale.toInt( QString::fromAscii(yytext), &ok, 10 );
if( ok )
return NUMBER_INT;
yylval->numberFloat = cLocale.toDouble( QString::fromAscii(yytext), &ok );
yylval->numberFloat = cLocale.toDouble( QString::fromAscii(yytext), &ok );
if( ok )
return NUMBER_FLOAT;
Expand Down
3 changes: 3 additions & 0 deletions tests/src/core/testqgsexpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ class TestQgsExpression: public QObject
QTest::newRow( "literal int" ) << "123" << false << QVariant( 123 );
QTest::newRow( "literal double" ) << "1.2" << false << QVariant( 1.2 );
QTest::newRow( "literal text" ) << "'hello'" << false << QVariant( "hello" );
QTest::newRow( "literal double" ) << ".000001" << false << QVariant( 0.000001 );
QTest::newRow( "literal double" ) << "1.0e-6" << false << QVariant( 0.000001 );
QTest::newRow( "literal double" ) << "1e-6" << false << QVariant( 0.000001 );

// unary minus
QTest::newRow( "unary minus double" ) << "-1.3" << false << QVariant( -1.3 );
Expand Down

0 comments on commit d833c22

Please sign in to comment.