a bit of refactoring
This commit is contained in:
19
settings.cpp
19
settings.cpp
@@ -1,4 +1,6 @@
|
||||
|
||||
#include "fast_double_parser.h"
|
||||
|
||||
#include "settings.h"
|
||||
#include "exception.h"
|
||||
#include "ml_date.h"
|
||||
@@ -14,17 +16,26 @@ std::vector<std::pair<std::string, std::string>> Settings::m_settings =
|
||||
|
||||
|
||||
|
||||
long Settings::string_to_int(const std::string &intstr) {
|
||||
return std::stoi(intstr);
|
||||
long Settings::string_to_long(const std::string &intstr) {
|
||||
try {
|
||||
return std::stol(intstr);
|
||||
} catch (std::invalid_argument &e) {
|
||||
throw Exception("error parsing as integer: " + intstr);
|
||||
}
|
||||
}
|
||||
|
||||
std::string Settings::int_to_string(long intval) {
|
||||
std::string Settings::long_to_string(long intval) {
|
||||
return std::to_string(intval);
|
||||
}
|
||||
|
||||
|
||||
double Settings::string_to_double(const std::string &doublestr) {
|
||||
return std::stod(doublestr); // TODO use fast parsing
|
||||
double result;
|
||||
const char * endptr = fast_double_parser::parse_number(doublestr.c_str(), &result);
|
||||
if (endptr == nullptr) {
|
||||
throw Exception("error parsing as double: " + doublestr);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string Settings::double_to_string(double d) {
|
||||
|
||||
Reference in New Issue
Block a user