1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/enc/trans/escape.trans
akr 76b3063022 * include/ruby/encoding.h (ECONV_XML_TEXT_ENCODER): renamed from
ECONV_HTML_TEXT_ENCODER.
  (ECONV_XML_ATTR_ENCODER): renamed from ECONV_HTML_ATTR_ENCODER.

* enc/trans/escape.trans: follow the renaming.

* transcode.c: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19191 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-06 14:05:10 +00:00

157 lines
3.2 KiB
Text

#include "transcode_data.h"
static int
fun_so_escape_xml_chref(void *statep, const unsigned char *s, size_t l, unsigned char *o)
{
switch (*s) {
case '&':
o[0] = '&';
o[1] = 'a';
o[2] = 'm';
o[3] = 'p';
o[4] = ';';
return 5;
case '<':
o[0] = '&';
o[1] = 'l';
o[2] = 't';
o[3] = ';';
return 4;
case '>':
o[0] = '&';
o[1] = 'g';
o[2] = 't';
o[3] = ';';
return 4;
case '"':
o[0] = '&';
o[1] = 'q';
o[2] = 'u';
o[3] = 'o';
o[4] = 't';
o[5] = ';';
return 6;
default:
rb_bug("unexpected char");
}
}
<%
map_amp = {}
map_amp["{00-25,27-FF}"] = :nomap
map_amp["26"] = :func_so
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"] = :func_so
map_xml_text["3C"] = :func_so
map_xml_text["3E"] = :func_so
transcode_generate_node(ActionMap.parse(map_xml_text), "escape_xml_text")
map_xml_attr = {}
map_xml_attr["{00-FF}"] = :func_so
transcode_generate_node(ActionMap.parse(map_xml_attr), "escape_xml_attr")
%>
<%= 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, &fun_so_escape_xml_chref
};
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, &fun_so_escape_xml_chref
};
#define END 0
#define NORMAL 1
static int
escape_xml_attr_init(void *statep)
{
unsigned char *sp = statep;
*sp = END;
return 0;
}
static int
fun_so_escape_xml_attr(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++] = '"';
}
switch (s[0]) {
case '&':
case '<':
case '>':
case '"':
n += fun_so_escape_xml_chref(statep, s, l, o+n);
break;
default:
o[n++] = s[0];
break;
}
return n;
}
static int
escape_xml_attr_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 = {
"", "xml-attr-escaped", escape_xml_attr,
TRANSCODE_TABLE_INFO,
1, /* input_unit_length */
1, /* max_input */
7, /* max_output */
stateful_encoder, /* stateful_type */
1, escape_xml_attr_init, escape_xml_attr_init,
NULL, NULL, NULL, fun_so_escape_xml_attr,
escape_xml_attr_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);
}