summaryrefslogtreecommitdiff
path: root/src/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'src/helpers')
-rw-r--r--src/helpers/MiscFunctions.cpp26
-rw-r--r--src/helpers/MiscFunctions.hpp1
2 files changed, 27 insertions, 0 deletions
diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp
index 2905ce2b..860d8456 100644
--- a/src/helpers/MiscFunctions.cpp
+++ b/src/helpers/MiscFunctions.cpp
@@ -722,6 +722,32 @@ int64_t configStringToInt(const std::string& VALUE) {
return std::stoll(VALUE);
}
+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(x, y);
+}
+
double normalizeAngleRad(double ang) {
if (ang > M_PI * 2) {
while (ang > M_PI * 2)
diff --git a/src/helpers/MiscFunctions.hpp b/src/helpers/MiscFunctions.hpp
index 23fc6e5a..d8a86b95 100644
--- a/src/helpers/MiscFunctions.hpp
+++ b/src/helpers/MiscFunctions.hpp
@@ -28,6 +28,7 @@ void logSystemInfo();
std::string execAndGet(const char*);
int64_t getPPIDof(int64_t pid);
int64_t configStringToInt(const std::string&);
+Vector2D configStringToVector2D(const std::string&);
std::optional<float> getPlusMinusKeywordResult(std::string in, float relative);
void matrixProjection(float mat[9], int w, int h, wl_output_transform tr);
double normalizeAngleRad(double ang);