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 6270ad5b7f * include/ruby/encoding.h (rb_econv_asciicompat_encoding): renamed
from rb_econv_stateless_encoding to apply stateless ASCII
  incompatible encodings such as UTF-16BE.

* io.c (make_writeconv): use rb_econv_asciicompat_encoding.

* transcode_data.h (rb_transcoder_asciicompat_type_t): renamed from
  rb_transcoder_stateful_type_t.
  (rb_transcoder): use rb_transcoder_asciicompat_type_t.

* transcode.c: follow the type change.
  (asciicompat_encoding_i): renamed from stateless_encoding_i.
  (rb_econv_asciicompat_encoding): renamed from
  rb_econv_stateless_encoding.
  (econv_s_asciicompat_encoding): method renamed.

* tool/transcode-tblgen.rb: follow the type change.

* enc/trans/utf_16_32.trans: follow the type change.
  rb_from_UTF_16BE to UTF-8 is asciicompat_decoder.
  rb_from_UTF_16LE to UTF-8 is asciicompat_decoder.
  rb_from_UTF_32BE to UTF-8 is asciicompat_decoder.
  rb_from_UTF_32LE to UTF-8 is asciicompat_decoder.
  UTF-8 to rb_to_UTF_16BE is asciicompat_encoder.
  UTF-8 to rb_to_UTF_16LE is asciicompat_encoder.
  UTF-8 to rb_to_UTF_32BE is asciicompat_encoder.
  UTF-8 to rb_to_UTF_32LE is asciicompat_encoder.

* enc/trans/newline.trans: follow the type change.  universal newline
  decoder is asciicompat_converter.

* enc/trans/escape.trans: follow the type change.

* enc/trans/iso2022.trans: ditto.

* enc/trans/japanese.trans: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19249 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-09-08 14:33:17 +00:00

94 lines
1.9 KiB
Text

#include "transcode_data.h"
<%
def hexstr(str)
str.unpack("H*")[0]
end
transcode_tblgen("", "amp-escaped", [
["{00-25,27-FF}", :nomap],
["26", hexstr("&amp;")]
])
transcode_tblgen("", "xml-text-escaped", [
["{00-25,27-3B,3D,3F-FF}", :nomap],
["26", hexstr("&amp;")],
["3C", hexstr("&lt;")],
["3E", hexstr("&gt;")]
])
transcode_tblgen("", "xml-attr-content-escaped", [
["{00-21,23-25,27-3B,3D,3F-FF}", :nomap],
["22", hexstr("&quot;")],
["26", hexstr("&amp;")],
["3C", hexstr("&lt;")],
["3E", hexstr("&gt;")]
])
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 %>
#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 */
asciicompat_encoder, /* asciicompat_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)
{
<%= transcode_register_code %>
rb_register_transcoder(&rb_escape_xml_attr_quote);
}