[string_util] fix bug in ReplaceSubstringsAfterOffset()
The problem with DoReplaceSubstringsAfterOffset was that the following search would not terminate: ReplaceSubstringsAfterOffset(std::string("aaabaa"), 0, "aa", "ccc"); The root cause of this is an algorithmic bug, where it was assumed that string::rfind and string::find would return the same matches in reversed order. The fix is to only scan forward using find(). For the length-expansion case, if capacity is insufficient, we swap with a temporary and build the result into new memory. If existing capacity suffices, we'll shift the tail of the string down to the new size, and then use left-to-right memmove loop of the length- contraction case, with the shifted tail as the src. BUG=749228 Review-Url: https://codereview.chromium.org/2979393002 Cr-Commit-Position: refs/heads/master@{#491170}
Showing
Please register or sign in to comment