MCPcopy Create free account
hub / github.com/clechasseur/pathcopycopy / ReplaceAll

Method ReplaceAll

PathCopyCopy/src/StringUtils.cpp:54–71  ·  view source on GitHub ↗

Replaces all instance of p_OldValue in p_rString with p_NewValue. @param p_rString String to modify (in-place). @param p_OldValue Old value to look for. @param p_NewValue Replacement value.

Source from the content-addressed store, hash-verified

52// @param p_NewValue Replacement value.
53//
54void StringUtils::ReplaceAll(std::wstring& p_rString,
55 const std::wstring& p_OldValue,
56 const std::wstring& p_NewValue)
57{
58 std::wstring::size_type pos = 0;
59 std::wstring::size_type from = 0;
60 do {
61 // Look for the next instance of the old value.
62 pos = p_rString.find(p_OldValue, from);
63 if (pos != std::wstring::npos) {
64 // Replace this instance with our replacement value.
65 p_rString.replace(pos, p_OldValue.size(), p_NewValue);
66
67 // Start looking after the replacement next time.
68 from = pos + p_NewValue.size();
69 }
70 } while (pos != std::wstring::npos);
71}
72
73//
74// Splits the given string using the given separators into parts.

Callers

nothing calls this directly

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected