summaryrefslogtreecommitdiff
path: root/boost/xpressive
diff options
context:
space:
mode:
Diffstat (limited to 'boost/xpressive')
-rw-r--r--boost/xpressive/detail/core/adaptor.hpp2
-rw-r--r--boost/xpressive/detail/static/type_traits.hpp55
-rw-r--r--boost/xpressive/detail/static/width_of.hpp19
-rw-r--r--boost/xpressive/regex_actions.hpp67
-rw-r--r--boost/xpressive/sub_match.hpp7
-rw-r--r--boost/xpressive/traits/cpp_regex_traits.hpp16
-rw-r--r--boost/xpressive/traits/detail/c_ctype.hpp12
-rw-r--r--boost/xpressive/xpressive_fwd.hpp2
8 files changed, 141 insertions, 39 deletions
diff --git a/boost/xpressive/detail/core/adaptor.hpp b/boost/xpressive/detail/core/adaptor.hpp
index 6afecf2f92..28aaa23247 100644
--- a/boost/xpressive/detail/core/adaptor.hpp
+++ b/boost/xpressive/detail/core/adaptor.hpp
@@ -41,7 +41,7 @@ struct xpression_adaptor
&& ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
// Ugh, gcc has an optimizer bug which elides this c'tor call
// resulting in pure virtual function calls.
- __attribute__((noinline))
+ __attribute__((__noinline__))
#endif
: xpr_(xpr)
{
diff --git a/boost/xpressive/detail/static/type_traits.hpp b/boost/xpressive/detail/static/type_traits.hpp
index 67ba77e328..15f00a4243 100644
--- a/boost/xpressive/detail/static/type_traits.hpp
+++ b/boost/xpressive/detail/static/type_traits.hpp
@@ -13,6 +13,8 @@
# pragma once
#endif
+#include <string>
+#include <boost/config.hpp>
#include <boost/mpl/bool.hpp>
#include <boost/iterator/iterator_traits.hpp>
#include <boost/type_traits/is_convertible.hpp>
@@ -55,6 +57,59 @@ struct is_random
{
};
+//////////////////////////////////////////////////////////////////////////
+// is_string_iterator
+//
+template<typename Iter>
+struct is_string_iterator
+ : mpl::false_
+{
+};
+
+template<>
+struct is_string_iterator<std::string::iterator>
+ : mpl::true_
+{
+};
+
+template<>
+struct is_string_iterator<std::string::const_iterator>
+ : mpl::true_
+{
+};
+
+#ifndef BOOST_NO_STD_WSTRING
+template<>
+struct is_string_iterator<std::wstring::iterator>
+ : mpl::true_
+{
+};
+
+template<>
+struct is_string_iterator<std::wstring::const_iterator>
+ : mpl::true_
+{
+};
+#endif
+
+///////////////////////////////////////////////////////////////////////////////
+// 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
diff --git a/boost/xpressive/detail/static/width_of.hpp b/boost/xpressive/detail/static/width_of.hpp
index eec6e5491d..f7f6f9ecd5 100644
--- a/boost/xpressive/detail/static/width_of.hpp
+++ b/boost/xpressive/detail/static/width_of.hpp
@@ -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 @@ namespace boost { namespace xpressive { namespace detail
{};
///////////////////////////////////////////////////////////////////////////////
- // 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>
diff --git a/boost/xpressive/regex_actions.hpp b/boost/xpressive/regex_actions.hpp
index e22b164a88..1f9617ba31 100644
--- a/boost/xpressive/regex_actions.hpp
+++ b/boost/xpressive/regex_actions.hpp
@@ -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>
@@ -35,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>
@@ -62,21 +66,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 +561,53 @@ namespace boost { namespace xpressive
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>("");
+ }
+
+ #ifndef BOOST_XPRESSIVE_NO_WREGEX
+ 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>("");
+ }
+ #endif
+
+ 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(
+ (xpressive::detail::is_char<char_type>::value)
+ , CAN_ONLY_CONVERT_FROM_CHARACTER_SEQUENCES
+ , (char_type)
+ );
+ return this->impl(val, xpressive::detail::is_string_iterator<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());
}
};
diff --git a/boost/xpressive/sub_match.hpp b/boost/xpressive/sub_match.hpp
index 5bd778ba9f..a5f9559983 100644
--- a/boost/xpressive/sub_match.hpp
+++ b/boost/xpressive/sub_match.hpp
@@ -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 @@ inline std::basic_ostream<Char, Traits> &operator <<
)
{
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);
diff --git a/boost/xpressive/traits/cpp_regex_traits.hpp b/boost/xpressive/traits/cpp_regex_traits.hpp
index 5d5c7fd0b1..74a904cd12 100644
--- a/boost/xpressive/traits/cpp_regex_traits.hpp
+++ b/boost/xpressive/traits/cpp_regex_traits.hpp
@@ -20,10 +20,12 @@
#include <string>
#include <locale>
#include <sstream>
+#include <climits>
#include <boost/config.hpp>
#include <boost/assert.hpp>
#include <boost/integer.hpp>
#include <boost/mpl/assert.hpp>
+#include <boost/static_assert.hpp>
#include <boost/detail/workaround.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/xpressive/detail/detail_fwd.hpp>
@@ -89,7 +91,7 @@ namespace detail
template<umaskex_t In, umaskex_t Out = highest_bit, bool Done = (0 == (Out & In))>
struct unused_mask
{
- BOOST_MPL_ASSERT_RELATION(1, !=, Out);
+ BOOST_STATIC_ASSERT(1 != Out);
BOOST_STATIC_CONSTANT(umaskex_t, value = (unused_mask<In, (Out >> 1)>::value));
};
@@ -121,6 +123,8 @@ namespace detail
umaskex_t const std_ctype_reserved = 0x8000;
#elif defined(_CPPLIB_VER) && defined(BOOST_WINDOWS)
umaskex_t const std_ctype_reserved = 0x8200;
+ #elif defined(_LIBCPP_VERSION)
+ umaskex_t const std_ctype_reserved = 0x8000;
#else
umaskex_t const std_ctype_reserved = 0;
#endif
@@ -205,6 +209,16 @@ namespace detail
return true;
}
+ // HACKHACK Cygwin and mingw have buggy ctype facets for wchar_t
+ #if defined(__CYGWIN__) || defined(__MINGW32_VERSION)
+ if (std::ctype_base::xdigit == ((std::ctype_base::mask)(umask_t)mask & std::ctype_base::xdigit))
+ {
+ typename std::char_traits<Char>::int_type i = std::char_traits<Char>::to_int_type(ch);
+ if(UCHAR_MAX >= i && std::isxdigit(static_cast<int>(i)))
+ return true;
+ }
+ #endif
+
#else
umaskex_t tmp = mask & ~non_std_ctype_masks;
diff --git a/boost/xpressive/traits/detail/c_ctype.hpp b/boost/xpressive/traits/detail/c_ctype.hpp
index 5ed5d97c78..40788c46cd 100644
--- a/boost/xpressive/traits/detail/c_ctype.hpp
+++ b/boost/xpressive/traits/detail/c_ctype.hpp
@@ -496,8 +496,7 @@ struct char_class_impl<char>
static bool isctype(char ch, char_class_type mask)
{
- using namespace std;
- if(0 != __isctype(static_cast<unsigned char>(ch), mask))
+ if(glibc_isctype(ch, mask))
{
return true;
}
@@ -511,6 +510,15 @@ struct char_class_impl<char>
return false;
}
+
+ static bool glibc_isctype(char ch, char_class_type mask)
+ {
+ #ifdef __isctype
+ return 0 != __isctype(ch, mask);
+ #else
+ return 0 != ((*__ctype_b_loc())[(int)(ch)] & (unsigned short int)mask);
+ #endif
+ }
};
#ifndef BOOST_XPRESSIVE_NO_WREGEX
diff --git a/boost/xpressive/xpressive_fwd.hpp b/boost/xpressive/xpressive_fwd.hpp
index 00c8c61506..8ae9035fe0 100644
--- a/boost/xpressive/xpressive_fwd.hpp
+++ b/boost/xpressive/xpressive_fwd.hpp
@@ -31,7 +31,7 @@
# define BOOST_XPRESSIVE_USE_C_TRAITS
#endif
-#if defined(BOOST_NO_CWCHAR) | defined(BOOST_NO_CWCTYPE) | defined(BOOST_NO_STD_WSTRING)
+#if defined(BOOST_NO_CWCHAR) || defined(BOOST_NO_CWCTYPE) || defined(BOOST_NO_STD_WSTRING)
# ifndef BOOST_XPRESSIVE_NO_WREGEX
# define BOOST_XPRESSIVE_NO_WREGEX
# endif