![]() |
|
|||
File indexing completed on 2025-02-22 09:55:55
0001 // Boost string_algo library trim.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_TRIM_ALL_HPP 0012 #define BOOST_STRING_TRIM_ALL_HPP 0013 0014 #include <boost/algorithm/string/config.hpp> 0015 0016 #include <boost/algorithm/string/trim.hpp> 0017 #include <boost/algorithm/string/classification.hpp> 0018 #include <boost/algorithm/string/find_format.hpp> 0019 #include <boost/algorithm/string/formatter.hpp> 0020 #include <boost/algorithm/string/finder.hpp> 0021 #include <locale> 0022 0023 /*! \file 0024 Defines trim_all algorithms. 0025 0026 Just like \c trim, \c trim_all removes all trailing and leading spaces from a 0027 sequence (string). In addition, spaces in the middle of the sequence are truncated 0028 to just one character. Space is recognized using given locales. 0029 0030 \c trim_fill acts as trim_all, but the spaces in the middle are replaces with 0031 a user-define sequence of character. 0032 0033 Parametric (\c _if) variants use a predicate (functor) to select which characters 0034 are to be trimmed.. 0035 Functions take a selection predicate as a parameter, which is used to determine 0036 whether a character is a space. Common predicates are provided in classification.hpp header. 0037 0038 */ 0039 0040 namespace boost { 0041 namespace algorithm { 0042 0043 // multi line trim ----------------------------------------------- // 0044 0045 //! Trim All - parametric 0046 /*! 0047 Remove all leading and trailing spaces from the input and 0048 compress all other spaces to a single character. 0049 The result is a trimmed copy of the input 0050 0051 \param Input An input sequence 0052 \param IsSpace A unary predicate identifying spaces 0053 \return A trimmed copy of the input 0054 */ 0055 template<typename SequenceT, typename PredicateT> 0056 inline SequenceT trim_all_copy_if(const SequenceT& Input, PredicateT IsSpace) 0057 { 0058 return 0059 ::boost::find_format_all_copy( 0060 ::boost::trim_copy_if(Input, IsSpace), 0061 ::boost::token_finder(IsSpace, ::boost::token_compress_on), 0062 ::boost::dissect_formatter(::boost::head_finder(1))); 0063 } 0064 0065 0066 //! Trim All 0067 /*! 0068 Remove all leading and trailing spaces from the input and 0069 compress all other spaces to a single character. 0070 The input sequence is modified in-place. 0071 0072 \param Input An input sequence 0073 \param IsSpace A unary predicate identifying spaces 0074 */ 0075 template<typename SequenceT, typename PredicateT> 0076 inline void trim_all_if(SequenceT& Input, PredicateT IsSpace) 0077 { 0078 ::boost::trim_if(Input, IsSpace); 0079 ::boost::find_format_all( 0080 Input, 0081 ::boost::token_finder(IsSpace, ::boost::token_compress_on), 0082 ::boost::dissect_formatter(::boost::head_finder(1))); 0083 } 0084 0085 0086 //! Trim All 0087 /*! 0088 Remove all leading and trailing spaces from the input and 0089 compress all other spaces to a single character. 0090 The result is a trimmed copy of the input 0091 0092 \param Input An input sequence 0093 \param Loc A locale used for 'space' classification 0094 \return A trimmed copy of the input 0095 */ 0096 template<typename SequenceT> 0097 inline SequenceT trim_all_copy(const SequenceT& Input, const std::locale& Loc =std::locale()) 0098 { 0099 return trim_all_copy_if(Input, ::boost::is_space(Loc)); 0100 } 0101 0102 0103 //! Trim All 0104 /*! 0105 Remove all leading and trailing spaces from the input and 0106 compress all other spaces to a single character. 0107 The input sequence is modified in-place. 0108 0109 \param Input An input sequence 0110 \param Loc A locale used for 'space' classification 0111 \return A trimmed copy of the input 0112 */ 0113 template<typename SequenceT> 0114 inline void trim_all(SequenceT& Input, const std::locale& Loc =std::locale()) 0115 { 0116 trim_all_if(Input, ::boost::is_space(Loc)); 0117 } 0118 0119 0120 //! Trim Fill - parametric 0121 /*! 0122 Remove all leading and trailing spaces from the input and 0123 replace all every block of consecutive spaces with a fill string 0124 defined by user. 0125 The result is a trimmed copy of the input 0126 0127 \param Input An input sequence 0128 \param Fill A string used to fill the inner spaces 0129 \param IsSpace A unary predicate identifying spaces 0130 \return A trimmed copy of the input 0131 */ 0132 template<typename SequenceT, typename RangeT, typename PredicateT> 0133 inline SequenceT trim_fill_copy_if(const SequenceT& Input, const RangeT& Fill, PredicateT IsSpace) 0134 { 0135 return 0136 ::boost::find_format_all_copy( 0137 ::boost::trim_copy_if(Input, IsSpace), 0138 ::boost::token_finder(IsSpace, ::boost::token_compress_on), 0139 ::boost::const_formatter(::boost::as_literal(Fill))); 0140 } 0141 0142 0143 //! Trim Fill 0144 /*! 0145 Remove all leading and trailing spaces from the input and 0146 replace all every block of consecutive spaces with a fill string 0147 defined by user. 0148 The input sequence is modified in-place. 0149 0150 \param Input An input sequence 0151 \param Fill A string used to fill the inner spaces 0152 \param IsSpace A unary predicate identifying spaces 0153 */ 0154 template<typename SequenceT, typename RangeT, typename PredicateT> 0155 inline void trim_fill_if(SequenceT& Input, const RangeT& Fill, PredicateT IsSpace) 0156 { 0157 ::boost::trim_if(Input, IsSpace); 0158 ::boost::find_format_all( 0159 Input, 0160 ::boost::token_finder(IsSpace, ::boost::token_compress_on), 0161 ::boost::const_formatter(::boost::as_literal(Fill))); 0162 } 0163 0164 0165 //! Trim Fill 0166 /*! 0167 Remove all leading and trailing spaces from the input and 0168 replace all every block of consecutive spaces with a fill string 0169 defined by user. 0170 The result is a trimmed copy of the input 0171 0172 \param Input An input sequence 0173 \param Fill A string used to fill the inner spaces 0174 \param Loc A locale used for 'space' classification 0175 \return A trimmed copy of the input 0176 */ 0177 template<typename SequenceT, typename RangeT> 0178 inline SequenceT trim_fill_copy(const SequenceT& Input, const RangeT& Fill, const std::locale& Loc =std::locale()) 0179 { 0180 return trim_fill_copy_if(Input, Fill, ::boost::is_space(Loc)); 0181 } 0182 0183 0184 //! Trim Fill 0185 /*! 0186 Remove all leading and trailing spaces from the input and 0187 replace all every block of consecutive spaces with a fill string 0188 defined by user. 0189 The input sequence is modified in-place. 0190 0191 \param Input An input sequence 0192 \param Fill A string used to fill the inner spaces 0193 \param Loc A locale used for 'space' classification 0194 \return A trimmed copy of the input 0195 */ 0196 template<typename SequenceT, typename RangeT> 0197 inline void trim_fill(SequenceT& Input, const RangeT& Fill, const std::locale& Loc =std::locale()) 0198 { 0199 trim_fill_if(Input, Fill, ::boost::is_space(Loc)); 0200 } 0201 0202 0203 } // namespace algorithm 0204 0205 // pull names to the boost namespace 0206 using algorithm::trim_all; 0207 using algorithm::trim_all_if; 0208 using algorithm::trim_all_copy; 0209 using algorithm::trim_all_copy_if; 0210 using algorithm::trim_fill; 0211 using algorithm::trim_fill_if; 0212 using algorithm::trim_fill_copy; 0213 using algorithm::trim_fill_copy_if; 0214 0215 } // namespace boost 0216 0217 #endif // BOOST_STRING_TRIM_ALL_HPP
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |