From 94056bf7f8fdef32da3cd78eff68d58560b4e6be Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 11 Aug 2016 12:49:23 +0100 Subject: Replace incorrect uses of raw_convert with a new locale_convert. --- src/lib/audio_content.cc | 1 + src/lib/cinema.cc | 5 +- src/lib/content.cc | 5 +- src/lib/dcp_content.cc | 1 + src/lib/ffmpeg_content.cc | 3 +- src/lib/locale_convert.cc | 122 ++++++++++++++++++++++++++++++++++++++++++++++ src/lib/locale_convert.h | 81 ++++++++++++++++++++++++++++++ src/lib/user_property.h | 4 +- src/lib/util.cc | 12 +++-- src/lib/video_content.cc | 5 +- src/lib/wscript | 1 + 11 files changed, 226 insertions(+), 14 deletions(-) create mode 100644 src/lib/locale_convert.cc create mode 100644 src/lib/locale_convert.h (limited to 'src/lib') diff --git a/src/lib/audio_content.cc b/src/lib/audio_content.cc index e66b8b998..25a7ef8a5 100644 --- a/src/lib/audio_content.cc +++ b/src/lib/audio_content.cc @@ -24,6 +24,7 @@ #include "config.h" #include "frame_rate_change.h" #include "compose.hpp" +#include "locale_convert.h" #include #include #include diff --git a/src/lib/cinema.cc b/src/lib/cinema.cc index 469cf2e6b..61862fa6d 100644 --- a/src/lib/cinema.cc +++ b/src/lib/cinema.cc @@ -30,6 +30,7 @@ using std::list; using std::string; using boost::shared_ptr; +using dcp::raw_convert; Cinema::Cinema (cxml::ConstNodePtr node) : name (node->string_child ("Name")) @@ -71,8 +72,8 @@ Cinema::as_xml (xmlpp::Element* parent) const parent->add_child("Notes")->add_child_text (notes); - parent->add_child("UTCOffsetHour")->add_child_text (dcp::raw_convert (_utc_offset_hour)); - parent->add_child("UTCOffsetMinute")->add_child_text (dcp::raw_convert (_utc_offset_minute)); + parent->add_child("UTCOffsetHour")->add_child_text (raw_convert (_utc_offset_hour)); + parent->add_child("UTCOffsetMinute")->add_child_text (raw_convert (_utc_offset_minute)); BOOST_FOREACH (shared_ptr i, _screens) { i->as_xml (parent->add_child ("Screen")); diff --git a/src/lib/content.cc b/src/lib/content.cc index 0fd503edd..536036ff7 100644 --- a/src/lib/content.cc +++ b/src/lib/content.cc @@ -27,6 +27,7 @@ #include "content_factory.h" #include "exceptions.h" #include "film.h" +#include "locale_convert.h" #include "job.h" #include "compose.hpp" #include @@ -365,7 +366,7 @@ Content::add_properties (list& p) const UserProperty ( UserProperty::VIDEO, _("Frame rate"), - raw_convert (_video_frame_rate.get(), 5), + locale_convert (_video_frame_rate.get(), 5), _("frames per second") ) ); @@ -374,7 +375,7 @@ Content::add_properties (list& p) const UserProperty ( UserProperty::GENERAL, _("Prepared for video frame rate"), - raw_convert (_video_frame_rate.get(), 5), + locale_convert (_video_frame_rate.get(), 5), _("frames per second") ) ); diff --git a/src/lib/dcp_content.cc b/src/lib/dcp_content.cc index 9e767596c..44c7ce578 100644 --- a/src/lib/dcp_content.cc +++ b/src/lib/dcp_content.cc @@ -30,6 +30,7 @@ #include "dcp_decoder.h" #include "subtitle_content.h" #include +#include #include #include #include diff --git a/src/lib/ffmpeg_content.cc b/src/lib/ffmpeg_content.cc index d64c82971..71cda084c 100644 --- a/src/lib/ffmpeg_content.cc +++ b/src/lib/ffmpeg_content.cc @@ -33,6 +33,7 @@ #include "exceptions.h" #include "frame_rate_change.h" #include "subtitle_content.h" +#include "locale_convert.h" #include #include extern "C" { @@ -566,7 +567,7 @@ FFmpegContent::add_properties (list& p) const p.push_back (UserProperty (UserProperty::VIDEO, _("Colourspace"), spaces[_colorspace])); if (_bits_per_pixel) { - p.push_back (UserProperty (UserProperty::VIDEO, _("Bits per pixel"), raw_convert (_bits_per_pixel.get ()))); + p.push_back (UserProperty (UserProperty::VIDEO, _("Bits per pixel"), _bits_per_pixel.get ())); } } diff --git a/src/lib/locale_convert.cc b/src/lib/locale_convert.cc new file mode 100644 index 000000000..6358c0f8c --- /dev/null +++ b/src/lib/locale_convert.cc @@ -0,0 +1,122 @@ +/* + Copyright (C) 2012-2016 Carl Hetherington + + This file is part of DCP-o-matic. + + DCP-o-matic is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + DCP-o-matic is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DCP-o-matic. If not, see . + +*/ + +#include "locale_convert.h" +#include +#include + +using std::string; + +template<> +string +locale_convert (int x, int) +{ + char buffer[64]; + snprintf (buffer, sizeof(buffer), "%d", x); + return buffer; +} + +template<> +string +locale_convert (int64_t x, int) +{ + char buffer[64]; + snprintf (buffer, sizeof(buffer), "%" PRId64, x); + return buffer; +} + +template<> +string +locale_convert (float x, int precision) +{ + char format[64]; + snprintf (format, sizeof(format), "%%.%df", precision); + char buffer[64]; + snprintf (buffer, sizeof(buffer), format, x); + return buffer; +} + +template<> +string +locale_convert (double x, int precision) +{ + char format[64]; + snprintf (format, sizeof(format), "%%.%df", precision); + char buffer[64]; + snprintf (buffer, sizeof(buffer), format, x); + return buffer; +} + +template<> +string +locale_convert (string x, int) +{ + return x; +} + +template<> +string +locale_convert (char* x, int) +{ + return x; +} + +template<> +string +locale_convert (char const * x, int) +{ + return x; +} + +template<> +int +locale_convert (string x, int) +{ + int y = 0; + sscanf (x.c_str(), "%d", &y); + return y; +} + +template<> +int64_t +locale_convert (string x, int) +{ + int64_t y = 0; + sscanf (x.c_str(), "%" PRId64, &y); + return y; +} + +template<> +float +locale_convert (string x, int) +{ + float y = 0; + sscanf (x.c_str(), "%f", &y); + return y; +} + +template<> +double +locale_convert (string x, int) +{ + double y = 0; + sscanf (x.c_str(), "%lf", &y); + return y; +} diff --git a/src/lib/locale_convert.h b/src/lib/locale_convert.h new file mode 100644 index 000000000..b5c38caae --- /dev/null +++ b/src/lib/locale_convert.h @@ -0,0 +1,81 @@ +/* + Copyright (C) 2012-2016 Carl Hetherington + + This file is part of DCP-o-matic. + + DCP-o-matic is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + DCP-o-matic is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DCP-o-matic. If not, see . + +*/ + +#ifndef DCPOMATIC_LOCALE_CONVERT_H +#define DCPOMATIC_LOCALE_CONVERT_H + +#include +#include + +template +P +locale_convert (Q x, int precision = 16) +{ + /* We can't write a generic version of locale_convert; all required + versions must be specialised. + */ + BOOST_STATIC_ASSERT (sizeof (Q) == 0); +} + +template <> +std::string +locale_convert (int x, int); + +template <> +std::string +locale_convert (int64_t x, int); + +template <> +std::string +locale_convert (float x, int precision); + +template <> +std::string +locale_convert (double x, int precision); + +template <> +std::string +locale_convert (std::string x, int); + +template <> +std::string +locale_convert (char* x, int); + +template <> +std::string +locale_convert (char const * x, int); + +template <> +int +locale_convert (std::string x, int); + +template <> +int64_t +locale_convert (std::string x, int); + +template <> +float +locale_convert (std::string x, int); + +template <> +double +locale_convert (std::string x, int); + +#endif diff --git a/src/lib/user_property.h b/src/lib/user_property.h index 6e147fd76..8b69b7687 100644 --- a/src/lib/user_property.h +++ b/src/lib/user_property.h @@ -21,7 +21,7 @@ #ifndef DCPOMATIC_USER_PROPERTY_H #define DCPOMATIC_USER_PROPERTY_H -#include +#include "locale_convert.h" class UserProperty { @@ -37,7 +37,7 @@ public: UserProperty (Category category_, std::string key_, T value_, std::string unit_ = "") : category (category_) , key (key_) - , value (dcp::raw_convert (value_)) + , value (locale_convert (value_)) , unit (unit_) {} diff --git a/src/lib/util.cc b/src/lib/util.cc index da45919b4..eedc7ddb5 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -36,7 +36,9 @@ #include "digester.h" #include "audio_processor.h" #include "compose.hpp" +#include "locale_convert.h" #include +#include #include #include #include @@ -140,10 +142,10 @@ seconds_to_approximate_hms (int s) if (hours) { if (m > 30 && !minutes) { /// TRANSLATORS: h here is an abbreviation for hours - ap += raw_convert(h + 1) + _("h"); + ap += locale_convert(h + 1) + _("h"); } else { /// TRANSLATORS: h here is an abbreviation for hours - ap += raw_convert(h) + _("h"); + ap += locale_convert(h) + _("h"); } if (minutes || seconds) { @@ -155,10 +157,10 @@ seconds_to_approximate_hms (int s) /* Minutes */ if (s > 30 && !seconds) { /// TRANSLATORS: m here is an abbreviation for minutes - ap += raw_convert(m + 1) + _("m"); + ap += locale_convert(m + 1) + _("m"); } else { /// TRANSLATORS: m here is an abbreviation for minutes - ap += raw_convert(m) + _("m"); + ap += locale_convert(m) + _("m"); } if (seconds) { @@ -169,7 +171,7 @@ seconds_to_approximate_hms (int s) if (seconds) { /* Seconds */ /// TRANSLATORS: s here is an abbreviation for seconds - ap += raw_convert(s) + _("s"); + ap += locale_convert(s) + _("s"); } return ap; diff --git a/src/lib/video_content.cc b/src/lib/video_content.cc index 20e0866a1..ac038678c 100644 --- a/src/lib/video_content.cc +++ b/src/lib/video_content.cc @@ -30,6 +30,7 @@ #include "exceptions.h" #include "frame_rate_change.h" #include "log.h" +#include "locale_convert.h" #include #include #include @@ -456,8 +457,8 @@ VideoContent::processing_description () const void VideoContent::add_properties (list& p) const { - p.push_back (UserProperty (UserProperty::VIDEO, _("Length"), raw_convert (length ()), _("video frames"))); - p.push_back (UserProperty (UserProperty::VIDEO, _("Size"), raw_convert (size().width) + "x" + raw_convert (size().height))); + p.push_back (UserProperty (UserProperty::VIDEO, _("Length"), length (), _("video frames"))); + p.push_back (UserProperty (UserProperty::VIDEO, _("Size"), size().width + "x" + size().height)); } void diff --git a/src/lib/wscript b/src/lib/wscript index 911ee0af4..074c12ad4 100644 --- a/src/lib/wscript +++ b/src/lib/wscript @@ -94,6 +94,7 @@ sources = """ job.cc job_manager.cc json_server.cc + locale_convert.cc log.cc log_entry.cc magick_image_proxy.cc -- cgit v1.2.3