Changeset 4097


Ignore:
Timestamp:
Sep 17, 2021, 2:06:55 AM (2 years ago)
Author:
Peter
Message:

use boost when functionality is available; prefer passing const& rather than passing by value, very unlikely to break any code, but obviously code that has been compiled against 0.19 headers need to be recompiled before linked against 0.20 lib.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/NEWS

    r4091 r4097  
    44
    55version 0.20 (released NOT YET)
     6  - utility::replace(3) now takes const string& rather than string
    67
    78  A complete list of closed tickets can be found here [[br]]
  • trunk/yat/utility/utility.cc

    r3999 r4097  
    2929#include "FileUtil.h"
    3030#include "stl_utility.h"
     31
     32#include <boost/algorithm/string/replace.hpp>
    3133
    3234#include <cassert>
     
    248250
    249251
    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)
    251254  {
    252255    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);
    268257  }
    269258
  • trunk/yat/utility/utility.h

    r3999 r4097  
    442442
    443443     \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);
    446451
    447452
Note: See TracChangeset for help on using the changeset viewer.