summaryrefslogtreecommitdiff
path: root/src/raw_convert.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/raw_convert.cc')
-rw-r--r--src/raw_convert.cc57
1 files changed, 22 insertions, 35 deletions
diff --git a/src/raw_convert.cc b/src/raw_convert.cc
index 7f61e87c..ef321bbf 100644
--- a/src/raw_convert.cc
+++ b/src/raw_convert.cc
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2014-2021 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2014-2022 Carl Hetherington <cth@carlh.net>
This file is part of libdcp.
@@ -34,6 +34,8 @@
#include "raw_convert.h"
#include "locale_convert.h"
+#include <fmt/core.h>
+#include <fmt/format.h>
#include <boost/algorithm/string.hpp>
@@ -41,19 +43,6 @@ using std::string;
using std::wstring;
-/** @param v Numeric value as an ASCII string */
-static
-string
-make_raw (string v)
-{
- struct lconv* lc = localeconv ();
- /* thousands_sep may be . so remove them before changing decimal points */
- boost::algorithm::replace_all (v, lc->thousands_sep, "");
- boost::algorithm::replace_all (v, lc->decimal_point, ".");
- return v;
-}
-
-
static
string
make_local (string v)
@@ -67,65 +56,65 @@ make_local (string v)
template <>
string
-dcp::raw_convert (unsigned char v, int precision, bool fixed)
+dcp::raw_convert (unsigned char v, int, bool)
{
- return make_raw (locale_convert<string> (v, precision, fixed));
+ return fmt::to_string(v);
}
template <>
string
-dcp::raw_convert (unsigned short int v, int precision, bool fixed)
+dcp::raw_convert (unsigned short int v, int, bool)
{
- return make_raw (locale_convert<string> (v, precision, fixed));
+ return fmt::to_string(v);
}
template <>
string
-dcp::raw_convert (int v, int precision, bool fixed)
+dcp::raw_convert (int v, int, bool)
{
- return make_raw (locale_convert<string> (v, precision, fixed));
+ return fmt::to_string(v);
}
template <>
string
-dcp::raw_convert (unsigned int v, int precision, bool fixed)
+dcp::raw_convert (unsigned int v, int, bool)
{
- return make_raw (locale_convert<string> (v, precision, fixed));
+ return fmt::to_string(v);
}
template <>
string
-dcp::raw_convert (long v, int precision, bool fixed)
+dcp::raw_convert (long v, int, bool)
{
- return make_raw (locale_convert<string> (v, precision, fixed));
+ return fmt::to_string(v);
}
template <>
string
-dcp::raw_convert (unsigned long v, int precision, bool fixed)
+dcp::raw_convert (unsigned long v, int, bool)
{
- return make_raw (locale_convert<string> (v, precision, fixed));
+ return fmt::to_string(v);
}
template <>
string
-dcp::raw_convert (long long v, int precision, bool fixed)
+dcp::raw_convert (long long v, int, bool)
{
- return make_raw (locale_convert<string> (v, precision, fixed));
+ return fmt::to_string(v);
}
template <>
string
-dcp::raw_convert (unsigned long long v, int precision, bool fixed)
+dcp::raw_convert (unsigned long long v, int, bool)
{
- return make_raw (locale_convert<string> (v, precision, fixed));
+ return fmt::to_string(v);
}
@@ -133,7 +122,7 @@ template <>
string
dcp::raw_convert (float v, int precision, bool fixed)
{
- return make_raw (locale_convert<string> (v, precision, fixed));
+ return fmt::format(fmt::format("{{:.{}{}}}", precision, fixed ? 'f' : 'g'), v);
}
@@ -141,7 +130,7 @@ template <>
string
dcp::raw_convert (double v, int precision, bool fixed)
{
- return make_raw (locale_convert<string> (v, precision, fixed));
+ return fmt::format(fmt::format("{{:.{}{}}}", precision, fixed ? 'f' : 'g'), v);
}
@@ -173,9 +162,7 @@ template <>
string
dcp::raw_convert (char v, int, bool)
{
- string s;
- s += v;
- return s;
+ return std::string(1, v);
}