Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-22 09:55:53

0001 //  Boost string_algo library classification.hpp header file  ---------------------------//
0002 
0003 //  Copyright Pavol Droba 2002-2003.
0004 //
0005 // Distributed under the Boost Software License, Version 1.0.
0006 //    (See accompanying file LICENSE_1_0.txt or copy at
0007 //          http://www.boost.org/LICENSE_1_0.txt)
0008 
0009 //  See http://www.boost.org/ for updates, documentation, and revision history.
0010 
0011 #ifndef BOOST_STRING_CLASSIFICATION_HPP
0012 #define BOOST_STRING_CLASSIFICATION_HPP
0013 
0014 #include <algorithm>
0015 #include <locale>
0016 #include <boost/range/value_type.hpp>
0017 #include <boost/range/as_literal.hpp>
0018 #include <boost/algorithm/string/detail/classification.hpp>
0019 #include <boost/algorithm/string/predicate_facade.hpp>
0020 
0021 
0022 /*! \file
0023     Classification predicates are included in the library to give 
0024     some more convenience when using algorithms like \c trim() and \c all(). 
0025     They wrap functionality of STL classification functions ( e.g. \c std::isspace() )
0026     into generic functors. 
0027 */
0028 
0029 namespace boost {
0030     namespace algorithm {
0031 
0032 //  classification functor generator -------------------------------------//
0033 
0034         //! is_classified predicate
0035         /*!
0036             Construct the \c is_classified predicate. This predicate holds if the input is
0037             of specified \c std::ctype category.
0038 
0039             \param Type A \c std::ctype category
0040             \param Loc A locale used for classification
0041             \return An instance of the \c is_classified predicate 
0042         */
0043         inline detail::is_classifiedF
0044         is_classified(std::ctype_base::mask Type, const std::locale& Loc=std::locale())
0045         {
0046             return detail::is_classifiedF(Type, Loc);
0047         }
0048 
0049         //! is_space predicate
0050         /*!
0051             Construct the \c is_classified predicate for the \c ctype_base::space category.   
0052 
0053             \param Loc A locale used for classification
0054             \return An instance of the \c is_classified predicate
0055         */
0056         inline detail::is_classifiedF 
0057         is_space(const std::locale& Loc=std::locale())
0058         {
0059             return detail::is_classifiedF(std::ctype_base::space, Loc);
0060         }
0061 
0062         //! is_alnum predicate
0063         /*!
0064             Construct the \c is_classified predicate for the \c ctype_base::alnum category.   
0065 
0066             \param Loc A locale used for classification
0067             \return An instance of the \c is_classified predicate 
0068         */
0069         inline detail::is_classifiedF 
0070         is_alnum(const std::locale& Loc=std::locale())
0071         {
0072             return detail::is_classifiedF(std::ctype_base::alnum, Loc);
0073         }
0074 
0075         //! is_alpha predicate
0076         /*!
0077             Construct the \c is_classified predicate for the \c ctype_base::alpha category.   
0078 
0079             \param Loc A locale used for classification
0080             \return An instance of the \c is_classified predicate 
0081         */
0082         inline detail::is_classifiedF 
0083         is_alpha(const std::locale& Loc=std::locale())
0084         {
0085             return detail::is_classifiedF(std::ctype_base::alpha, Loc);
0086         }
0087 
0088         //! is_cntrl predicate
0089         /*!
0090             Construct the \c is_classified predicate for the \c ctype_base::cntrl category.   
0091 
0092             \param Loc A locale used for classification
0093             \return An instance of the \c is_classified predicate 
0094         */
0095         inline detail::is_classifiedF 
0096         is_cntrl(const std::locale& Loc=std::locale())
0097         {
0098             return detail::is_classifiedF(std::ctype_base::cntrl, Loc);
0099         }
0100 
0101         //! is_digit predicate
0102         /*!
0103             Construct the \c is_classified predicate for the \c ctype_base::digit category.   
0104 
0105             \param Loc A locale used for classification
0106             \return An instance of the \c is_classified predicate 
0107         */
0108         inline detail::is_classifiedF 
0109         is_digit(const std::locale& Loc=std::locale())
0110         {
0111             return detail::is_classifiedF(std::ctype_base::digit, Loc);
0112         }
0113 
0114         //! is_graph predicate
0115         /*!
0116             Construct the \c is_classified predicate for the \c ctype_base::graph category.   
0117 
0118             \param Loc A locale used for classification
0119             \return An instance of the \c is_classified predicate 
0120         */
0121         inline detail::is_classifiedF
0122         is_graph(const std::locale& Loc=std::locale())
0123         {
0124             return detail::is_classifiedF(std::ctype_base::graph, Loc);
0125         }
0126 
0127         //! is_lower predicate
0128         /*!
0129             Construct the \c is_classified predicate for the \c ctype_base::lower category.   
0130 
0131             \param Loc A locale used for classification
0132             \return An instance of \c is_classified predicate 
0133         */
0134         inline detail::is_classifiedF 
0135         is_lower(const std::locale& Loc=std::locale())
0136         {
0137             return detail::is_classifiedF(std::ctype_base::lower, Loc);
0138         }
0139 
0140         //! is_print predicate
0141         /*!
0142             Construct the \c is_classified predicate for the \c ctype_base::print category.   
0143 
0144             \param Loc A locale used for classification
0145             \return An instance of the \c is_classified predicate 
0146         */
0147         inline detail::is_classifiedF 
0148         is_print(const std::locale& Loc=std::locale())
0149         {
0150             return detail::is_classifiedF(std::ctype_base::print, Loc);
0151         }
0152 
0153         //! is_punct predicate
0154         /*!
0155             Construct the \c is_classified predicate for the \c ctype_base::punct category.   
0156 
0157             \param Loc A locale used for classification
0158             \return An instance of the \c is_classified predicate 
0159         */
0160         inline detail::is_classifiedF 
0161         is_punct(const std::locale& Loc=std::locale())
0162         {
0163             return detail::is_classifiedF(std::ctype_base::punct, Loc);
0164         }
0165 
0166         //! is_upper predicate
0167         /*!
0168             Construct the \c is_classified predicate for the \c ctype_base::upper category.   
0169 
0170             \param Loc A locale used for classification
0171             \return An instance of the \c is_classified predicate 
0172         */
0173         inline detail::is_classifiedF 
0174         is_upper(const std::locale& Loc=std::locale())
0175         {
0176             return detail::is_classifiedF(std::ctype_base::upper, Loc);
0177         }
0178 
0179         //! is_xdigit predicate
0180         /*!
0181             Construct the \c is_classified predicate for the \c ctype_base::xdigit category.  
0182 
0183             \param Loc A locale used for classification
0184             \return An instance of the \c is_classified predicate 
0185         */
0186         inline detail::is_classifiedF 
0187         is_xdigit(const std::locale& Loc=std::locale())
0188         {
0189             return detail::is_classifiedF(std::ctype_base::xdigit, Loc);
0190         }
0191 
0192         //! is_any_of predicate
0193         /*!
0194             Construct the \c is_any_of predicate. The predicate holds if the input
0195             is included in the specified set of characters.
0196 
0197             \param Set A set of characters to be recognized
0198             \return An instance of the \c is_any_of predicate 
0199         */
0200         template<typename RangeT>
0201         inline detail::is_any_ofF<
0202             BOOST_STRING_TYPENAME range_value<RangeT>::type> 
0203         is_any_of( const RangeT& Set )
0204         {
0205             iterator_range<BOOST_STRING_TYPENAME range_const_iterator<RangeT>::type> lit_set(boost::as_literal(Set));
0206             return detail::is_any_ofF<BOOST_STRING_TYPENAME range_value<RangeT>::type>(lit_set); 
0207         }
0208 
0209         //! is_from_range predicate
0210         /*!
0211             Construct the \c is_from_range predicate. The predicate holds if the input
0212             is included in the specified range. (i.e. From <= Ch <= To )
0213 
0214             \param From The start of the range
0215             \param To The end of the range
0216             \return An instance of the \c is_from_range predicate 
0217         */
0218         template<typename CharT>
0219         inline detail::is_from_rangeF<CharT> is_from_range(CharT From, CharT To)
0220         {
0221             return detail::is_from_rangeF<CharT>(From,To); 
0222         }
0223         
0224         // predicate combinators ---------------------------------------------------//
0225 
0226         //! predicate 'and' composition predicate
0227         /*!
0228             Construct the \c class_and predicate. This predicate can be used
0229             to logically combine two classification predicates. \c class_and holds,
0230             if both predicates return true.
0231 
0232             \param Pred1 The first predicate
0233             \param Pred2 The second predicate
0234             \return An instance of the \c class_and predicate     
0235         */
0236         template<typename Pred1T, typename Pred2T>
0237         inline detail::pred_andF<Pred1T, Pred2T>
0238         operator&&( 
0239             const predicate_facade<Pred1T>& Pred1, 
0240             const predicate_facade<Pred2T>& Pred2 )
0241         {    
0242             // Doing the static_cast with the pointer instead of the reference
0243             // is a workaround for some compilers which have problems with
0244             // static_cast's of template references, i.e. CW8. /grafik/
0245             return detail::pred_andF<Pred1T,Pred2T>(
0246                 *static_cast<const Pred1T*>(&Pred1), 
0247                 *static_cast<const Pred2T*>(&Pred2) );
0248         }
0249 
0250         //! predicate 'or' composition predicate
0251         /*!
0252             Construct the \c class_or predicate. This predicate can be used
0253             to logically combine two classification predicates. \c class_or holds,
0254             if one of the predicates return true.
0255 
0256             \param Pred1 The first predicate
0257             \param Pred2 The second predicate
0258             \return An instance of the \c class_or predicate     
0259         */
0260         template<typename Pred1T, typename Pred2T>
0261         inline detail::pred_orF<Pred1T, Pred2T>
0262         operator||( 
0263             const predicate_facade<Pred1T>& Pred1, 
0264             const predicate_facade<Pred2T>& Pred2 )
0265         {    
0266             // Doing the static_cast with the pointer instead of the reference
0267             // is a workaround for some compilers which have problems with
0268             // static_cast's of template references, i.e. CW8. /grafik/
0269             return detail::pred_orF<Pred1T,Pred2T>(
0270                 *static_cast<const Pred1T*>(&Pred1), 
0271                 *static_cast<const Pred2T*>(&Pred2));
0272         }
0273 
0274         //! predicate negation operator
0275         /*!
0276             Construct the \c class_not predicate. This predicate represents a negation. 
0277             \c class_or holds if of the predicates return false.
0278 
0279             \param Pred The predicate to be negated
0280             \return An instance of the \c class_not predicate     
0281         */
0282         template<typename PredT>
0283         inline detail::pred_notF<PredT>
0284         operator!( const predicate_facade<PredT>& Pred )
0285         {
0286             // Doing the static_cast with the pointer instead of the reference
0287             // is a workaround for some compilers which have problems with
0288             // static_cast's of template references, i.e. CW8. /grafik/
0289             return detail::pred_notF<PredT>(*static_cast<const PredT*>(&Pred)); 
0290         }
0291 
0292     } // namespace algorithm
0293 
0294     // pull names to the boost namespace
0295     using algorithm::is_classified;
0296     using algorithm::is_space;
0297     using algorithm::is_alnum;
0298     using algorithm::is_alpha;
0299     using algorithm::is_cntrl;
0300     using algorithm::is_digit;
0301     using algorithm::is_graph;
0302     using algorithm::is_lower;
0303     using algorithm::is_upper;
0304     using algorithm::is_print;
0305     using algorithm::is_punct;
0306     using algorithm::is_xdigit;
0307     using algorithm::is_any_of;
0308     using algorithm::is_from_range;
0309 
0310 } // namespace boost
0311 
0312 #endif  // BOOST_STRING_PREDICATE_HPP