Skip to content

Commit

Permalink
-updated string replace function to take string_view parameter;
Browse files Browse the repository at this point in the history
  • Loading branch information
kamchatka-volcano committed Nov 24, 2024
1 parent 607a426 commit 53a0719
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions include/sfun/string_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,17 +174,18 @@ inline std::vector<std::string> split(std::string&& str, std::string_view delim
return stringList;
}

inline std::string replace(std::string str, std::string_view subStr, std::string_view val)
inline std::string replace(std::string_view str, std::string_view subStr, std::string_view val)
{
auto inputStr = std::string{str};
if (subStr.empty())
return str;
return inputStr;

auto pos = str.find(subStr);
auto pos = inputStr.find(subStr);
while (pos != std::string::npos) {
str.replace(pos, subStr.size(), val);
pos = str.find(subStr, pos + val.size());
inputStr.replace(pos, subStr.size(), val);
pos = inputStr.find(subStr, pos + val.size());
}
return str;
return inputStr;
}

template<typename TRange>
Expand Down

0 comments on commit 53a0719

Please sign in to comment.