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/newline.trans
akr f6441bf61c * transcode_data.h (rb_transcoding): remove stateful field.
add state field.
  (TRANSCODING_STATE): defined.
  (rb_transcoder): add fields: state_size, state_init_func,
  state_fini_func.
  change rb_transcoding* argument to void*.

* transcode.c (transcode_restartable0): use TRANSCODING_STATE for
  first arguments of transcoder functions.
  (rb_transcoding_open_by_transcoder): initialize state field.
  (rb_transcoding_close): finalize state field.

* tool/transcode-tblgen.rb: provide state size/init/fini.

* enc/trans/newline.trans (universal_newline_init): defined.
  (fun_so_universal_newline): take void* as a state pointer.
  (rb_universal_newline): provide state size/init/fini.
  (rb_crlf_newline): ditto.
  (rb_cr_newline): ditto.

* enc/trans/iso2022.trans (iso2022jp_init): defined.
  (fun_si_iso2022jp_to_eucjp): take void* as a state pointer.
  (fun_so_iso2022jp_to_eucjp): ditto.
  (fun_so_eucjp_to_iso2022jp): ditto.
  (iso2022jp_reset_sequence_size): ditto.
  (finish_eucjp_to_iso2022jp): ditto.
  (rb_ISO_2022_JP_to_EUC_JP): provide state size/init/fini.
  (rb_EUC_JP_to_ISO_2022_JP): ditto.

* enc/trans/utf_16_32.trans (fun_so_from_utf_16be): take void* as a
  state pointer.
  (fun_so_to_utf_16be): ditto.
  (fun_so_from_utf_16le): ditto.
  (fun_so_to_utf_16le): ditto.
  (fun_so_from_utf_32be): ditto.
  (fun_so_to_utf_32be): ditto.
  (fun_so_from_utf_32le): ditto.
  (fun_so_to_utf_32le): ditto.
  (rb_from_UTF_16BE): provide state size/init/fini.
  (rb_to_UTF_16BE): ditto.
  (rb_from_UTF_16LE): ditto.
  (rb_to_UTF_16LE): ditto.
  (rb_from_UTF_32BE): ditto.
  (rb_to_UTF_32BE): ditto.
  (rb_from_UTF_32LE): ditto.
  (rb_to_UTF_32LE): ditto.

* enc/trans/japanese.trans (fun_so_eucjp2sjis): take void* as a state
  pointer.
  (fun_so_sjis2eucjp): ditto.
  (rb_eucjp2sjis): provide state size/init/fini.
  (rb_sjis2eucjp): provide state size/init/fini.



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

106 lines
2.4 KiB
Text

#include "transcode_data.h"
<%
map_normalize = {}
map_normalize["{00-ff}"] = :func_so
transcode_generate_node(ActionMap.parse(map_normalize), "universal_newline")
map_crlf = {}
map_crlf["{00-09,0b-ff}"] = :nomap
map_crlf["0a"] = "0d0a"
transcode_generate_node(ActionMap.parse(map_crlf), "crlf_newline")
map_cr = {}
map_cr["{00-09,0b-ff}"] = :nomap
map_cr["0a"] = "0d"
transcode_generate_node(ActionMap.parse(map_cr), "cr_newline")
%>
<%= transcode_generated_code %>
#define NORMAL 0
#define JUST_AFTER_CR 1
static int
universal_newline_init(void *statep)
{
unsigned char *sp = statep;
*sp = NORMAL;
return 0;
}
static int
fun_so_universal_newline(void *statep, const unsigned char* s, size_t l, unsigned char* o)
{
unsigned char *sp = statep;
int len;
if (s[0] == '\n') {
if (*sp == NORMAL) {
o[0] = '\n';
len = 1;
}
else { /* JUST_AFTER_CR */
len = 0;
}
*sp = NORMAL;
}
else if (s[0] == '\r') {
o[0] = '\n';
len = 1;
*sp = JUST_AFTER_CR;
}
else {
o[0] = s[0];
len = 1;
*sp = NORMAL;
}
return len;
}
static const rb_transcoder
rb_universal_newline = {
"universal_newline", "", universal_newline,
TRANSCODE_TABLE_INFO,
1, /* input_unit_length */
1, /* max_input */
1, /* max_output */
stateful_decoder, /* stateful_type */
1, universal_newline_init, universal_newline_init, /* state_size, state_init, state_fini */
NULL, NULL, NULL, fun_so_universal_newline
};
static const rb_transcoder
rb_crlf_newline = {
"", "crlf_newline", crlf_newline,
TRANSCODE_TABLE_INFO,
1, /* input_unit_length */
1, /* max_input */
2, /* max_output */
stateless_converter, /* stateful_type */
0, NULL, NULL, /* state_size, state_init, state_fini */
NULL, NULL, NULL, NULL
};
static const rb_transcoder
rb_cr_newline = {
"", "cr_newline", cr_newline,
TRANSCODE_TABLE_INFO,
1, /* input_unit_length */
1, /* max_input */
1, /* max_output */
stateless_converter, /* stateful_type */
0, NULL, NULL, /* state_size, state_init, state_fini */
NULL, NULL, NULL, NULL
};
void
Init_newline(void)
{
rb_register_transcoder(&rb_universal_newline);
rb_register_transcoder(&rb_crlf_newline);
rb_register_transcoder(&rb_cr_newline);
}