From dbdc6fa19e2011dbcb59af1a55fbef2d9651e503 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Mon, 25 Aug 2003 10:21:09 +0000 Subject: [PATCH] Strings are postprocessed so that the special characters &, <, >, " are replaced by their HTML equivalents &, <, > and ". --- ChangeLog | 6 ++++++ src/tagwriter.cpp | 45 +++++++++++++++++++++++++++++++++++---------- 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index cdab785fe..0c1354abd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2003-08-25 Moritz Bunkus + + * mkvextract: Strings are postprocessed so that the special + characters &, <, >, " are replaced by their HTML equivalents + &, <, > and ". + 2003-08-24 Moritz Bunkus * mkvmerge: Disabled lacing by default and renamed --no-lacing to diff --git a/src/tagwriter.cpp b/src/tagwriter.cpp index 2242865ae..d28de6d33 100644 --- a/src/tagwriter.cpp +++ b/src/tagwriter.cpp @@ -50,11 +50,6 @@ static void print_tag(int level, const char *name, const char *fmt, ...) { mxprint(o, "\n", name); } -static void print_tag_and_free(int level, const char *name, char *str) { - print_tag(level, name, "%s", str); - safefree(str); -} - static void print_binary(int level, const char *name, EbmlElement *e) { EbmlBinary *b; string s; @@ -121,6 +116,38 @@ static void print_date(int level, const char *name, EbmlElement *e) { mxprint(o, "\n", name); } +static void print_string(int level, const char *name, const char *src) { + int idx; + string s; + + idx = 0; + s = ""; + while (src[idx] != 0) { + if (src[idx] == '&') + s += "&"; + else if (src[idx] == '<') + s += "<"; + else if (src[idx] == '>') + s += ">"; + else if (src[idx] == '"') + s += """; + else + s += src[idx]; + idx++; + } + for (idx = 0; idx < level; idx++) + mxprint(o, " "); + mxprint(o, "<%s>%s\n", name, s.c_str(), name); +} + +static void print_utf_string(int level, const char *name, EbmlElement *e) { + char *s; + + s = UTFstring_to_cstrutf8(*static_cast(e)); + print_string(level, name, s); + safefree(s); +} + static void print_unknown(int level, EbmlElement *e) { int idx; @@ -135,11 +162,9 @@ static void print_unknown(int level, EbmlElement *e) { int64(*static_cast(e))) #define pr_f(n) print_tag(level, n, "%f", \ float(*static_cast(e))) -#define pr_s(n) print_tag(level, n, "%s", \ - string(*static_cast(e)).c_str()) -#define pr_us(n) print_tag_and_free(level, n, \ - UTFstring_to_cstrutf8(UTFstring( \ - *static_cast(e)))) +#define pr_s(n) print_string(level, n, \ + string(*static_cast(e)).c_str()) +#define pr_us(n) print_utf_string(level, n, e) #define pr_d(n) print_date(level, n, e) #define pr_b(n) print_binary(level, n, e)