Jeff Thompson | 86b6d64 | 2013-10-17 15:01:56 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Copyright (c) 2004 |
| 4 | * John Maddock |
| 5 | * |
| 6 | * Use, modification and distribution are subject to the |
| 7 | * Boost Software License, Version 1.0. (See accompanying file |
| 8 | * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 9 | * |
| 10 | */ |
| 11 | |
| 12 | /* |
| 13 | * LOCATION: see http://www.boost.org for most recent version. |
| 14 | * FILE c_regex_traits.hpp |
| 15 | * VERSION see <ndnboost/version.hpp> |
| 16 | * DESCRIPTION: Declares regular expression traits class that wraps the global C locale. |
| 17 | */ |
| 18 | |
| 19 | #ifndef NDNBOOST_C_REGEX_TRAITS_HPP_INCLUDED |
| 20 | #define NDNBOOST_C_REGEX_TRAITS_HPP_INCLUDED |
| 21 | |
| 22 | #ifndef NDNBOOST_REGEX_CONFIG_HPP |
| 23 | #include <ndnboost/regex/config.hpp> |
| 24 | #endif |
| 25 | #ifndef NDNBOOST_REGEX_WORKAROUND_HPP |
| 26 | #include <ndnboost/regex/v4/regex_workaround.hpp> |
| 27 | #endif |
| 28 | |
| 29 | #include <cctype> |
| 30 | |
| 31 | #ifdef NDNBOOST_NO_STDC_NAMESPACE |
| 32 | namespace std{ |
| 33 | using ::strlen; using ::tolower; |
| 34 | } |
| 35 | #endif |
| 36 | |
| 37 | #ifdef NDNBOOST_MSVC |
| 38 | #pragma warning(push) |
| 39 | #pragma warning(disable: 4103) |
| 40 | #endif |
| 41 | #ifdef NDNBOOST_HAS_ABI_HEADERS |
| 42 | # include NDNBOOST_ABI_PREFIX |
| 43 | #endif |
| 44 | #ifdef NDNBOOST_MSVC |
| 45 | #pragma warning(pop) |
| 46 | #endif |
| 47 | |
| 48 | namespace ndnboost{ |
| 49 | |
| 50 | template <class charT> |
| 51 | struct c_regex_traits; |
| 52 | |
| 53 | template<> |
| 54 | struct NDNBOOST_REGEX_DECL c_regex_traits<char> |
| 55 | { |
| 56 | c_regex_traits(){} |
| 57 | typedef char char_type; |
| 58 | typedef std::size_t size_type; |
| 59 | typedef std::string string_type; |
| 60 | struct locale_type{}; |
| 61 | typedef ndnboost::uint32_t char_class_type; |
| 62 | |
| 63 | static size_type length(const char_type* p) |
| 64 | { |
| 65 | return (std::strlen)(p); |
| 66 | } |
| 67 | |
| 68 | char translate(char c) const |
| 69 | { |
| 70 | return c; |
| 71 | } |
| 72 | char translate_nocase(char c) const |
| 73 | { |
| 74 | return static_cast<char>((std::tolower)(static_cast<unsigned char>(c))); |
| 75 | } |
| 76 | |
| 77 | static string_type NDNBOOST_REGEX_CALL transform(const char* p1, const char* p2); |
| 78 | static string_type NDNBOOST_REGEX_CALL transform_primary(const char* p1, const char* p2); |
| 79 | |
| 80 | static char_class_type NDNBOOST_REGEX_CALL lookup_classname(const char* p1, const char* p2); |
| 81 | static string_type NDNBOOST_REGEX_CALL lookup_collatename(const char* p1, const char* p2); |
| 82 | |
| 83 | static bool NDNBOOST_REGEX_CALL isctype(char, char_class_type); |
| 84 | static int NDNBOOST_REGEX_CALL value(char, int); |
| 85 | |
| 86 | locale_type imbue(locale_type l) |
| 87 | { return l; } |
| 88 | locale_type getloc()const |
| 89 | { return locale_type(); } |
| 90 | |
| 91 | private: |
| 92 | // this type is not copyable: |
| 93 | c_regex_traits(const c_regex_traits&); |
| 94 | c_regex_traits& operator=(const c_regex_traits&); |
| 95 | }; |
| 96 | |
| 97 | #ifndef NDNBOOST_NO_WREGEX |
| 98 | template<> |
| 99 | struct NDNBOOST_REGEX_DECL c_regex_traits<wchar_t> |
| 100 | { |
| 101 | c_regex_traits(){} |
| 102 | typedef wchar_t char_type; |
| 103 | typedef std::size_t size_type; |
| 104 | typedef std::wstring string_type; |
| 105 | struct locale_type{}; |
| 106 | typedef ndnboost::uint32_t char_class_type; |
| 107 | |
| 108 | static size_type length(const char_type* p) |
| 109 | { |
| 110 | return (std::wcslen)(p); |
| 111 | } |
| 112 | |
| 113 | wchar_t translate(wchar_t c) const |
| 114 | { |
| 115 | return c; |
| 116 | } |
| 117 | wchar_t translate_nocase(wchar_t c) const |
| 118 | { |
| 119 | return (std::towlower)(c); |
| 120 | } |
| 121 | |
| 122 | static string_type NDNBOOST_REGEX_CALL transform(const wchar_t* p1, const wchar_t* p2); |
| 123 | static string_type NDNBOOST_REGEX_CALL transform_primary(const wchar_t* p1, const wchar_t* p2); |
| 124 | |
| 125 | static char_class_type NDNBOOST_REGEX_CALL lookup_classname(const wchar_t* p1, const wchar_t* p2); |
| 126 | static string_type NDNBOOST_REGEX_CALL lookup_collatename(const wchar_t* p1, const wchar_t* p2); |
| 127 | |
| 128 | static bool NDNBOOST_REGEX_CALL isctype(wchar_t, char_class_type); |
| 129 | static int NDNBOOST_REGEX_CALL value(wchar_t, int); |
| 130 | |
| 131 | locale_type imbue(locale_type l) |
| 132 | { return l; } |
| 133 | locale_type getloc()const |
| 134 | { return locale_type(); } |
| 135 | |
| 136 | private: |
| 137 | // this type is not copyable: |
| 138 | c_regex_traits(const c_regex_traits&); |
| 139 | c_regex_traits& operator=(const c_regex_traits&); |
| 140 | }; |
| 141 | |
| 142 | #ifdef NDNBOOST_REGEX_HAS_OTHER_WCHAR_T |
| 143 | // |
| 144 | // Provide an unsigned short version as well, so the user can link to this |
| 145 | // no matter whether they build with /Zc:wchar_t or not (MSVC specific). |
| 146 | // |
| 147 | template<> |
| 148 | struct NDNBOOST_REGEX_DECL c_regex_traits<unsigned short> |
| 149 | { |
| 150 | c_regex_traits(){} |
| 151 | typedef unsigned short char_type; |
| 152 | typedef std::size_t size_type; |
| 153 | typedef std::basic_string<unsigned short> string_type; |
| 154 | struct locale_type{}; |
| 155 | typedef ndnboost::uint32_t char_class_type; |
| 156 | |
| 157 | static size_type length(const char_type* p) |
| 158 | { |
| 159 | return (std::wcslen)((const wchar_t*)p); |
| 160 | } |
| 161 | |
| 162 | unsigned short translate(unsigned short c) const |
| 163 | { |
| 164 | return c; |
| 165 | } |
| 166 | unsigned short translate_nocase(unsigned short c) const |
| 167 | { |
| 168 | return (std::towlower)((wchar_t)c); |
| 169 | } |
| 170 | |
| 171 | static string_type NDNBOOST_REGEX_CALL transform(const unsigned short* p1, const unsigned short* p2); |
| 172 | static string_type NDNBOOST_REGEX_CALL transform_primary(const unsigned short* p1, const unsigned short* p2); |
| 173 | |
| 174 | static char_class_type NDNBOOST_REGEX_CALL lookup_classname(const unsigned short* p1, const unsigned short* p2); |
| 175 | static string_type NDNBOOST_REGEX_CALL lookup_collatename(const unsigned short* p1, const unsigned short* p2); |
| 176 | |
| 177 | static bool NDNBOOST_REGEX_CALL isctype(unsigned short, char_class_type); |
| 178 | static int NDNBOOST_REGEX_CALL value(unsigned short, int); |
| 179 | |
| 180 | locale_type imbue(locale_type l) |
| 181 | { return l; } |
| 182 | locale_type getloc()const |
| 183 | { return locale_type(); } |
| 184 | |
| 185 | private: |
| 186 | // this type is not copyable: |
| 187 | c_regex_traits(const c_regex_traits&); |
| 188 | c_regex_traits& operator=(const c_regex_traits&); |
| 189 | }; |
| 190 | |
| 191 | #endif |
| 192 | |
| 193 | #endif // NDNBOOST_NO_WREGEX |
| 194 | |
| 195 | } |
| 196 | |
| 197 | #ifdef NDNBOOST_MSVC |
| 198 | #pragma warning(push) |
| 199 | #pragma warning(disable: 4103) |
| 200 | #endif |
| 201 | #ifdef NDNBOOST_HAS_ABI_HEADERS |
| 202 | # include NDNBOOST_ABI_SUFFIX |
| 203 | #endif |
| 204 | #ifdef NDNBOOST_MSVC |
| 205 | #pragma warning(pop) |
| 206 | #endif |
| 207 | |
| 208 | #endif |
| 209 | |
| 210 | |
| 211 | |