diff --git a/include/boost/regex/v4/basic_regex.hpp b/include/boost/regex/v4/basic_regex.hpp index 6fa67348..e0feacfd 100644 --- a/include/boost/regex/v4/basic_regex.hpp +++ b/include/boost/regex/v4/basic_regex.hpp @@ -89,6 +89,12 @@ public: set_expression(ptr, f | regex_constants::use_except); return *this; } + reg_expression& assign(const charT* ptr, size_type len, flag_type f) + { + std::basic_string s(ptr, len); + set_expression(s.c_str(), f | regex_constants::use_except); + return *this; + } reg_expression& assign(const charT* first, const charT* last, @@ -172,9 +178,11 @@ public: locale_type BOOST_REGEX_CALL imbue(locale_type l){ return traits_inst.imbue(l); } locale_type BOOST_REGEX_CALL getloc()const{ return traits_inst.getloc(); } // - // flags: + // getflags: + // retained for backwards compatibility only, the base class has "flags" + // member which is now the prefered name: flag_type BOOST_REGEX_CALL getflags()const - { return flags(); } + { return this->flags(); } // // str: std::basic_string BOOST_REGEX_CALL str()const diff --git a/include/boost/regex/v4/match_results.hpp b/include/boost/regex/v4/match_results.hpp index a896cf42..8e82c1d3 100644 --- a/include/boost/regex/v4/match_results.hpp +++ b/include/boost/regex/v4/match_results.hpp @@ -38,7 +38,11 @@ private: #endif public: typedef sub_match value_type; +#ifndef BOOST_NO_STD_ALLOCATOR + typedef typename Allocator::const_reference const_reference; +#else typedef const value_type& const_reference; +#endif typedef const_reference reference; typedef typename vector_type::const_iterator const_iterator; typedef const_iterator iterator; @@ -116,9 +120,7 @@ public: { return m_subs[sub]; } - assert(0); - // we should never get here: - return m_subs[0]; + return m_null; } const_reference prefix() const @@ -181,6 +183,9 @@ public: m_subs[2].matched = true; m_subs[0].first = i; m_subs[0].matched = (m_subs[0].first != m_subs[0].second); + m_null.first = i; + m_null.second = i; + m_null.matched = false; } void BOOST_REGEX_CALL set_second(RandomAccessIterator i, size_type pos, bool m = true) @@ -193,6 +198,9 @@ public: { m_subs[0].first = i; m_subs[0].matched = (m_subs[0].first != m_subs[0].second); + m_null.first = i; + m_null.second = i; + m_null.matched = false; } } void BOOST_REGEX_CALL set_size(size_type n, RandomAccessIterator i, RandomAccessIterator j) @@ -244,6 +252,7 @@ public: private: vector_type m_subs; // subexpressions RandomAccessIterator m_base; // where the search started from + sub_match m_null; // a null match }; template diff --git a/include/boost/regex/v4/regex_iterator.hpp b/include/boost/regex/v4/regex_iterator.hpp index 82773005..9ef1dbab 100644 --- a/include/boost/regex/v4/regex_iterator.hpp +++ b/include/boost/regex/v4/regex_iterator.hpp @@ -107,17 +107,17 @@ public: pdata = that.pdata; return *this; } - bool operator==(const regex_iterator& that) + bool operator==(const regex_iterator& that)const { if((pdata.get() == 0) || (that.pdata.get() == 0)) return pdata.get() == that.pdata.get(); return pdata->compare(*(that.pdata.get())); } - bool operator!=(const regex_iterator& that) + bool operator!=(const regex_iterator& that)const { return !(*this == that); } - const value_type& operator*() + const value_type& operator*()const { return pdata->get(); } - const value_type* operator->() + const value_type* operator->()const { return &(pdata->get()); } regex_iterator& operator++() { diff --git a/include/boost/regex/v4/regex_token_iterator.hpp b/include/boost/regex/v4/regex_token_iterator.hpp index 94a34bd0..90fa7c21 100644 --- a/include/boost/regex/v4/regex_token_iterator.hpp +++ b/include/boost/regex/v4/regex_token_iterator.hpp @@ -211,17 +211,17 @@ public: pdata = that.pdata; return *this; } - bool operator==(const regex_token_iterator& that) + bool operator==(const regex_token_iterator& that)const { if((pdata.get() == 0) || (that.pdata.get() == 0)) return pdata.get() == that.pdata.get(); return pdata->compare(*(that.pdata.get())); } - bool operator!=(const regex_token_iterator& that) + bool operator!=(const regex_token_iterator& that)const { return !(*this == that); } - const value_type& operator*() + const value_type& operator*()const { return pdata->get(); } - const value_type* operator->() + const value_type* operator->()const { return &(pdata->get()); } regex_token_iterator& operator++() { diff --git a/include/boost/regex/v4/sub_match.hpp b/include/boost/regex/v4/sub_match.hpp index 80045a75..7e6712ac 100644 --- a/include/boost/regex/v4/sub_match.hpp +++ b/include/boost/regex/v4/sub_match.hpp @@ -102,156 +102,220 @@ struct sub_match : public std::pair // comparison to std::basic_string<> part 1: template -bool operator == (const std::basic_string::value_type, traits, Allocator>& s, +inline bool operator == (const std::basic_string::value_type, traits, Allocator>& s, const sub_match& m) { return s.compare(m.str()) == 0; } template -bool operator != (const std::basic_string::value_type, traits, Allocator>& s, +inline bool operator != (const std::basic_string::value_type, traits, Allocator>& s, const sub_match& m) { return s.compare(m.str()) != 0; } template -bool operator < (const std::basic_string::value_type, traits, Allocator>& s, +inline bool operator < (const std::basic_string::value_type, traits, Allocator>& s, const sub_match& m) { return s.compare(m.str()) < 0; } template -bool operator <= (const std::basic_string::value_type, traits, Allocator>& s, +inline bool operator <= (const std::basic_string::value_type, traits, Allocator>& s, const sub_match& m) { return s.compare(m.str()) <= 0; } template -bool operator >= (const std::basic_string::value_type, traits, Allocator>& s, +inline bool operator >= (const std::basic_string::value_type, traits, Allocator>& s, const sub_match& m) { return s.compare(m.str()) >= 0; } template -bool operator > (const std::basic_string::value_type, traits, Allocator>& s, +inline bool operator > (const std::basic_string::value_type, traits, Allocator>& s, const sub_match& m) { return s.compare(m.str()) > 0; } // comparison to std::basic_string<> part 2: template -bool operator == (const sub_match& m, +inline bool operator == (const sub_match& m, const std::basic_string::value_type, traits, Allocator>& s) { return m.str().compare(s) == 0; } template -bool operator != (const sub_match& m, +inline bool operator != (const sub_match& m, const std::basic_string::value_type, traits, Allocator>& s) { return m.str().compare(s) != 0; } template -bool operator < (const sub_match& m, +inline bool operator < (const sub_match& m, const std::basic_string::value_type, traits, Allocator>& s) { return m.str().compare(s) < 0; } template -bool operator > (const sub_match& m, +inline bool operator > (const sub_match& m, const std::basic_string::value_type, traits, Allocator>& s) { return m.str().compare(s) > 0; } template -bool operator <= (const sub_match& m, +inline bool operator <= (const sub_match& m, const std::basic_string::value_type, traits, Allocator>& s) { return m.str().compare(s) <= 0; } template -bool operator >= (const sub_match& m, +inline bool operator >= (const sub_match& m, const std::basic_string::value_type, traits, Allocator>& s) { return m.str().compare(s) >= 0; } // comparison to const charT* part 1: template -bool operator == (const sub_match& m, +inline bool operator == (const sub_match& m, typename re_detail::regex_iterator_traits::value_type const* s) { return m.str().compare(s) == 0; } template -bool operator != (const sub_match& m, +inline bool operator != (const sub_match& m, typename re_detail::regex_iterator_traits::value_type const* s) { return m.str().compare(s) != 0; } template -bool operator > (const sub_match& m, +inline bool operator > (const sub_match& m, typename re_detail::regex_iterator_traits::value_type const* s) { return m.str().compare(s) > 0; } template -bool operator < (const sub_match& m, +inline bool operator < (const sub_match& m, typename re_detail::regex_iterator_traits::value_type const* s) { return m.str().compare(s) < 0; } template -bool operator >= (const sub_match& m, +inline bool operator >= (const sub_match& m, typename re_detail::regex_iterator_traits::value_type const* s) { return m.str().compare(s) >= 0; } template -bool operator <= (const sub_match& m, +inline bool operator <= (const sub_match& m, typename re_detail::regex_iterator_traits::value_type const* s) { return m.str().compare(s) <= 0; } // comparison to const charT* part 2: template -bool operator == (typename re_detail::regex_iterator_traits::value_type const* s, +inline bool operator == (typename re_detail::regex_iterator_traits::value_type const* s, const sub_match& m) { return m.str().compare(s) == 0; } template -bool operator != (typename re_detail::regex_iterator_traits::value_type const* s, +inline bool operator != (typename re_detail::regex_iterator_traits::value_type const* s, const sub_match& m) { return m.str().compare(s) != 0; } template -bool operator < (typename re_detail::regex_iterator_traits::value_type const* s, +inline bool operator < (typename re_detail::regex_iterator_traits::value_type const* s, const sub_match& m) { return m.str().compare(s) > 0; } template -bool operator > (typename re_detail::regex_iterator_traits::value_type const* s, +inline bool operator > (typename re_detail::regex_iterator_traits::value_type const* s, const sub_match& m) { return m.str().compare(s) < 0; } template -bool operator <= (typename re_detail::regex_iterator_traits::value_type const* s, +inline bool operator <= (typename re_detail::regex_iterator_traits::value_type const* s, const sub_match& m) { return m.str().compare(s) >= 0; } template -bool operator >= (typename re_detail::regex_iterator_traits::value_type const* s, +inline bool operator >= (typename re_detail::regex_iterator_traits::value_type const* s, const sub_match& m) { return m.str().compare(s) <= 0; } // comparison to const charT& part 1: template -bool operator == (const sub_match& m, +inline bool operator == (const sub_match& m, typename re_detail::regex_iterator_traits::value_type const& s) { return m.str().compare(0, m.length(), &s, 1) == 0; } template -bool operator != (const sub_match& m, +inline bool operator != (const sub_match& m, typename re_detail::regex_iterator_traits::value_type const& s) { return m.str().compare(0, m.length(), &s, 1) != 0; } template -bool operator > (const sub_match& m, +inline bool operator > (const sub_match& m, typename re_detail::regex_iterator_traits::value_type const& s) { return m.str().compare(0, m.length(), &s, 1) > 0; } template -bool operator < (const sub_match& m, +inline bool operator < (const sub_match& m, typename re_detail::regex_iterator_traits::value_type const& s) { return m.str().compare(0, m.length(), &s, 1) < 0; } template -bool operator >= (const sub_match& m, +inline bool operator >= (const sub_match& m, typename re_detail::regex_iterator_traits::value_type const& s) { return m.str().compare(0, m.length(), &s, 1) >= 0; } template -bool operator <= (const sub_match& m, +inline bool operator <= (const sub_match& m, typename re_detail::regex_iterator_traits::value_type const& s) { return m.str().compare(0, m.length(), &s, 1) <= 0; } // comparison to const charT* part 2: template -bool operator == (typename re_detail::regex_iterator_traits::value_type const& s, +inline bool operator == (typename re_detail::regex_iterator_traits::value_type const& s, const sub_match& m) { return m.str().compare(0, m.length(), &s, 1) == 0; } template -bool operator != (typename re_detail::regex_iterator_traits::value_type const& s, +inline bool operator != (typename re_detail::regex_iterator_traits::value_type const& s, const sub_match& m) { return m.str().compare(0, m.length(), &s, 1) != 0; } template -bool operator < (typename re_detail::regex_iterator_traits::value_type const& s, +inline bool operator < (typename re_detail::regex_iterator_traits::value_type const& s, const sub_match& m) { return m.str().compare(0, m.length(), &s, 1) > 0; } template -bool operator > (typename re_detail::regex_iterator_traits::value_type const& s, +inline bool operator > (typename re_detail::regex_iterator_traits::value_type const& s, const sub_match& m) { return m.str().compare(0, m.length(), &s, 1) < 0; } template -bool operator <= (typename re_detail::regex_iterator_traits::value_type const& s, +inline bool operator <= (typename re_detail::regex_iterator_traits::value_type const& s, const sub_match& m) { return m.str().compare(0, m.length(), &s, 1) >= 0; } template -bool operator >= (typename re_detail::regex_iterator_traits::value_type const& s, +inline bool operator >= (typename re_detail::regex_iterator_traits::value_type const& s, const sub_match& m) { return m.str().compare(0, m.length(), &s, 1) <= 0; } +// addition operators: +template +inline std::basic_string::value_type, traits, Allocator> +operator + (const std::basic_string::value_type, traits, Allocator>& s, + const sub_match& m) +{ + std::basic_string::value_type, traits, Allocator> result; + result.reserve(s.size() + m.length() + 1); + return result.append(s).append(m.first, m.second); +} +template +inline std::basic_string::value_type, traits, Allocator> +operator + (const sub_match& m, + const std::basic_string::value_type, traits, Allocator>& s) +{ + std::basic_string::value_type, traits, Allocator> result; + result.reserve(s.size() + m.length() + 1); + return result.append(m.first, m.second).append(s); +} +template +inline std::basic_string::value_type> +operator + (typename re_detail::regex_iterator_traits::value_type const* s, + const sub_match& m) +{ + std::basic_string::value_type> result; + result.reserve(std::char_traits::value_type>::length(s) + m.length() + 1); + return result.append(s).append(m.first, m.second); +} +template +inline std::basic_string::value_type> +operator + (const sub_match& m, + typename re_detail::regex_iterator_traits::value_type const * s) +{ + std::basic_string::value_type> result; + result.reserve(std::char_traits::value_type>::length(s) + m.length() + 1); + return result.append(m.first, m.second).append(s); +} +template +inline std::basic_string::value_type> +operator + (typename re_detail::regex_iterator_traits::value_type const& s, + const sub_match& m) +{ + std::basic_string::value_type> result; + result.reserve(m.length() + 2); + return result.append(1, s).append(m.first, m.second); +} +template +inline std::basic_string::value_type> +operator + (const sub_match& m, + typename re_detail::regex_iterator_traits::value_type const& s) +{ + std::basic_string::value_type> result; + result.reserve(m.length() + 2); + return result.append(m.first, m.second).append(1, s); +} +template +inline std::basic_string::value_type> +operator + (const sub_match& m1, + const sub_match& m2) +{ + std::basic_string::value_type> result; + result.reserve(m1.length() + m2.length() + 1); + return result.append(m1.first, m1.second).append(m2.first, m2.second); +} #ifndef BOOST_NO_STD_LOCALE template std::basic_ostream&