From f025c9cd6f0396408ddc21483088d37fa44ff4a3 Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Thu, 7 Jul 2022 15:43:32 +0200 Subject: [PATCH] Adding overload for string conversion to float directly --- src/libslic3r/LocalesUtils.cpp | 16 +++++++++++++--- src/libslic3r/LocalesUtils.hpp | 1 + 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/libslic3r/LocalesUtils.cpp b/src/libslic3r/LocalesUtils.cpp index da372ba3fd..1be8e88e15 100644 --- a/src/libslic3r/LocalesUtils.cpp +++ b/src/libslic3r/LocalesUtils.cpp @@ -51,16 +51,26 @@ bool is_decimal_separator_point() return str[1] == '.'; } - -double string_to_double_decimal_point(const std::string_view str, size_t* pos /* = nullptr*/) +template +static T string_to_floating_decimal_point(const std::string_view str, size_t* pos /* = nullptr*/) { - double out; + T out; size_t p = fast_float::from_chars(str.data(), str.data() + str.size(), out).ptr - str.data(); if (pos) *pos = p; return out; } +double string_to_double_decimal_point(const std::string_view str, size_t* pos /* = nullptr*/) +{ + return string_to_floating_decimal_point(str, pos); +} + +float string_to_float_decimal_point(const std::string_view str, size_t* pos /* = nullptr*/) +{ + return string_to_floating_decimal_point(str, pos); +} + std::string float_to_string_decimal_point(double value, int precision/* = -1*/) { // Our Windows build server fully supports C++17 std::to_chars. Let's use it. diff --git a/src/libslic3r/LocalesUtils.hpp b/src/libslic3r/LocalesUtils.hpp index ce8030cebc..aec50fd9d1 100644 --- a/src/libslic3r/LocalesUtils.hpp +++ b/src/libslic3r/LocalesUtils.hpp @@ -42,6 +42,7 @@ bool is_decimal_separator_point(); std::string float_to_string_decimal_point(double value, int precision = -1); //std::string float_to_string_decimal_point(float value, int precision = -1); double string_to_double_decimal_point(const std::string_view str, size_t* pos = nullptr); +float string_to_float_decimal_point (const std::string_view str, size_t* pos = nullptr); // Set locales to "C". inline void set_c_locales()