Added validation code for mask_t objects.

This commit is contained in:
John Wiegley 2009-02-12 03:06:15 -04:00
parent eaac95147c
commit dc68903bb2
3 changed files with 14 additions and 0 deletions

View file

@ -42,6 +42,7 @@ mask_t::mask_t(const string& pat) : expr()
mask_t& mask_t::operator=(const string& pat)
{
expr.assign(pat.c_str(), regex::perl | regex::icase);
VERIFY(valid());
return *this;
}

View file

@ -77,12 +77,23 @@ public:
}
bool match(const string& str) const {
DEBUG("mask.match",
"Matching: \"" << str << "\" =~ /" << expr.str() << "/ = "
<< (boost::regex_search(str, expr) ? "true" : "false"));
return boost::regex_search(str, expr);
}
bool empty() const {
return expr.empty();
}
bool valid() const {
if (expr.status() != 0) {
DEBUG("ledger.validate", "mask_t: expr.status() != 0");
return false;
}
return true;
}
};
inline std::ostream& operator<<(std::ostream& out, const mask_t& mask) {

View file

@ -622,10 +622,12 @@ public:
mask_t& as_mask_lval() {
assert(is_mask());
_dup();
VERIFY(boost::get<mask_t>(storage->data).valid());
return boost::get<mask_t>(storage->data);
}
const mask_t& as_mask() const {
assert(is_mask());
VERIFY(boost::get<mask_t>(storage->data).valid());
return boost::get<mask_t>(storage->data);
}
void set_mask(const string& val) {