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.

This commit is contained in:
Moritz Bunkus 2005-05-22 17:40:11 +00:00
parent cbe0a25c38
commit b034ec2188
4 changed files with 22 additions and 20 deletions

View File

@ -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,

View File

@ -225,8 +225,9 @@ string MTX_DLL_API join(const char *pattern, vector<string> &strings);
void MTX_DLL_API strip(string &s, bool newlines = false);
void MTX_DLL_API strip(vector<string> &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

View File

@ -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 + "</" + name + ">";
m_copy_buffer += escape_xml(m_data_buffer) + "</" + name + ">";
--m_copy_depth;
if (0 == m_copy_depth) {

View File

@ -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