// file : cutl/re/re.cxx // copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC // license : MIT; see accompanying LICENSE file #include #ifndef LIBCUTL_EXTERNAL_BOOST # include #else # include #endif using namespace std; namespace cutl { namespace re { // // format_base // format_base:: ~format_base () throw () { } char const* format_base:: what () const throw () { return description_.c_str (); } // // basic_regex // template struct basic_regex::impl { typedef basic_string string_type; typedef tr1::basic_regex regex_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) {} regex_type r; }; template <> basic_regex:: ~basic_regex () { delete impl_; } template <> basic_regex:: ~basic_regex () { delete impl_; } template <> basic_regex:: basic_regex (basic_regex const& r) : impl_ (new impl (r.impl_->r)) { } template <> basic_regex:: basic_regex (basic_regex const& r) : impl_ (new impl (r.impl_->r)) { } template <> basic_regex& basic_regex:: operator= (basic_regex const& r) { impl_->r = r.impl_->r; return *this; } template <> basic_regex& basic_regex:: operator= (basic_regex const& r) { impl_->r = r.impl_->r; return *this; } template <> void basic_regex:: init (string_type const* s, bool icase) { try { 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)); } catch (tr1::regex_error const& e) { throw basic_format (s == 0 ? "" : *s, e.what ()); } } template <> void basic_regex:: init (string_type const* s, bool icase) { try { 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)); } catch (tr1::regex_error const& e) { throw basic_format (s == 0 ? L"" : *s, e.what ()); } } template <> bool basic_regex:: match (string_type const& s) const { return tr1::regex_match (s, impl_->r); } template <> bool basic_regex:: match (string_type const& s) const { return tr1::regex_match (s, impl_->r); } template <> bool basic_regex:: search (string_type const& s) const { return tr1::regex_search (s, impl_->r); } template <> bool basic_regex:: search (string_type const& s) const { return tr1::regex_search (s, impl_->r); } template <> string basic_regex:: replace (string_type const& s, string_type const& sub, bool first_only) const { tr1::regex_constants::match_flag_type f ( tr1::regex_constants::format_default); if (first_only) f |= tr1::regex_constants::format_first_only; return tr1::regex_replace (s, impl_->r, sub, f); } template <> wstring basic_regex:: replace (string_type const& s, string_type const& sub, bool first_only) const { tr1::regex_constants::match_flag_type f ( tr1::regex_constants::format_default); if (first_only) f |= tr1::regex_constants::format_first_only; 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 (); } } }