aboutsummaryrefslogtreecommitdiff
path: root/src/util/string.h
diff options
context:
space:
mode:
authorBen Woosley <ben.woosley@gmail.com>2020-02-12 23:01:45 -0500
committerBen Woosley <ben.woosley@gmail.com>2020-03-14 12:23:01 -0700
commitd056df033a1e88554f7cc39dd709a87b17cb49df (patch)
tree263b622b86b99015913624e20b40fc317777c3c7 /src/util/string.h
parent58c72880ff70807cf622cdebf1d6273f4041bd2e (diff)
Replace std::to_string with locale-independent alternative
Diffstat (limited to 'src/util/string.h')
-rw-r--r--src/util/string.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/util/string.h b/src/util/string.h
index 3db8fc8b98..694f0a1ca4 100644
--- a/src/util/string.h
+++ b/src/util/string.h
@@ -8,6 +8,8 @@
#include <attributes.h>
#include <cstring>
+#include <locale>
+#include <sstream>
#include <string>
#include <vector>
@@ -52,4 +54,16 @@ NODISCARD inline bool ValidAsCString(const std::string& str) noexcept
return str.size() == strlen(str.c_str());
}
+/**
+ * Locale-independent version of std::to_string
+ */
+template <typename T>
+std::string ToString(const T& t)
+{
+ std::ostringstream oss;
+ oss.imbue(std::locale::classic());
+ oss << t;
+ return oss.str();
+}
+
#endif // BITCOIN_UTIL_STRENCODINGS_H