/*
Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
- Copyright (C) 2000-2007 Paul Davis
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
#endif
}
-/** @param s A string.
- * @return Parts of the string split at spaces, except when a space is within quotation marks.
- */
-vector<string>
-split_at_spaces_considering_quotes (string s)
-{
- vector<string> out;
- bool in_quotes = false;
- string c;
- for (string::size_type i = 0; i < s.length(); ++i) {
- if (s[i] == ' ' && !in_quotes) {
- out.push_back (c);
- c = N_("");
- } else if (s[i] == '"') {
- in_quotes = !in_quotes;
- } else {
- c += s[i];
- }
- }
-
- out.push_back (c);
- return out;
-}
-
/** @param job Optional job for which to report progress */
string
md5_digest (vector<boost::filesystem::path> files, shared_ptr<Job> job)
return int (n + float(r) / 2) &~ (r - 1);
}
-/** Read a sequence of key / value pairs from a text stream;
- * the keys are the first words on the line, and the values are
- * the remainder of the line following the key. Lines beginning
- * with # are ignored.
- * @param s Stream to read.
- * @return key/value pairs.
- */
-multimap<string, string>
-read_key_value (istream &s)
-{
- multimap<string, string> kv;
-
- string line;
- while (getline (s, line)) {
- if (line.empty ()) {
- continue;
- }
-
- if (line[0] == '#') {
- continue;
- }
-
- if (line[line.size() - 1] == '\r') {
- line = line.substr (0, line.size() - 1);
- }
-
- size_t const s = line.find (' ');
- if (s == string::npos) {
- continue;
- }
-
- kv.insert (make_pair (line.substr (0, s), line.substr (s + 1)));
- }
-
- return kv;
-}
-
-string
-get_required_string (multimap<string, string> const & kv, string k)
-{
- if (kv.count (k) > 1) {
- throw StringError (N_("unexpected multiple keys in key-value set"));
- }
-
- multimap<string, string>::const_iterator i = kv.find (k);
-
- if (i == kv.end ()) {
- throw StringError (String::compose (_("missing key %1 in key-value set"), k));
- }
-
- return i->second;
-}
-
-int
-get_required_int (multimap<string, string> const & kv, string k)
-{
- string const v = get_required_string (kv, k);
- return raw_convert<int> (v);
-}
-
-float
-get_required_float (multimap<string, string> const & kv, string k)
-{
- string const v = get_required_string (kv, k);
- return raw_convert<float> (v);
-}
-
-string
-get_optional_string (multimap<string, string> const & kv, string k)
-{
- if (kv.count (k) > 1) {
- throw StringError (N_("unexpected multiple keys in key-value set"));
- }
-
- multimap<string, string>::const_iterator i = kv.find (k);
- if (i == kv.end ()) {
- return N_("");
- }
-
- return i->second;
-}
-
-int
-get_optional_int (multimap<string, string> const & kv, string k)
-{
- if (kv.count (k) > 1) {
- throw StringError (N_("unexpected multiple keys in key-value set"));
- }
-
- multimap<string, string>::const_iterator i = kv.find (k);
- if (i == kv.end ()) {
- return 0;
- }
-
- return raw_convert<int> (i->second);
-}
-
/** Trip an assert if the caller is not in the UI thread */
void
ensure_ui_thread ()
return p;
}
-string
-entities_to_text (string e)
-{
- boost::algorithm::replace_all (e, "%3A", ":");
- boost::algorithm::replace_all (e, "%2F", "/");
- return e;
-}
-
-int64_t
-divide_with_round (int64_t a, int64_t b)
-{
- if (a % b >= (b / 2)) {
- return (a + b - 1) / b;
- } else {
- return a / b;
- }
-}
-
/** Return a user-readable string summarising the versions of our dependencies */
string
dependency_version_summary ()
extern double seconds (struct timeval);
extern void dcpomatic_setup ();
extern void dcpomatic_setup_gettext_i18n (std::string);
-extern std::vector<std::string> split_at_spaces_considering_quotes (std::string);
extern std::string md5_digest (std::vector<boost::filesystem::path>, boost::shared_ptr<Job>);
extern void ensure_ui_thread ();
extern std::string audio_channel_name (int);
#endif
extern std::string tidy_for_filename (std::string);
extern dcp::Size fit_ratio_within (float ratio, dcp::Size, int);
-extern std::string entities_to_text (std::string e);
extern int dcp_audio_frame_rate (int);
extern int stride_round_up (int, int const *, int);
extern int round_to (float n, int r);
-extern std::multimap<std::string, std::string> read_key_value (std::istream& s);
-extern int get_required_int (std::multimap<std::string, std::string> const & kv, std::string k);
-extern float get_required_float (std::multimap<std::string, std::string> const & kv, std::string k);
-extern std::string get_required_string (std::multimap<std::string, std::string> const & kv, std::string k);
-extern int get_optional_int (std::multimap<std::string, std::string> const & kv, std::string k);
-extern std::string get_optional_string (std::multimap<std::string, std::string> const & kv, std::string k);
extern void* wrapped_av_malloc (size_t);
-extern int64_t divide_with_round (int64_t a, int64_t b);
extern ContentTimePeriod subtitle_period (AVSubtitle const &);
extern void set_backtrace_file (boost::filesystem::path);
using std::vector;
using boost::shared_ptr;
-BOOST_AUTO_TEST_CASE (split_at_spaces_considering_quotes_test)
-{
- string t = "Hello this is a string \"with quotes\" and indeed without them";
- vector<string> b = split_at_spaces_considering_quotes (t);
- vector<string>::iterator i = b.begin ();
- BOOST_CHECK_EQUAL (*i++, "Hello");
- BOOST_CHECK_EQUAL (*i++, "this");
- BOOST_CHECK_EQUAL (*i++, "is");
- BOOST_CHECK_EQUAL (*i++, "a");
- BOOST_CHECK_EQUAL (*i++, "string");
- BOOST_CHECK_EQUAL (*i++, "with quotes");
- BOOST_CHECK_EQUAL (*i++, "and");
- BOOST_CHECK_EQUAL (*i++, "indeed");
- BOOST_CHECK_EQUAL (*i++, "without");
- BOOST_CHECK_EQUAL (*i++, "them");
-}
-
BOOST_AUTO_TEST_CASE (md5_digest_test)
{
vector<boost::filesystem::path> p;
BOOST_CHECK_EQUAL (DCPTime (45312).round_up (29.976), DCPTime (48045));
}
-
-BOOST_AUTO_TEST_CASE (divide_with_round_test)
-{
- BOOST_CHECK_EQUAL (divide_with_round (0, 4), 0);
- BOOST_CHECK_EQUAL (divide_with_round (1, 4), 0);
- BOOST_CHECK_EQUAL (divide_with_round (2, 4), 1);
- BOOST_CHECK_EQUAL (divide_with_round (3, 4), 1);
- BOOST_CHECK_EQUAL (divide_with_round (4, 4), 1);
- BOOST_CHECK_EQUAL (divide_with_round (5, 4), 1);
- BOOST_CHECK_EQUAL (divide_with_round (6, 4), 2);
-
- BOOST_CHECK_EQUAL (divide_with_round (1000, 500), 2);
-}
-
BOOST_AUTO_TEST_CASE (timecode_test)
{
DCPTime t = DCPTime::from_seconds (2 * 60 * 60 + 4 * 60 + 31) + DCPTime::from_frames (19, 24);