From 937b96045830a2326daff83b70b892f2d25244ff Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 22 Dec 2014 23:35:43 +0000 Subject: [PATCH] Remove some unused code. --- src/lib/util.cc | 140 ---------------------------------------------- src/lib/util.h | 9 --- test/util_test.cc | 31 ---------- 3 files changed, 180 deletions(-) diff --git a/src/lib/util.cc b/src/lib/util.cc index 3ab864c2f..c0e32b778 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -1,6 +1,5 @@ /* Copyright (C) 2012-2014 Carl Hetherington - 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 @@ -418,30 +417,6 @@ dcpomatic_setup_gettext_i18n (string lang) #endif } -/** @param s A string. - * @return Parts of the string split at spaces, except when a space is within quotation marks. - */ -vector -split_at_spaces_considering_quotes (string s) -{ - vector 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 files, shared_ptr job) @@ -651,103 +626,6 @@ round_to (float n, int r) 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 -read_key_value (istream &s) -{ - multimap 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 const & kv, string k) -{ - if (kv.count (k) > 1) { - throw StringError (N_("unexpected multiple keys in key-value set")); - } - - multimap::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 const & kv, string k) -{ - string const v = get_required_string (kv, k); - return raw_convert (v); -} - -float -get_required_float (multimap const & kv, string k) -{ - string const v = get_required_string (kv, k); - return raw_convert (v); -} - -string -get_optional_string (multimap const & kv, string k) -{ - if (kv.count (k) > 1) { - throw StringError (N_("unexpected multiple keys in key-value set")); - } - - multimap::const_iterator i = kv.find (k); - if (i == kv.end ()) { - return N_(""); - } - - return i->second; -} - -int -get_optional_int (multimap const & kv, string k) -{ - if (kv.count (k) > 1) { - throw StringError (N_("unexpected multiple keys in key-value set")); - } - - multimap::const_iterator i = kv.find (k); - if (i == kv.end ()) { - return 0; - } - - return raw_convert (i->second); -} - /** Trip an assert if the caller is not in the UI thread */ void ensure_ui_thread () @@ -836,24 +714,6 @@ wrapped_av_malloc (size_t s) 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 () diff --git a/src/lib/util.h b/src/lib/util.h index ede53e0d9..9ae149ef4 100644 --- a/src/lib/util.h +++ b/src/lib/util.h @@ -61,7 +61,6 @@ extern std::string dependency_version_summary (); extern double seconds (struct timeval); extern void dcpomatic_setup (); extern void dcpomatic_setup_gettext_i18n (std::string); -extern std::vector split_at_spaces_considering_quotes (std::string); extern std::string md5_digest (std::vector, boost::shared_ptr); extern void ensure_ui_thread (); extern std::string audio_channel_name (int); @@ -72,18 +71,10 @@ extern boost::filesystem::path mo_path (); #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 read_key_value (std::istream& s); -extern int get_required_int (std::multimap const & kv, std::string k); -extern float get_required_float (std::multimap const & kv, std::string k); -extern std::string get_required_string (std::multimap const & kv, std::string k); -extern int get_optional_int (std::multimap const & kv, std::string k); -extern std::string get_optional_string (std::multimap 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); diff --git a/test/util_test.cc b/test/util_test.cc index 3817a8d08..43b7b9b1d 100644 --- a/test/util_test.cc +++ b/test/util_test.cc @@ -29,23 +29,6 @@ using std::string; 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 b = split_at_spaces_considering_quotes (t); - vector::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 p; @@ -75,20 +58,6 @@ BOOST_AUTO_TEST_CASE (dcptime_round_up_test) 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); -- 2.30.2