Changeset 4097
- Timestamp:
- Sep 17, 2021, 2:06:55 AM (2 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/NEWS
r4091 r4097 4 4 5 5 version 0.20 (released NOT YET) 6 - utility::replace(3) now takes const string& rather than string 6 7 7 8 A complete list of closed tickets can be found here [[br]] -
trunk/yat/utility/utility.cc
r3999 r4097 29 29 #include "FileUtil.h" 30 30 #include "stl_utility.h" 31 32 #include <boost/algorithm/string/replace.hpp> 31 33 32 34 #include <cassert> … … 248 250 249 251 250 void replace(std::string& str, std::string old_value, std::string new_value) 252 void replace(std::string& str, const std::string& old_value, 253 const std::string& new_value) 251 254 { 252 255 assert(old_value.size()); 253 std::string result; 254 std::back_insert_iterator<std::string> out(result); 255 std::string::iterator c = str.begin(); 256 while (c!=str.end()) { 257 if (str.end() - c >= static_cast<int>(old_value.size()) && 258 std::equal(old_value.begin(), old_value.end(), c)) { 259 std::copy(new_value.begin(), new_value.end(), out); 260 c += old_value.size(); 261 } 262 else { 263 *out = *c; 264 ++c; 265 } 266 } 267 str.swap(result); 256 boost::algorithm::replace_all(str, old_value, new_value); 268 257 } 269 258 -
trunk/yat/utility/utility.h
r3999 r4097 442 442 443 443 \since New in yat 0.10 444 */ 445 void replace(std::string& full_str, std::string old_str, std::string new_str); 444 445 \see <a href=https://www.boost.org/doc/libs/1_77_0/doc/html/boost/algorithm/replace_all.html> 446 boost::algorithm::replace_all(string&, const string&, const string&) 447 </a> 448 */ 449 void replace(std::string& full_str, const std::string& old_str, 450 const std::string& new_str); 446 451 447 452
Note: See TracChangeset
for help on using the changeset viewer.