From 44fde85b2496750b78939247d1d19a67c5b3dc71 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 14 Nov 2016 15:24:14 +0200 Subject: C++11-compatibility fixes and improvements --- cutl/re/re.cxx | 75 +++++++++++++++++++++++++++++++++------------------------- 1 file changed, 43 insertions(+), 32 deletions(-) (limited to 'cutl/re') diff --git a/cutl/re/re.cxx b/cutl/re/re.cxx index 3b132ab..5e1dc4a 100644 --- a/cutl/re/re.cxx +++ b/cutl/re/re.cxx @@ -4,12 +4,22 @@ #include -#include // LIBCUTL_EXTERNAL_BOOST - -#ifndef LIBCUTL_EXTERNAL_BOOST -# include +#include // LIBCUTL_* + +// For build2 build it is either C++11 regex or external Boost. +// +#ifdef LIBCUTL_BUILD2 +# ifdef LIBCUTL_CXX11 +# include +# else +# include +# endif #else -# include +# ifndef LIBCUTL_EXTERNAL_BOOST +# include +# else +# include +# endif #endif using namespace std; @@ -18,17 +28,18 @@ namespace cutl { namespace re { +#if defined(LIBCUTL_BUILD2) && defined(LIBCUTL_CXX11) + namespace ire = std; +#else + namespace ire = std::tr1; +#endif + // // format_base // - format_base:: - ~format_base () throw () - { - } - char const* format_base:: - what () const throw () + what () const LIBCUTL_NOTHROW_NOEXCEPT { return description_.c_str (); } @@ -40,17 +51,17 @@ namespace cutl struct basic_regex::impl { typedef basic_string string_type; - typedef tr1::basic_regex regex_type; + typedef ire::basic_regex regex_type; typedef typename regex_type::flag_type flag_type; impl () {} impl (regex_type const& r): r (r) {} impl (string_type const& s, bool icase) { - flag_type f (tr1::regex_constants::ECMAScript); + flag_type f (ire::regex_constants::ECMAScript); if (icase) - f |= tr1::regex_constants::icase; + f |= ire::regex_constants::icase; r.assign (s, f); } @@ -118,15 +129,15 @@ namespace cutl impl_ = s == 0 ? new impl : new impl (*s, icase); else { - impl::flag_type f (tr1::regex_constants::ECMAScript); + impl::flag_type f (ire::regex_constants::ECMAScript); if (icase) - f |= tr1::regex_constants::icase; + f |= ire::regex_constants::icase; impl_->r.assign (*s, f); } } - catch (tr1::regex_error const& e) + catch (ire::regex_error const& e) { throw basic_format (s == 0 ? "" : *s, e.what ()); } @@ -146,15 +157,15 @@ namespace cutl impl_ = s == 0 ? new impl : new impl (*s, icase); else { - impl::flag_type f (tr1::regex_constants::ECMAScript); + impl::flag_type f (ire::regex_constants::ECMAScript); if (icase) - f |= tr1::regex_constants::icase; + f |= ire::regex_constants::icase; impl_->r.assign (*s, f); } } - catch (tr1::regex_error const& e) + catch (ire::regex_error const& e) { throw basic_format (s == 0 ? L"" : *s, e.what ()); } @@ -166,28 +177,28 @@ namespace cutl bool basic_regex:: match (string_type const& s) const { - return tr1::regex_match (s, impl_->r); + return ire::regex_match (s, impl_->r); } template <> bool basic_regex:: match (string_type const& s) const { - return tr1::regex_match (s, impl_->r); + return ire::regex_match (s, impl_->r); } template <> bool basic_regex:: search (string_type const& s) const { - return tr1::regex_search (s, impl_->r); + return ire::regex_search (s, impl_->r); } template <> bool basic_regex:: search (string_type const& s) const { - return tr1::regex_search (s, impl_->r); + return ire::regex_search (s, impl_->r); } template <> @@ -196,13 +207,13 @@ namespace cutl string_type const& sub, bool first_only) const { - tr1::regex_constants::match_flag_type f ( - tr1::regex_constants::format_default); + ire::regex_constants::match_flag_type f ( + ire::regex_constants::format_default); if (first_only) - f |= tr1::regex_constants::format_first_only; + f |= ire::regex_constants::format_first_only; - return tr1::regex_replace (s, impl_->r, sub, f); + return ire::regex_replace (s, impl_->r, sub, f); } template <> @@ -211,13 +222,13 @@ namespace cutl string_type const& sub, bool first_only) const { - tr1::regex_constants::match_flag_type f ( - tr1::regex_constants::format_default); + ire::regex_constants::match_flag_type f ( + ire::regex_constants::format_default); if (first_only) - f |= tr1::regex_constants::format_first_only; + f |= ire::regex_constants::format_first_only; - return tr1::regex_replace (s, impl_->r, sub, f); + return ire::regex_replace (s, impl_->r, sub, f); } } } -- cgit v1.1