summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/util.cc16
-rw-r--r--src/lib/util.h1
2 files changed, 16 insertions, 1 deletions
diff --git a/src/lib/util.cc b/src/lib/util.cc
index f434f358e..61c9dac06 100644
--- a/src/lib/util.cc
+++ b/src/lib/util.cc
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2012-2016 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
@@ -85,6 +85,8 @@ using std::set_terminate;
using boost::shared_ptr;
using boost::thread;
using boost::optional;
+using boost::lexical_cast;
+using boost::bad_lexical_cast;
using dcp::Size;
/** Path to our executable, required by the stacktrace stuff and filled
@@ -622,3 +624,15 @@ audio_asset_filename (shared_ptr<dcp::SoundAsset> asset)
{
return "pcm_" + asset->id() + ".mxf";
}
+
+float
+relaxed_string_to_float (string s)
+{
+ try {
+ boost::algorithm::replace_all (s, ",", ".");
+ return lexical_cast<float> (s);
+ } catch (bad_lexical_cast) {
+ boost::algorithm::replace_all (s, ".", ",");
+ return lexical_cast<float> (s);
+ }
+}
diff --git a/src/lib/util.h b/src/lib/util.h
index 5cfdae5f9..640933f00 100644
--- a/src/lib/util.h
+++ b/src/lib/util.h
@@ -74,5 +74,6 @@ extern void set_backtrace_file (boost::filesystem::path);
extern std::map<std::string, std::string> split_get_request (std::string url);
extern std::string video_asset_filename (boost::shared_ptr<dcp::PictureAsset> asset);
extern std::string audio_asset_filename (boost::shared_ptr<dcp::SoundAsset> asset);
+extern float relaxed_string_to_float (std::string);
#endif