X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Futil.cc;h=d5b6cb9f4eaeed6ccc33a493ea6766eac9389446;hb=86d0fa1b9521abbffd63a82dd39e887f68812a6f;hp=3d90ccaa4fe7f6e1155c45cd8e2d6e7ec43e2c88;hpb=8259e2771f85c33c531a83fe1a78668f158208da;p=libdcp.git diff --git a/src/util.cc b/src/util.cc index 3d90ccaa..d5b6cb9f 100644 --- a/src/util.cc +++ b/src/util.cc @@ -55,6 +55,7 @@ #include #include #include +#include #include #include #include @@ -148,75 +149,6 @@ dcp::make_digest (boost::filesystem::path filename, function progr return Kumu::base64encode (byte_buffer, SHA_DIGEST_LENGTH, digest, 64); } -/** Convert a content kind to a string which can be used in a - * <ContentKind> node. - * @param kind ContentKind. - * @return string. - */ -string -dcp::content_kind_to_string (ContentKind kind) -{ - switch (kind) { - case FEATURE: - return "feature"; - case SHORT: - return "short"; - case TRAILER: - return "trailer"; - case TEST: - return "test"; - case TRANSITIONAL: - return "transitional"; - case RATING: - return "rating"; - case TEASER: - return "teaser"; - case POLICY: - return "policy"; - case PUBLIC_SERVICE_ANNOUNCEMENT: - return "psa"; - case ADVERTISEMENT: - return "advertisement"; - } - - DCP_ASSERT (false); -} - -/** Convert a string from a <ContentKind> node to a libdcp ContentKind. - * Reasonably tolerant about varying case. - * @param kind Content kind string. - * @return libdcp ContentKind. - */ -dcp::ContentKind -dcp::content_kind_from_string (string kind) -{ - transform (kind.begin(), kind.end(), kind.begin(), ::tolower); - - if (kind == "feature") { - return FEATURE; - } else if (kind == "short") { - return SHORT; - } else if (kind == "trailer") { - return TRAILER; - } else if (kind == "test") { - return TEST; - } else if (kind == "transitional") { - return TRANSITIONAL; - } else if (kind == "rating") { - return RATING; - } else if (kind == "teaser") { - return TEASER; - } else if (kind == "policy") { - return POLICY; - } else if (kind == "psa") { - return PUBLIC_SERVICE_ANNOUNCEMENT; - } else if (kind == "advertisement") { - return ADVERTISEMENT; - } - - DCP_ASSERT (false); -} - /** @param s A string. * @return true if the string contains only space, newline or tab characters, or is empty. */ @@ -417,3 +349,30 @@ dcp::openjpeg_version () { 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(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)); + } +}