aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2012-08-27 14:33:36 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2012-08-27 14:33:36 +0200
commitd7c8e3036f3ee38d5e2354990214ccaaa2a89e5a (patch)
tree7d2f7f5c31cc370a6a230c9053651cf7211148c7
parent526a1773d487207551495e7ca548c9c8876e6898 (diff)
Reimplement regex support not to rely on any extensions to std::tr1::regex
-rw-r--r--cutl/re.hxx14
-rw-r--r--cutl/re/re.cxx44
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<char>::
basic_regex (basic_regex const& r)
- : impl_ (new impl (r.impl_->r))
+ : str_ (r.str_), impl_ (new impl (r.impl_->r))
{
}
template <>
basic_regex<wchar_t>::
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<char>& basic_regex<char>::
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<wchar_t>& basic_regex<wchar_t>::
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<char>::
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<char> (s == 0 ? "" : *s, e.what ());
}
+
+ str_.swap (tmp);
}
template <>
void basic_regex<wchar_t>::
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<wchar_t> (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<char>::
- str () const
- {
- return impl_->r.str ();
- }
-
- template <>
- wstring basic_regex<wchar_t>::
- str () const
- {
- return impl_->r.str ();
- }
-
- template <>
- bool basic_regex<char>::
- empty () const
- {
- return impl_->r.empty ();
- }
-
- template <>
- bool basic_regex<wchar_t>::
- empty () const
- {
- return impl_->r.empty ();
- }
}
}