IfcParse: drop ostringstream from format_double per review #7696

std::to_chars is locale-independent, so the ostringstream and imbue(locale)
are no longer needed. Build the REAL string with plain std::string operations.
Output is unchanged (verified in standalone compile: same shortest values, all
round-trip). Addresses review feedback on #8309.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Petru Conduraru
2026-07-06 13:54:34 +03:00
committed by Thomas Krijnen
parent ee2b357d74
commit fa597536e1
+8 -9
View File
@@ -759,25 +759,24 @@ namespace {
// values with noise digits (0.0174532925199433 -> 0.017453292519943299), // values with noise digits (0.0174532925199433 -> 0.017453292519943299),
// which rewrote every REAL and produced huge diffs when a file was // which rewrote every REAL and produced huge diffs when a file was
// re-saved. See #7696. // re-saved. See #7696.
// std::to_chars is locale-independent, so no ostringstream/imbue is
// needed here.
char buf[64]; char buf[64];
const auto res = std::to_chars(buf, buf + sizeof(buf), d); const auto res = std::to_chars(buf, buf + sizeof(buf), d);
const std::string str(buf, res.ptr); const std::string str(buf, res.ptr);
std::ostringstream oss;
oss.imbue(std::locale::classic());
std::string::size_type e = str.find('e'); std::string::size_type e = str.find('e');
if (e == std::string::npos) { if (e == std::string::npos) {
e = str.find('E'); e = str.find('E');
} }
const std::string mantissa = str.substr(0, e); std::string result = str.substr(0, e);
oss << mantissa; if (result.find('.') == std::string::npos) {
if (mantissa.find('.') == std::string::npos) { result += '.';
oss << ".";
} }
if (e != std::string::npos) { if (e != std::string::npos) {
oss << "E"; result += 'E';
oss << str.substr(e + 1); result += str.substr(e + 1);
} }
return oss.str(); return result;
} }
static std::string format_binary(const boost::dynamic_bitset<>& b) { static std::string format_binary(const boost::dynamic_bitset<>& b) {