Ignore:
Timestamp:
Oct 28, 2013, 7:24:00 AM (8 years ago)
Author:
Peter
Message:

merge release 0.10.3 into trunk

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/yat/utility/utility.cc

    r2943 r3098  
    66  Copyright (C) 2010 Peter Johansson
    77  Copyright (C) 2012 Jari Häkkinen, Peter Johansson
     8  Copyright (C) 2013 Peter Johansson
    89
    910  This file is part of the yat library, http://dev.thep.lu.se/yat
     
    187188
    188189
     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
    189211}}} // end of namespace utility, yat and thep
Note: See TracChangeset for help on using the changeset viewer.