Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r79761 - in trunk/boost/xpressive: . detail/static
From: eric_at_[hidden]
Date: 2012-07-26 15:56:56


Author: eric_niebler
Date: 2012-07-26 15:56:55 EDT (Thu, 26 Jul 2012)
New Revision: 79761
URL: http://svn.boost.org/trac/boost/changeset/79761

Log:
op::as shouldn't assume string::iterator != char*
Text files modified:
   trunk/boost/xpressive/detail/static/type_traits.hpp | 18 ++++++++++++++++++
   trunk/boost/xpressive/detail/static/width_of.hpp | 19 +------------------
   trunk/boost/xpressive/regex_actions.hpp | 32 +++++++++++++++++---------------
   3 files changed, 36 insertions(+), 33 deletions(-)

Modified: trunk/boost/xpressive/detail/static/type_traits.hpp
==============================================================================
--- trunk/boost/xpressive/detail/static/type_traits.hpp (original)
+++ trunk/boost/xpressive/detail/static/type_traits.hpp 2012-07-26 15:56:55 EDT (Thu, 26 Jul 2012)
@@ -55,6 +55,24 @@
 {
 };
 
+///////////////////////////////////////////////////////////////////////////////
+// is_char
+//
+template<typename T>
+struct is_char
+ : mpl::false_
+{};
+
+template<>
+struct is_char<char>
+ : mpl::true_
+{};
+
+template<>
+struct is_char<wchar_t>
+ : mpl::true_
+{};
+
 }}} // namespace boost::xpressive::detail
 
 #endif

Modified: trunk/boost/xpressive/detail/static/width_of.hpp
==============================================================================
--- trunk/boost/xpressive/detail/static/width_of.hpp (original)
+++ trunk/boost/xpressive/detail/static/width_of.hpp 2012-07-26 15:56:55 EDT (Thu, 26 Jul 2012)
@@ -23,6 +23,7 @@
 #include <boost/mpl/equal_to.hpp>
 #include <boost/type_traits/is_same.hpp>
 #include <boost/xpressive/detail/detail_fwd.hpp>
+#include <boost/xpressive/detail/static/type_traits.hpp>
 #include <boost/proto/traits.hpp>
 
 namespace boost { namespace xpressive { namespace detail
@@ -67,24 +68,6 @@
     {};
 
     ///////////////////////////////////////////////////////////////////////////////
- // is_char
- //
- template<typename T>
- struct is_char
- : mpl::false_
- {};
-
- template<>
- struct is_char<char>
- : mpl::true_
- {};
-
- template<>
- struct is_char<wchar_t>
- : mpl::true_
- {};
-
- ///////////////////////////////////////////////////////////////////////////////
     // width_of_terminal
     //
     template<typename Expr, typename Char, bool IsXpr = is_xpr<Expr>::value>

Modified: trunk/boost/xpressive/regex_actions.hpp
==============================================================================
--- trunk/boost/xpressive/regex_actions.hpp (original)
+++ trunk/boost/xpressive/regex_actions.hpp 2012-07-26 15:56:55 EDT (Thu, 26 Jul 2012)
@@ -38,6 +38,7 @@
 #include <boost/xpressive/detail/core/matcher/attr_begin_matcher.hpp>
 #include <boost/xpressive/detail/core/matcher/predicate_matcher.hpp>
 #include <boost/xpressive/detail/utility/ignore_unused.hpp>
+#include <boost/xpressive/detail/static/type_traits.hpp>
 
 // These are very often needed by client code.
 #include <boost/typeof/std/map.hpp>
@@ -575,23 +576,9 @@
             {
                 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
             {
@@ -599,10 +586,25 @@
                 // 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)
+ (xpressive::detail::is_char<char_type>::value)
                   , CAN_ONLY_CONVERT_FROM_CHARACTER_SEQUENCES
                   , (char_type)
                 );
+ return this->impl(val, xpressive::detail::is_random<BidiIter>());
+ }
+
+ private:
+ template<typename RandIter>
+ T impl(sub_match<RandIter> const &val, mpl::true_) const
+ {
+ return val.matched
+ ? boost::lexical_cast<T>(boost::make_iterator_range(&*val.first, &*val.first + (val.second - val.first)))
+ : boost::lexical_cast<T>("");
+ }
+
+ template<typename BidiIter>
+ T impl(sub_match<BidiIter> const &val, mpl::false_) const
+ {
                 return boost::lexical_cast<T>(val.str());
             }
         };


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