#include <openssl/sha.h>
#include <boost/filesystem.hpp>
#include <boost/algorithm/string.hpp>
+#include <boost/foreach.hpp>
#include <stdexcept>
#include <iostream>
#include <iomanip>
#ifdef XMLSEC_CRYPTO_DYNAMIC_LOADING
if (xmlSecCryptoDLLoadLibrary(BAD_CAST XMLSEC_CRYPTO) < 0) {
- throw MiscError ("unable to load default xmlsec-crypto library");
+ throw MiscError (String::compose("unable to load default xmlsec-crypto library '%1'", reinterpret_cast<const char*>((XMLSEC_CRYPTO))));
}
#endif
{
return opj_version ();
}
+
+string
+dcp::spaces (int n)
+{
+ string s = "";
+ for (int i = 0; i < n; ++i) {
+ s += " ";
+ }
+ return s;
+}
+
+void
+dcp::indent (xmlpp::Element* element, int initial)
+{
+ xmlpp::Node* last = 0;
+ BOOST_FOREACH (xmlpp::Node * n, element->get_children()) {
+ xmlpp::Element* e = dynamic_cast<xmlpp::Element*>(n);
+ if (e) {
+ element->add_child_text_before (e, "\n" + spaces(initial + 2));
+ indent (e, initial + 2);
+ last = n;
+ }
+ }
+ if (last) {
+ element->add_child_text (last, "\n" + spaces(initial));
+ }
+}
+
+/** @return true if the day represented by \ref a is less than or
+ * equal to the one represented by \ref b, ignoring the time parts.
+ */
+bool
+dcp::day_less_than_or_equal (LocalTime a, LocalTime b)
+{
+ if (a.year() != b.year()) {
+ return a.year() < b.year();
+ }
+
+ if (a.month() != b.month()) {
+ return a.month() < b.month();
+ }
+
+ return a.day() <= b.day();
+}
+
+/** @return true if the day represented by \ref a is greater than or
+ * equal to the one represented by \ref b, ignoring the time parts.
+ */
+bool
+dcp::day_greater_than_or_equal (LocalTime a, LocalTime b)
+{
+ if (a.year() != b.year()) {
+ return a.year() > b.year();
+ }
+
+ if (a.month() != b.month()) {
+ return a.month() > b.month();
+ }
+
+ return a.day() >= b.day();
+}
+
+/** Try quite hard to find a string which starts with \ref base and is
+ * not in \ref existing.
+ */
+string
+dcp::unique_string (list<string> existing, string base)
+{
+ int const max_tries = existing.size() + 1;
+ for (int i = 0; i < max_tries; ++i) {
+ string trial = String::compose("%1%2", base, i);
+ if (find(existing.begin(), existing.end(), trial) == existing.end()) {
+ return trial;
+ }
+ }
+
+ DCP_ASSERT (false);
+}