Changeset 3093 for branches/0.10-stable
- Timestamp:
- Oct 21, 2013, 6:07:37 AM (9 years ago)
- Location:
- branches/0.10-stable
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/0.10-stable/NEWS
r3019 r3093 6 6 7 7 version 0.10.3 (released NOT YET) 8 - utility::replace(string&, string, string) is now implemented (bug #768) 8 9 9 10 A complete list of closed tickets can be found here [[br]] -
branches/0.10-stable/test/utility.cc
r2940 r3093 59 59 void test_fnmatch(test::Suite& suite); 60 60 bool test_fnmatch(bool, std::string, std::string); 61 void test_replace(test::Suite& suite); 61 62 62 63 template<typename InputIterator, typename Key> … … 216 217 test_dirname(suite); 217 218 test_fnmatch(suite); 219 test_replace(suite); 218 220 219 221 return suite.return_value(); … … 638 640 return false; 639 641 } 642 643 644 void test_replace(test::Suite& suite) 645 { 646 std::string s = "Some magic string!!!"; 647 utility::replace(s, "magic", "arbitrary"); 648 if (!suite.add(s=="Some arbitrary string!!!")) 649 suite.err() << "error: " << s << "\n"; 650 } -
branches/0.10-stable/yat/utility/utility.cc
r2940 r3093 6 6 Copyright (C) 2010 Peter Johansson 7 7 Copyright (C) 2012 Jari Häkkinen, Peter Johansson 8 Copyright (C) 2013 Peter Johansson 8 9 9 10 This file is part of the yat library, http://dev.thep.lu.se/yat … … 187 188 188 189 190 void replace(std::string& str, std::string old_value, std::string new_value) 191 { 192 assert(old_value.size()); 193 std::string result; 194 std::back_insert_iterator<std::string> out(result); 195 std::string::iterator c = str.begin(); 196 while (c!=str.end()) { 197 if (str.end() - c >= static_cast<int>(old_value.size()) && 198 std::equal(old_value.begin(), old_value.end(), c)) { 199 std::copy(new_value.begin(), new_value.end(), out); 200 c += old_value.size(); 201 } 202 else { 203 *out = *c; 204 ++c; 205 } 206 } 207 str.swap(result); 208 } 209 210 189 211 }}} // end of namespace utility, yat and thep
Note: See TracChangeset
for help on using the changeset viewer.