summaryrefslogtreecommitdiffstats
path: root/external/libodfgen/0001-tdf-101077-make-double-string-conversion-locale-agno.patch.1
blob: 1fc4e6b9d2615ac2fad247196fb0ea51c9d55a79 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
From 68e0c8e4c834df57bc9a0e8da72151f69ff5e7a6 Mon Sep 17 00:00:00 2001
From: David Tardon <dtardon@redhat.com>
Date: Fri, 12 Aug 2016 12:50:39 +0200
Subject: [PATCH] tdf#101077 make double->string conversion locale-agnostic

---
 src/OdsGenerator.cxx | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/src/OdsGenerator.cxx b/src/OdsGenerator.cxx
index 52e135e..8cb7203 100644
--- a/src/OdsGenerator.cxx
+++ b/src/OdsGenerator.cxx
@@ -26,6 +26,8 @@
 
 #include <librevenge/librevenge.h>
 
+#include <iomanip>
+#include <locale>
 #include <map>
 #include <stack>
 #include <sstream>
@@ -46,6 +48,19 @@
 #include "OdcGenerator.hxx"
 #include "OdfGenerator.hxx"
 
+namespace
+{
+
+librevenge::RVNGString makePreciseStr(const double value)
+{
+	std::ostringstream os;
+	os.imbue(std::locale::classic());
+	os << std::fixed << std::setprecision(8) << value;
+	return os.str().c_str();
+}
+
+}
+
 class OdsGeneratorPrivate : public OdfGenerator
 {
 public:
@@ -968,10 +983,10 @@ void OdsGenerator::openSheetCell(const librevenge::RVNGPropertyList &propList)
 					// we need the maximum precision here, so we must avoid getStr() when possible
 					librevenge::RVNGString value;
 					if (propList["librevenge:value"]->getUnit()==librevenge::RVNG_GENERIC)
-						value.sprintf("%.8f", propList["librevenge:value"]->getDouble());
+						value = makePreciseStr(propList["librevenge:value"]->getDouble());
 					else if (propList["librevenge:value"]->getUnit()==librevenge::RVNG_PERCENT)
 					{
-						value.sprintf("%.8f", propList["librevenge:value"]->getDouble()*100.);
+						value = makePreciseStr(propList["librevenge:value"]->getDouble()*100.);
 						value.append('%');
 					}
 					else
-- 
2.7.4