28 lines
619 B
C++
28 lines
619 B
C++
#pragma once
|
|
|
|
#include <optional>
|
|
#include <string>
|
|
namespace bts {
|
|
|
|
inline std::string uppercase_copy(const std::string &cs) {
|
|
std::string s = cs;
|
|
std::transform(s.begin(), s.end(), s.begin(), ::toupper);
|
|
return s;
|
|
}
|
|
|
|
template <class T, class T2>
|
|
std::optional<T>
|
|
parse_enum(const std::string &value, const std::string &prefix, T2 parse) {
|
|
auto temp = value;
|
|
T result;
|
|
if (temp.find(prefix) == std::string::npos) {
|
|
temp = prefix + "_" + temp;
|
|
}
|
|
if (parse(temp, &result)) {
|
|
return {result};
|
|
} else {
|
|
return std::nullopt;
|
|
}
|
|
}
|
|
} // namespace bts
|