X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Fraw_convert.cc;h=7d3d1a72002b49511ca439eef728674b213fa063;hb=refs%2Ftags%2Fv1.8.4;hp=432ce394273aabd08986c7fc04f12d416305185b;hpb=732f931e0559f29100b56f7f4a6e6be8820f0ff7;p=libdcp.git diff --git a/src/raw_convert.cc b/src/raw_convert.cc index 432ce394..7d3d1a72 100644 --- a/src/raw_convert.cc +++ b/src/raw_convert.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2014-2016 Carl Hetherington + Copyright (C) 2014-2021 Carl Hetherington This file is part of libdcp. @@ -31,23 +31,29 @@ files in the program, then also delete it here. */ + #include "raw_convert.h" #include "locale_convert.h" #include + using std::string; using std::wstring; + +/** @param v Numeric value as an ASCII string */ static string make_raw (string v) { struct lconv* lc = localeconv (); - boost::algorithm::replace_all (v, lc->decimal_point, "."); + /* 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) @@ -58,6 +64,23 @@ make_local (string v) return v; } + +template <> +string +dcp::raw_convert (unsigned char v, int precision, bool fixed) +{ + return make_raw (locale_convert (v, precision, fixed)); +} + + +template <> +string +dcp::raw_convert (unsigned short int v, int precision, bool fixed) +{ + return make_raw (locale_convert (v, precision, fixed)); +} + + template <> string dcp::raw_convert (int v, int precision, bool fixed) @@ -65,6 +88,7 @@ dcp::raw_convert (int v, int precision, bool fixed) return make_raw (locale_convert (v, precision, fixed)); } + template <> string dcp::raw_convert (unsigned int v, int precision, bool fixed) @@ -72,6 +96,7 @@ dcp::raw_convert (unsigned int v, int precision, bool fixed) return make_raw (locale_convert (v, precision, fixed)); } + template <> string dcp::raw_convert (long v, int precision, bool fixed) @@ -79,6 +104,7 @@ dcp::raw_convert (long v, int precision, bool fixed) return make_raw (locale_convert (v, precision, fixed)); } + template <> string dcp::raw_convert (unsigned long v, int precision, bool fixed) @@ -86,6 +112,7 @@ dcp::raw_convert (unsigned long v, int precision, bool fixed) return make_raw (locale_convert (v, precision, fixed)); } + template <> string dcp::raw_convert (long long v, int precision, bool fixed) @@ -93,6 +120,7 @@ dcp::raw_convert (long long v, int precision, bool fixed) return make_raw (locale_convert (v, precision, fixed)); } + template <> string dcp::raw_convert (unsigned long long v, int precision, bool fixed) @@ -100,6 +128,7 @@ dcp::raw_convert (unsigned long long v, int precision, bool fixed) return make_raw (locale_convert (v, precision, fixed)); } + template <> string dcp::raw_convert (float v, int precision, bool fixed) @@ -107,6 +136,7 @@ dcp::raw_convert (float v, int precision, bool fixed) return make_raw (locale_convert (v, precision, fixed)); } + template <> string dcp::raw_convert (double v, int precision, bool fixed) @@ -114,6 +144,7 @@ dcp::raw_convert (double v, int precision, bool fixed) return make_raw (locale_convert (v, precision, fixed)); } + template <> string dcp::raw_convert (char const * v, int, bool) @@ -121,6 +152,7 @@ dcp::raw_convert (char const * v, int, bool) return v; } + template <> string dcp::raw_convert (char* v, int, bool) @@ -128,6 +160,7 @@ dcp::raw_convert (char* v, int, bool) return v; } + template <> string dcp::raw_convert (string v, int, bool) @@ -135,6 +168,7 @@ dcp::raw_convert (string v, int, bool) return v; } + template <> string dcp::raw_convert (char v, int, bool) @@ -144,6 +178,7 @@ dcp::raw_convert (char v, int, bool) return s; } + template <> string dcp::raw_convert (wchar_t const * v, int, bool) @@ -152,6 +187,23 @@ dcp::raw_convert (wchar_t const * v, int, bool) return string (w.begin(), w.end()); } + +template <> +unsigned char +dcp::raw_convert (std::string v, int precision, bool fixed) +{ + return locale_convert (make_local (v), precision, fixed); +} + + +template <> +unsigned short int +dcp::raw_convert (std::string v, int precision, bool fixed) +{ + return locale_convert (make_local (v), precision, fixed); +} + + template <> int dcp::raw_convert (string v, int precision, bool fixed) @@ -159,6 +211,7 @@ dcp::raw_convert (string v, int precision, bool fixed) return locale_convert (make_local (v), precision, fixed); } + template <> long dcp::raw_convert (string v, int precision, bool fixed) @@ -166,6 +219,31 @@ dcp::raw_convert (string v, int precision, bool fixed) return locale_convert (make_local (v), precision, fixed); } + +template <> +unsigned long +dcp::raw_convert (string v, int precision, bool fixed) +{ + return locale_convert (make_local (v), precision, fixed); +} + + +template <> +long long +dcp::raw_convert (string v, int precision, bool fixed) +{ + return locale_convert (make_local (v), precision, fixed); +} + + +template <> +unsigned long long +dcp::raw_convert (string v, int precision, bool fixed) +{ + return locale_convert (make_local (v), precision, fixed); +} + + template <> int dcp::raw_convert (char const * v, int precision, bool fixed) @@ -173,6 +251,7 @@ dcp::raw_convert (char const * v, int precision, bool fixed) return locale_convert (make_local (v), precision, fixed); } + template <> float dcp::raw_convert (string v, int precision, bool fixed) @@ -180,6 +259,7 @@ dcp::raw_convert (string v, int precision, bool fixed) return locale_convert (make_local (v), precision, fixed); } + template <> float dcp::raw_convert (char const * v, int precision, bool fixed) @@ -187,6 +267,7 @@ dcp::raw_convert (char const * v, int precision, bool fixed) return locale_convert (make_local (v), precision, fixed); } + template <> double dcp::raw_convert (string v, int precision, bool fixed) @@ -194,6 +275,7 @@ dcp::raw_convert (string v, int precision, bool fixed) return locale_convert (make_local (v), precision, fixed); } + template <> double dcp::raw_convert (char const * v, int precision, bool fixed)