![]() |
|
|||
File indexing completed on 2025-02-22 09:55:54
0001 // Boost string_algo library find.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_FIND_HPP 0012 #define BOOST_STRING_FIND_HPP 0013 0014 #include <boost/algorithm/string/config.hpp> 0015 0016 #include <boost/range/iterator_range_core.hpp> 0017 #include <boost/range/begin.hpp> 0018 #include <boost/range/end.hpp> 0019 #include <boost/range/iterator.hpp> 0020 #include <boost/range/as_literal.hpp> 0021 0022 #include <boost/algorithm/string/finder.hpp> 0023 #include <boost/algorithm/string/compare.hpp> 0024 #include <boost/algorithm/string/constants.hpp> 0025 0026 /*! \file 0027 Defines a set of find algorithms. The algorithms are searching 0028 for a substring of the input. The result is given as an \c iterator_range 0029 delimiting the substring. 0030 */ 0031 0032 namespace boost { 0033 namespace algorithm { 0034 0035 // Generic find -----------------------------------------------// 0036 0037 //! Generic find algorithm 0038 /*! 0039 Search the input using the given finder. 0040 0041 \param Input A string which will be searched. 0042 \param Finder Finder object used for searching. 0043 \return 0044 An \c iterator_range delimiting the match. 0045 Returned iterator is either \c RangeT::iterator or 0046 \c RangeT::const_iterator, depending on the constness of 0047 the input parameter. 0048 */ 0049 template<typename RangeT, typename FinderT> 0050 inline iterator_range< 0051 BOOST_STRING_TYPENAME range_iterator<RangeT>::type> 0052 find( 0053 RangeT& Input, 0054 const FinderT& Finder) 0055 { 0056 iterator_range<BOOST_STRING_TYPENAME range_iterator<RangeT>::type> lit_input(::boost::as_literal(Input)); 0057 0058 return Finder(::boost::begin(lit_input),::boost::end(lit_input)); 0059 } 0060 0061 // find_first -----------------------------------------------// 0062 0063 //! Find first algorithm 0064 /*! 0065 Search for the first occurrence of the substring in the input. 0066 0067 \param Input A string which will be searched. 0068 \param Search A substring to be searched for. 0069 \return 0070 An \c iterator_range delimiting the match. 0071 Returned iterator is either \c RangeT::iterator or 0072 \c RangeT::const_iterator, depending on the constness of 0073 the input parameter. 0074 0075 \note This function provides the strong exception-safety guarantee 0076 */ 0077 template<typename Range1T, typename Range2T> 0078 inline iterator_range< 0079 BOOST_STRING_TYPENAME range_iterator<Range1T>::type> 0080 find_first( 0081 Range1T& Input, 0082 const Range2T& Search) 0083 { 0084 return ::boost::algorithm::find(Input, ::boost::algorithm::first_finder(Search)); 0085 } 0086 0087 //! Find first algorithm ( case insensitive ) 0088 /*! 0089 Search for the first occurrence of the substring in the input. 0090 Searching is case insensitive. 0091 0092 \param Input A string which will be searched. 0093 \param Search A substring to be searched for. 0094 \param Loc A locale used for case insensitive comparison 0095 \return 0096 An \c iterator_range delimiting the match. 0097 Returned iterator is either \c Range1T::iterator or 0098 \c Range1T::const_iterator, depending on the constness of 0099 the input parameter. 0100 0101 \note This function provides the strong exception-safety guarantee 0102 */ 0103 template<typename Range1T, typename Range2T> 0104 inline iterator_range< 0105 BOOST_STRING_TYPENAME range_iterator<Range1T>::type> 0106 ifind_first( 0107 Range1T& Input, 0108 const Range2T& Search, 0109 const std::locale& Loc=std::locale()) 0110 { 0111 return ::boost::algorithm::find(Input, ::boost::algorithm::first_finder(Search,is_iequal(Loc))); 0112 } 0113 0114 // find_last -----------------------------------------------// 0115 0116 //! Find last algorithm 0117 /*! 0118 Search for the last occurrence of the substring in the input. 0119 0120 \param Input A string which will be searched. 0121 \param Search A substring to be searched for. 0122 \return 0123 An \c iterator_range delimiting the match. 0124 Returned iterator is either \c Range1T::iterator or 0125 \c Range1T::const_iterator, depending on the constness of 0126 the input parameter. 0127 0128 \note This function provides the strong exception-safety guarantee 0129 */ 0130 template<typename Range1T, typename Range2T> 0131 inline iterator_range< 0132 BOOST_STRING_TYPENAME range_iterator<Range1T>::type> 0133 find_last( 0134 Range1T& Input, 0135 const Range2T& Search) 0136 { 0137 return ::boost::algorithm::find(Input, ::boost::algorithm::last_finder(Search)); 0138 } 0139 0140 //! Find last algorithm ( case insensitive ) 0141 /*! 0142 Search for the last match a string in the input. 0143 Searching is case insensitive. 0144 0145 \param Input A string which will be searched. 0146 \param Search A substring to be searched for. 0147 \param Loc A locale used for case insensitive comparison 0148 \return 0149 An \c iterator_range delimiting the match. 0150 Returned iterator is either \c Range1T::iterator or 0151 \c Range1T::const_iterator, depending on the constness of 0152 the input parameter. 0153 0154 \note This function provides the strong exception-safety guarantee 0155 */ 0156 template<typename Range1T, typename Range2T> 0157 inline iterator_range< 0158 BOOST_STRING_TYPENAME range_iterator<Range1T>::type> 0159 ifind_last( 0160 Range1T& Input, 0161 const Range2T& Search, 0162 const std::locale& Loc=std::locale()) 0163 { 0164 return ::boost::algorithm::find(Input, ::boost::algorithm::last_finder(Search, is_iequal(Loc))); 0165 } 0166 0167 // find_nth ----------------------------------------------------------------------// 0168 0169 //! Find n-th algorithm 0170 /*! 0171 Search for the n-th (zero-indexed) occurrence of the substring in the 0172 input. 0173 0174 \param Input A string which will be searched. 0175 \param Search A substring to be searched for. 0176 \param Nth An index (zero-indexed) of the match to be found. 0177 For negative N, the matches are counted from the end of string. 0178 \return 0179 An \c iterator_range delimiting the match. 0180 Returned iterator is either \c Range1T::iterator or 0181 \c Range1T::const_iterator, depending on the constness of 0182 the input parameter. 0183 */ 0184 template<typename Range1T, typename Range2T> 0185 inline iterator_range< 0186 BOOST_STRING_TYPENAME range_iterator<Range1T>::type> 0187 find_nth( 0188 Range1T& Input, 0189 const Range2T& Search, 0190 int Nth) 0191 { 0192 return ::boost::algorithm::find(Input, ::boost::algorithm::nth_finder(Search,Nth)); 0193 } 0194 0195 //! Find n-th algorithm ( case insensitive ). 0196 /*! 0197 Search for the n-th (zero-indexed) occurrence of the substring in the 0198 input. Searching is case insensitive. 0199 0200 \param Input A string which will be searched. 0201 \param Search A substring to be searched for. 0202 \param Nth An index (zero-indexed) of the match to be found. 0203 For negative N, the matches are counted from the end of string. 0204 \param Loc A locale used for case insensitive comparison 0205 \return 0206 An \c iterator_range delimiting the match. 0207 Returned iterator is either \c Range1T::iterator or 0208 \c Range1T::const_iterator, depending on the constness of 0209 the input parameter. 0210 0211 0212 \note This function provides the strong exception-safety guarantee 0213 */ 0214 template<typename Range1T, typename Range2T> 0215 inline iterator_range< 0216 BOOST_STRING_TYPENAME range_iterator<Range1T>::type> 0217 ifind_nth( 0218 Range1T& Input, 0219 const Range2T& Search, 0220 int Nth, 0221 const std::locale& Loc=std::locale()) 0222 { 0223 return ::boost::algorithm::find(Input, ::boost::algorithm::nth_finder(Search,Nth,is_iequal(Loc))); 0224 } 0225 0226 // find_head ----------------------------------------------------------------------// 0227 0228 //! Find head algorithm 0229 /*! 0230 Get the head of the input. Head is a prefix of the string of the 0231 given size. If the input is shorter then required, whole input is considered 0232 to be the head. 0233 0234 \param Input An input string 0235 \param N Length of the head 0236 For N>=0, at most N characters are extracted. 0237 For N<0, at most size(Input)-|N| characters are extracted. 0238 \return 0239 An \c iterator_range delimiting the match. 0240 Returned iterator is either \c Range1T::iterator or 0241 \c Range1T::const_iterator, depending on the constness of 0242 the input parameter. 0243 0244 \note This function provides the strong exception-safety guarantee 0245 */ 0246 template<typename RangeT> 0247 inline iterator_range< 0248 BOOST_STRING_TYPENAME range_iterator<RangeT>::type> 0249 find_head( 0250 RangeT& Input, 0251 int N) 0252 { 0253 return ::boost::algorithm::find(Input, ::boost::algorithm::head_finder(N)); 0254 } 0255 0256 // find_tail ----------------------------------------------------------------------// 0257 0258 //! Find tail algorithm 0259 /*! 0260 Get the tail of the input. Tail is a suffix of the string of the 0261 given size. If the input is shorter then required, whole input is considered 0262 to be the tail. 0263 0264 \param Input An input string 0265 \param N Length of the tail. 0266 For N>=0, at most N characters are extracted. 0267 For N<0, at most size(Input)-|N| characters are extracted. 0268 \return 0269 An \c iterator_range delimiting the match. 0270 Returned iterator is either \c RangeT::iterator or 0271 \c RangeT::const_iterator, depending on the constness of 0272 the input parameter. 0273 0274 0275 \note This function provides the strong exception-safety guarantee 0276 */ 0277 template<typename RangeT> 0278 inline iterator_range< 0279 BOOST_STRING_TYPENAME range_iterator<RangeT>::type> 0280 find_tail( 0281 RangeT& Input, 0282 int N) 0283 { 0284 return ::boost::algorithm::find(Input, ::boost::algorithm::tail_finder(N)); 0285 } 0286 0287 // find_token --------------------------------------------------------------------// 0288 0289 //! Find token algorithm 0290 /*! 0291 Look for a given token in the string. Token is a character that matches the 0292 given predicate. 0293 If the "token compress mode" is enabled, adjacent tokens are considered to be one match. 0294 0295 \param Input A input string. 0296 \param Pred A unary predicate to identify a token 0297 \param eCompress Enable/Disable compressing of adjacent tokens 0298 \return 0299 An \c iterator_range delimiting the match. 0300 Returned iterator is either \c RangeT::iterator or 0301 \c RangeT::const_iterator, depending on the constness of 0302 the input parameter. 0303 0304 \note This function provides the strong exception-safety guarantee 0305 */ 0306 template<typename RangeT, typename PredicateT> 0307 inline iterator_range< 0308 BOOST_STRING_TYPENAME range_iterator<RangeT>::type> 0309 find_token( 0310 RangeT& Input, 0311 PredicateT Pred, 0312 token_compress_mode_type eCompress=token_compress_off) 0313 { 0314 return ::boost::algorithm::find(Input, ::boost::algorithm::token_finder(Pred, eCompress)); 0315 } 0316 0317 } // namespace algorithm 0318 0319 // pull names to the boost namespace 0320 using algorithm::find; 0321 using algorithm::find_first; 0322 using algorithm::ifind_first; 0323 using algorithm::find_last; 0324 using algorithm::ifind_last; 0325 using algorithm::find_nth; 0326 using algorithm::ifind_nth; 0327 using algorithm::find_head; 0328 using algorithm::find_tail; 0329 using algorithm::find_token; 0330 0331 } // namespace boost 0332 0333 0334 #endif // BOOST_STRING_FIND_HPP
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |