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