File indexing completed on 2025-01-31 10:02:38
0001
0002
0003
0004
0005
0006
0007
0008
0009 #if !defined(BOOST_SPIRIT_X3_STRING_TRAITS_OCTOBER_2008_1252PM)
0010 #define BOOST_SPIRIT_X3_STRING_TRAITS_OCTOBER_2008_1252PM
0011
0012 #include <string>
0013 #include <boost/mpl/bool.hpp>
0014
0015 namespace boost { namespace spirit { namespace x3 { namespace traits
0016 {
0017
0018
0019
0020 template <typename String>
0021 struct extract_c_string;
0022
0023 template <typename String>
0024 struct extract_c_string
0025 {
0026 template <typename T>
0027 static T const* call (T* str)
0028 {
0029 return (T const*)str;
0030 }
0031
0032 template <typename T>
0033 static T const* call (T const* str)
0034 {
0035 return str;
0036 }
0037 };
0038
0039
0040 template <typename T>
0041 struct extract_c_string<T const>
0042 {
0043 static decltype(auto) call(T const str)
0044 {
0045 return extract_c_string<T>::call(str);
0046 }
0047 };
0048
0049
0050 template <typename T>
0051 struct extract_c_string<T&>
0052 {
0053 static decltype(auto) call(T& str)
0054 {
0055 return extract_c_string<T>::call(str);
0056 }
0057 };
0058
0059
0060 template <typename T>
0061 struct extract_c_string<T const&>
0062 {
0063 static decltype(auto) call(T const& str)
0064 {
0065 return extract_c_string<T>::call(str);
0066 }
0067 };
0068
0069 template <typename T, typename Traits, typename Allocator>
0070 struct extract_c_string<std::basic_string<T, Traits, Allocator> >
0071 {
0072 typedef std::basic_string<T, Traits, Allocator> string;
0073
0074 static T const* call (string const& str)
0075 {
0076 return str.c_str();
0077 }
0078 };
0079
0080 template <typename T>
0081 decltype(auto) get_c_string(T* str)
0082 {
0083 return extract_c_string<T*>::call(str);
0084 }
0085
0086 template <typename T>
0087 decltype(auto) get_c_string(T const* str)
0088 {
0089 return extract_c_string<T const*>::call(str);
0090 }
0091
0092 template <typename String>
0093 decltype(auto) get_c_string(String& str)
0094 {
0095 return extract_c_string<String>::call(str);
0096 }
0097
0098 template <typename String>
0099 decltype(auto) get_c_string(String const& str)
0100 {
0101 return extract_c_string<String>::call(str);
0102 }
0103
0104
0105
0106
0107
0108
0109
0110 template <typename T>
0111 inline T const* get_string_begin(T const* str) { return str; }
0112
0113 template <typename T>
0114 inline T* get_string_begin(T* str) { return str; }
0115
0116 template <typename T>
0117 inline T const* get_string_end(T const* str)
0118 {
0119 T const* last = str;
0120 while (*last)
0121 last++;
0122 return last;
0123 }
0124
0125 template <typename T>
0126 inline T* get_string_end(T* str)
0127 {
0128 T* last = str;
0129 while (*last)
0130 last++;
0131 return last;
0132 }
0133
0134
0135 template <typename T, typename Str>
0136 inline typename Str::const_iterator get_string_begin(Str const& str)
0137 { return str.begin(); }
0138
0139 template <typename T, typename Str>
0140 inline typename Str::iterator
0141 get_string_begin(Str& str)
0142 { return str.begin(); }
0143
0144 template <typename T, typename Str>
0145 inline typename Str::const_iterator get_string_end(Str const& str)
0146 { return str.end(); }
0147
0148 template <typename T, typename Str>
0149 inline typename Str::iterator
0150 get_string_end(Str& str)
0151 { return str.end(); }
0152 }}}}
0153
0154 #endif