File src/ItemFilter.cpp changed (mode: 100644) (index df4eba0..46c3eff) |
... |
... |
ItemFilter::passes(std::function<std::string(const std::string &)> accessor, |
70 |
70 |
{ |
{ |
71 |
71 |
error.clear(); |
error.clear(); |
72 |
72 |
|
|
|
73 |
|
auto test = [](const Cond &cond, const std::string &val) { |
|
74 |
|
switch (cond.op) { |
|
75 |
|
case Op::eq: return (val == cond.value); |
|
76 |
|
case Op::ne: return (val != cond.value); |
|
77 |
|
case Op::iccontains: return boost::icontains(val, cond.value); |
|
78 |
|
case Op::icnotcontain: return !boost::icontains(val, cond.value); |
|
79 |
|
} |
|
80 |
|
assert(false && "Unhandled operation type."); |
|
81 |
|
return false; |
|
82 |
|
}; |
|
83 |
|
|
73 |
84 |
auto err = [&error](const Cond &cond) { |
auto err = [&error](const Cond &cond) { |
74 |
85 |
if (!error.empty()) { |
if (!error.empty()) { |
75 |
86 |
error += '\n'; |
error += '\n'; |
|
... |
... |
ItemFilter::passes(std::function<std::string(const std::string &)> accessor, |
78 |
89 |
}; |
}; |
79 |
90 |
|
|
80 |
91 |
for (const Cond &cond : conds) { |
for (const Cond &cond : conds) { |
81 |
|
const std::string &val = accessor(cond.key); |
|
82 |
|
switch (cond.op) { |
|
83 |
|
case Op::eq: |
|
84 |
|
if (val != cond.value) { |
|
85 |
|
err(cond); |
|
86 |
|
} |
|
87 |
|
continue; |
|
88 |
|
case Op::ne: |
|
89 |
|
if (val == cond.value) { |
|
90 |
|
err(cond); |
|
91 |
|
} |
|
92 |
|
continue; |
|
93 |
|
case Op::iccontains: |
|
94 |
|
if (!boost::icontains(val, cond.value)) { |
|
95 |
|
err(cond); |
|
96 |
|
} |
|
97 |
|
continue; |
|
98 |
|
case Op::icnotcontain: |
|
99 |
|
if (boost::icontains(val, cond.value)) { |
|
100 |
|
err(cond); |
|
101 |
|
} |
|
102 |
|
continue; |
|
|
92 |
|
if (!test(cond, accessor(cond.key))) { |
|
93 |
|
err(cond); |
103 |
94 |
} |
} |
104 |
|
assert(false && "Unhandled operation type."); |
|
105 |
95 |
} |
} |
106 |
96 |
|
|
107 |
97 |
return error.empty(); |
return error.empty(); |