improved expression widget so as to convert size Equal searches into a proper range

This commit is contained in:
csoler 2023-01-07 15:08:10 +01:00
parent 1447306d65
commit fa071a1c50

View File

@ -122,9 +122,9 @@ RsRegularExpression::Expression* ExpressionWidget::getRsExpression()
highVal = exprParamElem->getIntHighValue();
if (lowVal >highVal)
{
lowVal = lowVal^highVal; // csoler: wow, that is some style!
highVal = lowVal^highVal;
lowVal = lowVal^highVal;
auto tmp=lowVal;
lowVal = highVal;
highVal = tmp;
}
}
@ -174,11 +174,42 @@ RsRegularExpression::Expression* ExpressionWidget::getRsExpression()
else
{
uint64_t s = exprParamElem->getIntValue() ;
auto cond = exprCondElem->getRelOperator();
bool MB = false;
if(s >= (uint64_t)(1024*1024*1024))
expr = new RsRegularExpression::SizeExpressionMB(exprCondElem->getRelOperator(), (int)(s/(1024*1024))) ;
{
MB=true;
s >>= 20;
}
// Specific case for Equal operator, which we convert to a range, so as to avoid matching arbitrary digits
if(cond == RsRegularExpression::Equals)
{
// Now compute a proper interval. For that we look for the largest non significant digit, and add/remove 50% of it.
int i=0;
while(!(s & (1<<i)) && i<32)
i++;
if(i==0)
if(MB)
expr = new RsRegularExpression::SizeExpressionMB(RsRegularExpression::Equals, (int)s) ;
else
expr = new RsRegularExpression::SizeExpression(RsRegularExpression::Equals, (int)s) ;
else
if(MB)
expr = new RsRegularExpression::SizeExpressionMB(RsRegularExpression::InRange, (int)s - (1<<(i-1)), (int)s + (1<<(i-1)));
else
expr = new RsRegularExpression::SizeExpression(RsRegularExpression::InRange, (int)s - (1<<(i-1)), (int)s + (1<<(i-1)));
}
else
expr = new RsRegularExpression::SizeExpression(exprCondElem->getRelOperator(), (int)s) ;
{
if(MB)
expr = new RsRegularExpression::SizeExpressionMB(cond, (int)s);
else
expr = new RsRegularExpression::SizeExpression(cond, (int)s) ;
}
}
break;
};