15bool parseUnsigned(
const std::string& text, T& value,
int base = 10) noexcept {
16 static_assert(std::is_integral_v<T> && std::is_unsigned_v<T>);
23 const char* begin = text.data();
24 const char* end = text.data() + text.size();
25 const auto result = std::from_chars(begin, end, parsed, base);
26 if (result.ec != std::errc() || result.ptr != end) {
35bool parseSigned(
const std::string& text, T& value,
int base = 10) noexcept {
36 static_assert(std::is_integral_v<T> && std::is_signed_v<T>);
43 const char* begin = text.data();
44 const char* end = text.data() + text.size();
45 const auto result = std::from_chars(begin, end, parsed, base);
46 if (result.ec != std::errc() || result.ptr != end) {
54inline bool parseDouble(
const std::string& text,
double& value)
noexcept {
61 const double parsed = std::strtod(text.c_str(), &end);
62 if (errno == ERANGE || end != text.c_str() + text.size()) {
70inline bool parseLongDouble(
const std::string& text,
long double& value)
noexcept {
77 const long double parsed = std::strtold(text.c_str(), &end);
78 if (errno == ERANGE || end != text.c_str() + text.size()) {
124 long double raw = 0.0L;
129 const long double degrees = std::floor(raw / 100.0L);
130 const long double minutes = raw - (degrees * 100.0L);
131 value =
static_cast<double>(degrees + (minutes / 60.0L));
bool parseLongDouble(const std::string &text, long double &value) noexcept
bool parseNmeaCoordinate(const std::string &text, double &value) noexcept
bool parseDouble(const std::string &text, double &value) noexcept
bool parseOptionalInt(const std::string &text, int &value) noexcept
bool parseUnsigned(const std::string &text, T &value, int base=10) noexcept
bool parseOptionalUnsigned(const std::string &text, unsigned int &value) noexcept
bool parseOptionalLongDouble(const std::string &text, long double &value) noexcept
bool parseOptionalDouble(const std::string &text, double &value) noexcept
bool parseSigned(const std::string &text, T &value, int base=10) noexcept