Use npos member variables instead of full type

This commit is contained in:
Jacek Galowicz 2023-11-02 10:13:55 +01:00
parent 7115edc85a
commit 0bc66e529f
2 changed files with 8 additions and 8 deletions

View File

@ -90,7 +90,7 @@ Path canonPath(PathView path, bool resolveSymlinks)
/* Normal component; copy it. */
else {
s += '/';
if (const auto slash = path.find('/'); slash == std::string::npos) {
if (const auto slash = path.find('/'); slash == path.npos) {
s += path;
path = {};
} else {
@ -123,7 +123,7 @@ Path canonPath(PathView path, bool resolveSymlinks)
Path dirOf(const PathView path)
{
Path::size_type pos = path.rfind('/');
if (pos == std::string::npos)
if (pos == path.npos)
return ".";
return pos == 0 ? "/" : Path(path, 0, pos);
}
@ -139,7 +139,7 @@ std::string_view baseNameOf(std::string_view path)
last -= 1;
auto pos = path.rfind('/', last);
if (pos == std::string::npos)
if (pos == path.npos)
pos = 0;
else
pos += 1;

View File

@ -52,9 +52,9 @@ template<class C> C tokenizeString(std::string_view s, std::string_view separato
{
C result;
auto pos = s.find_first_not_of(separators, 0);
while (pos != std::string_view::npos) {
while (pos != s.npos) {
auto end = s.find_first_of(separators, pos + 1);
if (end == std::string_view::npos) end = s.size();
if (end == s.npos) end = s.size();
result.insert(result.end(), std::string(s, pos, end - pos));
pos = s.find_first_not_of(separators, end);
}
@ -69,7 +69,7 @@ template std::vector<std::string> tokenizeString(std::string_view s, std::string
std::string chomp(std::string_view s)
{
size_t i = s.find_last_not_of(" \n\r\t");
return i == std::string_view::npos ? "" : std::string(s, 0, i + 1);
return i == s.npos ? "" : std::string(s, 0, i + 1);
}
@ -89,7 +89,7 @@ std::string replaceStrings(
{
if (from.empty()) return res;
size_t pos = 0;
while ((pos = res.find(from, pos)) != std::string::npos) {
while ((pos = res.find(from, pos)) != res.npos) {
res.replace(pos, from.size(), to);
pos += to.size();
}
@ -102,7 +102,7 @@ std::string rewriteStrings(std::string s, const StringMap & rewrites)
for (auto & i : rewrites) {
if (i.first == i.second) continue;
size_t j = 0;
while ((j = s.find(i.first, j)) != std::string::npos)
while ((j = s.find(i.first, j)) != s.npos)
s.replace(j, i.first.size(), i.second);
}
return s;