mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Merge pull request #1110 from csoler/v0.6-FT
added toStdString() method to search strings so as to display what is…
This commit is contained in:
commit
8368a764fc
@ -28,6 +28,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include "util/rsprint.h"
|
||||||
#include "retroshare/rstypes.h"
|
#include "retroshare/rstypes.h"
|
||||||
|
|
||||||
/******************************************************************************************
|
/******************************************************************************************
|
||||||
@ -127,6 +128,7 @@ public:
|
|||||||
virtual ~Expression() {};
|
virtual ~Expression() {};
|
||||||
|
|
||||||
virtual void linearize(LinearizedExpression& e) const = 0 ;
|
virtual void linearize(LinearizedExpression& e) const = 0 ;
|
||||||
|
virtual std::string toStdString() const = 0 ;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CompoundExpression : public Expression
|
class CompoundExpression : public Expression
|
||||||
@ -155,6 +157,18 @@ public:
|
|||||||
delete Rexp;
|
delete Rexp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual std::string toStdString() const
|
||||||
|
{
|
||||||
|
switch(Op)
|
||||||
|
{
|
||||||
|
case AndOp: return "(" + Lexp->toStdString() + ") AND (" + Rexp->toStdString() +")" ;
|
||||||
|
case OrOp: return "(" + Lexp->toStdString() + ") OR (" + Rexp->toStdString() +")" ;
|
||||||
|
case XorOp: return "(" + Lexp->toStdString() + ") XOR (" + Rexp->toStdString() +")" ;
|
||||||
|
default:
|
||||||
|
return "" ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
virtual void linearize(LinearizedExpression& e) const ;
|
virtual void linearize(LinearizedExpression& e) const ;
|
||||||
private:
|
private:
|
||||||
Expression *Lexp;
|
Expression *Lexp;
|
||||||
@ -169,6 +183,7 @@ public:
|
|||||||
StringExpression(enum StringOperator op, std::list<std::string> &t, bool ic): Op(op),terms(t), IgnoreCase(ic){}
|
StringExpression(enum StringOperator op, std::list<std::string> &t, bool ic): Op(op),terms(t), IgnoreCase(ic){}
|
||||||
|
|
||||||
virtual void linearize(LinearizedExpression& e) const ;
|
virtual void linearize(LinearizedExpression& e) const ;
|
||||||
|
virtual std::string toStdString(const std::string& varstr) const;
|
||||||
protected:
|
protected:
|
||||||
bool evalStr(const std::string &str);
|
bool evalStr(const std::string &str);
|
||||||
|
|
||||||
@ -184,6 +199,7 @@ public:
|
|||||||
RelExpression(enum RelOperator op, T lv, T hv): Op(op), LowerValue(lv), HigherValue(hv) {}
|
RelExpression(enum RelOperator op, T lv, T hv): Op(op), LowerValue(lv), HigherValue(hv) {}
|
||||||
|
|
||||||
virtual void linearize(LinearizedExpression& e) const ;
|
virtual void linearize(LinearizedExpression& e) const ;
|
||||||
|
virtual std::string toStdString(const std::string& typestr) const;
|
||||||
protected:
|
protected:
|
||||||
bool evalRel(T val);
|
bool evalRel(T val);
|
||||||
|
|
||||||
@ -214,6 +230,22 @@ bool RelExpression<T>::evalRel(T val) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
std::string RelExpression<T>::toStdString(const std::string& typestr) const
|
||||||
|
{
|
||||||
|
std::string LowerValueStr = RsUtil::NumberToString(LowerValue) ;
|
||||||
|
|
||||||
|
switch (Op) {
|
||||||
|
case Equals: return typestr + " = " + LowerValueStr ;
|
||||||
|
case GreaterEquals: return typestr + " <= "+ LowerValueStr ;
|
||||||
|
case Greater: return typestr + " < " + LowerValueStr ;
|
||||||
|
case SmallerEquals: return typestr + " >= "+ LowerValueStr ;
|
||||||
|
case Smaller: return typestr + " > " + LowerValueStr ;
|
||||||
|
case InRange: return LowerValueStr + " <= " + typestr + " <= " + RsUtil::NumberToString(HigherValue) ;
|
||||||
|
default:
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/******************************************************************************************
|
/******************************************************************************************
|
||||||
Binary Predicate for Case Insensitive search
|
Binary Predicate for Case Insensitive search
|
||||||
@ -245,6 +277,8 @@ public:
|
|||||||
StringExpression(op,t,ic) {}
|
StringExpression(op,t,ic) {}
|
||||||
bool eval(const ExpFileEntry& file);
|
bool eval(const ExpFileEntry& file);
|
||||||
|
|
||||||
|
virtual std::string toStdString() const { return StringExpression::toStdString("NAME"); }
|
||||||
|
|
||||||
virtual void linearize(LinearizedExpression& e) const
|
virtual void linearize(LinearizedExpression& e) const
|
||||||
{
|
{
|
||||||
e._tokens.push_back(LinearizedExpression::EXPR_NAME) ;
|
e._tokens.push_back(LinearizedExpression::EXPR_NAME) ;
|
||||||
@ -258,6 +292,8 @@ public:
|
|||||||
StringExpression(op,t,ic) {}
|
StringExpression(op,t,ic) {}
|
||||||
bool eval(const ExpFileEntry& file);
|
bool eval(const ExpFileEntry& file);
|
||||||
|
|
||||||
|
virtual std::string toStdString()const { return StringExpression::toStdString("PATH"); }
|
||||||
|
|
||||||
virtual void linearize(LinearizedExpression& e) const
|
virtual void linearize(LinearizedExpression& e) const
|
||||||
{
|
{
|
||||||
e._tokens.push_back(LinearizedExpression::EXPR_PATH) ;
|
e._tokens.push_back(LinearizedExpression::EXPR_PATH) ;
|
||||||
@ -271,6 +307,8 @@ public:
|
|||||||
StringExpression(op,t,ic) {}
|
StringExpression(op,t,ic) {}
|
||||||
bool eval(const ExpFileEntry& file);
|
bool eval(const ExpFileEntry& file);
|
||||||
|
|
||||||
|
virtual std::string toStdString()const { return StringExpression::toStdString("EXTENSION"); }
|
||||||
|
|
||||||
virtual void linearize(LinearizedExpression& e) const
|
virtual void linearize(LinearizedExpression& e) const
|
||||||
{
|
{
|
||||||
e._tokens.push_back(LinearizedExpression::EXPR_EXT) ;
|
e._tokens.push_back(LinearizedExpression::EXPR_EXT) ;
|
||||||
@ -284,6 +322,8 @@ public:
|
|||||||
StringExpression(op,t, true) {}
|
StringExpression(op,t, true) {}
|
||||||
bool eval(const ExpFileEntry& file);
|
bool eval(const ExpFileEntry& file);
|
||||||
|
|
||||||
|
virtual std::string toStdString() const { return StringExpression::toStdString("HASH"); }
|
||||||
|
|
||||||
virtual void linearize(LinearizedExpression& e) const
|
virtual void linearize(LinearizedExpression& e) const
|
||||||
{
|
{
|
||||||
e._tokens.push_back(LinearizedExpression::EXPR_HASH) ;
|
e._tokens.push_back(LinearizedExpression::EXPR_HASH) ;
|
||||||
@ -304,6 +344,8 @@ public:
|
|||||||
RelExpression<int>(op,lv,hv) {}
|
RelExpression<int>(op,lv,hv) {}
|
||||||
bool eval(const ExpFileEntry& file);
|
bool eval(const ExpFileEntry& file);
|
||||||
|
|
||||||
|
virtual std::string toStdString() const { return RelExpression<int>::toStdString("DATE"); }
|
||||||
|
|
||||||
virtual void linearize(LinearizedExpression& e) const
|
virtual void linearize(LinearizedExpression& e) const
|
||||||
{
|
{
|
||||||
e._tokens.push_back(LinearizedExpression::EXPR_DATE) ;
|
e._tokens.push_back(LinearizedExpression::EXPR_DATE) ;
|
||||||
@ -319,6 +361,8 @@ public:
|
|||||||
RelExpression<int>(op,lv,hv) {}
|
RelExpression<int>(op,lv,hv) {}
|
||||||
bool eval(const ExpFileEntry& file);
|
bool eval(const ExpFileEntry& file);
|
||||||
|
|
||||||
|
virtual std::string toStdString() const { return RelExpression<int>::toStdString("SIZE"); }
|
||||||
|
|
||||||
virtual void linearize(LinearizedExpression& e) const
|
virtual void linearize(LinearizedExpression& e) const
|
||||||
{
|
{
|
||||||
e._tokens.push_back(LinearizedExpression::EXPR_SIZE) ;
|
e._tokens.push_back(LinearizedExpression::EXPR_SIZE) ;
|
||||||
@ -334,6 +378,8 @@ public:
|
|||||||
RelExpression<int>(op,lv,hv) {}
|
RelExpression<int>(op,lv,hv) {}
|
||||||
bool eval(const ExpFileEntry& file);
|
bool eval(const ExpFileEntry& file);
|
||||||
|
|
||||||
|
virtual std::string toStdString() const { return RelExpression<int>::toStdString("SIZE"); }
|
||||||
|
|
||||||
virtual void linearize(LinearizedExpression& e) const
|
virtual void linearize(LinearizedExpression& e) const
|
||||||
{
|
{
|
||||||
e._tokens.push_back(LinearizedExpression::EXPR_SIZE_MB) ;
|
e._tokens.push_back(LinearizedExpression::EXPR_SIZE_MB) ;
|
||||||
@ -348,6 +394,8 @@ public:
|
|||||||
PopExpression(const LinearizedExpression& e) ;
|
PopExpression(const LinearizedExpression& e) ;
|
||||||
bool eval(const ExpFileEntry& file);
|
bool eval(const ExpFileEntry& file);
|
||||||
|
|
||||||
|
virtual std::string toStdString() const { return RelExpression<int>::toStdString("POPULARITY"); }
|
||||||
|
|
||||||
virtual void linearize(LinearizedExpression& e) const
|
virtual void linearize(LinearizedExpression& e) const
|
||||||
{
|
{
|
||||||
e._tokens.push_back(LinearizedExpression::EXPR_POP) ;
|
e._tokens.push_back(LinearizedExpression::EXPR_POP) ;
|
||||||
|
@ -1785,6 +1785,10 @@ void RsTurtleRegExpSearchRequestItem::performLocalSearch(std::list<TurtleFileInf
|
|||||||
if(exp == NULL)
|
if(exp == NULL)
|
||||||
return ;
|
return ;
|
||||||
|
|
||||||
|
#ifdef P3TURTLE_DEBUG
|
||||||
|
std::cerr << "Local search on exp: " << exp->toStdString() << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
// now, search!
|
// now, search!
|
||||||
rsFiles->SearchBoolExp(exp,initialResults,RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_SEARCHABLE,PeerId());
|
rsFiles->SearchBoolExp(exp,initialResults,RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_SEARCHABLE,PeerId());
|
||||||
|
|
||||||
|
@ -128,6 +128,32 @@ static bool StrContains( const std::string & str1, const std::string & str2,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::string StringExpression::toStdString(const std::string& varstr) const
|
||||||
|
{
|
||||||
|
std::string strlist ;
|
||||||
|
for (auto iter = terms.begin(); iter != terms.end(); ++iter )
|
||||||
|
strlist += *iter + ",";
|
||||||
|
|
||||||
|
if(!strlist.empty())
|
||||||
|
strlist.pop_back(); // pops the last ","
|
||||||
|
|
||||||
|
switch(Op)
|
||||||
|
{
|
||||||
|
case ContainsAllStrings: return varstr + " CONTAINS ALL "+strlist ;
|
||||||
|
case ContainsAnyStrings: if(terms.size() == 1)
|
||||||
|
return varstr + " CONTAINS "+strlist ;
|
||||||
|
else
|
||||||
|
return varstr + " CONTAINS ONE OF "+strlist ;
|
||||||
|
case EqualsString: if(terms.size() == 1)
|
||||||
|
return varstr + " IS "+strlist ;
|
||||||
|
else
|
||||||
|
return varstr + " IS ONE OF "+strlist ;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return "" ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool StringExpression :: evalStr ( const std::string &str ){
|
bool StringExpression :: evalStr ( const std::string &str ){
|
||||||
std::list<std::string>::iterator iter;
|
std::list<std::string>::iterator iter;
|
||||||
switch (Op) {
|
switch (Op) {
|
||||||
|
Loading…
Reference in New Issue
Block a user