Ticket #1152: find_format.patch
File find_format.patch, 15.5 KB (added by , 13 years ago) |
---|
-
boost/algorithm/string/detail/find_format_all.hpp
29 29 typename InputT, 30 30 typename FinderT, 31 31 typename FormatterT, 32 typename FindResultT >33 inline OutputIteratorT find_format_all_copy_impl(34 OutputIteratorT Output,35 const InputT& Input,36 FinderT Finder,37 FormatterT Formatter,38 const FindResultT& FindResult )39 {40 return find_format_all_copy_impl2(41 Output,42 Input,43 Finder,44 Formatter,45 FindResult,46 Formatter(FindResult) );47 }48 49 template<50 typename OutputIteratorT,51 typename InputT,52 typename FinderT,53 typename FormatterT,54 32 typename FindResultT, 55 33 typename FormatResultT > 56 34 inline OutputIteratorT find_format_all_copy_impl2( … … 79 57 while( M ) 80 58 { 81 59 // Copy the beginning of the sequence 82 std::copy( LastMatch, M.begin(), Output );60 Output = std::copy( LastMatch, M.begin(), Output ); 83 61 // Copy formated result 84 std::copy( ::boost::begin(M.format_result()), ::boost::end(M.format_result()), Output );62 Output = std::copy( ::boost::begin(M.format_result()), ::boost::end(M.format_result()), Output ); 85 63 86 64 // Proceed to the next match 87 65 LastMatch=M.end(); … … 89 67 } 90 68 91 69 // Copy the rest of the sequence 92 std::copy( LastMatch, ::boost::end(Input), Output );70 Output = std::copy( LastMatch, ::boost::end(Input), Output ); 93 71 94 72 return Output; 95 73 } 96 74 97 // find_format_all_copy implementation ----------------------------------------------//98 99 75 template< 100 typename InputT, 76 typename OutputIteratorT, 77 typename InputT, 101 78 typename FinderT, 102 79 typename FormatterT, 103 80 typename FindResultT > 104 inline InputT find_format_all_copy_impl( 81 inline OutputIteratorT find_format_all_copy_impl( 82 OutputIteratorT Output, 105 83 const InputT& Input, 106 84 FinderT Finder, 107 85 FormatterT Formatter, 108 const FindResultT& FindResult) 109 { 110 return find_format_all_copy_impl2( 86 const FindResultT& FindResult ) 87 { 88 return find_format_all_copy_impl2( 89 Output, 111 90 Input, 112 91 Finder, 113 92 Formatter, … … 115 94 Formatter(FindResult) ); 116 95 } 117 96 97 // find_format_all_copy implementation ----------------------------------------------// 98 118 99 template< 119 100 typename InputT, 120 101 typename FinderT, … … 164 145 return Output; 165 146 } 166 147 167 // find_format_all implementation ------------------------------------------------// 168 169 template< 170 typename InputT, 148 template< 149 typename InputT, 171 150 typename FinderT, 172 151 typename FormatterT, 173 152 typename FindResultT > 174 inline void find_format_all_impl(175 InputT& Input,153 inline InputT find_format_all_copy_impl( 154 const InputT& Input, 176 155 FinderT Finder, 177 156 FormatterT Formatter, 178 FindResultTFindResult)157 const FindResultT& FindResult) 179 158 { 180 find_format_all_impl2(159 return find_format_all_copy_impl2( 181 160 Input, 182 161 Finder, 183 162 Formatter, … … 185 164 Formatter(FindResult) ); 186 165 } 187 166 167 // find_format_all implementation ------------------------------------------------// 168 188 169 template< 189 170 typename InputT, 190 171 typename FinderT, … … 255 236 insert( Input, ::boost::end(Input), Storage.begin(), Storage.end() ); 256 237 } 257 238 } 239 240 template< 241 typename InputT, 242 typename FinderT, 243 typename FormatterT, 244 typename FindResultT > 245 inline void find_format_all_impl( 246 InputT& Input, 247 FinderT Finder, 248 FormatterT Formatter, 249 FindResultT FindResult) 250 { 251 find_format_all_impl2( 252 Input, 253 Finder, 254 Formatter, 255 FindResult, 256 Formatter(FindResult) ); 257 } 258 258 259 259 } // namespace detail 260 260 } // namespace algorithm -
boost/algorithm/string/detail/find_format.hpp
28 28 typename OutputIteratorT, 29 29 typename InputT, 30 30 typename FormatterT, 31 typename FindResultT >32 inline OutputIteratorT find_format_copy_impl(33 OutputIteratorT Output,34 const InputT& Input,35 FormatterT Formatter,36 const FindResultT& FindResult )37 {38 return find_format_copy_impl2(39 Output,40 Input,41 Formatter,42 FindResult,43 Formatter(FindResult) );44 }45 46 template<47 typename OutputIteratorT,48 typename InputT,49 typename FormatterT,50 31 typename FindResultT, 51 32 typename FormatResultT > 52 33 inline OutputIteratorT find_format_copy_impl2( … … 68 49 if ( !M ) 69 50 { 70 51 // Match not found - return original sequence 71 std::copy( ::boost::begin(Input), ::boost::end(Input), Output );52 Output = std::copy( ::boost::begin(Input), ::boost::end(Input), Output ); 72 53 return Output; 73 54 } 74 55 75 56 // Copy the beginning of the sequence 76 std::copy( ::boost::begin(Input), ::boost::begin(M), Output );57 Output = std::copy( ::boost::begin(Input), ::boost::begin(M), Output ); 77 58 // Format find result 78 59 // Copy formated result 79 std::copy( ::boost::begin(M.format_result()), ::boost::end(M.format_result()), Output );60 Output = std::copy( ::boost::begin(M.format_result()), ::boost::end(M.format_result()), Output ); 80 61 // Copy the rest of the sequence 81 std::copy( M.end(), ::boost::end(Input), Output );62 Output = std::copy( M.end(), ::boost::end(Input), Output ); 82 63 83 64 return Output; 84 65 } 85 66 86 // find_format_copy implementation --------------------------------------------------//87 88 67 template< 89 typename InputT, 68 typename OutputIteratorT, 69 typename InputT, 90 70 typename FormatterT, 91 71 typename FindResultT > 92 inline InputT find_format_copy_impl( 72 inline OutputIteratorT find_format_copy_impl( 73 OutputIteratorT Output, 93 74 const InputT& Input, 94 75 FormatterT Formatter, 95 const FindResultT& FindResult) 96 { 97 return find_format_copy_impl2( 76 const FindResultT& FindResult ) 77 { 78 return find_format_copy_impl2( 79 Output, 98 80 Input, 99 81 Formatter, 100 82 FindResult, 101 83 Formatter(FindResult) ); 102 84 } 103 85 86 // find_format_copy implementation --------------------------------------------------// 87 104 88 template< 105 89 typename InputT, 106 90 typename FormatterT, … … 138 122 return Output; 139 123 } 140 124 141 // replace implementation ----------------------------------------------------// 142 143 template< 144 typename InputT, 125 template< 126 typename InputT, 145 127 typename FormatterT, 146 128 typename FindResultT > 147 inline void find_format_impl(148 InputT& Input,129 inline InputT find_format_copy_impl( 130 const InputT& Input, 149 131 FormatterT Formatter, 150 132 const FindResultT& FindResult) 151 133 { 152 find_format_impl2(134 return find_format_copy_impl2( 153 135 Input, 154 136 Formatter, 155 137 FindResult, 156 138 Formatter(FindResult) ); 157 139 } 158 140 141 // replace implementation ----------------------------------------------------// 142 159 143 template< 160 144 typename InputT, 161 145 typename FormatterT, … … 185 169 // Replace match 186 170 replace( Input, M.begin(), M.end(), M.format_result() ); 187 171 } 172 173 template< 174 typename InputT, 175 typename FormatterT, 176 typename FindResultT > 177 inline void find_format_impl( 178 InputT& Input, 179 FormatterT Formatter, 180 const FindResultT& FindResult) 181 { 182 find_format_impl2( 183 Input, 184 Formatter, 185 FindResult, 186 Formatter(FindResult) ); 187 } 188 188 189 189 } // namespace detail 190 190 } // namespace algorithm -
libs/algorithm/string/test/find_format_test.cpp
1 // Boost string_algo library find_format_test.cpp file ------------------// 2 3 // Copyright (c) 2009 Steven Watanabe 4 // Distributed under the Boost Software License, Version 1.0. (See 5 // accompanying file LICENSE_1_0.txt or copy at 6 // http://www.boost.org/LICENSE_1_0.txt) 7 8 // See http://www.boost.org for updates, documentation, and revision history. 9 10 #include <boost/algorithm/string/find_format.hpp> 11 #include <boost/algorithm/string/finder.hpp> 12 #include <boost/algorithm/string/formatter.hpp> 13 14 // Include unit test framework 15 #include <boost/test/included/test_exec_monitor.hpp> 16 17 #include <boost/test/test_tools.hpp> 18 19 void find_format_test() 20 { 21 const std::string source = "$replace $replace"; 22 std::string expected = "ok $replace"; 23 std::string output(80, '\0'); 24 25 std::string::iterator pos = 26 boost::find_format_copy(output.begin(), 27 source, 28 boost::first_finder("$replace"), 29 boost::const_formatter("ok")); 30 BOOST_CHECK(pos == output.begin() + expected.size()); 31 output.erase(std::remove(output.begin(), output.end(), '\0'), output.end()); 32 BOOST_CHECK_EQUAL(output, expected); 33 34 output = boost::find_format_copy(source, boost::first_finder("$replace"), boost::const_formatter("ok")); 35 BOOST_CHECK_EQUAL(output, expected); 36 37 // now try finding a string that doesn't exist 38 output.resize(80); 39 pos = boost::find_format_copy(output.begin(), 40 source, 41 boost::first_finder("$noreplace"), 42 boost::const_formatter("bad")); 43 BOOST_CHECK(pos == output.begin() + source.size()); 44 output.erase(std::remove(output.begin(), output.end(), '\0'), output.end()); 45 BOOST_CHECK_EQUAL(output, source); 46 47 output = boost::find_format_copy(source, boost::first_finder("$noreplace"), boost::const_formatter("bad")); 48 BOOST_CHECK_EQUAL(output, source); 49 50 // in place version 51 output = source; 52 boost::find_format(output, boost::first_finder("$replace"), boost::const_formatter("ok")); 53 BOOST_CHECK_EQUAL(output, expected); 54 output = source; 55 boost::find_format(output, boost::first_finder("$noreplace"), boost::const_formatter("bad")); 56 BOOST_CHECK_EQUAL(output, source); 57 } 58 59 void find_format_all_test() 60 { 61 const std::string source = "$replace $replace"; 62 std::string expected = "ok ok"; 63 std::string output(80, '\0'); 64 65 std::string::iterator pos = 66 boost::find_format_all_copy(output.begin(), 67 source, 68 boost::first_finder("$replace"), 69 boost::const_formatter("ok")); 70 BOOST_CHECK(pos == output.begin() + expected.size()); 71 output.erase(std::remove(output.begin(), output.end(), '\0'), output.end()); 72 BOOST_CHECK_EQUAL(output, expected); 73 74 output = boost::find_format_all_copy(source, boost::first_finder("$replace"), boost::const_formatter("ok")); 75 BOOST_CHECK_EQUAL(output, expected); 76 77 // now try finding a string that doesn't exist 78 output.resize(80); 79 pos = boost::find_format_all_copy(output.begin(), 80 source, 81 boost::first_finder("$noreplace"), 82 boost::const_formatter("bad")); 83 BOOST_CHECK(pos == output.begin() + source.size()); 84 output.erase(std::remove(output.begin(), output.end(), '\0'), output.end()); 85 BOOST_CHECK_EQUAL(output, source); 86 87 output = boost::find_format_all_copy(source, boost::first_finder("$noreplace"), boost::const_formatter("bad")); 88 BOOST_CHECK_EQUAL(output, source); 89 90 // in place version 91 output = source; 92 boost::find_format_all(output, boost::first_finder("$replace"), boost::const_formatter("ok")); 93 BOOST_CHECK_EQUAL(output, expected); 94 output = source; 95 boost::find_format_all(output, boost::first_finder("$noreplace"), boost::const_formatter("bad")); 96 BOOST_CHECK_EQUAL(output, source); 97 } 98 99 int test_main( int, char*[] ) 100 { 101 find_format_test(); 102 find_format_all_test(); 103 104 return 0; 105 } -
libs/algorithm/string/test/Jamfile.v2
Property changes on: libs\algorithm\string\test\find_format_test.cpp ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Id Name: svn:eol-style + native
59 59 : 60 60 : regex 61 61 ] 62 [ run 63 find_format_test.cpp 64 : : 65 : 66 : find_format 67 ] 62 68 ; 63 69