diff options
| author | vaxerski <43317083+vaxerski@users.noreply.github.com> | 2022-04-20 16:53:41 +0200 |
|---|---|---|
| committer | vaxerski <43317083+vaxerski@users.noreply.github.com> | 2022-04-20 16:53:41 +0200 |
| commit | 87b849129427ab664130aa1abc8ade0485328e33 (patch) | |
| tree | 7275db50df7f47389d1f91948cede19ded8c26a5 /src/helpers | |
| parent | 418e2d96aef0b52d1f93eb3dfe7d08906c7c719c (diff) | |
Added the splitratio dispatcher
Diffstat (limited to 'src/helpers')
| -rw-r--r-- | src/helpers/MiscFunctions.cpp | 38 | ||||
| -rw-r--r-- | src/helpers/MiscFunctions.hpp | 4 |
2 files changed, 41 insertions, 1 deletions
diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp index 63751781..489fa02a 100644 --- a/src/helpers/MiscFunctions.cpp +++ b/src/helpers/MiscFunctions.cpp @@ -73,4 +73,42 @@ std::string removeBeginEndSpacesTabs(std::string str) { } return str; +} + +float getPlusMinusKeywordResult(std::string source, float relative) { + float result = INT_MAX; + + if (source.find_first_of("+") == 0) { + try { + if (source.find('.') != std::string::npos) + result = relative + std::stof(source.substr(1)); + else + result = relative + std::stoi(source.substr(1)); + } catch (...) { + Debug::log(ERR, "Invalid arg \"%s\" in getPlusMinusKeywordResult!", source.c_str()); + return INT_MAX; + } + } else if (source.find_first_of("-") == 0) { + try { + if (source.find('.') != std::string::npos) + result = relative - std::stof(source.substr(1)); + else + result = relative - std::stoi(source.substr(1)); + } catch (...) { + Debug::log(ERR, "Invalid arg \"%s\" in getPlusMinusKeywordResult!", source.c_str()); + return INT_MAX; + } + } else { + try { + if (source.find('.') != std::string::npos) + result = stof(source); + else + result = stoi(source); + } catch (...) { + Debug::log(ERR, "Invalid arg \"%s\" in getPlusMinusKeywordResult!", source.c_str()); + return INT_MAX; + } + } + + return result; }
\ No newline at end of file diff --git a/src/helpers/MiscFunctions.hpp b/src/helpers/MiscFunctions.hpp index 08e69e34..4fb42e12 100644 --- a/src/helpers/MiscFunctions.hpp +++ b/src/helpers/MiscFunctions.hpp @@ -6,4 +6,6 @@ void addWLSignal(wl_signal*, wl_listener*, void* pOwner, std::string ownerString void wlr_signal_emit_safe(struct wl_signal *signal, void *data); std::string getFormat(const char *fmt, ...); // Basically Debug::log to a string void scaleBox(wlr_box*, float); -std::string removeBeginEndSpacesTabs(std::string);
\ No newline at end of file +std::string removeBeginEndSpacesTabs(std::string); + +float getPlusMinusKeywordResult(std::string in, float relative);
\ No newline at end of file |
