From 8c64a4bad710fb18e9b84812bd680a89d1e93661 Mon Sep 17 00:00:00 2001 From: Vaxry <43317083+vaxerski@users.noreply.github.com> Date: Tue, 11 Jun 2024 17:17:45 +0200 Subject: 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 --- src/helpers/MiscFunctions.cpp | 61 ++++--------------------------------------- 1 file changed, 5 insertions(+), 56 deletions(-) (limited to 'src/helpers/MiscFunctions.cpp') 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 #endif +#include +using namespace Hyprutils::String; #if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) #include @@ -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 getPlusMinusKeywordResult(std::string source, float relative) { try { return relative + stof(source); @@ -223,31 +206,6 @@ std::optional 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 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 getBacktrace() { std::vector callstack; -- cgit v1.2.3