Changed regex_token_iterator to return a sub_match rather than a std::string (it's more efficient).

[SVN r20613]
This commit is contained in:
John Maddock
2003-11-03 11:25:30 +00:00
parent de9338cedf
commit 23f71d7727
4 changed files with 62 additions and 22 deletions

View File

@ -209,6 +209,9 @@ using std::distance;
# ifdef BOOST_REGEX_DYN_LINK
# define BOOST_DYN_LINK
# endif
#ifdef BOOST_REGEX_DIAG
# define BOOST_LIB_DIAGNOSTIC
#endif
# include <boost/config/auto_link.hpp>
#endif

View File

@ -44,6 +44,9 @@ namespace boost{
# pragma warning(disable:4700)
#endif
// testing
#define TEST_BECKER_INTERFACE
template <class BidirectionalIterator,
class charT,
class traits,
@ -51,13 +54,17 @@ template <class BidirectionalIterator,
class regex_token_iterator_implementation
{
typedef basic_regex<charT, traits, Allocator> regex_type;
#ifdef TEST_BECKER_INTERFACE
typedef sub_match<BidirectionalIterator> value_type;
#else
typedef std::basic_string<charT> value_type;
#endif
match_results<BidirectionalIterator> what; // current match
BidirectionalIterator end; // end of search area
const regex_type* pre; // the expression
match_flag_type flags; // match flags
std::basic_string<charT> result; // the current string result
value_type result; // the current string result
int N; // the current sub-expression being enumerated
std::vector<int> subs; // the sub-expressions to enumerate
@ -99,12 +106,22 @@ public:
if(regex_search(first, end, what, *pre, flags) == true)
{
N = 0;
#ifdef TEST_BECKER_INTERFACE
result = ((subs[N] == -1) ? what.prefix() : what[(int)subs[N]]);
#else
result = ((subs[N] == -1) ? value_type(what.prefix().str()) : value_type(what[(int)subs[N]].str()));
#endif
return true;
}
else if((subs[N] == -1) && (first != end))
{
#ifdef TEST_BECKER_INTERFACE
result.first = first;
result.second = end;
result.matched = true;
#else
result = value_type(first, end);
#endif
return true;
}
return false;
@ -119,7 +136,7 @@ public:
&& (what[0].first == that.what[0].first)
&& (what[0].second == that.what[0].second);
}
const std::basic_string<charT>& get()
const value_type& get()
{ return result; }
bool next()
{
@ -128,7 +145,11 @@ public:
if(N+1 < (int)subs.size())
{
++N;
#ifdef TEST_BECKER_INTERFACE
result =((subs[N] == -1) ? what.prefix().first : what[subs[N]]);
#else
result =((subs[N] == -1) ? value_type(what.prefix().first, what.prefix().second) : value_type(what[subs[N]].first, what[subs[N]].second));
#endif
return true;
}
if(what.prefix().first != what[0].second)
@ -137,13 +158,23 @@ public:
if(regex_search(last_end, end, what, *pre, ((what[0].first == what[0].second) ? flags | regex_constants::match_not_initial_null : flags)))
{
N =0;
#ifdef TEST_BECKER_INTERFACE
result =((subs[N] == -1) ? what.prefix() : what[subs[N]]);
#else
result =((subs[N] == -1) ? value_type(what.prefix().first, what.prefix().second) : value_type(what[subs[N]].first, what[subs[N]].second));
#endif
return true;
}
else if((last_end != end) && (subs[0] == -1))
{
N =-1;
#ifdef TEST_BECKER_INTERFACE
result.first = last_end;
result.second = end;
result.matched = true;
#else
result = value_type(last_end, end);
#endif
return true;
}
return false;
@ -161,7 +192,11 @@ private:
typedef shared_ptr<impl> pimpl;
public:
typedef basic_regex<charT, traits, Allocator> regex_type;
#ifdef TEST_BECKER_INTERFACE
typedef sub_match<BidirectionalIterator> value_type;
#else
typedef std::basic_string<charT> value_type;
#endif
typedef typename re_detail::regex_iterator_traits<BidirectionalIterator>::difference_type
difference_type;
typedef const value_type* pointer;