#include "transcode_data.h" <% def str1(str) str.unpack("H*")[0] end map_amp = {} map_amp["{00-25,27-FF}"] = :nomap map_amp["26"] = str1("&") transcode_generate_node(ActionMap.parse(map_amp), "escape_amp_as_chref") map_xml_text = {} map_xml_text["{00-25,27-3B,3D,3F-FF}"] = :nomap map_xml_text["26"] = str1("&") map_xml_text["3C"] = str1("<") map_xml_text["3E"] = str1(">") transcode_generate_node(ActionMap.parse(map_xml_text), "escape_xml_text") map_xml_attr_content = {} map_xml_attr_content["{00-21,23-25,27-3B,3D,3F-FF}"] = :nomap map_xml_attr_content["22"] = str1(""") map_xml_attr_content["26"] = str1("&") map_xml_attr_content["3C"] = str1("<") map_xml_attr_content["3E"] = str1(">") transcode_generate_node(ActionMap.parse(map_xml_attr_content), "escape_xml_attr_content") 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") %> <%= transcode_generated_code %> static const rb_transcoder rb_escape_amp_as_chref = { "", "amp-escaped", escape_amp_as_chref, TRANSCODE_TABLE_INFO, 1, /* input_unit_length */ 1, /* max_input */ 5, /* max_output */ stateless_converter, /* stateful_type */ 0, NULL, NULL, NULL, NULL, NULL, NULL }; static const rb_transcoder rb_escape_xml_text = { "", "xml-text-escaped", escape_xml_text, TRANSCODE_TABLE_INFO, 1, /* input_unit_length */ 1, /* max_input */ 5, /* max_output */ stateless_converter, /* stateful_type */ 0, NULL, NULL, NULL, NULL, NULL, NULL }; static const rb_transcoder rb_escape_xml_attr_content = { "", "xml-attr-content-escaped", escape_xml_attr_content, TRANSCODE_TABLE_INFO, 1, /* input_unit_length */ 1, /* max_input */ 6, /* max_output */ stateless_converter, /* stateful_type */ 0, NULL, NULL, NULL, NULL, NULL, NULL }; #define END 0 #define NORMAL 1 static int escape_xml_attr_quote_init(void *statep) { unsigned char *sp = statep; *sp = END; return 0; } static int fun_so_escape_xml_attr_quote(void *statep, const unsigned char *s, size_t l, unsigned char *o) { unsigned char *sp = statep; int n = 0; if (*sp == END) { *sp = NORMAL; o[n++] = '"'; } o[n++] = s[0]; return n; } static int escape_xml_attr_quote_finish(void *statep, unsigned char *o) { unsigned char *sp = statep; int n = 0; if (*sp == END) { o[n++] = '"'; } o[n++] = '"'; *sp = END; return n; } static const rb_transcoder rb_escape_xml_attr_quote = { "", "xml-attr-quoted", escape_xml_attr_quote, TRANSCODE_TABLE_INFO, 1, /* input_unit_length */ 1, /* max_input */ 7, /* max_output */ stateful_encoder, /* stateful_type */ 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 }; void Init_escape(void) { rb_register_transcoder(&rb_escape_amp_as_chref); rb_register_transcoder(&rb_escape_xml_text); rb_register_transcoder(&rb_escape_xml_attr_content); rb_register_transcoder(&rb_escape_xml_attr_quote); }