1 ///////////////////////////////////////////////////////////////////////////////
2 /// \file null_regex_traits.hpp
3 /// Contains the definition of the null_regex_traits\<\> template, which is a
4 /// stub regex traits implementation that can be used by static and dynamic
5 /// regexes for searching non-character data.
7 // Copyright 2008 Eric Niebler. Distributed under the Boost
8 // Software License, Version 1.0. (See accompanying file
9 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
11 #ifndef BOOST_XPRESSIVE_TRAITS_NULL_REGEX_TRAITS_HPP_EAN_10_04_2005
12 #define BOOST_XPRESSIVE_TRAITS_NULL_REGEX_TRAITS_HPP_EAN_10_04_2005
14 // MS compatible compilers support #pragma once
20 #include <boost/assert.hpp>
21 #include <boost/mpl/assert.hpp>
22 #include <boost/xpressive/detail/detail_fwd.hpp>
23 #include <boost/xpressive/detail/utility/never_true.hpp>
24 #include <boost/xpressive/detail/utility/ignore_unused.hpp>
26 namespace boost { namespace xpressive
31 struct not_a_locale {};
34 struct regex_traits_version_1_tag;
36 ///////////////////////////////////////////////////////////////////////////////
39 /// \brief stub regex_traits for non-char data
41 template<typename Elem>
42 struct null_regex_traits
44 typedef Elem char_type;
45 typedef std::vector<char_type> string_type;
46 typedef detail::not_a_locale locale_type;
47 typedef int char_class_type;
48 typedef regex_traits_version_1_tag version_tag;
50 /// Initialize a null_regex_traits object.
52 null_regex_traits(locale_type = locale_type())
56 /// Checks two null_regex_traits objects for equality
59 bool operator ==(null_regex_traits<char_type> const &that) const
61 detail::ignore_unused(that);
65 /// Checks two null_regex_traits objects for inequality
68 bool operator !=(null_regex_traits<char_type> const &that) const
70 detail::ignore_unused(that);
74 /// Convert a char to a Elem
76 /// \param ch The source character.
78 char_type widen(char ch) const
83 /// Returns a hash value for a Elem in the range [0, UCHAR_MAX]
85 /// \param ch The source character.
86 /// \return a value between 0 and UCHAR_MAX, inclusive.
87 static unsigned char hash(char_type ch)
89 return static_cast<unsigned char>(ch);
94 /// \param ch The source character.
96 static char_type translate(char_type ch)
103 /// \param ch The source character.
105 static char_type translate_nocase(char_type ch)
110 /// Checks to see if a character is within a character range.
112 /// \param first The bottom of the range, inclusive.
113 /// \param last The top of the range, inclusive.
114 /// \param ch The source character.
115 /// \return first <= ch && ch <= last.
116 static bool in_range(char_type first, char_type last, char_type ch)
118 return first <= ch && ch <= last;
121 /// Checks to see if a character is within a character range.
123 /// \param first The bottom of the range, inclusive.
124 /// \param last The top of the range, inclusive.
125 /// \param ch The source character.
126 /// \return first <= ch && ch <= last.
127 /// \attention Since the null_regex_traits does not do case-folding,
128 /// this function is equivalent to in_range().
129 static bool in_range_nocase(char_type first, char_type last, char_type ch)
131 return first <= ch && ch <= last;
134 /// Returns a sort key for the character sequence designated by the iterator range [F1, F2)
135 /// such that if the character sequence [G1, G2) sorts before the character sequence [H1, H2)
136 /// then v.transform(G1, G2) < v.transform(H1, H2).
138 /// \attention Not currently used
139 template<typename FwdIter>
140 static string_type transform(FwdIter begin, FwdIter end)
142 return string_type(begin, end);
145 /// Returns a sort key for the character sequence designated by the iterator range [F1, F2)
146 /// such that if the character sequence [G1, G2) sorts before the character sequence [H1, H2)
147 /// when character case is not considered then
148 /// v.transform_primary(G1, G2) < v.transform_primary(H1, H2).
150 /// \attention Not currently used
151 template<typename FwdIter>
152 static string_type transform_primary(FwdIter begin, FwdIter end)
154 return string_type(begin, end);
157 /// Returns a sequence of characters that represents the collating element
158 /// consisting of the character sequence designated by the iterator range [F1, F2).
159 /// Returns an empty string if the character sequence is not a valid collating element.
161 /// \attention Not currently used
162 template<typename FwdIter>
163 static string_type lookup_collatename(FwdIter begin, FwdIter end)
165 detail::ignore_unused(begin);
166 detail::ignore_unused(end);
167 return string_type();
170 /// The null_regex_traits does not have character classifications, so lookup_classname()
173 /// \param begin not used
174 /// \param end not used
175 /// \param icase not used
176 /// \return static_cast\<char_class_type\>(0)
177 template<typename FwdIter>
178 static char_class_type lookup_classname(FwdIter begin, FwdIter end, bool icase)
180 detail::ignore_unused(begin);
181 detail::ignore_unused(end);
182 detail::ignore_unused(icase);
186 /// The null_regex_traits does not have character classifications, so isctype()
189 /// \param ch not used
190 /// \param mask not used
192 static bool isctype(char_type ch, char_class_type mask)
194 detail::ignore_unused(ch);
195 detail::ignore_unused(mask);
199 /// The null_regex_traits recognizes no elements as digits, so value() is unused.
201 /// \param ch not used
202 /// \param radix not used
204 static int value(char_type ch, int radix)
206 detail::ignore_unused(ch);
207 detail::ignore_unused(radix);
213 /// \param loc not used
215 static locale_type imbue(locale_type loc)
220 /// Returns locale_type().
222 /// \return locale_type()
223 static locale_type getloc()
225 return locale_type();