diff --git a/include/SemVer.h b/include/SemVer.h index 18ae18e0..5e710787 100644 --- a/include/SemVer.h +++ b/include/SemVer.h @@ -44,12 +44,12 @@ namespace OpenShock { inline bool operator>(const SemVer& other) const { return !(*this <= other); } inline bool operator>=(const SemVer& other) const { return !(*this < other); } - bool operator==(const std::string_view& other) const; - inline bool operator!=(const std::string_view& other) const { return !(*this == other); } - bool operator<(const std::string_view& other) const; - inline bool operator<=(const std::string_view& other) const { return *this < other || *this == other; } - inline bool operator>(const std::string_view& other) const { return !(*this <= other); } - inline bool operator>=(const std::string_view& other) const { return !(*this < other); } + bool operator==(std::string_view other) const; + inline bool operator!=(std::string_view other) const { return !(*this == other); } + bool operator<(std::string_view other) const; + inline bool operator<=(std::string_view other) const { return *this < other || *this == other; } + inline bool operator>(std::string_view other) const { return !(*this <= other); } + inline bool operator>=(std::string_view other) const { return !(*this < other); } bool isValid() const; diff --git a/include/util/StringUtils.h b/include/util/StringUtils.h index dd8336e9..7b216910 100644 --- a/include/util/StringUtils.h +++ b/include/util/StringUtils.h @@ -11,7 +11,7 @@ namespace OpenShock { bool FormatToString(std::string& out, const char* format, ...); - constexpr std::string_view StringTrimLeft(const std::string_view view) { + constexpr std::string_view StringTrimLeft(std::string_view view) { if (view.empty()) { return view; } @@ -23,7 +23,7 @@ namespace OpenShock { return view.substr(pos); } - constexpr std::string_view StringTrimRight(const std::string_view view) { + constexpr std::string_view StringTrimRight(std::string_view view) { if (view.empty()) { return view; } @@ -35,14 +35,14 @@ namespace OpenShock { return view.substr(0, pos + 1); } - constexpr std::string_view StringTrim(const std::string_view view) { + constexpr std::string_view StringTrim(std::string_view view) { return StringTrimLeft(StringTrimRight(view)); } - constexpr bool StringStartsWith(const std::string_view view, std::string_view prefix) { + constexpr bool StringStartsWith(std::string_view view, std::string_view prefix) { return view.size() >= prefix.size() && view.substr(0, prefix.size()) == prefix; } template - constexpr bool TryStringSplit(const std::string_view view, char delimiter, std::string_view (&out)[N]) { + constexpr bool TryStringSplit(std::string_view view, char delimiter, std::string_view (&out)[N]) { std::size_t pos = 0; std::size_t idx = 0; while (pos < view.size() && idx < N) { @@ -58,12 +58,12 @@ namespace OpenShock { return idx == N; } - std::vector StringSplit(const std::string_view view, char delimiter, std::size_t maxSplits = std::numeric_limits::max()); - std::vector StringSplit(const std::string_view view, bool (*predicate)(char delimiter), std::size_t maxSplits = std::numeric_limits::max()); - std::vector StringSplitNewLines(const std::string_view view, std::size_t maxSplits = std::numeric_limits::max()); - std::vector StringSplitWhiteSpace(const std::string_view view, std::size_t maxSplits = std::numeric_limits::max()); + std::vector StringSplit(std::string_view view, char delimiter, std::size_t maxSplits = std::numeric_limits::max()); + std::vector StringSplit(std::string_view view, bool (*predicate)(char delimiter), std::size_t maxSplits = std::numeric_limits::max()); + std::vector StringSplitNewLines(std::string_view view, std::size_t maxSplits = std::numeric_limits::max()); + std::vector StringSplitWhiteSpace(std::string_view view, std::size_t maxSplits = std::numeric_limits::max()); - bool StringIEquals(const std::string_view a, const std::string_view b); + bool StringIEquals(std::string_view a, std::string_view b); String StringToArduinoString(std::string_view view); } // namespace OpenShock diff --git a/src/SemVer.cpp b/src/SemVer.cpp index 5cac5c61..aeaec3b8 100644 --- a/src/SemVer.cpp +++ b/src/SemVer.cpp @@ -298,7 +298,7 @@ bool SemVer::operator<(const SemVer& other) const return build < other.build; } -bool SemVer::operator==(const std::string_view& other) const +bool SemVer::operator==(std::string_view other) const { SemVer otherSemVer; if (!OpenShock::TryParseSemVer(other, otherSemVer)) { @@ -308,7 +308,7 @@ bool SemVer::operator==(const std::string_view& other) const return *this == otherSemVer; } -bool SemVer::operator<(const std::string_view& other) const +bool SemVer::operator<(std::string_view other) const { SemVer otherSemVer; if (!OpenShock::TryParseSemVer(other, otherSemVer)) { diff --git a/src/util/StringUtils.cpp b/src/util/StringUtils.cpp index dcaf65bc..8a555232 100644 --- a/src/util/StringUtils.cpp +++ b/src/util/StringUtils.cpp @@ -58,7 +58,7 @@ bool OpenShock::FormatToString(std::string& out, const char* format, ...) { return true; } -std::vector OpenShock::StringSplit(const std::string_view view, char delimiter, std::size_t maxSplits) { +std::vector OpenShock::StringSplit(std::string_view view, char delimiter, std::size_t maxSplits) { if (view.empty()) { return {}; } @@ -85,7 +85,7 @@ std::vector OpenShock::StringSplit(const std::string_view view return result; } -std::vector OpenShock::StringSplit(const std::string_view view, bool (*predicate)(char delimiter), std::size_t maxSplits) { +std::vector OpenShock::StringSplit(std::string_view view, bool (*predicate)(char delimiter), std::size_t maxSplits) { if (view.empty()) { return {}; } @@ -111,19 +111,19 @@ std::vector OpenShock::StringSplit(const std::string_view view return result; } -std::vector OpenShock::StringSplitNewLines(const std::string_view view, std::size_t maxSplits) { +std::vector OpenShock::StringSplitNewLines(std::string_view view, std::size_t maxSplits) { return StringSplit( view, [](char c) { return c == '\r' || c == '\n'; }, maxSplits ); } -std::vector OpenShock::StringSplitWhiteSpace(const std::string_view view, std::size_t maxSplits) { +std::vector OpenShock::StringSplitWhiteSpace(std::string_view view, std::size_t maxSplits) { return StringSplit( view, [](char c) { return isspace(c) != 0; }, maxSplits ); } -bool OpenShock::StringIEquals(const std::string_view a, const std::string_view b) +bool OpenShock::StringIEquals(std::string_view a, std::string_view b) { if (a.size() != b.size()) return false; return strncasecmp(a.data(), b.data(), a.size()) == 0;