summaryrefslogtreecommitdiff
path: root/src/helpers/MiscFunctions.cpp
diff options
context:
space:
mode:
authorVaxry <43317083+vaxerski@users.noreply.github.com>2024-06-11 17:17:45 +0200
committerGitHub <noreply@github.com>2024-06-11 17:17:45 +0200
commit8c64a4bad710fb18e9b84812bd680a89d1e93661 (patch)
tree2439b8408abd8e14f6af35ef9cfbeb7c51429f99 /src/helpers/MiscFunctions.cpp
parent1f46296ea05f9a8e6020ab694b531c91a1abdfa6 (diff)
core: move to hyprutils for utils (#6385)
* core: move to hyprutils for utils Nix: add hyprutils dep * Meson: add hyprutils dep * flake.lock: update --------- Co-authored-by: Mihai Fufezan <mihai@fufexan.net>
Diffstat (limited to 'src/helpers/MiscFunctions.cpp')
-rw-r--r--src/helpers/MiscFunctions.cpp61
1 files changed, 5 insertions, 56 deletions
diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp
index 32cd9868..b1d734c8 100644
--- a/src/helpers/MiscFunctions.cpp
+++ b/src/helpers/MiscFunctions.cpp
@@ -13,6 +13,8 @@
#ifdef HAS_EXECINFO
#include <execinfo.h>
#endif
+#include <hyprutils/string/String.hpp>
+using namespace Hyprutils::String;
#if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
#include <sys/sysctl.h>
@@ -195,25 +197,6 @@ std::string escapeJSONStrings(const std::string& str) {
return oss.str();
}
-std::string removeBeginEndSpacesTabs(std::string str) {
- if (str.empty())
- return str;
-
- int countBefore = 0;
- while (str[countBefore] == ' ' || str[countBefore] == '\t') {
- countBefore++;
- }
-
- int countAfter = 0;
- while ((int)str.length() - countAfter - 1 >= 0 && (str[str.length() - countAfter - 1] == ' ' || str[str.length() - 1 - countAfter] == '\t')) {
- countAfter++;
- }
-
- str = str.substr(countBefore, str.length() - countBefore - countAfter);
-
- return str;
-}
-
std::optional<float> getPlusMinusKeywordResult(std::string source, float relative) {
try {
return relative + stof(source);
@@ -223,31 +206,6 @@ std::optional<float> getPlusMinusKeywordResult(std::string source, float relativ
}
}
-bool isNumber(const std::string& str, bool allowfloat) {
-
- std::string copy = str;
- if (*copy.begin() == '-')
- copy = copy.substr(1);
-
- if (copy.empty())
- return false;
-
- bool point = !allowfloat;
- for (auto& c : copy) {
- if (c == '.') {
- if (point)
- return false;
- point = true;
- continue;
- }
-
- if (!std::isdigit(c))
- return false;
- }
-
- return true;
-}
-
bool isDirection(const std::string& arg) {
return arg == "l" || arg == "r" || arg == "u" || arg == "d" || arg == "t" || arg == "b";
}
@@ -579,7 +537,7 @@ int getWorkspaceIDFromString(const std::string& in, std::string& outName) {
std::optional<std::string> cleanCmdForWorkspace(const std::string& inWorkspaceName, std::string dirtyCmd) {
- std::string cmd = removeBeginEndSpacesTabs(dirtyCmd);
+ std::string cmd = trim(dirtyCmd);
if (!cmd.empty()) {
std::string rules;
@@ -748,7 +706,7 @@ int64_t configStringToInt(const std::string& VALUE) {
} else if (VALUE.starts_with("rgba(") && VALUE.ends_with(')')) {
const auto VALUEWITHOUTFUNC = VALUE.substr(5, VALUE.length() - 6);
- if (removeBeginEndSpacesTabs(VALUEWITHOUTFUNC).length() != 8) {
+ if (trim(VALUEWITHOUTFUNC).length() != 8) {
Debug::log(WARN, "invalid length {} for rgba", VALUEWITHOUTFUNC.length());
throw std::invalid_argument("rgba() expects length of 8 characters (4 bytes)");
}
@@ -760,7 +718,7 @@ int64_t configStringToInt(const std::string& VALUE) {
} else if (VALUE.starts_with("rgb(") && VALUE.ends_with(')')) {
const auto VALUEWITHOUTFUNC = VALUE.substr(4, VALUE.length() - 5);
- if (removeBeginEndSpacesTabs(VALUEWITHOUTFUNC).length() != 6) {
+ if (trim(VALUEWITHOUTFUNC).length() != 6) {
Debug::log(WARN, "invalid length {} for rgb", VALUEWITHOUTFUNC.length());
throw std::invalid_argument("rgb() expects length of 6 characters (3 bytes)");
}
@@ -822,15 +780,6 @@ double normalizeAngleRad(double ang) {
return ang;
}
-std::string replaceInString(std::string subject, const std::string& search, const std::string& replace) {
- size_t pos = 0;
- while ((pos = subject.find(search, pos)) != std::string::npos) {
- subject.replace(pos, search.length(), replace);
- pos += replace.length();
- }
- return subject;
-}
-
std::vector<SCallstackFrameInfo> getBacktrace() {
std::vector<SCallstackFrameInfo> callstack;