From fa071a1c50509450205ba15b0387fb0d141e5fcd Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 7 Jan 2023 15:08:10 +0100 Subject: [PATCH] improved expression widget so as to convert size Equal searches into a proper range --- .../src/gui/advsearch/expressionwidget.cpp | 41 ++++++++++++++++--- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/retroshare-gui/src/gui/advsearch/expressionwidget.cpp b/retroshare-gui/src/gui/advsearch/expressionwidget.cpp index 5e5eee1ea..dc1738825 100644 --- a/retroshare-gui/src/gui/advsearch/expressionwidget.cpp +++ b/retroshare-gui/src/gui/advsearch/expressionwidget.cpp @@ -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<getRelOperator(), (int)s) ; + { + if(MB) + expr = new RsRegularExpression::SizeExpressionMB(cond, (int)s); + else + expr = new RsRegularExpression::SizeExpression(cond, (int)s) ; + } } break; };