From be8833cb1ac9ce81aa0e3cac4cbb319f6d8875d4 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 28 Aug 2012 14:53:07 +0200 Subject: Tighten up regex implementation --- cutl/re/re.cxx | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) (limited to 'cutl') diff --git a/cutl/re/re.cxx b/cutl/re/re.cxx index c996f4e..95a6411 100644 --- a/cutl/re/re.cxx +++ b/cutl/re/re.cxx @@ -39,13 +39,19 @@ namespace cutl { typedef basic_string string_type; typedef tr1::basic_regex regex_type; + typedef typename regex_type::flag_type flag_type; impl () {} - 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) {} + impl (string_type const& s, bool icase) + { + flag_type f (tr1::regex_constants::ECMAScript); + + if (icase) + f |= tr1::regex_constants::icase; + + r.assign (s, f); + } regex_type r; }; @@ -109,9 +115,14 @@ namespace cutl if (impl_ == 0) impl_ = s == 0 ? new impl : new impl (*s, icase); else - impl_->r.assign (*s, - tr1::regex_constants::ECMAScript | - (icase ? tr1::regex_constants::icase : 0)); + { + impl::flag_type f (tr1::regex_constants::ECMAScript); + + if (icase) + f |= tr1::regex_constants::icase; + + impl_->r.assign (*s, f); + } } catch (tr1::regex_error const& e) { @@ -132,9 +143,14 @@ namespace cutl if (impl_ == 0) impl_ = s == 0 ? new impl : new impl (*s, icase); else - impl_->r.assign (*s, - tr1::regex_constants::ECMAScript | - (icase ? tr1::regex_constants::icase : 0)); + { + impl::flag_type f (tr1::regex_constants::ECMAScript); + + if (icase) + f |= tr1::regex_constants::icase; + + impl_->r.assign (*s, f); + } } catch (tr1::regex_error const& e) { -- cgit v1.1