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,
|
void FilterConfigNode::addFilter(const string &property,
|
||||||
const string &value)
|
const string &value)
|
||||||
{
|
{
|
||||||
m_filter.set(property, value);
|
m_filter[property] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FilterConfigNode::setFilter(const ConfigFilter &filter)
|
void FilterConfigNode::setFilter(const ConfigFilter &filter)
|
||||||
|
|
|
@ -43,16 +43,10 @@ using namespace std;
|
||||||
*/
|
*/
|
||||||
class FilterConfigNode : public ConfigNode {
|
class FilterConfigNode : public ConfigNode {
|
||||||
public:
|
public:
|
||||||
class ConfigFilter : public map<string, string> {
|
/** a case-insensitive string to string mapping */
|
||||||
|
class ConfigFilter : public map<string, string, Nocase<string> > {
|
||||||
public:
|
public:
|
||||||
/** add the mapping, regardless whether it exists already or not */
|
/** format as <key> = <value> lines */
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
operator string () const {
|
operator string () const {
|
||||||
vector<string> res;
|
vector<string> res;
|
||||||
|
|
||||||
|
@ -64,14 +58,6 @@ class FilterConfigNode : public ConfigNode {
|
||||||
sort(res.begin(), res.end());
|
sort(res.begin(), res.end());
|
||||||
return join("\n", 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 */
|
/** read-write access to underlying node */
|
||||||
|
|
|
@ -418,7 +418,7 @@ bool SyncEvolutionCmdline::parseProp(const ConfigPropertyRegistry &validProps,
|
||||||
m_err << "ERROR: " << cmdOpt(opt, param) << ": " << error << endl;
|
m_err << "ERROR: " << cmdOpt(opt, param) << ": " << error << endl;
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
props.set(propstr, paramstr);
|
props[propstr] = paramstr;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,11 +21,20 @@
|
||||||
|
|
||||||
#include <base/test.h>
|
#include <base/test.h>
|
||||||
|
|
||||||
|
#include <boost/algorithm/string/case_conv.hpp>
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
using namespace std;
|
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 */
|
/** 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)
|
template<class T> string join(const string &sep, T begin, T end)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue