mosesdecoder/probingpt/util.cpp
2017-07-19 22:44:32 +01:00

26 lines
653 B
C++

#include <cctype>
#include "util.h"
#include "util/exception.hh"
namespace probingpt
{
template<>
bool Scan<bool>(const std::string &input)
{
std::string lc = ToLower(input);
if (lc == "yes" || lc == "y" || lc == "true" || lc == "1") return true;
if (lc == "no" || lc == "n" || lc == "false" || lc == "0") return false;
UTIL_THROW2("Could not interpret " << input << " as a boolean. After lowercasing, valid values are yes, y, true, 1, no, n, false, and 0.");
}
const std::string ToLower(const std::string& str)
{
std::string lc(str);
std::transform(lc.begin(), lc.end(), lc.begin(), (int (*)(int))std::tolower);
return
lc ;
}
}