From d7c8e3036f3ee38d5e2354990214ccaaa2a89e5a Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 27 Aug 2012 14:33:36 +0200 Subject: Reimplement regex support not to rely on any extensions to std::tr1::regex --- cutl/re.hxx | 14 +++++++++++--- cutl/re/re.cxx | 44 ++++++++++++++------------------------------ 2 files changed, 25 insertions(+), 33 deletions(-) diff --git a/cutl/re.hxx b/cutl/re.hxx index 6bca3f5..92dfdd5 100644 --- a/cutl/re.hxx +++ b/cutl/re.hxx @@ -107,11 +107,17 @@ namespace cutl bool first_only = false) const; public: - string_type - str () const; + string_type const& + str () const + { + return str_; + } bool - empty () const; + empty () const + { + return str_.empty (); + } private: void @@ -119,6 +125,8 @@ namespace cutl private: struct impl; + + string_type str_; // Text representation of regex. impl* impl_; }; diff --git a/cutl/re/re.cxx b/cutl/re/re.cxx index f2a6a67..c996f4e 100644 --- a/cutl/re/re.cxx +++ b/cutl/re/re.cxx @@ -67,14 +67,14 @@ namespace cutl template <> basic_regex:: basic_regex (basic_regex const& r) - : impl_ (new impl (r.impl_->r)) + : str_ (r.str_), impl_ (new impl (r.impl_->r)) { } template <> basic_regex:: basic_regex (basic_regex const& r) - : impl_ (new impl (r.impl_->r)) + : str_ (r.str_), impl_ (new impl (r.impl_->r)) { } @@ -82,7 +82,9 @@ namespace cutl basic_regex& basic_regex:: operator= (basic_regex const& r) { + string_type tmp (r.str_); impl_->r = r.impl_->r; + str_.swap (tmp); return *this; } @@ -90,7 +92,9 @@ namespace cutl basic_regex& basic_regex:: operator= (basic_regex const& r) { + string_type tmp (r.str_); impl_->r = r.impl_->r; + str_.swap (tmp); return *this; } @@ -98,6 +102,8 @@ namespace cutl void basic_regex:: init (string_type const* s, bool icase) { + string_type tmp (s == 0 ? string_type () : *s); + try { if (impl_ == 0) @@ -111,12 +117,16 @@ namespace cutl { throw basic_format (s == 0 ? "" : *s, e.what ()); } + + str_.swap (tmp); } template <> void basic_regex:: init (string_type const* s, bool icase) { + string_type tmp (s == 0 ? string_type () : *s); + try { if (impl_ == 0) @@ -130,6 +140,8 @@ namespace cutl { throw basic_format (s == 0 ? L"" : *s, e.what ()); } + + str_.swap (tmp); } template <> @@ -189,33 +201,5 @@ namespace cutl return tr1::regex_replace (s, impl_->r, sub, f); } - - template <> - string basic_regex:: - str () const - { - return impl_->r.str (); - } - - template <> - wstring basic_regex:: - str () const - { - return impl_->r.str (); - } - - template <> - bool basic_regex:: - empty () const - { - return impl_->r.empty (); - } - - template <> - bool basic_regex:: - empty () const - { - return impl_->r.empty (); - } } } -- cgit v1.1