From 7930f7685811eb9e9f76651b6ef3dd9fe140b6fe Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 9 Oct 2018 19:20:01 +0100 Subject: More raw/locale_convert. --- src/locale_convert.cc | 27 +++++++++++++++++++++++++++ src/locale_convert.h | 12 ++++++++++++ src/raw_convert.cc | 14 ++++++++++++++ src/raw_convert.h | 8 ++++++++ 4 files changed, 61 insertions(+) (limited to 'src') diff --git a/src/locale_convert.cc b/src/locale_convert.cc index 0f0b5fa2..5e7c350f 100644 --- a/src/locale_convert.cc +++ b/src/locale_convert.cc @@ -197,6 +197,33 @@ dcp::locale_convert (boost::filesystem::path x, int, bool) return x.string(); } +template<> +unsigned char +dcp::locale_convert (string x, int, bool) +{ + unsigned char y = 0; + sscanf (x.c_str(), "%hhu", &y); + return y; +} + +template<> +unsigned short int +dcp::locale_convert (string x, int, bool) +{ + unsigned short int y = 0; + sscanf (x.c_str(), "%hu", &y); + return y; +} + +template<> +unsigned int +dcp::locale_convert (string x, int, bool) +{ + int y = 0; + sscanf (x.c_str(), "%u", &y); + return y; +} + template<> int dcp::locale_convert (string x, int, bool) diff --git a/src/locale_convert.h b/src/locale_convert.h index 96309fd2..7d09c8e7 100644 --- a/src/locale_convert.h +++ b/src/locale_convert.h @@ -115,6 +115,18 @@ template <> std::string locale_convert (boost::filesystem::path x, int, bool); +template <> +unsigned char +locale_convert (std::string x, int, bool); + +template <> +unsigned short int +locale_convert (std::string x, int, bool); + +template <> +unsigned int +locale_convert (std::string x, int, bool); + template <> int locale_convert (std::string x, int, bool); diff --git a/src/raw_convert.cc b/src/raw_convert.cc index e1b909c0..f51a10f6 100644 --- a/src/raw_convert.cc +++ b/src/raw_convert.cc @@ -168,6 +168,20 @@ 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) diff --git a/src/raw_convert.h b/src/raw_convert.h index 90d94771..4945c7f8 100644 --- a/src/raw_convert.h +++ b/src/raw_convert.h @@ -112,6 +112,14 @@ template <> std::string raw_convert (char v, int, bool); +template <> +unsigned char +raw_convert (std::string v, int, bool); + +template <> +unsigned short int +raw_convert (std::string v, int, bool); + template <> int raw_convert (std::string v, int, bool); -- cgit v1.2.3