Skip to content

Commit

Permalink
Update ex9_43.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
sanerror authored Oct 16, 2016
1 parent f8967fc commit b39e900
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions ch09/ex9_43.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ using std::string;
void Replace(string& s, const string& oldVal, const string& newVal)
{
for (auto beg = s.begin(); beg != s.end(); ) {
++beg;
if (*beg != oldVal.front()) continue;
if (std::distance(beg, s.end()) <
std::distance(oldVal.begin(), oldVal.end()))
break;
if (string{ beg, beg + oldVal.size() } == oldVal) {
if (*beg == oldVal.front() && string{ beg, beg + oldVal.size() } == oldVal) {
beg = s.erase(beg, beg + oldVal.size());
beg = s.insert(beg, newVal.cbegin(), newVal.cend()) + newVal.size();
}
else {
++beg;
}
}
}

int main()
{
{
Expand Down

0 comments on commit b39e900

Please sign in to comment.