1 /*
2  *
3  * Copyright (c) 2003
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         regex_traits.hpp
15   *   VERSION      see <boost/version.hpp>
16   *   DESCRIPTION: Declares regular expression traits classes.
17   */
18 
19 #ifndef BOOST_REGEX_TRAITS_HPP_INCLUDED
20 #define BOOST_REGEX_TRAITS_HPP_INCLUDED
21 
22 #ifndef BOOST_REGEX_CONFIG_HPP
23 #include <boost/regex/config.hpp>
24 #endif
25 #ifndef BOOST_REGEX_WORKAROUND_HPP
26 #include <boost/regex/v4/regex_workaround.hpp>
27 #endif
28 #ifndef BOOST_REGEX_SYNTAX_TYPE_HPP
29 #include <boost/regex/v4/syntax_type.hpp>
30 #endif
31 #ifndef BOOST_REGEX_ERROR_TYPE_HPP
32 #include <boost/regex/v4/error_type.hpp>
33 #endif
34 #ifndef BOOST_REGEX_TRAITS_DEFAULTS_HPP_INCLUDED
35 #include <boost/regex/v4/regex_traits_defaults.hpp>
36 #endif
37 #ifndef BOOST_NO_STD_LOCALE
38 #  ifndef BOOST_CPP_REGEX_TRAITS_HPP_INCLUDED
39 #     include <boost/regex/v4/cpp_regex_traits.hpp>
40 #  endif
41 #endif
42 #if !BOOST_WORKAROUND(__BORLANDC__, < 0x560)
43 #  ifndef BOOST_C_REGEX_TRAITS_HPP_INCLUDED
44 #     include <boost/regex/v4/c_regex_traits.hpp>
45 #  endif
46 #endif
47 #if defined(_WIN32) && !defined(BOOST_REGEX_NO_W32)
48 #  ifndef BOOST_W32_REGEX_TRAITS_HPP_INCLUDED
49 #     include <boost/regex/v4/w32_regex_traits.hpp>
50 #  endif
51 #endif
52 #ifndef BOOST_REGEX_FWD_HPP_INCLUDED
53 #include <boost/regex_fwd.hpp>
54 #endif
55 
56 #include "boost/mpl/has_xxx.hpp"
57 #include <boost/static_assert.hpp>
58 
59 #ifdef BOOST_HAS_ABI_HEADERS
60 #  include BOOST_ABI_PREFIX
61 #endif
62 
63 namespace boost{
64 
65 template <class charT, class implementationT >
66 struct regex_traits : public implementationT
67 {
regex_traitsboost::regex_traits68    regex_traits() : implementationT() {}
69 };
70 
71 //
72 // class regex_traits_wrapper.
73 // this is what our implementation will actually store;
74 // it provides default implementations of the "optional"
75 // interfaces that we support, in addition to the
76 // required "standard" ones:
77 //
78 namespace re_detail{
79 #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !BOOST_WORKAROUND(__HP_aCC, BOOST_TESTED_AT(55500))
80 BOOST_MPL_HAS_XXX_TRAIT_DEF(boost_extensions_tag)
81 #else
82 template<class T>
83 struct has_boost_extensions_tag
84 {
85    BOOST_STATIC_CONSTANT(bool, value = false);
86 };
87 #endif
88 
89 template <class BaseT>
90 struct default_wrapper : public BaseT
91 {
92    typedef typename BaseT::char_type char_type;
error_stringboost::re_detail::default_wrapper93    std::string error_string(::boost::regex_constants::error_type e)const
94    {
95       return ::boost::re_detail::get_default_error_string(e);
96    }
syntax_typeboost::re_detail::default_wrapper97    ::boost::regex_constants::syntax_type syntax_type(char_type c)const
98    {
99       return ((c & 0x7f) == c) ? get_default_syntax_type(static_cast<char>(c)) : ::boost::regex_constants::syntax_char;
100    }
escape_syntax_typeboost::re_detail::default_wrapper101    ::boost::regex_constants::escape_syntax_type escape_syntax_type(char_type c)const
102    {
103       return ((c & 0x7f) == c) ? get_default_escape_syntax_type(static_cast<char>(c)) : ::boost::regex_constants::escape_type_identity;
104    }
toiboost::re_detail::default_wrapper105    int toi(const char_type*& p1, const char_type* p2, int radix)const
106    {
107       return ::boost::re_detail::global_toi(p1, p2, radix, *this);
108    }
translateboost::re_detail::default_wrapper109    char_type translate(char_type c, bool icase)const
110    {
111       return (icase ? this->translate_nocase(c) : this->translate(c));
112    }
translateboost::re_detail::default_wrapper113    char_type translate(char_type c)const
114    {
115       return BaseT::translate(c);
116    }
tolowerboost::re_detail::default_wrapper117    char_type tolower(char_type c)const
118    {
119       return ::boost::re_detail::global_lower(c);
120    }
toupperboost::re_detail::default_wrapper121    char_type toupper(char_type c)const
122    {
123       return ::boost::re_detail::global_upper(c);
124    }
125 };
126 
127 template <class BaseT, bool has_extensions>
128 struct compute_wrapper_base
129 {
130    typedef BaseT type;
131 };
132 #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !BOOST_WORKAROUND(__HP_aCC, BOOST_TESTED_AT(55500))
133 template <class BaseT>
134 struct compute_wrapper_base<BaseT, false>
135 {
136    typedef default_wrapper<BaseT> type;
137 };
138 #else
139 template <>
140 struct compute_wrapper_base<c_regex_traits<char>, false>
141 {
142    typedef default_wrapper<c_regex_traits<char> > type;
143 };
144 #ifndef BOOST_NO_WREGEX
145 template <>
146 struct compute_wrapper_base<c_regex_traits<wchar_t>, false>
147 {
148    typedef default_wrapper<c_regex_traits<wchar_t> > type;
149 };
150 #endif
151 #endif
152 
153 } // namespace re_detail
154 
155 template <class BaseT>
156 struct regex_traits_wrapper
157    : public ::boost::re_detail::compute_wrapper_base<
158                BaseT,
159                ::boost::re_detail::has_boost_extensions_tag<BaseT>::value
160             >::type
161 {
regex_traits_wrapperboost::regex_traits_wrapper162    regex_traits_wrapper(){}
163 private:
164    regex_traits_wrapper(const regex_traits_wrapper&);
165    regex_traits_wrapper& operator=(const regex_traits_wrapper&);
166 };
167 
168 } // namespace boost
169 
170 #ifdef BOOST_HAS_ABI_HEADERS
171 #  include BOOST_ABI_SUFFIX
172 #endif
173 
174 #endif // include
175 
176