mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-27 05:55:02 +03:00
new files
This commit is contained in:
parent
023a946a5b
commit
2483c3595b
24
probingpt/util.cpp
Normal file
24
probingpt/util.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
#include "util.hh"
|
||||
#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 ;
|
||||
}
|
||||
|
||||
}
|
24
probingpt/util.hh
Normal file
24
probingpt/util.hh
Normal file
@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
namespace probingpt
|
||||
{
|
||||
|
||||
//! convert string to variable of type T. Used to reading floats, int etc from files
|
||||
template<typename T>
|
||||
inline T Scan(const std::string &input)
|
||||
{
|
||||
std::stringstream stream(input);
|
||||
T ret;
|
||||
stream >> ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
//! Specialisation to understand yes/no y/n true/false 0/1
|
||||
template<>
|
||||
bool Scan<bool>(const std::string &input);
|
||||
|
||||
const std::string ToLower(const std::string& str);
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user