diff options
author | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-02-22 13:02:26 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-02-22 14:32:45 +0100 |
commit | 81e4f170d8ba4ccbcfa1e6c07bd0522dfc3b6e08 (patch) | |
tree | e2619b16a5331e5760d94be389d0a3a01427293f /src/utils | |
parent | d047db79f7034e0e75a85a656d18f40716d197b9 (diff) | |
download | Mana-81e4f170d8ba4ccbcfa1e6c07bd0522dfc3b6e08.tar.gz Mana-81e4f170d8ba4ccbcfa1e6c07bd0522dfc3b6e08.tar.bz2 Mana-81e4f170d8ba4ccbcfa1e6c07bd0522dfc3b6e08.tar.xz Mana-81e4f170d8ba4ccbcfa1e6c07bd0522dfc3b6e08.zip |
General code cleanups
* Use default member initializers
* Use range-based loops
* Don't use 'else' after 'return'
* Removed some unused includes
* Construct empty strings with std::string() instead of ""
* Clear strings with .clear() instead of assigning ""
* Check whether strings are empty with .empty() instead of comparing to ""
* Removed redundant initializations
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/path.cpp | 18 | ||||
-rw-r--r-- | src/utils/sha256.cpp | 2 | ||||
-rw-r--r-- | src/utils/stringutils.cpp | 8 |
3 files changed, 13 insertions, 15 deletions
diff --git a/src/utils/path.cpp b/src/utils/path.cpp index 95db40d3..c78f0fd7 100644 --- a/src/utils/path.cpp +++ b/src/utils/path.cpp @@ -75,10 +75,8 @@ namespace utils { return path1 + path2; } - else - { - return path1 + "/" + path2; - } + + return path1 + "/" + path2; } /** @@ -86,14 +84,14 @@ namespace utils */ std::string cleanPath(const std::string &path) { - size_t prev, cur; - std::string part, result; + std::string part; + std::string result; std::vector<std::string> pathStack; - prev = 0; + size_t prev = 0; while (true) { - cur = path.find_first_of("/\\", prev); + size_t cur = path.find_first_of("/\\", prev); if (cur == std::string::npos) { // FIXME add everything from prev to the end @@ -114,12 +112,12 @@ namespace utils { // do nothing } - else if (part == "") + else if (part.empty()) { if (pathStack.empty() && cur == 0) { // handle first empty match before the root slash - pathStack.push_back(std::string()); + pathStack.emplace_back(); } else { diff --git a/src/utils/sha256.cpp b/src/utils/sha256.cpp index a18e5f18..0e44af7a 100644 --- a/src/utils/sha256.cpp +++ b/src/utils/sha256.cpp @@ -264,7 +264,7 @@ std::string SHA256Hash(const char *src, int len) SHA256Final(&ctx, bytehash); // Convert it to hex const char* hxc = "0123456789abcdef"; - std::string hash = ""; + std::string hash; for (unsigned char i : bytehash) { hash += hxc[i / 16]; diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp index 57138005..32fc3b0c 100644 --- a/src/utils/stringutils.cpp +++ b/src/utils/stringutils.cpp @@ -187,8 +187,8 @@ bool getBoolFromString(const std::string &text, bool def) return true; if (a == "false" || a == "0" || a == "off" || a == "no" || a == "n") return false; - else - return def; + + return def; } std::string autocomplete(const std::vector<std::string> &candidates, @@ -196,7 +196,7 @@ std::string autocomplete(const std::vector<std::string> &candidates, { auto i = candidates.begin(); toLower(base); - std::string newName(""); + std::string newName; while (i != candidates.end()) { @@ -208,7 +208,7 @@ std::string autocomplete(const std::vector<std::string> &candidates, std::string::size_type pos = name.find(base, 0); if (pos == 0) { - if (newName != "") + if (!newName.empty()) { toLower(newName); newName = findSameSubstring(name, newName); |