From b034ec2188c9324c9127abbe33836b165165cc9e Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Sun, 22 May 2005 17:40:11 +0000 Subject: [PATCH] Moved the XML node name creation function into common.cpp. Escape the contents the XML way before putting them into CodecPrivate or the data blocks. --- src/common/common.cpp | 15 +++++++++++++++ src/common/common.h | 3 ++- src/input/r_usf.cpp | 23 +++++------------------ src/input/r_usf.h | 1 - 4 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/common/common.cpp b/src/common/common.cpp index 2bd40f43d..92787ecc9 100644 --- a/src/common/common.cpp +++ b/src/common/common.cpp @@ -908,6 +908,21 @@ escape_xml(const string &source, return dst; } +string +create_xml_node_name(const char *name, + const char **atts) { + int i; + string node_name; + + node_name = string("<") + name; + for (i = 0; (NULL != atts[i]) && (NULL != atts[i + 1]); i += 2) + node_name += string(" ") + atts[i] + "=\"" + + escape_xml(atts[i + 1], true) + "\""; + node_name += ">"; + + return node_name; +} + bool starts_with(const string &s, const char *start, diff --git a/src/common/common.h b/src/common/common.h index 6c0239f17..4e002d8e0 100644 --- a/src/common/common.h +++ b/src/common/common.h @@ -225,8 +225,9 @@ string MTX_DLL_API join(const char *pattern, vector &strings); void MTX_DLL_API strip(string &s, bool newlines = false); void MTX_DLL_API strip(vector &v, bool newlines = false); string MTX_DLL_API escape(const string &src); -string MTX_DLL_API escape_xml(const string &src, bool escape_quotes = false); string MTX_DLL_API unescape(const string &src); +string MTX_DLL_API escape_xml(const string &src, bool escape_quotes = false); +string MTX_DLL_API create_xml_node_name(const char *name, const char **atts); bool MTX_DLL_API starts_with(const string &s, const char *start, int maxlen = -1); inline bool diff --git a/src/input/r_usf.cpp b/src/input/r_usf.cpp index 51898d01f..0bedff3e7 100644 --- a/src/input/r_usf.cpp +++ b/src/input/r_usf.cpp @@ -158,21 +158,6 @@ usf_reader_c::~usf_reader_c() { XML_ParserFree(m_parser); } -string -usf_reader_c::create_node_name(const char *name, - const char **atts) { - int i; - string node_name; - - node_name = string("<") + name; - for (i = 0; (NULL != atts[i]) && (NULL != atts[i + 1]); i += 2) - node_name += string(" ") + atts[i] + "=\"" + - escape_xml(atts[i + 1], true) + "\""; - node_name += ">"; - - return node_name; -} - void usf_reader_c::start_cb(const char *name, const char **atts) { @@ -190,7 +175,8 @@ usf_reader_c::start_cb(const char *name, // Just copy the data. if (m_strip) strip(m_data_buffer); - m_copy_buffer += m_data_buffer + create_node_name(name, atts); + m_copy_buffer += escape_xml(m_data_buffer) + + create_xml_node_name(name, atts); ++m_copy_depth; m_data_buffer = ""; @@ -254,7 +240,8 @@ usf_reader_c::start_cb(const char *name, } else if (m_parents.size() == 2) { m_copy_depth = 1; strip(m_data_buffer); - m_copy_buffer = m_data_buffer + create_node_name(name, atts); + m_copy_buffer = escape_xml(m_data_buffer) + + create_xml_node_name(name, atts); m_strip = true; } @@ -285,7 +272,7 @@ usf_reader_c::end_cb(const char *name) { m_copy_buffer.erase(m_copy_buffer.length() - 1); m_copy_buffer += "/>"; } else - m_copy_buffer += m_data_buffer + ""; + m_copy_buffer += escape_xml(m_data_buffer) + ""; --m_copy_depth; if (0 == m_copy_depth) { diff --git a/src/input/r_usf.h b/src/input/r_usf.h index 1b83d7a1b..2e809bd68 100644 --- a/src/input/r_usf.h +++ b/src/input/r_usf.h @@ -87,7 +87,6 @@ public: private: virtual int64_t parse_timecode(const char *s); - virtual string create_node_name(const char *name, const char **atts); }; #endif // __R_USF_H