From 38845775fcbb4e398638d0f30043299c81d34c01 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sat, 8 Jun 2024 23:27:27 +0200 Subject: [PATCH] core: move to hyprutils for utils --- CMakeLists.txt | 2 +- src/helpers/VarList.cpp | 55 ---------------------------- src/helpers/VarList.hpp | 63 -------------------------------- src/renderer/widgets/IWidget.cpp | 4 +- 4 files changed, 4 insertions(+), 120 deletions(-) delete mode 100644 src/helpers/VarList.cpp delete mode 100644 src/helpers/VarList.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index cfab691..7bf6a74 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,7 +39,7 @@ message(STATUS "Checking deps...") find_package(Threads REQUIRED) find_package(PkgConfig REQUIRED) find_package(OpenGL REQUIRED) -pkg_check_modules(deps REQUIRED IMPORTED_TARGET wayland-client wayland-protocols wayland-egl hyprlang>=0.4.0 egl opengl xkbcommon libjpeg libwebp libmagic cairo pangocairo libdrm gbm) +pkg_check_modules(deps REQUIRED IMPORTED_TARGET wayland-client wayland-protocols wayland-egl hyprlang>=0.4.0 egl opengl xkbcommon libjpeg libwebp libmagic cairo pangocairo libdrm gbm hyprutils>=0.1.1) file(GLOB_RECURSE SRCFILES CONFIGURE_DEPENDS "src/*.cpp") add_executable(hyprlock ${SRCFILES}) diff --git a/src/helpers/VarList.cpp b/src/helpers/VarList.cpp deleted file mode 100644 index 518acde..0000000 --- a/src/helpers/VarList.cpp +++ /dev/null @@ -1,55 +0,0 @@ -#include "VarList.hpp" -#include -#include - -static 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; -} - -CVarList::CVarList(const std::string& in, const size_t lastArgNo, const char delim, const bool removeEmpty) { - if (in.empty()) - m_vArgs.emplace_back(""); - - std::string args{in}; - size_t idx = 0; - size_t pos = 0; - std::ranges::replace_if( - args, [&](const char& c) { return delim == 's' ? std::isspace(c) : c == delim; }, 0); - - for (const auto& s : args | std::views::split(0)) { - if (removeEmpty && s.empty()) - continue; - if (++idx == lastArgNo) { - m_vArgs.emplace_back(removeBeginEndSpacesTabs(in.substr(pos))); - break; - } - pos += s.size() + 1; - m_vArgs.emplace_back(removeBeginEndSpacesTabs(std::string_view{s}.data())); - } -} - -std::string CVarList::join(const std::string& joiner, size_t from, size_t to) const { - size_t last = to == 0 ? size() : to; - - std::string rolling; - for (size_t i = from; i < last; ++i) { - rolling += m_vArgs[i] + (i + 1 < last ? joiner : ""); - } - - return rolling; -} \ No newline at end of file diff --git a/src/helpers/VarList.hpp b/src/helpers/VarList.hpp deleted file mode 100644 index 1374da6..0000000 --- a/src/helpers/VarList.hpp +++ /dev/null @@ -1,63 +0,0 @@ -#pragma once -#include -#include -#include - -class CVarList { - public: - /** Split string into arg list - @param lastArgNo stop splitting after argv reaches maximum size, last arg will contain rest of unsplit args - @param delim if delimiter is 's', use std::isspace - @param removeEmpty remove empty args from argv - */ - CVarList(const std::string& in, const size_t maxSize = 0, const char delim = ',', const bool removeEmpty = false); - - ~CVarList() = default; - - size_t size() const { - return m_vArgs.size(); - } - - std::string join(const std::string& joiner, size_t from = 0, size_t to = 0) const; - - void map(std::function func) { - for (auto& s : m_vArgs) - func(s); - } - - void append(const std::string arg) { - m_vArgs.emplace_back(arg); - } - - std::string operator[](const size_t& idx) const { - if (idx >= m_vArgs.size()) - return ""; - return m_vArgs[idx]; - } - - // for range-based loops - std::vector::iterator begin() { - return m_vArgs.begin(); - } - std::vector::const_iterator begin() const { - return m_vArgs.begin(); - } - std::vector::iterator end() { - return m_vArgs.end(); - } - std::vector::const_iterator end() const { - return m_vArgs.end(); - } - - bool contains(const std::string& el) { - for (auto& a : m_vArgs) { - if (a == el) - return true; - } - - return false; - } - - private: - std::vector m_vArgs; -}; \ No newline at end of file diff --git a/src/renderer/widgets/IWidget.cpp b/src/renderer/widgets/IWidget.cpp index b1879fc..08aa1c2 100644 --- a/src/renderer/widgets/IWidget.cpp +++ b/src/renderer/widgets/IWidget.cpp @@ -1,10 +1,12 @@ #include "IWidget.hpp" #include "../../helpers/Log.hpp" -#include "../../helpers/VarList.hpp" #include "../../core/hyprlock.hpp" #include #include #include +#include + +using namespace Hyprutils::String; #if defined(_LIBCPP_VERSION) && _LIBCPP_VERSION < 190100 #pragma comment(lib, "date-tz")