30 std::string_view toReplace,std::string_view replaceWith)
35 buf.reserve(s.length());
37 while ((pos=s.find(toReplace, prevPos))!=std::string::npos)
39 buf.append(s, prevPos, pos - prevPos);
41 prevPos = pos + toReplace.length();
43 buf.append(s, prevPos, s.size() - prevPos);
51 std::string_view toReplace,std::string_view replaceWith)
56 buf.reserve(s.length());
58 while ((pos=s.find(toReplace, prevPos))!=std::string::npos)
60 buf.append(s, prevPos, pos - prevPos);
62 prevPos = pos + toReplace.length();
64 buf.append(s, prevPos, s.size() - prevPos);
74 static auto isspace = [](
char c){
return c==
' ' || c==
'\t' || c==
'\n' || c==
'\r'; };
75 size_t sl = s.length();
76 if (sl==0 || (!isspace(s[0]) && !isspace(s[sl-1])))
return s;
77 size_t start=0,
end=sl-1;
78 while (start<sl && isspace(s[start])) start++;
79 if (start==sl)
return s.substr(0,0);
80 while (
end>start && isspace(s[
end]))
end--;
81 return s.substr(start,
end+1-start);
92 if (s[s.length()-1]!=c) s+=c;
DirIterator end(const DirIterator &) noexcept
std::string substituteStringView(std::string_view s, std::string_view toReplace, std::string_view replaceWith)
Returns a new string where occurrences of substring toReplace in string s are replaced by string repl...
void addTerminalCharIfMissing(std::string &s, char c)
void substituteInplace(std::string &s, std::string_view toReplace, std::string_view replaceWith)
Replaces occurrences of substring toReplace in string s with string replaceWith.
std::string_view stripWhiteSpace(std::string_view s)
Given a string view s, returns a new, narrower view on that string, skipping over any leading or trai...