a bit of refactoring

This commit is contained in:
2021-12-18 14:52:33 +01:00
parent 906df74847
commit eebb270f47
11 changed files with 96 additions and 96 deletions

View File

@@ -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) {