Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: /// \file null_regex_traits.hpp Chris@16: /// Contains the definition of the null_regex_traits\<\> template, which is a Chris@16: /// stub regex traits implementation that can be used by static and dynamic Chris@16: /// regexes for searching non-character data. Chris@16: // Chris@16: // Copyright 2008 Eric Niebler. Distributed under the Boost Chris@16: // Software License, Version 1.0. (See accompanying file Chris@16: // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: #ifndef BOOST_XPRESSIVE_TRAITS_NULL_REGEX_TRAITS_HPP_EAN_10_04_2005 Chris@16: #define BOOST_XPRESSIVE_TRAITS_NULL_REGEX_TRAITS_HPP_EAN_10_04_2005 Chris@16: Chris@16: // MS compatible compilers support #pragma once Chris@101: #if defined(_MSC_VER) Chris@16: # pragma once Chris@16: #endif Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost { namespace xpressive Chris@16: { Chris@16: Chris@16: namespace detail Chris@16: { Chris@16: struct not_a_locale {}; Chris@16: } Chris@16: Chris@16: struct regex_traits_version_1_tag; Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // null_regex_traits Chris@16: // Chris@16: /// \brief stub regex_traits for non-char data Chris@16: /// Chris@16: template Chris@16: struct null_regex_traits Chris@16: { Chris@16: typedef Elem char_type; Chris@16: typedef std::vector string_type; Chris@16: typedef detail::not_a_locale locale_type; Chris@16: typedef int char_class_type; Chris@16: typedef regex_traits_version_1_tag version_tag; Chris@16: Chris@16: /// Initialize a null_regex_traits object. Chris@16: /// Chris@16: null_regex_traits(locale_type = locale_type()) Chris@16: { Chris@16: } Chris@16: Chris@16: /// Checks two null_regex_traits objects for equality Chris@16: /// Chris@16: /// \return true. Chris@16: bool operator ==(null_regex_traits const &that) const Chris@16: { Chris@16: detail::ignore_unused(that); Chris@16: return true; Chris@16: } Chris@16: Chris@16: /// Checks two null_regex_traits objects for inequality Chris@16: /// Chris@16: /// \return false. Chris@16: bool operator !=(null_regex_traits const &that) const Chris@16: { Chris@16: detail::ignore_unused(that); Chris@16: return false; Chris@16: } Chris@16: Chris@16: /// Convert a char to a Elem Chris@16: /// Chris@16: /// \param ch The source character. Chris@16: /// \return Elem(ch). Chris@16: char_type widen(char ch) const Chris@16: { Chris@16: return char_type(ch); Chris@16: } Chris@16: Chris@16: /// Returns a hash value for a Elem in the range [0, UCHAR_MAX] Chris@16: /// Chris@16: /// \param ch The source character. Chris@16: /// \return a value between 0 and UCHAR_MAX, inclusive. Chris@16: static unsigned char hash(char_type ch) Chris@16: { Chris@16: return static_cast(ch); Chris@16: } Chris@16: Chris@16: /// No-op Chris@16: /// Chris@16: /// \param ch The source character. Chris@16: /// \return ch Chris@16: static char_type translate(char_type ch) Chris@16: { Chris@16: return ch; Chris@16: } Chris@16: Chris@16: /// No-op Chris@16: /// Chris@16: /// \param ch The source character. Chris@16: /// \return ch Chris@16: static char_type translate_nocase(char_type ch) Chris@16: { Chris@16: return ch; Chris@16: } Chris@16: Chris@16: /// Checks to see if a character is within a character range. Chris@16: /// Chris@16: /// \param first The bottom of the range, inclusive. Chris@16: /// \param last The top of the range, inclusive. Chris@16: /// \param ch The source character. Chris@16: /// \return first <= ch && ch <= last. Chris@16: static bool in_range(char_type first, char_type last, char_type ch) Chris@16: { Chris@16: return first <= ch && ch <= last; Chris@16: } Chris@16: Chris@16: /// Checks to see if a character is within a character range. Chris@16: /// Chris@16: /// \param first The bottom of the range, inclusive. Chris@16: /// \param last The top of the range, inclusive. Chris@16: /// \param ch The source character. Chris@16: /// \return first <= ch && ch <= last. Chris@16: /// \attention Since the null_regex_traits does not do case-folding, Chris@16: /// this function is equivalent to in_range(). Chris@16: static bool in_range_nocase(char_type first, char_type last, char_type ch) Chris@16: { Chris@16: return first <= ch && ch <= last; Chris@16: } Chris@16: Chris@16: /// Returns a sort key for the character sequence designated by the iterator range [F1, F2) Chris@16: /// such that if the character sequence [G1, G2) sorts before the character sequence [H1, H2) Chris@16: /// then v.transform(G1, G2) < v.transform(H1, H2). Chris@16: /// Chris@16: /// \attention Not currently used Chris@16: template Chris@16: static string_type transform(FwdIter begin, FwdIter end) Chris@16: { Chris@16: return string_type(begin, end); Chris@16: } Chris@16: Chris@16: /// Returns a sort key for the character sequence designated by the iterator range [F1, F2) Chris@16: /// such that if the character sequence [G1, G2) sorts before the character sequence [H1, H2) Chris@16: /// when character case is not considered then Chris@16: /// v.transform_primary(G1, G2) < v.transform_primary(H1, H2). Chris@16: /// Chris@16: /// \attention Not currently used Chris@16: template Chris@16: static string_type transform_primary(FwdIter begin, FwdIter end) Chris@16: { Chris@16: return string_type(begin, end); Chris@16: } Chris@16: Chris@16: /// Returns a sequence of characters that represents the collating element Chris@16: /// consisting of the character sequence designated by the iterator range [F1, F2). Chris@16: /// Returns an empty string if the character sequence is not a valid collating element. Chris@16: /// Chris@16: /// \attention Not currently used Chris@16: template Chris@16: static string_type lookup_collatename(FwdIter begin, FwdIter end) Chris@16: { Chris@16: detail::ignore_unused(begin); Chris@16: detail::ignore_unused(end); Chris@16: return string_type(); Chris@16: } Chris@16: Chris@16: /// The null_regex_traits does not have character classifications, so lookup_classname() Chris@16: /// is unused. Chris@16: /// Chris@16: /// \param begin not used Chris@16: /// \param end not used Chris@16: /// \param icase not used Chris@16: /// \return static_cast\(0) Chris@16: template Chris@16: static char_class_type lookup_classname(FwdIter begin, FwdIter end, bool icase) Chris@16: { Chris@16: detail::ignore_unused(begin); Chris@16: detail::ignore_unused(end); Chris@16: detail::ignore_unused(icase); Chris@16: return 0; Chris@16: } Chris@16: Chris@16: /// The null_regex_traits does not have character classifications, so isctype() Chris@16: /// is unused. Chris@16: /// Chris@16: /// \param ch not used Chris@16: /// \param mask not used Chris@16: /// \return false Chris@16: static bool isctype(char_type ch, char_class_type mask) Chris@16: { Chris@16: detail::ignore_unused(ch); Chris@16: detail::ignore_unused(mask); Chris@16: return false; Chris@16: } Chris@16: Chris@16: /// The null_regex_traits recognizes no elements as digits, so value() is unused. Chris@16: /// Chris@16: /// \param ch not used Chris@16: /// \param radix not used Chris@16: /// \return -1 Chris@16: static int value(char_type ch, int radix) Chris@16: { Chris@16: detail::ignore_unused(ch); Chris@16: detail::ignore_unused(radix); Chris@16: return -1; Chris@16: } Chris@16: Chris@16: /// Not used Chris@16: /// Chris@16: /// \param loc not used Chris@16: /// \return loc Chris@16: static locale_type imbue(locale_type loc) Chris@16: { Chris@16: return loc; Chris@16: } Chris@16: Chris@16: /// Returns locale_type(). Chris@16: /// Chris@16: /// \return locale_type() Chris@16: static locale_type getloc() Chris@16: { Chris@16: return locale_type(); Chris@16: } Chris@16: }; Chris@16: Chris@16: }} Chris@16: Chris@16: #endif