• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 ///////////////////////////////////////////////////////////////////////////////
2 /// \file regex_traits.hpp
3 /// Includes the C regex traits or the CPP regex traits header file depending on the
4 /// BOOST_XPRESSIVE_USE_C_TRAITS macro.
5 //
6 //  Copyright 2008 Eric Niebler. Distributed under the Boost
7 //  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 #ifndef BOOST_XPRESSIVE_REGEX_TRAITS_HPP_EAN_10_04_2005
11 #define BOOST_XPRESSIVE_REGEX_TRAITS_HPP_EAN_10_04_2005
12 
13 // MS compatible compilers support #pragma once
14 #if defined(_MSC_VER)
15 # pragma once
16 #endif
17 
18 #include <boost/type_traits/is_convertible.hpp>
19 #include <boost/xpressive/detail/detail_fwd.hpp>
20 
21 #ifdef BOOST_XPRESSIVE_USE_C_TRAITS
22 # include <boost/xpressive/traits/c_regex_traits.hpp>
23 #else
24 # include <boost/xpressive/traits/cpp_regex_traits.hpp>
25 #endif
26 
27 namespace boost { namespace xpressive
28 {
29 
30 ///////////////////////////////////////////////////////////////////////////////
31 // regex_traits_version_1_tag
32 /// Tag used to denote that a traits class conforms to the version 1 traits
33 /// interface.
34 struct regex_traits_version_1_tag
35 {
36 };
37 
38 ///////////////////////////////////////////////////////////////////////////////
39 // regex_traits_version_2_tag
40 /// Tag used to denote that a traits class conforms to the version 2 traits
41 /// interface.
42 struct regex_traits_version_2_tag
43   : regex_traits_version_1_tag
44 {
45 };
46 
47 ///////////////////////////////////////////////////////////////////////////////
48 // regex_traits_version_1_case_fold_tag DEPRECATED use has_fold_case trait
49 /// INTERNAL ONLY
50 ///
51 struct regex_traits_version_1_case_fold_tag
52   : regex_traits_version_1_tag
53 {
54 };
55 
56 ///////////////////////////////////////////////////////////////////////////////
57 // has_fold_case
58 /// Trait used to denote that a traits class has the fold_case member function.
59 template<typename Traits>
60 struct has_fold_case
61   : is_convertible<
62         typename Traits::version_tag *
63       , regex_traits_version_1_case_fold_tag *
64     >
65 {
66 };
67 
68 ///////////////////////////////////////////////////////////////////////////////
69 // regex_traits
70 /// Thin wrapper around the default regex_traits implementation, either
71 /// cpp_regex_traits or c_regex_traits
72 ///
73 template<typename Char, typename Impl>
74 struct regex_traits
75   : Impl
76 {
77     typedef typename Impl::locale_type locale_type;
78 
regex_traitsboost::xpressive::regex_traits79     regex_traits()
80       : Impl()
81     {
82     }
83 
regex_traitsboost::xpressive::regex_traits84     explicit regex_traits(locale_type const &loc)
85       : Impl(loc)
86     {
87     }
88 };
89 
90 ///////////////////////////////////////////////////////////////////////////////
91 // lookup_classname
92 /// INTERNAL ONLY
93 template<typename Traits, std::size_t N>
94 inline typename Traits::char_class_type
lookup_classname(Traits const & traits,char const (& cname)[N],bool icase)95 lookup_classname(Traits const &traits, char const (&cname)[N], bool icase)
96 {
97     typename Traits::char_type name[N] = {0};
98     for(std::size_t j = 0; j < N-1; ++j)
99     {
100         name[j] = traits.widen(cname[j]);
101     }
102     return traits.lookup_classname(name, name + N - 1, icase);
103 }
104 
105 }}
106 
107 #endif
108