mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-02-06 13:54:14 +01:00
[util] Make bool and tristate options case-insensitive
This commit is contained in:
parent
dd7ffbc803
commit
9eb83c187c
@ -1,7 +1,9 @@
|
|||||||
|
#include <array>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
@ -573,15 +575,13 @@ namespace dxvk {
|
|||||||
bool Config::parseOptionValue(
|
bool Config::parseOptionValue(
|
||||||
const std::string& value,
|
const std::string& value,
|
||||||
bool& result) {
|
bool& result) {
|
||||||
if (value == "True") {
|
static const std::array<std::pair<const char*, bool>, 2> s_lookup = {{
|
||||||
result = true;
|
{ "true", true },
|
||||||
return true;
|
{ "false", false },
|
||||||
} else if (value == "False") {
|
}};
|
||||||
result = false;
|
|
||||||
return true;
|
return parseStringOption(value,
|
||||||
} else {
|
s_lookup.begin(), s_lookup.end(), result);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -620,18 +620,34 @@ namespace dxvk {
|
|||||||
bool Config::parseOptionValue(
|
bool Config::parseOptionValue(
|
||||||
const std::string& value,
|
const std::string& value,
|
||||||
Tristate& result) {
|
Tristate& result) {
|
||||||
if (value == "True") {
|
static const std::array<std::pair<const char*, Tristate>, 3> s_lookup = {{
|
||||||
result = Tristate::True;
|
{ "true", Tristate::True },
|
||||||
return true;
|
{ "false", Tristate::False },
|
||||||
} else if (value == "False") {
|
{ "auto", Tristate::Auto },
|
||||||
result = Tristate::False;
|
}};
|
||||||
return true;
|
|
||||||
} else if (value == "Auto") {
|
return parseStringOption(value,
|
||||||
result = Tristate::Auto;
|
s_lookup.begin(), s_lookup.end(), result);
|
||||||
return true;
|
}
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
|
template<typename I, typename V>
|
||||||
|
bool Config::parseStringOption(
|
||||||
|
std::string str,
|
||||||
|
I begin,
|
||||||
|
I end,
|
||||||
|
V& value) {
|
||||||
|
std::transform(str.begin(), str.end(), str.begin(),
|
||||||
|
[] (unsigned char c) { return (c >= 'A' && c <= 'Z') ? (c + 'a' - 'A') : c; });
|
||||||
|
|
||||||
|
for (auto i = begin; i != end; i++) {
|
||||||
|
if (str == i->first) {
|
||||||
|
value = i->second;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -125,6 +125,13 @@ namespace dxvk {
|
|||||||
const std::string& value,
|
const std::string& value,
|
||||||
Tristate& result);
|
Tristate& result);
|
||||||
|
|
||||||
|
template<typename I, typename V>
|
||||||
|
static bool parseStringOption(
|
||||||
|
std::string str,
|
||||||
|
I begin,
|
||||||
|
I end,
|
||||||
|
V& value);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user