summaryrefslogtreecommitdiff
path: root/src/helpers/MiscFunctions.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/helpers/MiscFunctions.cpp')
-rw-r--r--src/helpers/MiscFunctions.cpp113
1 files changed, 0 insertions, 113 deletions
diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp
index 5aa58a2c..e0903069 100644
--- a/src/helpers/MiscFunctions.cpp
+++ b/src/helpers/MiscFunctions.cpp
@@ -572,119 +572,6 @@ int64_t getPPIDof(int64_t pid) {
#endif
}
-std::expected<int64_t, std::string> configStringToInt(const std::string& VALUE) {
- auto parseHex = [](const std::string& value) -> std::expected<int64_t, std::string> {
- try {
- size_t position;
- auto result = stoll(value, &position, 16);
- if (position == value.size())
- return result;
- } catch (const std::exception&) {}
- return std::unexpected("invalid hex " + value);
- };
- if (VALUE.starts_with("0x")) {
- // Values with 0x are hex
- return parseHex(VALUE);
- } else if (VALUE.starts_with("rgba(") && VALUE.ends_with(')')) {
- const auto VALUEWITHOUTFUNC = trim(VALUE.substr(5, VALUE.length() - 6));
-
- // try doing it the comma way first
- if (std::ranges::count(VALUEWITHOUTFUNC, ',') == 3) {
- // cool
- std::string rolling = VALUEWITHOUTFUNC;
- auto r = configStringToInt(trim(rolling.substr(0, rolling.find(','))));
- rolling = rolling.substr(rolling.find(',') + 1);
- auto g = configStringToInt(trim(rolling.substr(0, rolling.find(','))));
- rolling = rolling.substr(rolling.find(',') + 1);
- auto b = configStringToInt(trim(rolling.substr(0, rolling.find(','))));
- rolling = rolling.substr(rolling.find(',') + 1);
- uint8_t a = 0;
-
- if (!r || !g || !b)
- return std::unexpected("failed parsing " + VALUEWITHOUTFUNC);
-
- try {
- a = std::round(std::stof(trim(rolling.substr(0, rolling.find(',')))) * 255.f);
- } catch (std::exception& e) { return std::unexpected("failed parsing " + VALUEWITHOUTFUNC); }
-
- return a * sc<Config::INTEGER>(0x1000000) + *r * sc<Config::INTEGER>(0x10000) + *g * sc<Config::INTEGER>(0x100) + *b;
- } else if (VALUEWITHOUTFUNC.length() == 8) {
- const auto RGBA = parseHex(VALUEWITHOUTFUNC);
-
- if (!RGBA)
- return RGBA;
- // now we need to RGBA -> ARGB. The config holds ARGB only.
- return (*RGBA >> 8) + 0x1000000 * (*RGBA & 0xFF);
- }
-
- return std::unexpected("rgba() expects length of 8 characters (4 bytes) or 4 comma separated values");
-
- } else if (VALUE.starts_with("rgb(") && VALUE.ends_with(')')) {
- const auto VALUEWITHOUTFUNC = trim(VALUE.substr(4, VALUE.length() - 5));
-
- // try doing it the comma way first
- if (std::ranges::count(VALUEWITHOUTFUNC, ',') == 2) {
- // cool
- std::string rolling = VALUEWITHOUTFUNC;
- auto r = configStringToInt(trim(rolling.substr(0, rolling.find(','))));
- rolling = rolling.substr(rolling.find(',') + 1);
- auto g = configStringToInt(trim(rolling.substr(0, rolling.find(','))));
- rolling = rolling.substr(rolling.find(',') + 1);
- auto b = configStringToInt(trim(rolling.substr(0, rolling.find(','))));
-
- if (!r || !g || !b)
- return std::unexpected("failed parsing " + VALUEWITHOUTFUNC);
-
- return sc<Config::INTEGER>(0xFF000000) + *r * sc<Config::INTEGER>(0x10000) + *g * sc<Config::INTEGER>(0x100) + *b;
- } else if (VALUEWITHOUTFUNC.length() == 6) {
- auto r = parseHex(VALUEWITHOUTFUNC);
- return r ? *r + 0xFF000000 : r;
- }
-
- return std::unexpected("rgb() expects length of 6 characters (3 bytes) or 3 comma separated values");
- } else if (VALUE.starts_with("true") || VALUE.starts_with("on") || VALUE.starts_with("yes")) {
- return 1;
- } else if (VALUE.starts_with("false") || VALUE.starts_with("off") || VALUE.starts_with("no")) {
- return 0;
- }
-
- if (VALUE.empty() || !isNumber(VALUE, false))
- return std::unexpected("cannot parse \"" + VALUE + "\" as an int.");
-
- try {
- const auto RES = std::stoll(VALUE);
- return RES;
- } catch (std::exception& e) { return std::unexpected(std::string{"stoll threw: "} + e.what()); }
-
- return std::unexpected("parse error");
-}
-
-Vector2D configStringToVector2D(const std::string& VALUE) {
- std::istringstream iss(VALUE);
- std::string token;
-
- if (!std::getline(iss, token, ' ') && !std::getline(iss, token, ','))
- throw std::invalid_argument("Invalid string format");
-
- if (!isNumber(token))
- throw std::invalid_argument("Invalid x value");
-
- long long x = std::stoll(token);
-
- if (!std::getline(iss, token))
- throw std::invalid_argument("Invalid string format");
-
- if (!isNumber(token))
- throw std::invalid_argument("Invalid y value");
-
- long long y = std::stoll(token);
-
- if (std::getline(iss, token))
- throw std::invalid_argument("Invalid string format");
-
- return Vector2D(sc<double>(x), sc<double>(y));
-}
-
double normalizeAngleRad(double ang) {
if (ang > M_PI * 2) {
while (ang > M_PI * 2)