X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fraw_convert.cc;h=b4dcb5be92ec41eac566e73a3b8caafbeb49987c;hb=b509d21444a1f486b8713a1a652c0f816b2af0cb;hp=42622bfe7ae0cfee94d0c0f1d9b0971435394f79;hpb=3652809182f2ff89e552a519658cba2afc57ce28;p=libdcp.git diff --git a/src/raw_convert.cc b/src/raw_convert.cc index 42622bfe..b4dcb5be 100644 --- a/src/raw_convert.cc +++ b/src/raw_convert.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2014 Carl Hetherington + Copyright (C) 2014-2016 Carl Hetherington This file is part of libdcp. @@ -36,14 +36,17 @@ #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; } @@ -57,6 +60,20 @@ 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) @@ -134,6 +151,37 @@ dcp::raw_convert (string v, int, bool) return v; } +template <> +string +dcp::raw_convert (char v, int, bool) +{ + string s; + s += v; + return s; +} + +template <> +string +dcp::raw_convert (wchar_t const * v, int, bool) +{ + wstring w (v); + 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) @@ -141,6 +189,34 @@ 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) +{ + 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)