From ded15374d58b30bc4e74934437b6a8e91706b38f Mon Sep 17 00:00:00 2001 From: TopchetoEU <36534413+TopchetoEU@users.noreply.github.com> Date: Tue, 4 Oct 2022 19:33:30 +0300 Subject: [PATCH] fix: replace -1u with std::string::npos or -1 --- include/lang/version.hh | 4 ++-- src/lsproj.cc | 12 ++++++------ src/main/options.cc | 2 +- src/utils/strings.cc | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/include/lang/version.hh b/include/lang/version.hh index 89b3fc3..efa577b 100644 --- a/include/lang/version.hh +++ b/include/lang/version.hh @@ -34,7 +34,7 @@ namespace ppc { inline bool operator !=(version_t other) const { return !(*this == other); } version_t(uint16_t major, uint16_t minor, uint32_t revision) : major(major), minor(minor), revision(revision) { } - version_t(uint16_t major, uint16_t minor) : version_t(major, minor, -1u) { } - version_t(uint16_t major) : version_t(major, -1u, -1u) { } + version_t(uint16_t major, uint16_t minor) : version_t(major, minor, -1) { } + version_t(uint16_t major) : version_t(major, -1, -1) { } }; } diff --git a/src/lsproj.cc b/src/lsproj.cc index 8df6e4e..934dd33 100644 --- a/src/lsproj.cc +++ b/src/lsproj.cc @@ -15,11 +15,11 @@ std::string read_str(std::istream &f, const std::string &skip_chars, const std:: while (true) { c = f.get(); auto a = end_chars.find(c); - if (c == -1 || a != -1ull) { + if (c == -1 || a != std::string::npos) { end_char = c; return ""; } - if ((a = skip_chars.find(c)) == -1ull) { + if ((a = skip_chars.find(c)) == std::string::npos) { f.unget(); break; } @@ -27,7 +27,7 @@ std::string read_str(std::istream &f, const std::string &skip_chars, const std:: while (true) { c = f.get(); - if (c == -1 || end_chars.find(c) != -1ull) { + if (c == -1 || end_chars.find(c) != std::string::npos) { end_char = c; break; } @@ -35,7 +35,7 @@ std::string read_str(std::istream &f, const std::string &skip_chars, const std:: res.push_back(c); } while (true) { - if (skip_chars.find(res.back()) != -1ull) res.pop_back(); + if (skip_chars.find(res.back()) != std::string::npos) res.pop_back(); else break; } @@ -63,14 +63,14 @@ project_t read_project(std::istream &f) { }; } - if (name.find(',') != -1ull || name.find(' ') != -1ull) { + if (name.find(',') != std::string::npos || name.find(' ') != std::string::npos) { throw (std::string)"The name of a project may not contain spaces or commas."; } while (true) { std::string dep = read_str(f, " \v\t\r\n", ",\n", end_ch); - if (dep.find(' ') != -1ull) { + if (dep.find(' ') != std::string::npos) { throw (std::string)"The name of a dependency may not contain spaces."; } diff --git a/src/main/options.cc b/src/main/options.cc index d5b46c2..9328a1c 100644 --- a/src/main/options.cc +++ b/src/main/options.cc @@ -6,7 +6,7 @@ using namespace ppc; bool check_shorthand(std::string &option, const options::flag_t &flag) { if (option.size() < 2 || option[0] != '-') return false; - if (option.size() == 2 && std::string { flag.shorthands }.find(option[1]) != -1u) { + if (option.size() == 2 && std::string { flag.shorthands }.find(option[1]) != std::string::npos) { option = ""; return true; } diff --git a/src/utils/strings.cc b/src/utils/strings.cc index 4982718..1482a81 100644 --- a/src/utils/strings.cc +++ b/src/utils/strings.cc @@ -8,7 +8,7 @@ std::vector str::split(const std::string &splittable, std::initiali std::vector res; for (char c : splittable) { - if (std::string { splitters }.find(c) == -1u) { + if (std::string { splitters }.find(c) == std::string::npos) { buff << c; } else { @@ -29,10 +29,10 @@ std::vector str::split(const std::string &splittable, std::initiali std::string str::trim(std::string splittable, std::initializer_list splitters) { auto split = std::string { splitters }; - while (!splittable.empty() && split.find(splittable[0]) != -1u) { + while (!splittable.empty() && split.find(splittable[0]) != std::string::npos) { splittable = splittable.substr(1); } - while (!splittable.empty() && split.find(splittable[splittable.length() - 1]) != -1u) { + while (!splittable.empty() && split.find(splittable[splittable.length() - 1]) != std::string::npos) { splittable = splittable.substr(0, splittable.length() - 1); }