Skip to content

Commit

Permalink
fix(Archive): only use std::to_chars for integers
Browse files Browse the repository at this point in the history
  • Loading branch information
lmichaelis committed Dec 27, 2023
1 parent 7f87774 commit 815e503
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/archive/ArchiveAscii.cc
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ namespace zenkit {
}

template <typename T, size_t N>
std::string_view intosv(std::array<char, N>& buf, T v) {
std::enable_if_t<!std::is_floating_point_v<T>, std::string_view> intosv(std::array<char, N>& buf, T v) {
auto r = std::to_chars(buf.begin(), buf.end(), v);
return std::string_view {buf.begin(), static_cast<size_t>(r.ptr - buf.begin())};
}
Expand Down Expand Up @@ -324,9 +324,7 @@ namespace zenkit {
}

void WriteArchiveAscii::write_float(std::string_view name, float v) {
std::array<char, std::numeric_limits<float>::max_exponent10 + std::numeric_limits<float>::max_digits10 + 2>
buf {};
this->write_entry(name, "float", intosv(buf, v));
this->write_entry(name, "float", std::to_string(v));
}

void WriteArchiveAscii::write_byte(std::string_view name, std::uint8_t v) {
Expand Down Expand Up @@ -400,10 +398,8 @@ namespace zenkit {
this->_m_write->write_string(name);
this->_m_write->write_string("=rawFloat:");

std::array<char, std::numeric_limits<float>::max_exponent10 + std::numeric_limits<float>::max_digits10 + 2>
buf {};
for (auto i = 0u; i < length; ++i) {
this->_m_write->write_string(intosv(buf, v[i]));
this->_m_write->write_string(std::to_string(v[i]));
this->_m_write->write_char(' ');
}

Expand Down

0 comments on commit 815e503

Please sign in to comment.