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 7a0bea4fd3 * include/ruby/encoding.h (rb_econv_t): add fields: in_buf_start,
in_data_start, in_data_end, in_buf_end and last_trans_index.
  (rb_econv_output): removed.
  (rb_econv_insert_output): declared.
  (rb_econv_encoding_to_insert_output): declared.

* enc/trans/newline.trans (rb_universal_newline): stateful_type
  changed.

* transcode.c (transcode_restartable0): initialize inchar_start,
  tc->recognized_len and next_table at beginning of the loop.
  (rb_econv_open_by_transcoder_entries): initialize new fields.
  (rb_econv_open): setup last_trans_index.
  (trans_sweep): last out_buf_start can be non-NULL now.
  (rb_econv_convert): check last out_buf_start and in_buf_start at
  first.
  (rb_econv_output_with_destination_encoding): removed.
  (econv_just_convert): removed.
  (rb_econv_output): removed.
  (econv_primitive_output): method removed.
  (rb_econv_encoding_to_insert_output): new function.
  (allocate_converted_string): new function.
  (rb_econv_insert_output): new function.
  (econv_primitive_insert_output): new method.
  (output_replacement_character): use rb_econv_insert_output.  unused
  arguments removed.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18654 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-08-16 05:32:42 +00:00

94 lines
2 KiB
Text

#include "transcode_data.h"
<%
map_normalize = {}
map_normalize["{00-ff}"] = :func_so
%>
<%= transcode_generate_node(ActionMap.parse(map_normalize), "universal_newline") %>
static int
fun_so_universal_newline(rb_transcoding* t, const unsigned char* s, size_t l, unsigned char* o)
{
int len;
/*
t->stateful[0] == 0 : normal
t->stateful[0] == 1 : just after '\r'
*/
if (s[0] == '\n') {
if (t->stateful[0] == 0) {
o[0] = '\n';
len = 1;
}
else {
len = 0;
}
t->stateful[0] = 0;
}
else if (s[0] == '\r') {
o[0] = '\n';
len = 1;
t->stateful[0] = 1;
}
else {
o[0] = s[0];
len = 1;
t->stateful[0] = 0;
}
return len;
}
static const rb_transcoder
rb_universal_newline = {
"universal_newline", "", &universal_newline,
1, /* input_unit_length */
1, /* max_input */
1, /* max_output */
stateless_converter, /* stateful_type */
NULL, NULL, NULL, fun_so_universal_newline
};
<%
map_crlf = {}
map_crlf["{00-09,0b-ff}"] = :nomap
map_crlf["0a"] = "0d0a"
%>
<%= transcode_generate_node(ActionMap.parse(map_crlf), "crlf_newline") %>
static const rb_transcoder
rb_crlf_newline = {
"", "crlf_newline", &crlf_newline,
1, /* input_unit_length */
1, /* max_input */
2, /* max_output */
stateless_converter, /* stateful_type */
NULL, NULL, NULL, NULL
};
<%
map_cr = {}
map_cr["{00-09,0b-ff}"] = :nomap
map_cr["0a"] = "0d"
%>
<%= transcode_generate_node(ActionMap.parse(map_cr), "cr_newline") %>
static const rb_transcoder
rb_cr_newline = {
"", "cr_newline", &cr_newline,
1, /* input_unit_length */
1, /* max_input */
1, /* max_output */
stateless_converter, /* stateful_type */
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);
}