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