
Hello, in the following class: class MyClass : public boost::regex {...} I want to be able to switch between case-sensitive and non-sensitive matching so i defined this method: void MyClass::setIgnoreCase(bool ignoreCase /* = true */) { assign(str(), ignoreCase? (flags() | boost::regex::icase) : (flags() | (~boost::regex::icase))); } but then I get segmentation fault. I know this is caused by bitwise negation (~) but i don't know why. Do you? -- Pozdrawiam Michał Nowotka

Michał Nowotka wrote:
Hello, in the following class:
class MyClass : public boost::regex {...}
I want to be able to switch between case-sensitive and non-sensitive matching so i defined this method:
void MyClass::setIgnoreCase(bool ignoreCase /* = true */) { assign(str(), ignoreCase? (flags() | boost::regex::icase) : (flags() | (~boost::regex::icase))); }
Shouldn't that be & (~boost::regex::icase))); With the '|' you set all bits to 1, except to the one which really interests you...
but then I get segmentation fault.
If the above wasn't the cause, a small, but complete (compiling) example would certainly help :-) Regards, Roland

Ok, so this is simple example - stupid but should work: #include <boost/regex.hpp> #include <iostream> class Mask : public boost::regex { public: Mask(const std::string& str) :boost::regex() { assign(str,boost::regex::optimize); } Mask(const Mask& other) :boost::regex(other.str(), other.flags()) {} void setIgnoreCase(bool ignoreCase = true) { assign(str(), ~boost::regbase::icase); } }; int main(int argc, char **argv) { Mask mask("foo"); mask.setIgnoreCase(); } then: $ g++ example.cpp -lboost_regex-mt $ ./a.out Segmentation fault -- Regards Michał Nowotka
participants (3)
-
John Maddock
-
Michał Nowotka
-
Roland Bock