fixed backend tests (progress)
This commit is contained in:
@@ -131,7 +131,7 @@ result<DestType, conversion_error> to(const std::string &source, std::enable_if_
|
||||
}
|
||||
|
||||
template < typename DestType >
|
||||
result<DestType, conversion_error> to(const std::string &source, std::enable_if_t<std::is_integral_v<DestType> && std::is_unsigned_v<DestType>>* = nullptr)
|
||||
result<DestType, conversion_error> to(const std::string &source, std::enable_if_t<std::is_integral_v<DestType> && std::is_unsigned_v<DestType> && !std::is_same_v<DestType, bool>>* = nullptr)
|
||||
{
|
||||
if (source.empty()) {
|
||||
return failure(conversion_error::MissingData/*, "failed to convert empty string"}*/);
|
||||
@@ -167,17 +167,27 @@ result<DestType, conversion_error> to(const blob &source, std::enable_if_t<std::
|
||||
return ok(source);
|
||||
}
|
||||
|
||||
// template < typename DestType >
|
||||
// result<DestType, conversion_error> to(const std::string &source, std::enable_if_t<std::is_same_v<DestType, blob>>* = nullptr) {
|
||||
// if (source.empty()) {
|
||||
// return failure(conversion_error::MissingData/*, "failed to convert empty string"}*/);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
static std::unordered_map<std::string, bool> string_to_bool_map = {
|
||||
{"true", true},
|
||||
{"t", true},
|
||||
{"on", true},
|
||||
{"1", true},
|
||||
{"false", false},
|
||||
{"f", false},
|
||||
{"off", false},
|
||||
{"0", false}
|
||||
};
|
||||
|
||||
template < typename DestType, typename SourceType >
|
||||
result<DestType, conversion_error> to(const SourceType &source, std::enable_if_t<std::is_same_v<SourceType, std::string> &&std::is_same_v<DestType, bool>>* = nullptr) {
|
||||
template < typename DestType >
|
||||
result<DestType, conversion_error> to(const std::string &source, std::enable_if_t<std::is_same_v<DestType, bool>>* = nullptr) {
|
||||
if (source.empty()) {
|
||||
return failure(conversion_error::MissingData);
|
||||
}
|
||||
@@ -188,6 +198,18 @@ result<DestType, conversion_error> to(const SourceType &source, std::enable_if_t
|
||||
return ok(it->second);
|
||||
}
|
||||
|
||||
template < typename DestType >
|
||||
result<DestType, conversion_error> to(const char *source, std::enable_if_t<std::is_same_v<DestType, bool>>* = nullptr) {
|
||||
if (strlen(source) == 0) {
|
||||
return failure(conversion_error::MissingData);
|
||||
}
|
||||
const auto it = string_to_bool_map.find(source);
|
||||
if (it == string_to_bool_map.end()) {
|
||||
return failure(conversion_error::NotConvertable);
|
||||
}
|
||||
return ok(it->second);
|
||||
}
|
||||
|
||||
template < typename DestType, typename SourceType >
|
||||
result<DestType, conversion_error> to(const SourceType &source, std::enable_if_t<std::is_same_v<SourceType, bool> &&std::is_same_v<DestType, std::string>>* = nullptr) {
|
||||
return ok(std::string(source ? "true" : "false"));
|
||||
|
||||
Reference in New Issue
Block a user