Chris@16: // Boost string_algo library classification.hpp header file ---------------------------// Chris@16: Chris@16: // Copyright Pavol Droba 2002-2003. Chris@16: // Chris@16: // Distributed under the Boost Software License, Version 1.0. Chris@16: // (See accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: // See http://www.boost.org/ for updates, documentation, and revision history. Chris@16: Chris@16: #ifndef BOOST_STRING_CLASSIFICATION_HPP Chris@16: #define BOOST_STRING_CLASSIFICATION_HPP Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: Chris@16: /*! \file Chris@16: Classification predicates are included in the library to give Chris@16: some more convenience when using algorithms like \c trim() and \c all(). Chris@16: They wrap functionality of STL classification functions ( e.g. \c std::isspace() ) Chris@16: into generic functors. Chris@16: */ Chris@16: Chris@16: namespace boost { Chris@16: namespace algorithm { Chris@16: Chris@16: // classification functor generator -------------------------------------// Chris@16: Chris@16: //! is_classified predicate Chris@16: /*! Chris@16: Construct the \c is_classified predicate. This predicate holds if the input is Chris@16: of specified \c std::ctype category. Chris@16: Chris@16: \param Type A \c std::ctype category Chris@16: \param Loc A locale used for classification Chris@16: \return An instance of the \c is_classified predicate Chris@16: */ Chris@16: inline detail::is_classifiedF Chris@16: is_classified(std::ctype_base::mask Type, const std::locale& Loc=std::locale()) Chris@16: { Chris@16: return detail::is_classifiedF(Type, Loc); Chris@16: } Chris@16: Chris@16: //! is_space predicate Chris@16: /*! Chris@16: Construct the \c is_classified predicate for the \c ctype_base::space category. Chris@16: Chris@16: \param Loc A locale used for classification Chris@16: \return An instance of the \c is_classified predicate Chris@16: */ Chris@16: inline detail::is_classifiedF Chris@16: is_space(const std::locale& Loc=std::locale()) Chris@16: { Chris@16: return detail::is_classifiedF(std::ctype_base::space, Loc); Chris@16: } Chris@16: Chris@16: //! is_alnum predicate Chris@16: /*! Chris@16: Construct the \c is_classified predicate for the \c ctype_base::alnum category. Chris@16: Chris@16: \param Loc A locale used for classification Chris@16: \return An instance of the \c is_classified predicate Chris@16: */ Chris@16: inline detail::is_classifiedF Chris@16: is_alnum(const std::locale& Loc=std::locale()) Chris@16: { Chris@16: return detail::is_classifiedF(std::ctype_base::alnum, Loc); Chris@16: } Chris@16: Chris@16: //! is_alpha predicate Chris@16: /*! Chris@16: Construct the \c is_classified predicate for the \c ctype_base::alpha category. Chris@16: Chris@16: \param Loc A locale used for classification Chris@16: \return An instance of the \c is_classified predicate Chris@16: */ Chris@16: inline detail::is_classifiedF Chris@16: is_alpha(const std::locale& Loc=std::locale()) Chris@16: { Chris@16: return detail::is_classifiedF(std::ctype_base::alpha, Loc); Chris@16: } Chris@16: Chris@16: //! is_cntrl predicate Chris@16: /*! Chris@16: Construct the \c is_classified predicate for the \c ctype_base::cntrl category. Chris@16: Chris@16: \param Loc A locale used for classification Chris@16: \return An instance of the \c is_classified predicate Chris@16: */ Chris@16: inline detail::is_classifiedF Chris@16: is_cntrl(const std::locale& Loc=std::locale()) Chris@16: { Chris@16: return detail::is_classifiedF(std::ctype_base::cntrl, Loc); Chris@16: } Chris@16: Chris@16: //! is_digit predicate Chris@16: /*! Chris@16: Construct the \c is_classified predicate for the \c ctype_base::digit category. Chris@16: Chris@16: \param Loc A locale used for classification Chris@16: \return An instance of the \c is_classified predicate Chris@16: */ Chris@16: inline detail::is_classifiedF Chris@16: is_digit(const std::locale& Loc=std::locale()) Chris@16: { Chris@16: return detail::is_classifiedF(std::ctype_base::digit, Loc); Chris@16: } Chris@16: Chris@16: //! is_graph predicate Chris@16: /*! Chris@16: Construct the \c is_classified predicate for the \c ctype_base::graph category. Chris@16: Chris@16: \param Loc A locale used for classification Chris@16: \return An instance of the \c is_classified predicate Chris@16: */ Chris@16: inline detail::is_classifiedF Chris@16: is_graph(const std::locale& Loc=std::locale()) Chris@16: { Chris@16: return detail::is_classifiedF(std::ctype_base::graph, Loc); Chris@16: } Chris@16: Chris@16: //! is_lower predicate Chris@16: /*! Chris@16: Construct the \c is_classified predicate for the \c ctype_base::lower category. Chris@16: Chris@16: \param Loc A locale used for classification Chris@16: \return An instance of \c is_classified predicate Chris@16: */ Chris@16: inline detail::is_classifiedF Chris@16: is_lower(const std::locale& Loc=std::locale()) Chris@16: { Chris@16: return detail::is_classifiedF(std::ctype_base::lower, Loc); Chris@16: } Chris@16: Chris@16: //! is_print predicate Chris@16: /*! Chris@16: Construct the \c is_classified predicate for the \c ctype_base::print category. Chris@16: Chris@16: \param Loc A locale used for classification Chris@16: \return An instance of the \c is_classified predicate Chris@16: */ Chris@16: inline detail::is_classifiedF Chris@16: is_print(const std::locale& Loc=std::locale()) Chris@16: { Chris@16: return detail::is_classifiedF(std::ctype_base::print, Loc); Chris@16: } Chris@16: Chris@16: //! is_punct predicate Chris@16: /*! Chris@16: Construct the \c is_classified predicate for the \c ctype_base::punct category. Chris@16: Chris@16: \param Loc A locale used for classification Chris@16: \return An instance of the \c is_classified predicate Chris@16: */ Chris@16: inline detail::is_classifiedF Chris@16: is_punct(const std::locale& Loc=std::locale()) Chris@16: { Chris@16: return detail::is_classifiedF(std::ctype_base::punct, Loc); Chris@16: } Chris@16: Chris@16: //! is_upper predicate Chris@16: /*! Chris@16: Construct the \c is_classified predicate for the \c ctype_base::upper category. Chris@16: Chris@16: \param Loc A locale used for classification Chris@16: \return An instance of the \c is_classified predicate Chris@16: */ Chris@16: inline detail::is_classifiedF Chris@16: is_upper(const std::locale& Loc=std::locale()) Chris@16: { Chris@16: return detail::is_classifiedF(std::ctype_base::upper, Loc); Chris@16: } Chris@16: Chris@16: //! is_xdigit predicate Chris@16: /*! Chris@16: Construct the \c is_classified predicate for the \c ctype_base::xdigit category. Chris@16: Chris@16: \param Loc A locale used for classification Chris@16: \return An instance of the \c is_classified predicate Chris@16: */ Chris@16: inline detail::is_classifiedF Chris@16: is_xdigit(const std::locale& Loc=std::locale()) Chris@16: { Chris@16: return detail::is_classifiedF(std::ctype_base::xdigit, Loc); Chris@16: } Chris@16: Chris@16: //! is_any_of predicate Chris@16: /*! Chris@16: Construct the \c is_any_of predicate. The predicate holds if the input Chris@16: is included in the specified set of characters. Chris@16: Chris@16: \param Set A set of characters to be recognized Chris@16: \return An instance of the \c is_any_of predicate Chris@16: */ Chris@16: template Chris@16: inline detail::is_any_ofF< Chris@16: BOOST_STRING_TYPENAME range_value::type> Chris@16: is_any_of( const RangeT& Set ) Chris@16: { Chris@16: iterator_range::type> lit_set(boost::as_literal(Set)); Chris@16: return detail::is_any_ofF::type>(lit_set); Chris@16: } Chris@16: Chris@16: //! is_from_range predicate Chris@16: /*! Chris@16: Construct the \c is_from_range predicate. The predicate holds if the input Chris@16: is included in the specified range. (i.e. From <= Ch <= To ) Chris@16: Chris@16: \param From The start of the range Chris@16: \param To The end of the range Chris@16: \return An instance of the \c is_from_range predicate Chris@16: */ Chris@16: template Chris@16: inline detail::is_from_rangeF is_from_range(CharT From, CharT To) Chris@16: { Chris@16: return detail::is_from_rangeF(From,To); Chris@16: } Chris@16: Chris@16: // predicate combinators ---------------------------------------------------// Chris@16: Chris@16: //! predicate 'and' composition predicate Chris@16: /*! Chris@16: Construct the \c class_and predicate. This predicate can be used Chris@16: to logically combine two classification predicates. \c class_and holds, Chris@16: if both predicates return true. Chris@16: Chris@16: \param Pred1 The first predicate Chris@16: \param Pred2 The second predicate Chris@16: \return An instance of the \c class_and predicate Chris@16: */ Chris@16: template Chris@16: inline detail::pred_andF Chris@16: operator&&( Chris@16: const predicate_facade& Pred1, Chris@16: const predicate_facade& Pred2 ) Chris@16: { Chris@16: // Doing the static_cast with the pointer instead of the reference Chris@16: // is a workaround for some compilers which have problems with Chris@16: // static_cast's of template references, i.e. CW8. /grafik/ Chris@16: return detail::pred_andF( Chris@16: *static_cast(&Pred1), Chris@16: *static_cast(&Pred2) ); Chris@16: } Chris@16: Chris@16: //! predicate 'or' composition predicate Chris@16: /*! Chris@16: Construct the \c class_or predicate. This predicate can be used Chris@16: to logically combine two classification predicates. \c class_or holds, Chris@16: if one of the predicates return true. Chris@16: Chris@16: \param Pred1 The first predicate Chris@16: \param Pred2 The second predicate Chris@16: \return An instance of the \c class_or predicate Chris@16: */ Chris@16: template Chris@16: inline detail::pred_orF Chris@16: operator||( Chris@16: const predicate_facade& Pred1, Chris@16: const predicate_facade& Pred2 ) Chris@16: { Chris@16: // Doing the static_cast with the pointer instead of the reference Chris@16: // is a workaround for some compilers which have problems with Chris@16: // static_cast's of template references, i.e. CW8. /grafik/ Chris@16: return detail::pred_orF( Chris@16: *static_cast(&Pred1), Chris@16: *static_cast(&Pred2)); Chris@16: } Chris@16: Chris@16: //! predicate negation operator Chris@16: /*! Chris@16: Construct the \c class_not predicate. This predicate represents a negation. Chris@16: \c class_or holds if of the predicates return false. Chris@16: Chris@16: \param Pred The predicate to be negated Chris@16: \return An instance of the \c class_not predicate Chris@16: */ Chris@16: template Chris@16: inline detail::pred_notF Chris@16: operator!( const predicate_facade& Pred ) Chris@16: { Chris@16: // Doing the static_cast with the pointer instead of the reference Chris@16: // is a workaround for some compilers which have problems with Chris@16: // static_cast's of template references, i.e. CW8. /grafik/ Chris@16: return detail::pred_notF(*static_cast(&Pred)); Chris@16: } Chris@16: Chris@16: } // namespace algorithm Chris@16: Chris@16: // pull names to the boost namespace Chris@16: using algorithm::is_classified; Chris@16: using algorithm::is_space; Chris@16: using algorithm::is_alnum; Chris@16: using algorithm::is_alpha; Chris@16: using algorithm::is_cntrl; Chris@16: using algorithm::is_digit; Chris@16: using algorithm::is_graph; Chris@16: using algorithm::is_lower; Chris@16: using algorithm::is_upper; Chris@16: using algorithm::is_print; Chris@16: using algorithm::is_punct; Chris@16: using algorithm::is_xdigit; Chris@16: using algorithm::is_any_of; Chris@16: using algorithm::is_from_range; Chris@16: Chris@16: } // namespace boost Chris@16: Chris@16: #endif // BOOST_STRING_PREDICATE_HPP