Improve String Handling

This commit is contained in:
Jacek Galowicz 2023-11-02 15:49:22 +01:00
parent 0bc66e529f
commit 1885d579db
3 changed files with 10 additions and 7 deletions

View file

@ -116,7 +116,11 @@ Path canonPath(PathView path, bool resolveSymlinks)
}
}
return s.empty() ? "/" : std::move(s);
if (s.empty()) {
s = "/";
}
return s;
}

View file

@ -122,12 +122,11 @@ bool hasSuffix(std::string_view s, std::string_view suffix)
}
std::string toLower(const std::string & s)
std::string toLower(std::string s)
{
std::string r(s);
for (auto & c : r)
for (auto & c : s)
c = std::tolower(c);
return r;
return s;
}
@ -135,7 +134,7 @@ std::string shellEscape(const std::string_view s)
{
std::string r;
r.reserve(s.size() + 2);
r += "'";
r += '\'';
for (auto & i : s)
if (i == '\'') r += "'\\''"; else r += i;
r += '\'';

View file

@ -180,7 +180,7 @@ bool hasSuffix(std::string_view s, std::string_view suffix);
/**
* Convert a string to lower case.
*/
std::string toLower(const std::string & s);
std::string toLower(std::string s);
/**