From 231a4c16b3dee47d026b6b176b01a9df1d43aa56 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 27 Jul 2012 12:06:08 +0200 Subject: Add support for case-insensitive regex --- cutl/re.hxx | 19 +++++++++++++++---- cutl/re/re.cxx | 21 ++++++++++++++------- 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 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:: - 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:: - 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) { -- cgit v1.1