Chris@16
|
1 ///////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
2 /// \file null_regex_traits.hpp
|
Chris@16
|
3 /// Contains the definition of the null_regex_traits\<\> template, which is a
|
Chris@16
|
4 /// stub regex traits implementation that can be used by static and dynamic
|
Chris@16
|
5 /// regexes for searching non-character data.
|
Chris@16
|
6 //
|
Chris@16
|
7 // Copyright 2008 Eric Niebler. Distributed under the Boost
|
Chris@16
|
8 // Software License, Version 1.0. (See accompanying file
|
Chris@16
|
9 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
10
|
Chris@16
|
11 #ifndef BOOST_XPRESSIVE_TRAITS_NULL_REGEX_TRAITS_HPP_EAN_10_04_2005
|
Chris@16
|
12 #define BOOST_XPRESSIVE_TRAITS_NULL_REGEX_TRAITS_HPP_EAN_10_04_2005
|
Chris@16
|
13
|
Chris@16
|
14 // MS compatible compilers support #pragma once
|
Chris@101
|
15 #if defined(_MSC_VER)
|
Chris@16
|
16 # pragma once
|
Chris@16
|
17 #endif
|
Chris@16
|
18
|
Chris@16
|
19 #include <vector>
|
Chris@16
|
20 #include <boost/assert.hpp>
|
Chris@16
|
21 #include <boost/mpl/assert.hpp>
|
Chris@16
|
22 #include <boost/xpressive/detail/detail_fwd.hpp>
|
Chris@16
|
23 #include <boost/xpressive/detail/utility/never_true.hpp>
|
Chris@16
|
24 #include <boost/xpressive/detail/utility/ignore_unused.hpp>
|
Chris@16
|
25
|
Chris@16
|
26 namespace boost { namespace xpressive
|
Chris@16
|
27 {
|
Chris@16
|
28
|
Chris@16
|
29 namespace detail
|
Chris@16
|
30 {
|
Chris@16
|
31 struct not_a_locale {};
|
Chris@16
|
32 }
|
Chris@16
|
33
|
Chris@16
|
34 struct regex_traits_version_1_tag;
|
Chris@16
|
35
|
Chris@16
|
36 ///////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
37 // null_regex_traits
|
Chris@16
|
38 //
|
Chris@16
|
39 /// \brief stub regex_traits for non-char data
|
Chris@16
|
40 ///
|
Chris@16
|
41 template<typename Elem>
|
Chris@16
|
42 struct null_regex_traits
|
Chris@16
|
43 {
|
Chris@16
|
44 typedef Elem char_type;
|
Chris@16
|
45 typedef std::vector<char_type> string_type;
|
Chris@16
|
46 typedef detail::not_a_locale locale_type;
|
Chris@16
|
47 typedef int char_class_type;
|
Chris@16
|
48 typedef regex_traits_version_1_tag version_tag;
|
Chris@16
|
49
|
Chris@16
|
50 /// Initialize a null_regex_traits object.
|
Chris@16
|
51 ///
|
Chris@16
|
52 null_regex_traits(locale_type = locale_type())
|
Chris@16
|
53 {
|
Chris@16
|
54 }
|
Chris@16
|
55
|
Chris@16
|
56 /// Checks two null_regex_traits objects for equality
|
Chris@16
|
57 ///
|
Chris@16
|
58 /// \return true.
|
Chris@16
|
59 bool operator ==(null_regex_traits<char_type> const &that) const
|
Chris@16
|
60 {
|
Chris@16
|
61 detail::ignore_unused(that);
|
Chris@16
|
62 return true;
|
Chris@16
|
63 }
|
Chris@16
|
64
|
Chris@16
|
65 /// Checks two null_regex_traits objects for inequality
|
Chris@16
|
66 ///
|
Chris@16
|
67 /// \return false.
|
Chris@16
|
68 bool operator !=(null_regex_traits<char_type> const &that) const
|
Chris@16
|
69 {
|
Chris@16
|
70 detail::ignore_unused(that);
|
Chris@16
|
71 return false;
|
Chris@16
|
72 }
|
Chris@16
|
73
|
Chris@16
|
74 /// Convert a char to a Elem
|
Chris@16
|
75 ///
|
Chris@16
|
76 /// \param ch The source character.
|
Chris@16
|
77 /// \return Elem(ch).
|
Chris@16
|
78 char_type widen(char ch) const
|
Chris@16
|
79 {
|
Chris@16
|
80 return char_type(ch);
|
Chris@16
|
81 }
|
Chris@16
|
82
|
Chris@16
|
83 /// Returns a hash value for a Elem in the range [0, UCHAR_MAX]
|
Chris@16
|
84 ///
|
Chris@16
|
85 /// \param ch The source character.
|
Chris@16
|
86 /// \return a value between 0 and UCHAR_MAX, inclusive.
|
Chris@16
|
87 static unsigned char hash(char_type ch)
|
Chris@16
|
88 {
|
Chris@16
|
89 return static_cast<unsigned char>(ch);
|
Chris@16
|
90 }
|
Chris@16
|
91
|
Chris@16
|
92 /// No-op
|
Chris@16
|
93 ///
|
Chris@16
|
94 /// \param ch The source character.
|
Chris@16
|
95 /// \return ch
|
Chris@16
|
96 static char_type translate(char_type ch)
|
Chris@16
|
97 {
|
Chris@16
|
98 return ch;
|
Chris@16
|
99 }
|
Chris@16
|
100
|
Chris@16
|
101 /// No-op
|
Chris@16
|
102 ///
|
Chris@16
|
103 /// \param ch The source character.
|
Chris@16
|
104 /// \return ch
|
Chris@16
|
105 static char_type translate_nocase(char_type ch)
|
Chris@16
|
106 {
|
Chris@16
|
107 return ch;
|
Chris@16
|
108 }
|
Chris@16
|
109
|
Chris@16
|
110 /// Checks to see if a character is within a character range.
|
Chris@16
|
111 ///
|
Chris@16
|
112 /// \param first The bottom of the range, inclusive.
|
Chris@16
|
113 /// \param last The top of the range, inclusive.
|
Chris@16
|
114 /// \param ch The source character.
|
Chris@16
|
115 /// \return first <= ch && ch <= last.
|
Chris@16
|
116 static bool in_range(char_type first, char_type last, char_type ch)
|
Chris@16
|
117 {
|
Chris@16
|
118 return first <= ch && ch <= last;
|
Chris@16
|
119 }
|
Chris@16
|
120
|
Chris@16
|
121 /// Checks to see if a character is within a character range.
|
Chris@16
|
122 ///
|
Chris@16
|
123 /// \param first The bottom of the range, inclusive.
|
Chris@16
|
124 /// \param last The top of the range, inclusive.
|
Chris@16
|
125 /// \param ch The source character.
|
Chris@16
|
126 /// \return first <= ch && ch <= last.
|
Chris@16
|
127 /// \attention Since the null_regex_traits does not do case-folding,
|
Chris@16
|
128 /// this function is equivalent to in_range().
|
Chris@16
|
129 static bool in_range_nocase(char_type first, char_type last, char_type ch)
|
Chris@16
|
130 {
|
Chris@16
|
131 return first <= ch && ch <= last;
|
Chris@16
|
132 }
|
Chris@16
|
133
|
Chris@16
|
134 /// Returns a sort key for the character sequence designated by the iterator range [F1, F2)
|
Chris@16
|
135 /// such that if the character sequence [G1, G2) sorts before the character sequence [H1, H2)
|
Chris@16
|
136 /// then v.transform(G1, G2) < v.transform(H1, H2).
|
Chris@16
|
137 ///
|
Chris@16
|
138 /// \attention Not currently used
|
Chris@16
|
139 template<typename FwdIter>
|
Chris@16
|
140 static string_type transform(FwdIter begin, FwdIter end)
|
Chris@16
|
141 {
|
Chris@16
|
142 return string_type(begin, end);
|
Chris@16
|
143 }
|
Chris@16
|
144
|
Chris@16
|
145 /// Returns a sort key for the character sequence designated by the iterator range [F1, F2)
|
Chris@16
|
146 /// such that if the character sequence [G1, G2) sorts before the character sequence [H1, H2)
|
Chris@16
|
147 /// when character case is not considered then
|
Chris@16
|
148 /// v.transform_primary(G1, G2) < v.transform_primary(H1, H2).
|
Chris@16
|
149 ///
|
Chris@16
|
150 /// \attention Not currently used
|
Chris@16
|
151 template<typename FwdIter>
|
Chris@16
|
152 static string_type transform_primary(FwdIter begin, FwdIter end)
|
Chris@16
|
153 {
|
Chris@16
|
154 return string_type(begin, end);
|
Chris@16
|
155 }
|
Chris@16
|
156
|
Chris@16
|
157 /// Returns a sequence of characters that represents the collating element
|
Chris@16
|
158 /// consisting of the character sequence designated by the iterator range [F1, F2).
|
Chris@16
|
159 /// Returns an empty string if the character sequence is not a valid collating element.
|
Chris@16
|
160 ///
|
Chris@16
|
161 /// \attention Not currently used
|
Chris@16
|
162 template<typename FwdIter>
|
Chris@16
|
163 static string_type lookup_collatename(FwdIter begin, FwdIter end)
|
Chris@16
|
164 {
|
Chris@16
|
165 detail::ignore_unused(begin);
|
Chris@16
|
166 detail::ignore_unused(end);
|
Chris@16
|
167 return string_type();
|
Chris@16
|
168 }
|
Chris@16
|
169
|
Chris@16
|
170 /// The null_regex_traits does not have character classifications, so lookup_classname()
|
Chris@16
|
171 /// is unused.
|
Chris@16
|
172 ///
|
Chris@16
|
173 /// \param begin not used
|
Chris@16
|
174 /// \param end not used
|
Chris@16
|
175 /// \param icase not used
|
Chris@16
|
176 /// \return static_cast\<char_class_type\>(0)
|
Chris@16
|
177 template<typename FwdIter>
|
Chris@16
|
178 static char_class_type lookup_classname(FwdIter begin, FwdIter end, bool icase)
|
Chris@16
|
179 {
|
Chris@16
|
180 detail::ignore_unused(begin);
|
Chris@16
|
181 detail::ignore_unused(end);
|
Chris@16
|
182 detail::ignore_unused(icase);
|
Chris@16
|
183 return 0;
|
Chris@16
|
184 }
|
Chris@16
|
185
|
Chris@16
|
186 /// The null_regex_traits does not have character classifications, so isctype()
|
Chris@16
|
187 /// is unused.
|
Chris@16
|
188 ///
|
Chris@16
|
189 /// \param ch not used
|
Chris@16
|
190 /// \param mask not used
|
Chris@16
|
191 /// \return false
|
Chris@16
|
192 static bool isctype(char_type ch, char_class_type mask)
|
Chris@16
|
193 {
|
Chris@16
|
194 detail::ignore_unused(ch);
|
Chris@16
|
195 detail::ignore_unused(mask);
|
Chris@16
|
196 return false;
|
Chris@16
|
197 }
|
Chris@16
|
198
|
Chris@16
|
199 /// The null_regex_traits recognizes no elements as digits, so value() is unused.
|
Chris@16
|
200 ///
|
Chris@16
|
201 /// \param ch not used
|
Chris@16
|
202 /// \param radix not used
|
Chris@16
|
203 /// \return -1
|
Chris@16
|
204 static int value(char_type ch, int radix)
|
Chris@16
|
205 {
|
Chris@16
|
206 detail::ignore_unused(ch);
|
Chris@16
|
207 detail::ignore_unused(radix);
|
Chris@16
|
208 return -1;
|
Chris@16
|
209 }
|
Chris@16
|
210
|
Chris@16
|
211 /// Not used
|
Chris@16
|
212 ///
|
Chris@16
|
213 /// \param loc not used
|
Chris@16
|
214 /// \return loc
|
Chris@16
|
215 static locale_type imbue(locale_type loc)
|
Chris@16
|
216 {
|
Chris@16
|
217 return loc;
|
Chris@16
|
218 }
|
Chris@16
|
219
|
Chris@16
|
220 /// Returns locale_type().
|
Chris@16
|
221 ///
|
Chris@16
|
222 /// \return locale_type()
|
Chris@16
|
223 static locale_type getloc()
|
Chris@16
|
224 {
|
Chris@16
|
225 return locale_type();
|
Chris@16
|
226 }
|
Chris@16
|
227 };
|
Chris@16
|
228
|
Chris@16
|
229 }}
|
Chris@16
|
230
|
Chris@16
|
231 #endif
|