mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-15 22:05:53 +08:00
Adding overload for string conversion to float directly
This commit is contained in:
parent
bea962b6fe
commit
f025c9cd6f
@ -51,16 +51,26 @@ bool is_decimal_separator_point()
|
|||||||
return str[1] == '.';
|
return str[1] == '.';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class T>
|
||||||
double string_to_double_decimal_point(const std::string_view str, size_t* pos /* = nullptr*/)
|
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();
|
size_t p = fast_float::from_chars(str.data(), str.data() + str.size(), out).ptr - str.data();
|
||||||
if (pos)
|
if (pos)
|
||||||
*pos = p;
|
*pos = p;
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double string_to_double_decimal_point(const std::string_view str, size_t* pos /* = nullptr*/)
|
||||||
|
{
|
||||||
|
return string_to_floating_decimal_point<double>(str, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
float string_to_float_decimal_point(const std::string_view str, size_t* pos /* = nullptr*/)
|
||||||
|
{
|
||||||
|
return string_to_floating_decimal_point<float>(str, pos);
|
||||||
|
}
|
||||||
|
|
||||||
std::string float_to_string_decimal_point(double value, int precision/* = -1*/)
|
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.
|
// Our Windows build server fully supports C++17 std::to_chars. Let's use it.
|
||||||
|
@ -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(double value, int precision = -1);
|
||||||
//std::string float_to_string_decimal_point(float 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);
|
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".
|
// Set locales to "C".
|
||||||
inline void set_c_locales()
|
inline void set_c_locales()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user