2023-09-09 14:32:55 +00:00
|
|
|
#pragma once
|
|
|
|
|
2023-09-09 16:18:12 +00:00
|
|
|
#include <cctype>
|
2023-09-09 14:32:55 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <map>
|
2023-09-09 16:18:12 +00:00
|
|
|
#include <stdexcept>
|
2023-09-09 14:32:55 +00:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
namespace waybar::util {
|
|
|
|
|
2023-09-09 16:18:12 +00:00
|
|
|
template <typename EnumType>
|
2023-09-09 14:32:55 +00:00
|
|
|
struct EnumParser {
|
|
|
|
EnumParser() {}
|
|
|
|
|
2023-09-09 16:18:12 +00:00
|
|
|
EnumType sortStringToEnum(const std::string& str,
|
|
|
|
const std::map<std::string, EnumType>& enumMap) {
|
|
|
|
// Convert the input string to uppercase
|
2023-09-09 14:38:03 +00:00
|
|
|
std::string uppercaseStr;
|
|
|
|
for (char c : str) {
|
2023-09-09 16:18:12 +00:00
|
|
|
uppercaseStr += std::toupper(c);
|
2023-09-09 14:38:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
auto it = enumMap.find(uppercaseStr);
|
2023-09-09 14:32:55 +00:00
|
|
|
if (it != enumMap.end()) {
|
|
|
|
return it->second;
|
|
|
|
} else {
|
|
|
|
throw std::invalid_argument("Invalid string representation for enum");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
~EnumParser() = default;
|
|
|
|
};
|
|
|
|
} // namespace waybar::util
|