summaryrefslogtreecommitdiff
path: root/include/tools
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2024-04-14 11:25:21 +0100
committerMike Kaganski <mike.kaganski@collabora.com>2024-04-14 15:13:10 +0200
commit1f1f4232001fa23ec1a1bf67d605fda9df542eec (patch)
tree7ced650d6b784829fb3cb957d8b71443b2ed7ae1 /include/tools
parent7f2283c2986ff94766cc1d2c076fb34a2c88a31a (diff)
Round in XmlWriter::attribute when passing a double
Before, it truncated. Rounding provides a closer value. Change-Id: I213e6ae34ada2f5081cb2c8b2ef431448c712b37 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165947 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'include/tools')
-rw-r--r--include/tools/XmlWriter.hxx13
1 files changed, 12 insertions, 1 deletions
diff --git a/include/tools/XmlWriter.hxx b/include/tools/XmlWriter.hxx
index 400748611bd5..03cc151b2624 100644
--- a/include/tools/XmlWriter.hxx
+++ b/include/tools/XmlWriter.hxx
@@ -10,6 +10,9 @@
#ifndef INCLUDED_TOOLS_XMLWRITER_HXX
#define INCLUDED_TOOLS_XMLWRITER_HXX
+#include <sal/config.h>
+
+#include <basegfx/numeric/ftools.hxx>
#include <tools/toolsdllapi.h>
#include <rtl/string.hxx>
#include <memory>
@@ -52,7 +55,15 @@ public:
void attribute(const char* sTagName, const OString& aValue);
void attribute(const OString& sTagName, const OString& aValue);
void attribute(const char* sTagName, std::u16string_view aValue);
- void attribute(const char* sTagName, sal_Int32 aNumber);
+ void attribute(const char* sTagName, sal_Int64 aNumber);
+ template <typename T>
+ requires std::is_arithmetic_v<T> void attribute(const char* sTagName, T aNumber)
+ {
+ if constexpr (std::is_floating_point_v<T>)
+ return attribute(sTagName, basegfx::fround64(aNumber));
+ else
+ return attribute(sTagName, static_cast<sal_Int64>(aNumber));
+ }
void attributeDouble(const char* sTagName, double aNumber);
void attributeBase64(const char* sTagName, std::vector<sal_uInt8> const& rValueInBytes);
void attributeBase64(const char* sTagName, std::vector<char> const& rValueInBytes);