Skip to content

Commit

Permalink
refactor: make parsing sort-by more lenient
Browse files Browse the repository at this point in the history
  • Loading branch information
khaneliman committed Sep 9, 2023
1 parent 8ea2626 commit 8ce64ea
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion include/util/enum.hpp
Expand Up @@ -12,10 +12,16 @@ struct EnumParser {
enum SORT_METHOD { ID, NAME, NUMBER, DEFAULT };

SORT_METHOD sortStringToEnum(const std::string& str) {
// Convert the input string to uppercase (make it lenient on config input)
std::string uppercaseStr;
for (char c : str) {
uppercaseStr += std::toupper(c);
}

static const std::map<std::string, SORT_METHOD> enumMap = {
{"ID", ID}, {"NAME", NAME}, {"NUMBER", NUMBER}, {"DEFAULT", DEFAULT}};

auto it = enumMap.find(str);
auto it = enumMap.find(uppercaseStr);
if (it != enumMap.end()) {
return it->second;
} else {
Expand Down

0 comments on commit 8ce64ea

Please sign in to comment.