/*============================================================================= Copyright (c) 2001-2010 Joel de Guzman Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) ================================================_==============================*/ #if !defined(BOOST_SPIRIT_STRING_TRAITS_OCTOBER_2008_1252PM) #define BOOST_SPIRIT_STRING_TRAITS_OCTOBER_2008_1252PM #if defined(_MSC_VER) #pragma once #endif #include #include #include #include #include #include #if defined(__GNUC__) && (__GNUC__ < 4) #include #endif namespace boost { namespace spirit { namespace traits { /////////////////////////////////////////////////////////////////////////// // Determine if T is a string /////////////////////////////////////////////////////////////////////////// template struct is_string : mpl::false_ {}; template struct is_string : is_string {}; template <> struct is_string : mpl::true_ {}; template <> struct is_string : mpl::true_ {}; template <> struct is_string : mpl::true_ {}; template <> struct is_string : mpl::true_ {}; template struct is_string : mpl::true_ {}; template struct is_string : mpl::true_ {}; template struct is_string : mpl::true_ {}; template struct is_string : mpl::true_ {}; template struct is_string : mpl::true_ {}; template struct is_string : mpl::true_ {}; template struct is_string : mpl::true_ {}; template struct is_string : mpl::true_ {}; template struct is_string > : mpl::true_ {}; /////////////////////////////////////////////////////////////////////////// // Get the underlying char type of a string /////////////////////////////////////////////////////////////////////////// template struct char_type_of; template struct char_type_of : char_type_of {}; template <> struct char_type_of : mpl::identity {}; template <> struct char_type_of : mpl::identity {}; template <> struct char_type_of : mpl::identity {}; template <> struct char_type_of : mpl::identity {}; template struct char_type_of : mpl::identity {}; template struct char_type_of : mpl::identity {}; template struct char_type_of : mpl::identity {}; template struct char_type_of : mpl::identity {}; template struct char_type_of : mpl::identity {}; template struct char_type_of : mpl::identity {}; template struct char_type_of : mpl::identity {}; template struct char_type_of : mpl::identity {}; template struct char_type_of > : mpl::identity {}; /////////////////////////////////////////////////////////////////////////// // Get the C string from a string /////////////////////////////////////////////////////////////////////////// template inline T* get_c_string(T* str) { return str; } template inline T const* get_c_string(T const* str) { return str; } template inline T const* get_c_string(std::basic_string& str) { return str.c_str(); } template inline T const* get_c_string(std::basic_string const& str) { return str.c_str(); } /////////////////////////////////////////////////////////////////////////// // Get the begin/end iterators from a string /////////////////////////////////////////////////////////////////////////// // Implementation for C-style strings. // gcc 3.x.x has problems resolving ambiguities here #if defined(__GNUC__) && (__GNUC__ < 4) template inline typename add_const::type * get_begin(T* str) { return str; } template inline typename add_const::type* get_end(T* str) { T* last = str; while (*last) last++; return last; } #else template inline T const* get_begin(T const* str) { return str; } template inline T* get_begin(T* str) { return str; } template inline T const* get_end(T const* str) { T const* last = str; while (*last) last++; return last; } template inline T* get_end(T* str) { T* last = str; while (*last) last++; return last; } #endif // Implementation for containers (includes basic_string). template inline typename Str::const_iterator get_begin(Str const& str) { return str.begin(); } template inline typename Str::iterator get_begin(Str& str BOOST_PROTO_DISABLE_IF_IS_CONST(Str)) { return str.begin(); } template inline typename Str::const_iterator get_end(Str const& str) { return str.end(); } template inline typename Str::iterator get_end(Str& str BOOST_PROTO_DISABLE_IF_IS_CONST(Str)) { return str.end(); } // Default implementation for other types: try a C-style string // conversion. // These overloads are explicitly disabled for containers, // as they would be ambiguous with the previous ones. template inline typename disable_if , T const*>::type get_begin(Str const& str) { return str; } template inline typename disable_if , T const*>::type get_end(Str const& str) { return get_end(get_begin(str)); } }}} #endif