summaryrefslogtreecommitdiff
path: root/enc/trans
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-09-07 03:13:29 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-09-07 03:13:29 +0000
commit020e681eece7359f1cfcda9871b600084507dbb1 (patch)
tree7235e608341c13a79b9518f009f48d2e68d509cc /enc/trans
parent120772041e7addfc574e3b045cb4fc6a3517f4f4 (diff)
* include/ruby/encoding.h (ECONV_XML_ATTR_CONTENT_ENCODER): defined.
(ECONV_STATEFUL_ENCODER_MASK): defined. (ECONV_XML_ATTR_QUOTE_ENCODER): defined. (ECONV_XML_ATTR_ENCODER): removed. * enc/trans/escape.trans (rb_escape_xml_attr_content): defined. (rb_escape_xml_attr_quote): defined. (rb_escape_xml_attr): removed. * io.c (NEED_WRITECONV): writeconv is required if supplemental converter is used. (make_writeconv): apply stateful encoder in writeconv. * transcode.c: follow the constant change. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19209 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'enc/trans')
-rw-r--r--enc/trans/escape.trans59
1 files changed, 35 insertions, 24 deletions
diff --git a/enc/trans/escape.trans b/enc/trans/escape.trans
index 0641c6e251..a64114f533 100644
--- a/enc/trans/escape.trans
+++ b/enc/trans/escape.trans
@@ -52,9 +52,18 @@ fun_so_escape_xml_chref(void *statep, const unsigned char *s, size_t l, unsigned
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")
+ map_xml_attr_content = {}
+ map_xml_attr_content["{00-21,23-25,27-3B,3D,3F-FF}"] = :nomap
+ map_xml_attr_content["22"] = :func_so
+ map_xml_attr_content["26"] = :func_so
+ map_xml_attr_content["3C"] = :func_so
+ map_xml_attr_content["3E"] = :func_so
+ 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 %>
@@ -83,11 +92,23 @@ rb_escape_xml_text = {
NULL, NULL, NULL, &fun_so_escape_xml_chref
};
+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, &fun_so_escape_xml_chref
+};
+
#define END 0
#define NORMAL 1
static int
-escape_xml_attr_init(void *statep)
+escape_xml_attr_quote_init(void *statep)
{
unsigned char *sp = statep;
*sp = END;
@@ -95,7 +116,7 @@ escape_xml_attr_init(void *statep)
}
static int
-fun_so_escape_xml_attr(void *statep, const unsigned char *s, size_t l, unsigned char *o)
+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;
@@ -103,23 +124,12 @@ fun_so_escape_xml_attr(void *statep, const unsigned char *s, size_t l, unsigned
*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;
- }
+ o[n++] = s[0];
return n;
}
static int
-escape_xml_attr_finish(void *statep, unsigned char *o)
+escape_xml_attr_quote_finish(void *statep, unsigned char *o)
{
unsigned char *sp = statep;
int n = 0;
@@ -135,16 +145,16 @@ escape_xml_attr_finish(void *statep, unsigned char *o)
}
static const rb_transcoder
-rb_escape_xml_attr = {
- "", "xml-attr-escaped", escape_xml_attr,
+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_init, escape_xml_attr_init,
- NULL, NULL, NULL, fun_so_escape_xml_attr,
- escape_xml_attr_finish
+ 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
@@ -152,6 +162,7 @@ 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);
+ rb_register_transcoder(&rb_escape_xml_attr_content);
+ rb_register_transcoder(&rb_escape_xml_attr_quote);
}