aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2012-07-27 12:06:08 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2012-07-27 12:06:08 +0200
commit231a4c16b3dee47d026b6b176b01a9df1d43aa56 (patch)
tree17dd0afca3ec24aac46d7579b8fbfa491624c716
parente3da7b73054d94c65bb58933eae6bc82b40dd719 (diff)
Add support for case-insensitive regex
-rw-r--r--cutl/re.hxx19
-rw-r--r--cutl/re/re.cxx21
2 files changed, 29 insertions, 11 deletions
diff --git a/cutl/re.hxx b/cutl/re.hxx
index 7638bb4..6bca3f5 100644
--- a/cutl/re.hxx
+++ b/cutl/re.hxx
@@ -66,15 +66,26 @@ namespace cutl
~basic_regex ();
- basic_regex (): impl_ (0) {init (0);}
+ basic_regex (): impl_ (0) {init (0, false);}
explicit
- basic_regex (string_type const& s): impl_ (0) {init (&s);}
+ basic_regex (string_type const& s, bool icase = false)
+ : impl_ (0)
+ {
+ init (&s, icase);
+ }
basic_regex&
operator= (string_type const& s)
{
- init (&s);
+ init (&s, false);
+ return *this;
+ }
+
+ basic_regex&
+ assign (string_type const& s, bool icase = false)
+ {
+ init (&s, icase);
return *this;
}
@@ -104,7 +115,7 @@ namespace cutl
private:
void
- init (string_type const*);
+ init (string_type const*, bool);
private:
struct impl;
diff --git a/cutl/re/re.cxx b/cutl/re/re.cxx
index 8e46d59..f2a6a67 100644
--- a/cutl/re/re.cxx
+++ b/cutl/re/re.cxx
@@ -41,7 +41,10 @@ namespace cutl
typedef tr1::basic_regex<C> regex_type;
impl () {}
- impl (string_type const& s): r (s, tr1::regex_constants::ECMAScript) {}
+ impl (string_type const& s, bool icase)
+ : r (s,
+ tr1::regex_constants::ECMAScript |
+ (icase ? tr1::regex_constants::icase : 0)) {}
impl (regex_type const& r): r (r) {}
regex_type r;
@@ -93,14 +96,16 @@ namespace cutl
template <>
void basic_regex<char>::
- init (string_type const* s)
+ init (string_type const* s, bool icase)
{
try
{
if (impl_ == 0)
- impl_ = s == 0 ? new impl : new impl (*s);
+ impl_ = s == 0 ? new impl : new impl (*s, icase);
else
- impl_->r = *s;
+ impl_->r.assign (*s,
+ tr1::regex_constants::ECMAScript |
+ (icase ? tr1::regex_constants::icase : 0));
}
catch (tr1::regex_error const& e)
{
@@ -110,14 +115,16 @@ namespace cutl
template <>
void basic_regex<wchar_t>::
- init (string_type const* s)
+ init (string_type const* s, bool icase)
{
try
{
if (impl_ == 0)
- impl_ = s == 0 ? new impl : new impl (*s);
+ impl_ = s == 0 ? new impl : new impl (*s, icase);
else
- impl_->r = *s;
+ impl_->r.assign (*s,
+ tr1::regex_constants::ECMAScript |
+ (icase ? tr1::regex_constants::icase : 0));
}
catch (tr1::regex_error const& e)
{