gnucash master: [c++ options] Fix locale dependency in test-gnc-option-scheme-output.

John Ralls jralls at code.gnucash.org
Thu Mar 2 15:34:12 EST 2023


Updated	 via  https://github.com/Gnucash/gnucash/commit/1eecb9f5 (commit)
	from  https://github.com/Gnucash/gnucash/commit/e9f6bf7a (commit)



commit 1eecb9f5c0d50cd9f409177542f8295182c7f982
Author: John Ralls <jralls at ceridwen.us>
Date:   Thu Mar 2 12:19:19 2023 -0800

    [c++ options] Fix locale dependency in test-gnc-option-scheme-output.
    
    Created by using std::to_string() in GncOptionRangeValue::serialize.
    It wraps sprintf that reads the locale. Use ostringstream instead.

diff --git a/bindings/guile/test/test-gnc-option-scheme-output.scm b/bindings/guile/test/test-gnc-option-scheme-output.scm
index e1a960299..f133c297f 100644
--- a/bindings/guile/test/test-gnc-option-scheme-output.scm
+++ b/bindings/guile/test/test-gnc-option-scheme-output.scm
@@ -139,7 +139,7 @@
 " (if (exact-integer? value)
       (if (< value 100)
           (format #f "'(percent . ~d)" value)
-          (format #f "'(pixels . ~f)" value))
+          (format #f "'(pixels . ~d)" value))
       (format #f "'~f" value)
       )))
 
diff --git a/libgnucash/engine/gnc-option-impl.cpp b/libgnucash/engine/gnc-option-impl.cpp
index 820e8e88a..0f61e0995 100644
--- a/libgnucash/engine/gnc-option-impl.cpp
+++ b/libgnucash/engine/gnc-option-impl.cpp
@@ -21,7 +21,6 @@
  *                                                                  *
 \********************************************************************/
 
-//#include "options.h"
 #include "gnc-option-impl.hpp"
 #include "gnc-datetime.hpp"
 #include "guid.hpp"
@@ -832,7 +831,13 @@ template <typename ValueType> std::string
 GncOptionRangeValue<ValueType>::serialize() const noexcept
 {
     if constexpr (std::is_arithmetic_v<ValueType>)
-        return std::to_string(m_value);
+    {
+        std::ostringstream ostr;
+        if constexpr(is_same_decayed_v<ValueType, double>)
+            ostr << std::showpoint << std::fixed;
+        ostr << m_value;
+        return ostr.str();
+    }
     return "";
 }
 



Summary of changes:
 bindings/guile/test/test-gnc-option-scheme-output.scm | 2 +-
 libgnucash/engine/gnc-option-impl.cpp                 | 9 +++++++--
 2 files changed, 8 insertions(+), 3 deletions(-)



More information about the gnucash-changes mailing list