Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r77920 - in branches/release: . boost boost/xpressive
From: eric_at_[hidden]
Date: 2012-04-11 14:13:03


Author: eric_niebler
Date: 2012-04-11 14:13:02 EDT (Wed, 11 Apr 2012)
New Revision: 77920
URL: http://svn.boost.org/trac/boost/changeset/77920

Log:
merge [77913] from trunk
Properties modified:
   branches/release/ (props changed)
   branches/release/boost/ (props changed)
   branches/release/boost/xpressive/ (props changed)
Text files modified:
   branches/release/boost/xpressive/regex_actions.hpp | 63 +++++++++++++++++++++++++++++----------
   branches/release/boost/xpressive/sub_match.hpp | 7 ++++
   2 files changed, 54 insertions(+), 16 deletions(-)

Modified: branches/release/boost/xpressive/regex_actions.hpp
==============================================================================
--- branches/release/boost/xpressive/regex_actions.hpp (original)
+++ branches/release/boost/xpressive/regex_actions.hpp 2012-04-11 14:13:02 EDT (Wed, 11 Apr 2012)
@@ -20,14 +20,17 @@
 #include <boost/mpl/if.hpp>
 #include <boost/mpl/or.hpp>
 #include <boost/mpl/int.hpp>
+#include <boost/mpl/assert.hpp>
 #include <boost/noncopyable.hpp>
 #include <boost/lexical_cast.hpp>
 #include <boost/throw_exception.hpp>
 #include <boost/utility/enable_if.hpp>
+#include <boost/type_traits/is_same.hpp>
 #include <boost/type_traits/is_const.hpp>
 #include <boost/type_traits/is_integral.hpp>
 #include <boost/type_traits/remove_cv.hpp>
 #include <boost/type_traits/remove_reference.hpp>
+#include <boost/range/iterator_range.hpp>
 #include <boost/xpressive/detail/detail_fwd.hpp>
 #include <boost/xpressive/detail/core/state.hpp>
 #include <boost/xpressive/detail/core/matcher/attr_matcher.hpp>
@@ -62,21 +65,6 @@
 #pragma warning(disable : 4610) // can never be instantiated - user defined constructor required
 #endif
 
-namespace boost
-{
- namespace detail
- {
- // Bit of a hack to make lexical_cast work with wide sub_match
- template<typename T>
- struct stream_char;
-
- template<typename BidiIter>
- struct stream_char<xpressive::sub_match<BidiIter> >
- : boost::iterator_value<BidiIter>
- {};
- }
-}
-
 namespace boost { namespace xpressive
 {
 
@@ -572,7 +560,50 @@
             template<typename Value>
             T operator()(Value const &val) const
             {
- return lexical_cast<T>(val);
+ return boost::lexical_cast<T>(val);
+ }
+
+ // Hack around some limitations in boost::lexical_cast
+ T operator()(csub_match const &val) const
+ {
+ return val.matched
+ ? boost::lexical_cast<T>(boost::make_iterator_range(val.first, val.second))
+ : boost::lexical_cast<T>("");
+ }
+
+ T operator()(wcsub_match const &val) const
+ {
+ return val.matched
+ ? boost::lexical_cast<T>(boost::make_iterator_range(val.first, val.second))
+ : boost::lexical_cast<T>(L"");
+ }
+
+ T operator()(ssub_match const &val) const
+ {
+ return val.matched
+ ? boost::lexical_cast<T>(boost::make_iterator_range(&*val.first, &*val.first + (val.second - val.first)))
+ : boost::lexical_cast<T>("");
+ }
+
+ T operator()(wssub_match const &val) const
+ {
+ return val.matched
+ ? boost::lexical_cast<T>(boost::make_iterator_range(&*val.first, &*val.first + (val.second - val.first)))
+ : boost::lexical_cast<T>(L"");
+ }
+
+ template<typename BidiIter>
+ T operator()(sub_match<BidiIter> const &val) const
+ {
+ // If this assert fires, you're trying to coerce a sequences of non-characters
+ // to some other type. Xpressive doesn't know how to do that.
+ typedef typename iterator_value<BidiIter>::type char_type;
+ BOOST_MPL_ASSERT_MSG(
+ (mpl::or_<is_same<char_type, char>, is_same<char_type, wchar_t> >::value)
+ , CAN_ONLY_CONVERT_FROM_CHARACTER_SEQUENCES
+ , (char_type)
+ );
+ return boost::lexical_cast<T>(val.str());
             }
         };
 

Modified: branches/release/boost/xpressive/sub_match.hpp
==============================================================================
--- branches/release/boost/xpressive/sub_match.hpp (original)
+++ branches/release/boost/xpressive/sub_match.hpp 2012-04-11 14:13:02 EDT (Wed, 11 Apr 2012)
@@ -20,6 +20,8 @@
 #include <utility>
 #include <iterator>
 #include <algorithm>
+#include <boost/mpl/assert.hpp>
+#include <boost/type_traits/is_same.hpp>
 #include <boost/iterator/iterator_traits.hpp>
 #include <boost/xpressive/detail/detail_fwd.hpp>
 
@@ -146,6 +148,11 @@
 )
 {
     typedef typename iterator_value<BidiIter>::type char_type;
+ BOOST_MPL_ASSERT_MSG(
+ (boost::is_same<Char, char_type>::value)
+ , CHARACTER_TYPES_OF_STREAM_AND_SUB_MATCH_MUST_MATCH
+ , (Char, char_type)
+ );
     if(sub.matched)
     {
         std::ostream_iterator<char_type, Char, Traits> iout(sout);


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk