Use raw_convert instead of boost::lexical_cast as it seems
authorCarl Hetherington <cth@carlh.net>
Sun, 11 May 2014 22:59:19 +0000 (23:59 +0100)
committerCarl Hetherington <cth@carlh.net>
Sun, 11 May 2014 22:59:19 +0000 (23:59 +0100)
that lexical_cast will sometimes use a thousands separator
(i.e. it will convert 1234 to a string 1,234).  It appears
not to be possible safely to turn this off (you have to set
the global locale).  Instead, raw_convert uses a stringstream
which you can imbue() with std::locale::classic() to turn off
the locale-specific behaviour.

12 files changed:
src/asset.cc
src/cpl.cc
src/dcp.cc
src/dcp_time.cc
src/mono_picture_asset.cc
src/mono_picture_asset_writer.cc
src/mxf_asset.cc
src/parse/subtitle.cc
src/picture_asset.cc
src/sound_asset.cc
src/subtitle_asset.cc
src/types.cc

index 4ad29dde8226a75d6eaffdf7f022804f42f04e7f..00ad67bc5a17dfc46e8a8bc495552eb78a40a4c7 100644 (file)
@@ -23,7 +23,6 @@
 
 #include <iostream>
 #include <boost/filesystem.hpp>
-#include <boost/lexical_cast.hpp>
 #include <boost/function.hpp>
 #include <libxml++/nodes/element.h>
 #include "AS_DCP.h"
 #include "util.h"
 #include "metadata.h"
 #include "compose.hpp"
+#include "raw_convert.h"
 
 using std::string;
 using boost::shared_ptr;
-using boost::lexical_cast;
 using namespace libdcp;
 
 Asset::Asset (boost::filesystem::path directory, boost::filesystem::path file_name)
@@ -59,7 +58,7 @@ Asset::write_to_pkl (xmlpp::Node* node, bool interop) const
        asset->add_child("Id")->add_child_text ("urn:uuid:" + _uuid);
        asset->add_child("AnnotationText")->add_child_text (_file_name.string ());
        asset->add_child("Hash")->add_child_text (digest ());
-       asset->add_child("Size")->add_child_text (lexical_cast<string> (boost::filesystem::file_size(path())));
+       asset->add_child("Size")->add_child_text (raw_convert<string> (boost::filesystem::file_size(path())));
        if (interop) {
                asset->add_child("Type")->add_child_text (String::compose ("application/x-smpte-mxf;asdcpKind=%1", asdcp_kind ()));
        } else {
@@ -77,7 +76,7 @@ Asset::write_to_assetmap (xmlpp::Node* node) const
        chunk->add_child("Path")->add_child_text (_file_name.string ());
        chunk->add_child("VolumeIndex")->add_child_text ("1");
        chunk->add_child("Offset")->add_child_text ("0");
-       chunk->add_child("Length")->add_child_text (lexical_cast<string> (boost::filesystem::file_size(path())));
+       chunk->add_child("Length")->add_child_text (raw_convert<string> (boost::filesystem::file_size(path())));
 }
 
 boost::filesystem::path
index e333df0db717adfb3f1d09353e6f801a5703ed21..5079b4f632b3e95b4484d19564853ff299b43d4d 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012-2013 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -31,6 +31,7 @@
 #include "signer.h"
 #include "exceptions.h"
 #include "compose.hpp"
+#include "raw_convert.h"
 
 using std::string;
 using std::stringstream;
@@ -248,7 +249,7 @@ CPL::write_to_pkl (xmlpp::Node* node, bool interop) const
        xmlpp::Node* asset = node->add_child ("Asset");
        asset->add_child("Id")->add_child_text ("urn:uuid:" + _id);
        asset->add_child("Hash")->add_child_text (_digest);
-       asset->add_child("Size")->add_child_text (lexical_cast<string> (_length));
+       asset->add_child("Size")->add_child_text (raw_convert<string> (_length));
        if (interop) {
                asset->add_child("Type")->add_child_text ("text/xml;asdcpKind=CPL");
        } else {
@@ -285,7 +286,7 @@ CPL::write_to_assetmap (xmlpp::Node* node) const
        chunk->add_child("Path")->add_child_text (_id + "_cpl.xml");
        chunk->add_child("VolumeIndex")->add_child_text ("1");
        chunk->add_child("Offset")->add_child_text("0");
-       chunk->add_child("Length")->add_child_text(lexical_cast<string> (_length));
+       chunk->add_child("Length")->add_child_text (raw_convert<string> (_length));
 }
        
        
index 7748a97f94ef52ba043c2b157ea5b6082abe5b58..7cce30feb31c77ab44558690310a5965fc434f27 100644 (file)
@@ -26,9 +26,7 @@
 #include <cassert>
 #include <iostream>
 #include <boost/filesystem.hpp>
-#include <boost/lexical_cast.hpp>
 #include <boost/algorithm/string.hpp>
-#include <boost/lexical_cast.hpp>
 #include <libxml++/libxml++.h>
 #include <xmlsec/xmldsig.h>
 #include <xmlsec/app.h>
@@ -46,6 +44,7 @@
 #include "cpl.h"
 #include "signer.h"
 #include "kdm.h"
+#include "raw_convert.h"
 
 using std::string;
 using std::list;
@@ -55,7 +54,6 @@ using std::copy;
 using std::back_inserter;
 using std::make_pair;
 using boost::shared_ptr;
-using boost::lexical_cast;
 using namespace libdcp;
 
 DCP::DCP (boost::filesystem::path directory)
@@ -191,7 +189,7 @@ DCP::write_assetmap (string pkl_uuid, int pkl_length, bool interop, XMLMetadata
        chunk->add_child("Path")->add_child_text (pkl_uuid + "_pkl.xml");
        chunk->add_child("VolumeIndex")->add_child_text ("1");
        chunk->add_child("Offset")->add_child_text ("0");
-       chunk->add_child("Length")->add_child_text (lexical_cast<string> (pkl_length));
+       chunk->add_child("Length")->add_child_text (raw_convert<string> (pkl_length));
        
        for (list<shared_ptr<CPL> >::const_iterator i = _cpls.begin(); i != _cpls.end(); ++i) {
                (*i)->write_to_assetmap (asset_list);
index 14155fdb01929fa352424cfc81a2855107916b1b..d597e3dc203e765e10e2d20ec9331a7e0de637f1 100644 (file)
 #include <iostream>
 #include <vector>
 #include <boost/algorithm/string.hpp>
-#include <boost/lexical_cast.hpp>
 #include <cmath>
 #include "dcp_time.h"
 #include "exceptions.h"
+#include "raw_convert.h"
 
 using namespace std;
 using namespace boost;
@@ -78,10 +78,10 @@ Time::Time (string time)
                boost::throw_exception (DCPReadError ("unrecognised time specification"));
        }
        
-       h = lexical_cast<int> (b[0]);
-       m = lexical_cast<int> (b[1]);
-       s = lexical_cast<int> (b[2]);
-       t = lexical_cast<int> (b[3]);
+       h = raw_convert<int> (b[0]);
+       m = raw_convert<int> (b[1]);
+       s = raw_convert<int> (b[2]);
+       t = raw_convert<int> (b[3]);
 }
 
 bool
index 0ac48d37b8077eb7b45b65c70743f7721131f639..f70db2b44d9cdc9d55d1b1b6d9f2d86d1d7dd2cc 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012-2013 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
index 6f0ba973044391a479b639fb9a1f1974b0975aa4..ebf3ec00967acdd1ea633e62ffc56aa598b2a155 100644 (file)
@@ -29,7 +29,6 @@ using std::istream;
 using std::ostream;
 using std::string;
 using boost::shared_ptr;
-using boost::lexical_cast;
 using namespace libdcp;
 
 struct MonoPictureAssetWriter::ASDCPState : public ASDCPStateBase
index c2428a3c193ffccf01fc7fdcd745230922341a75..f16fd35beee98eaf02b615ef9e3415beeb8a078b 100644 (file)
@@ -23,7 +23,6 @@
 
 #include <iostream>
 #include <boost/filesystem.hpp>
-#include <boost/lexical_cast.hpp>
 #include <libxml++/nodes/element.h>
 #include "AS_DCP.h"
 #include "KM_prng.h"
 #include "metadata.h"
 #include "exceptions.h"
 #include "kdm.h"
+#include "raw_convert.h"
 
 using std::string;
 using std::list;
 using std::pair;
 using boost::shared_ptr;
-using boost::lexical_cast;
 using boost::dynamic_pointer_cast;
 using namespace libdcp;
 
@@ -117,10 +116,10 @@ MXFAsset::write_to_cpl (xmlpp::Element* node) const
        }
        a->add_child ("Id")->add_child_text ("urn:uuid:" + _uuid);
        a->add_child ("AnnotationText")->add_child_text (_file_name.string ());
-       a->add_child ("EditRate")->add_child_text (lexical_cast<string> (_edit_rate) + " 1");
-       a->add_child ("IntrinsicDuration")->add_child_text (lexical_cast<string> (_intrinsic_duration));
-       a->add_child ("EntryPoint")->add_child_text (lexical_cast<string> (_entry_point));
-       a->add_child ("Duration")->add_child_text (lexical_cast<string> (_duration));
+       a->add_child ("EditRate")->add_child_text (raw_convert<string> (_edit_rate) + " 1");
+       a->add_child ("IntrinsicDuration")->add_child_text (raw_convert<string> (_intrinsic_duration));
+       a->add_child ("EntryPoint")->add_child_text (raw_convert<string> (_entry_point));
+       a->add_child ("Duration")->add_child_text (raw_convert<string> (_duration));
        if (!_key_id.empty ()) {
                a->add_child("KeyId")->add_child_text ("urn:uuid:" + _key_id);
        }
index 914be677050f5981d88e3b2c0277171e24be116f..a4b0410a3d4b296d4e940b700f4ef3bf6573f218 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012-2013 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -20,6 +20,7 @@
 #include <boost/shared_ptr.hpp>
 #include <boost/optional.hpp>
 #include "subtitle.h"
+#include "../raw_convert.h"
 #include "../types.h"
 
 using std::string;
@@ -114,7 +115,7 @@ Subtitle::fade_time (shared_ptr<const cxml::Node> node, string name)
        } else if (u.find (":") != string::npos) {
                t = Time (u);
        } else {
-               t = Time (0, 0, 0, lexical_cast<int> (u));
+               t = Time (0, 0, 0, raw_convert<int> (u));
        }
 
        if (t > Time (0, 0, 8, 0)) {
index b2eecee565038732c097f0fd11de4d22392870d2..8d3b0347fe144a9ef8c3f8acd4cfaa6f4800f631 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -36,6 +36,7 @@
 #include "exceptions.h"
 #include "xyz_frame.h"
 #include "picture_asset_writer.h"
+#include "raw_convert.h"
 
 using std::string;
 using std::ostream;
@@ -71,13 +72,13 @@ PictureAsset::write_to_cpl (xmlpp::Element* node) const
 
        assert (i != c.end ());
 
-       (*i)->add_child ("FrameRate")->add_child_text (lexical_cast<string> (_edit_rate * edit_rate_factor ()) + " 1");
+       (*i)->add_child ("FrameRate")->add_child_text (raw_convert<string> (_edit_rate * edit_rate_factor ()) + " 1");
        if (_interop) {
                stringstream s;
                s << std::fixed << std::setprecision (2) << (float (_size.width) / _size.height);
                (*i)->add_child ("ScreenAspectRatio")->add_child_text (s.str ());
        } else {
-               (*i)->add_child ("ScreenAspectRatio")->add_child_text (lexical_cast<string> (_size.width) + " " + lexical_cast<string> (_size.height));
+               (*i)->add_child ("ScreenAspectRatio")->add_child_text (raw_convert<string> (_size.width) + " " + raw_convert<string> (_size.height));
        }
 }
 
index 95244b902469eb0779bf0c85628d0989596e3587..54fbdb88b5727df4f9800404f0d0c14382f219e5 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
index 4eb1a9cdf54fe95257d5784f22cf01bf8474a8ba..89269fb039afeac18e973c81a6c23b2f643f0491 100644 (file)
@@ -19,7 +19,6 @@
 
 #include <fstream>
 #include <cerrno>
-#include <boost/lexical_cast.hpp>
 #include <boost/algorithm/string.hpp>
 #include <libxml++/nodes/element.h>
 #include "AS_DCP.h"
@@ -28,6 +27,7 @@
 #include "parse/subtitle.h"
 #include "util.h"
 #include "xml.h"
+#include "raw_convert.h"
 
 using std::string;
 using std::list;
@@ -36,7 +36,6 @@ using std::ofstream;
 using std::stringstream;
 using std::cout;
 using boost::shared_ptr;
-using boost::lexical_cast;
 using boost::optional;
 using namespace libdcp;
 
@@ -378,7 +377,7 @@ SubtitleAsset::xml_as_string () const
        if (_movie_title) {
                root->add_child("MovieTitle")->add_child_text (_movie_title.get ());
        }
-       root->add_child("ReelNumber")->add_child_text (lexical_cast<string> (_reel_number));
+       root->add_child("ReelNumber")->add_child_text (raw_convert<string> (_reel_number));
        root->add_child("Language")->add_child_text (_language);
 
        if (_load_font_nodes.size() > 1) {
@@ -446,7 +445,7 @@ SubtitleAsset::xml_as_string () const
                        font->set_attribute ("Id", id);
                        font->set_attribute ("Italic", italic ? "yes" : "no");
                        font->set_attribute ("Color", color.to_argb_string());
-                       font->set_attribute ("Size", lexical_cast<string> (size));
+                       font->set_attribute ("Size", raw_convert<string> (size));
                        font->set_attribute ("Effect", effect_to_string (effect));
                        font->set_attribute ("EffectColor", effect_color.to_argb_string());
                        font->set_attribute ("Script", "normal");
@@ -462,11 +461,11 @@ SubtitleAsset::xml_as_string () const
                            )) {
 
                        subtitle = font->add_child ("Subtitle");
-                       subtitle->set_attribute ("SpotNumber", lexical_cast<string> (spot_number++));
+                       subtitle->set_attribute ("SpotNumber", raw_convert<string> (spot_number++));
                        subtitle->set_attribute ("TimeIn", (*i)->in().to_string());
                        subtitle->set_attribute ("TimeOut", (*i)->out().to_string());
-                       subtitle->set_attribute ("FadeUpTime", lexical_cast<string> ((*i)->fade_up_time().to_ticks()));
-                       subtitle->set_attribute ("FadeDownTime", lexical_cast<string> ((*i)->fade_down_time().to_ticks()));
+                       subtitle->set_attribute ("FadeUpTime", raw_convert<string> ((*i)->fade_up_time().to_ticks()));
+                       subtitle->set_attribute ("FadeDownTime", raw_convert<string> ((*i)->fade_down_time().to_ticks()));
 
                        last_in = (*i)->in ();
                        last_out = (*i)->out ();
@@ -476,7 +475,7 @@ SubtitleAsset::xml_as_string () const
 
                xmlpp::Element* text = subtitle->add_child ("Text");
                text->set_attribute ("VAlign", valign_to_string ((*i)->v_align()));             
-               text->set_attribute ("VPosition", lexical_cast<string> ((*i)->v_position()));
+               text->set_attribute ("VPosition", raw_convert<string> ((*i)->v_position()));
                text->add_child_text ((*i)->text());
        }
 
index 693b9ab20272ee810407fd36a1e55b0071f0a0e8..f45e3345b8b5894c62a14dbf5ed44de98333b7aa 100644 (file)
@@ -1,3 +1,22 @@
+/*
+    Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
+
+    This program 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.
+
+    This program 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 this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
 #include <vector>
 #include <cstdio>
 #include <iomanip>
@@ -5,6 +24,7 @@
 #include <boost/algorithm/string.hpp>
 #include "types.h"
 #include "exceptions.h"
+#include "raw_convert.h"
 
 using namespace std;
 using namespace libdcp;
@@ -17,8 +37,8 @@ Fraction::Fraction (string s)
        if (b.size() != 2) {
                boost::throw_exception (XMLError ("malformed fraction " + s + " in XML node"));
        }
-       numerator = lexical_cast<int> (b[0]);
-       denominator = lexical_cast<int> (b[1]);
+       numerator = raw_convert<int> (b[0]);
+       denominator = raw_convert<int> (b[1]);
 }
 
 bool