simplified ConfigFilter: now uses keys as they are, but with case-insensitive compare
git-svn-id: https://zeitsenke.de/svn/SyncEvolution/trunk@656 15ad00c4-1369-45f4-8270-35d70d36bdcd
This commit is contained in:
parent
6e44db26f3
commit
e8cd3777d5
|
@ -37,7 +37,7 @@ FilterConfigNode::FilterConfigNode(const boost::shared_ptr<const ConfigNode> &no
|
|||
void FilterConfigNode::addFilter(const string &property,
|
||||
const string &value)
|
||||
{
|
||||
m_filter.set(property, value);
|
||||
m_filter[property] = value;
|
||||
}
|
||||
|
||||
void FilterConfigNode::setFilter(const ConfigFilter &filter)
|
||||
|
|
|
@ -43,16 +43,10 @@ using namespace std;
|
|||
*/
|
||||
class FilterConfigNode : public ConfigNode {
|
||||
public:
|
||||
class ConfigFilter : public map<string, string> {
|
||||
/** a case-insensitive string to string mapping */
|
||||
class ConfigFilter : public map<string, string, Nocase<string> > {
|
||||
public:
|
||||
/** add the mapping, regardless whether it exists already or not */
|
||||
void set(const string &property, const string &value) {
|
||||
pair<iterator, bool> inserted = insert(make_pair(boost::to_lower_copy(property), value));
|
||||
if (!inserted.second) {
|
||||
inserted.first->second = value;
|
||||
}
|
||||
}
|
||||
|
||||
/** format as <key> = <value> lines */
|
||||
operator string () const {
|
||||
vector<string> res;
|
||||
|
||||
|
@ -64,14 +58,6 @@ class FilterConfigNode : public ConfigNode {
|
|||
sort(res.begin(), res.end());
|
||||
return join("\n", res.begin(), res.end());
|
||||
}
|
||||
|
||||
iterator find(const string &property) {
|
||||
return map<string, string>::find(boost::to_lower_copy(property));
|
||||
}
|
||||
|
||||
const_iterator find(const string &property) const {
|
||||
return map<string, string>::find(boost::to_lower_copy(property));
|
||||
}
|
||||
};
|
||||
|
||||
/** read-write access to underlying node */
|
||||
|
|
|
@ -418,7 +418,7 @@ bool SyncEvolutionCmdline::parseProp(const ConfigPropertyRegistry &validProps,
|
|||
m_err << "ERROR: " << cmdOpt(opt, param) << ": " << error << endl;
|
||||
return false;
|
||||
} else {
|
||||
props.set(propstr, paramstr);
|
||||
props[propstr] = paramstr;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,11 +21,20 @@
|
|||
|
||||
#include <base/test.h>
|
||||
|
||||
#include <boost/algorithm/string/case_conv.hpp>
|
||||
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
using namespace std;
|
||||
|
||||
/** case-insensitive comparison for assoziative containers */
|
||||
template <class T> class Nocase : public std::binary_function<T, T, bool> {
|
||||
public:
|
||||
bool operator()(const T &x, const T &y) const { return boost::to_lower_copy(x) < boost::to_lower_copy(y); }
|
||||
};
|
||||
|
||||
|
||||
/** concatenate all members of an iterator range, using sep between each pair of entries */
|
||||
template<class T> string join(const string &sep, T begin, T end)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue