2008-09-05 17:29:12 -04:00
|
|
|
#include "transcode_data.h"
|
|
|
|
|
|
|
|
<%
|
2008-09-07 07:03:24 -04:00
|
|
|
def hexstr(str)
|
2008-09-07 05:13:16 -04:00
|
|
|
str.unpack("H*")[0]
|
|
|
|
end
|
|
|
|
|
2008-09-12 13:30:07 -04:00
|
|
|
transcode_tblgen("", "amp_escape", [
|
2008-09-07 06:46:30 -04:00
|
|
|
["{00-25,27-FF}", :nomap],
|
2008-09-07 07:03:24 -04:00
|
|
|
["26", hexstr("&")]
|
2010-03-20 23:38:58 -04:00
|
|
|
], nil)
|
2008-09-07 06:46:30 -04:00
|
|
|
|
2008-09-12 13:30:07 -04:00
|
|
|
transcode_tblgen("", "xml_text_escape", [
|
2008-09-07 06:46:30 -04:00
|
|
|
["{00-25,27-3B,3D,3F-FF}", :nomap],
|
2008-09-07 07:03:24 -04:00
|
|
|
["26", hexstr("&")],
|
|
|
|
["3C", hexstr("<")],
|
|
|
|
["3E", hexstr(">")]
|
2010-03-20 23:38:58 -04:00
|
|
|
], nil)
|
2008-09-07 06:46:30 -04:00
|
|
|
|
2008-09-12 13:30:07 -04:00
|
|
|
transcode_tblgen("", "xml_attr_content_escape", [
|
2008-09-07 06:46:30 -04:00
|
|
|
["{00-21,23-25,27-3B,3D,3F-FF}", :nomap],
|
2008-09-07 07:03:24 -04:00
|
|
|
["22", hexstr(""")],
|
|
|
|
["26", hexstr("&")],
|
|
|
|
["3C", hexstr("<")],
|
|
|
|
["3E", hexstr(">")]
|
2010-03-20 23:38:58 -04:00
|
|
|
], nil)
|
2008-09-06 23:13:29 -04:00
|
|
|
|
|
|
|
map_xml_attr_quote = {}
|
|
|
|
map_xml_attr_quote["{00-FF}"] = :func_so
|
|
|
|
transcode_generate_node(ActionMap.parse(map_xml_attr_quote), "escape_xml_attr_quote")
|
2008-09-05 17:29:12 -04:00
|
|
|
%>
|
|
|
|
|
|
|
|
<%= transcode_generated_code %>
|
|
|
|
|
2008-09-05 23:20:51 -04:00
|
|
|
#define END 0
|
|
|
|
#define NORMAL 1
|
|
|
|
|
|
|
|
static int
|
2008-09-06 23:13:29 -04:00
|
|
|
escape_xml_attr_quote_init(void *statep)
|
2008-09-05 23:20:51 -04:00
|
|
|
{
|
|
|
|
unsigned char *sp = statep;
|
|
|
|
*sp = END;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-09-14 14:35:17 -04:00
|
|
|
static ssize_t
|
2008-09-14 14:06:20 -04:00
|
|
|
fun_so_escape_xml_attr_quote(void *statep, const unsigned char *s, size_t l, unsigned char *o, size_t osize)
|
2008-09-05 23:20:51 -04:00
|
|
|
{
|
|
|
|
unsigned char *sp = statep;
|
|
|
|
int n = 0;
|
|
|
|
if (*sp == END) {
|
|
|
|
*sp = NORMAL;
|
|
|
|
o[n++] = '"';
|
|
|
|
}
|
2008-09-06 23:13:29 -04:00
|
|
|
o[n++] = s[0];
|
2008-09-05 23:20:51 -04:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2008-09-14 14:35:17 -04:00
|
|
|
static ssize_t
|
2008-09-14 14:06:20 -04:00
|
|
|
escape_xml_attr_quote_finish(void *statep, unsigned char *o, size_t osize)
|
2008-09-05 23:20:51 -04:00
|
|
|
{
|
|
|
|
unsigned char *sp = statep;
|
|
|
|
int n = 0;
|
|
|
|
|
|
|
|
if (*sp == END) {
|
|
|
|
o[n++] = '"';
|
|
|
|
}
|
|
|
|
|
|
|
|
o[n++] = '"';
|
|
|
|
*sp = END;
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2008-09-05 17:29:12 -04:00
|
|
|
static const rb_transcoder
|
2008-09-06 23:13:29 -04:00
|
|
|
rb_escape_xml_attr_quote = {
|
2008-09-12 13:30:07 -04:00
|
|
|
"", "xml_attr_quote", escape_xml_attr_quote,
|
2008-09-05 17:29:12 -04:00
|
|
|
TRANSCODE_TABLE_INFO,
|
|
|
|
1, /* input_unit_length */
|
|
|
|
1, /* max_input */
|
2008-09-05 23:20:51 -04:00
|
|
|
7, /* max_output */
|
2008-09-08 10:33:17 -04:00
|
|
|
asciicompat_encoder, /* asciicompat_type */
|
2008-09-06 23:13:29 -04:00
|
|
|
1, escape_xml_attr_quote_init, escape_xml_attr_quote_init,
|
|
|
|
NULL, NULL, NULL, fun_so_escape_xml_attr_quote,
|
|
|
|
escape_xml_attr_quote_finish
|
2008-09-05 17:29:12 -04:00
|
|
|
};
|
|
|
|
|
2012-05-16 01:39:06 -04:00
|
|
|
TRANS_INIT(escape)
|
2008-09-05 17:29:12 -04:00
|
|
|
{
|
2008-09-07 06:46:30 -04:00
|
|
|
<%= transcode_register_code %>
|
2008-09-06 23:13:29 -04:00
|
|
|
rb_register_transcoder(&rb_escape_xml_attr_quote);
|
2008-09-05 17:29:12 -04:00
|
|
|
}
|
|
|
|
|