This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: Regex refactoring
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: Tim Shen <timshen91 at gmail dot com>
- Cc: "libstdc++" <libstdc++ at gcc dot gnu dot org>
- Date: Fri, 8 Nov 2013 18:59:48 +0000
- Subject: Re: Regex refactoring
- Authentication-results: sourceware.org; auth=none
- References: <CAH6eHdQJwYAF5Yy6k3AGY_D4+fifjF5g57iZUAOeQ4C4wiazWA at mail dot gmail dot com> <CAPrifD=MTgD2rhjcWiibONcMLk9otpH6Q6vELh2siR4iovyxCQ at mail dot gmail dot com> <CAH6eHdSNdajgLtNK0NHuhWKTt2ND89xaOrR_knjfn_GymdrU3Q at mail dot gmail dot com> <CAH6eHdQ2tyNF+LMhMvMD2kOF=9p4cXYUH3E8cJ2P7ufsBDRXbw at mail dot gmail dot com>
I'm also thinking about this change to avoid allocating memory in
regex::assign(). It isn't exactly what the standard requires, but I'm
not sure if the difference matters:
--- a/libstdc++-v3/include/bits/regex.h
+++ b/libstdc++-v3/include/bits/regex.h
@@ -618,7 +618,7 @@ _GLIBCXX_END_NAMESPACE_VERSION
*/
basic_regex&
assign(const _Ch_type* __p, std::size_t __len, flag_type __flags)
- { return this->assign(string_type(__p, __len), __flags); }
+ { return this->assign(__p, __p + __len, __flags); }
/**
* @brief Assigns a new regular expression to a regex object from a
@@ -635,12 +635,7 @@ _GLIBCXX_END_NAMESPACE_VERSION
basic_regex&
assign(const basic_string<_Ch_type, _Ch_typeraits, _Alloc>& __s,
flag_type __flags = ECMAScript)
- {
- _M_flags = __flags;
- _M_automaton = __detail::__compile_nfa(__s.begin(), __s.end(),
- _M_traits, _M_flags);
- return *this;
- }
+ { return this->assign(__s.begin(), __s.end(), __flags); }
/**
* @brief Assigns a new regular expression to a regex object.
@@ -659,7 +654,12 @@ _GLIBCXX_END_NAMESPACE_VERSION
basic_regex&
assign(_InputIterator __first, _InputIterator __last,
flag_type __flags = ECMAScript)
- { return this->assign(string_type(__first, __last), __flags); }
+ {
+ _M_flags = __flags;
+ _M_automaton = __detail::__compile_nfa(__first, __last,
+ _M_traits, _M_flags);
+ return *this;
+ }
/**
* @brief Assigns a new regular expression to a regex object.