blob: adc90dd2c354dd17daf487b7f8a66d7cb9b09e1d [file] [log] [blame]
From 91c8f61a89346c5874a4009bfb6950db8f560377 Mon Sep 17 00:00:00 2001
From: Luigi 'Comio' Mantellini <luigi.mantellini@gmail.com>
Date: Mon, 24 Mar 2014 08:35:25 +0100
Subject: [PATCH] Format string using ostringstream and avoiding #if/#endef
---
Foundation/src/NumberFormatter.cpp | 31 +++++++++++--------------------
1 file changed, 11 insertions(+), 20 deletions(-)
diff --git a/Foundation/src/NumberFormatter.cpp b/Foundation/src/NumberFormatter.cpp
index b7b27e7..714acab 100644
--- a/Foundation/src/NumberFormatter.cpp
+++ b/Foundation/src/NumberFormatter.cpp
@@ -36,6 +36,8 @@
#include "Poco/NumberFormatter.h"
#include "Poco/MemoryStream.h"
+#include <ios>
+#include <sstream>
#include <iomanip>
#if !defined(POCO_NO_LOCALE)
#include <locale>
@@ -43,15 +45,6 @@
#include <cinttypes>
-#if defined(_MSC_VER) || defined(__MINGW32__)
- #define I64_FMT "I64"
-#elif defined(__APPLE__)
- #define I64_FMT "q"
-#else
- #define I64_FMT "ll"
-#endif
-
-
namespace Poco {
@@ -384,13 +377,15 @@ void NumberFormatter::append(std::string& str, double value, int width, int prec
void NumberFormatter::append(std::string& str, const void* ptr)
{
- char buffer[24];
-#if defined(POCO_PTR_IS_64_BIT)
- std::sprintf(buffer, "%016" PRIXPTR, (UIntPtr) ptr);
-#else
- std::sprintf(buffer, "%08" PRIXPTR, (UIntPtr) ptr);
-#endif
- str.append(buffer);
+ std::ostringstream os;
+
+ os << std::hex
+ << std::setw(sizeof(ptr) * 2)
+ << std::setfill('0')
+ << setiosflags(std::ios::uppercase)
+ << ptr;
+
+ str.append(os.str());
}