Skip to content

Commit

Permalink
Add support for modulo operator (%) in rule based rendering. See ticket
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandro Santilli authored and mach0 committed Dec 18, 2011
1 parent cab91b5 commit ccbd7aa
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/qgssearchstringlexer.ll
Expand Up @@ -109,7 +109,7 @@ string "'"{str_char}*"'"
"||" { return CONCAT; }
[+-/*^] { return yytext[0]; }
[+-/*^%] { return yytext[0]; }
[()] { return yytext[0]; }
Expand Down
1 change: 1 addition & 0 deletions src/core/qgssearchstringparser.yy
Expand Up @@ -171,6 +171,7 @@ scalar_exp:
}
| scalar_exp '^' scalar_exp { $$ = new QgsSearchTreeNode(QgsSearchTreeNode::opPOW, $1, $3); joinTmpNodes($$,$1,$3); }
| scalar_exp '*' scalar_exp { $$ = new QgsSearchTreeNode(QgsSearchTreeNode::opMUL, $1, $3); joinTmpNodes($$,$1,$3); }
| scalar_exp '%' scalar_exp { $$ = new QgsSearchTreeNode(QgsSearchTreeNode::opMOD, $1, $3); joinTmpNodes($$,$1,$3); }
| scalar_exp '/' scalar_exp { $$ = new QgsSearchTreeNode(QgsSearchTreeNode::opDIV, $1, $3); joinTmpNodes($$,$1,$3); }
| scalar_exp '+' scalar_exp { $$ = new QgsSearchTreeNode(QgsSearchTreeNode::opPLUS, $1, $3); joinTmpNodes($$,$1,$3); }
| scalar_exp '-' scalar_exp { $$ = new QgsSearchTreeNode(QgsSearchTreeNode::opMINUS,$1, $3); joinTmpNodes($$,$1,$3); }
Expand Down
5 changes: 5 additions & 0 deletions src/core/qgssearchtreenode.cpp
Expand Up @@ -268,6 +268,7 @@ QString QgsSearchTreeNode::makeSearchString()
case opPLUS: str += "+"; break;
case opMINUS: str += "-"; break;
case opMUL: str += "*"; break;
case opMOD: str += "%"; break;
case opDIV: str += "/"; break;
case opPOW: str += "^"; break;

Expand Down Expand Up @@ -776,6 +777,10 @@ QgsSearchTreeValue QgsSearchTreeNode::valueAgainst( const QgsFieldMap& fields, Q
return QgsSearchTreeValue( val1 - val2 );
case opMUL:
return QgsSearchTreeValue( val1 * val2 );
case opMOD:
// NOTE: we _might_ support float operators, like postgresql does
// see 83c94a886c059 commit in postgresql git repo for more info
return QgsSearchTreeValue( int(val1) % int(val2) );
case opDIV:
if ( val2 == 0 )
return QgsSearchTreeValue( 2, "" ); // division by zero
Expand Down
1 change: 1 addition & 0 deletions src/core/qgssearchtreenode.h
Expand Up @@ -66,6 +66,7 @@ class CORE_EXPORT QgsSearchTreeNode
opPLUS,
opMINUS,
opMUL,
opMOD,
opDIV,
opPOW,
opSQRT,
Expand Down

0 comments on commit ccbd7aa

Please sign in to comment.