From 27eb8e46ff9beb31ada69741e03f0875cd541028 Mon Sep 17 00:00:00 2001 From: John Maddock Date: Thu, 7 Oct 2010 07:23:58 +0000 Subject: [PATCH] Stop accessing/comparing singular iterators. Fixes #4708. [SVN r65800] --- include/boost/regex/v4/sub_match.hpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/include/boost/regex/v4/sub_match.hpp b/include/boost/regex/v4/sub_match.hpp index 1c79e39a..34a86840 100644 --- a/include/boost/regex/v4/sub_match.hpp +++ b/include/boost/regex/v4/sub_match.hpp @@ -56,7 +56,7 @@ struct sub_match : public std::pair template operator std::basic_string ()const { - return std::basic_string(this->first, this->second); + return matched ? std::basic_string(this->first, this->second) : std::basic_string(); } #else operator std::basic_string ()const @@ -66,19 +66,22 @@ struct sub_match : public std::pair #endif difference_type BOOST_REGEX_CALL length()const { - difference_type n = ::boost::re_detail::distance((BidiIterator)this->first, (BidiIterator)this->second); + difference_type n = matched ? ::boost::re_detail::distance((BidiIterator)this->first, (BidiIterator)this->second) : 0; return n; } std::basic_string str()const { std::basic_string result; - std::size_t len = ::boost::re_detail::distance((BidiIterator)this->first, (BidiIterator)this->second); - result.reserve(len); - BidiIterator i = this->first; - while(i != this->second) + if(matched) { - result.append(1, *i); - ++i; + std::size_t len = ::boost::re_detail::distance((BidiIterator)this->first, (BidiIterator)this->second); + result.reserve(len); + BidiIterator i = this->first; + while(i != this->second) + { + result.append(1, *i); + ++i; + } } return result; }