2008-08-13 01:30:42 -04:00
|
|
|
#include "transcode_data.h"
|
|
|
|
|
|
|
|
<%
|
|
|
|
map_normalize = {}
|
|
|
|
map_normalize["{00-ff}"] = :func_so
|
2008-08-31 13:35:00 -04:00
|
|
|
|
|
|
|
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")
|
2008-08-13 01:30:42 -04:00
|
|
|
%>
|
|
|
|
|
2008-08-31 13:35:00 -04:00
|
|
|
<%= transcode_generated_code %>
|
2008-08-13 01:30:42 -04:00
|
|
|
|
|
|
|
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 */
|
2008-08-22 12:44:00 -04:00
|
|
|
stateful_decoder, /* stateful_type */
|
2008-08-13 01:30:42 -04:00
|
|
|
NULL, NULL, NULL, fun_so_universal_newline
|
|
|
|
};
|
|
|
|
|
2008-08-13 01:48:57 -04:00
|
|
|
static const rb_transcoder
|
|
|
|
rb_crlf_newline = {
|
|
|
|
"", "crlf_newline", &crlf_newline,
|
|
|
|
1, /* input_unit_length */
|
|
|
|
1, /* max_input */
|
|
|
|
2, /* max_output */
|
2008-08-15 19:13:01 -04:00
|
|
|
stateless_converter, /* stateful_type */
|
2008-08-13 01:48:57 -04:00
|
|
|
NULL, NULL, NULL, NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static const rb_transcoder
|
|
|
|
rb_cr_newline = {
|
|
|
|
"", "cr_newline", &cr_newline,
|
|
|
|
1, /* input_unit_length */
|
|
|
|
1, /* max_input */
|
|
|
|
1, /* max_output */
|
2008-08-15 19:13:01 -04:00
|
|
|
stateless_converter, /* stateful_type */
|
2008-08-13 01:48:57 -04:00
|
|
|
NULL, NULL, NULL, NULL
|
|
|
|
};
|
2008-08-13 01:30:42 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
Init_newline(void)
|
|
|
|
{
|
|
|
|
rb_register_transcoder(&rb_universal_newline);
|
2008-08-13 01:48:57 -04:00
|
|
|
rb_register_transcoder(&rb_crlf_newline);
|
|
|
|
rb_register_transcoder(&rb_cr_newline);
|
2008-08-13 01:30:42 -04:00
|
|
|
}
|
|
|
|
|