mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* enc/trans/newline.trans (rb_crlf_newline): new transcoder.
(rb_cr_newline): new transcoder. * transcode.c (trans_open_i): one more exra room for input newline converter. (rb_trans_open): crlf newline and cr newline implemented. (Init_transcode): Encoding::Converter::CRLF_NEWLINE and Encoding::Converter::LF_NEWLINE defined. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18557 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
74a2a7bdbf
commit
a14d5eb09b
4 changed files with 72 additions and 2 deletions
13
ChangeLog
13
ChangeLog
|
@ -1,3 +1,14 @@
|
||||||
|
Wed Aug 13 14:45:37 2008 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
|
* enc/trans/newline.trans (rb_crlf_newline): new transcoder.
|
||||||
|
(rb_cr_newline): new transcoder.
|
||||||
|
|
||||||
|
* transcode.c (trans_open_i): one more exra room for input newline
|
||||||
|
converter.
|
||||||
|
(rb_trans_open): crlf newline and cr newline implemented.
|
||||||
|
(Init_transcode): Encoding::Converter::CRLF_NEWLINE and
|
||||||
|
Encoding::Converter::LF_NEWLINE defined.
|
||||||
|
|
||||||
Wed Aug 13 14:22:16 2008 Tanaka Akira <akr@fsij.org>
|
Wed Aug 13 14:22:16 2008 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
* enc/trans/newline.trans: new file.
|
* enc/trans/newline.trans: new file.
|
||||||
|
@ -8,7 +19,7 @@ Wed Aug 13 14:22:16 2008 Tanaka Akira <akr@fsij.org>
|
||||||
(CRLF_NEWLINE): defined.
|
(CRLF_NEWLINE): defined.
|
||||||
(CR_NEWLINE): defined.
|
(CR_NEWLINE): defined.
|
||||||
(rb_trans_open_by_transcoder_entries): initialize last_tc.
|
(rb_trans_open_by_transcoder_entries): initialize last_tc.
|
||||||
(trans_open_i): allocate one more room for newline converter.
|
(trans_open_i): allocate one more room for output newline converter.
|
||||||
(rb_trans_open): universal newline implemented.
|
(rb_trans_open): universal newline implemented.
|
||||||
(more_output_buffer): take max_output argument instead ts.
|
(more_output_buffer): take max_output argument instead ts.
|
||||||
(output_replacement_character): take tc argument instead of ts.
|
(output_replacement_character): take tc argument instead of ts.
|
||||||
|
|
|
@ -47,10 +47,45 @@ rb_universal_newline = {
|
||||||
NULL, NULL, NULL, fun_so_universal_newline
|
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 */
|
||||||
|
NULL, NULL, NULL, NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
<%
|
||||||
|
map_crlf = {}
|
||||||
|
map_crlf["{00-09,0b-ff}"] = :nomap
|
||||||
|
map_crlf["0a"] = "0d"
|
||||||
|
%>
|
||||||
|
|
||||||
|
<%= transcode_generate_node(ActionMap.parse(map_crlf), "cr_newline") %>
|
||||||
|
|
||||||
|
static const rb_transcoder
|
||||||
|
rb_cr_newline = {
|
||||||
|
"", "cr_newline", &cr_newline,
|
||||||
|
1, /* input_unit_length */
|
||||||
|
1, /* max_input */
|
||||||
|
1, /* max_output */
|
||||||
|
NULL, NULL, NULL, NULL
|
||||||
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
Init_newline(void)
|
Init_newline(void)
|
||||||
{
|
{
|
||||||
rb_register_transcoder(&rb_universal_newline);
|
rb_register_transcoder(&rb_universal_newline);
|
||||||
|
rb_register_transcoder(&rb_crlf_newline);
|
||||||
|
rb_register_transcoder(&rb_cr_newline);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,4 +64,16 @@ class TestEncodingConverter < Test::Unit::TestCase
|
||||||
ret = ec.primitive_convert(src="\nvwx", dst="", 50, Encoding::Converter::PARTIAL_INPUT)
|
ret = ec.primitive_convert(src="\nvwx", dst="", 50, Encoding::Converter::PARTIAL_INPUT)
|
||||||
assert_equal([:ibuf_empty, "", "vwx"], [ret, src, dst])
|
assert_equal([:ibuf_empty, "", "vwx"], [ret, src, dst])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_crlf_newline
|
||||||
|
ec = Encoding::Converter.new("UTF-8", "EUC-JP", Encoding::Converter::CRLF_NEWLINE)
|
||||||
|
ret = ec.primitive_convert(src="abc\ndef", dst="", 50, 0)
|
||||||
|
assert_equal([:finished, "", "abc\r\ndef"], [ret, src, dst])
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_cr_newline
|
||||||
|
ec = Encoding::Converter.new("UTF-8", "EUC-JP", Encoding::Converter::CR_NEWLINE)
|
||||||
|
ret = ec.primitive_convert(src="abc\ndef", dst="", 50, 0)
|
||||||
|
assert_equal([:finished, "", "abc\rdef"], [ret, src, dst])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
14
transcode.c
14
transcode.c
|
@ -683,7 +683,7 @@ trans_open_i(const char *from, const char *to, int depth, void *arg)
|
||||||
transcoder_entry_t **entries;
|
transcoder_entry_t **entries;
|
||||||
|
|
||||||
if (!*entries_ptr) {
|
if (!*entries_ptr) {
|
||||||
entries = ALLOC_N(transcoder_entry_t *, depth+1+1);
|
entries = ALLOC_N(transcoder_entry_t *, depth+1+2);
|
||||||
*entries_ptr = entries;
|
*entries_ptr = entries;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -704,6 +704,16 @@ rb_trans_open(const char *from, const char *to, int flags)
|
||||||
if (num_trans < 0 || !entries)
|
if (num_trans < 0 || !entries)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
if (flags & (CRLF_NEWLINE|CR_NEWLINE)) {
|
||||||
|
char *name = (flags & CRLF_NEWLINE) ? "crlf_newline" : "cr_newline";
|
||||||
|
transcoder_entry_t *e = get_transcoder_entry("", name);
|
||||||
|
if (!e)
|
||||||
|
return NULL;
|
||||||
|
MEMMOVE(entries+1, entries, transcoder_entry_t *, num_trans);
|
||||||
|
entries[0] = e;
|
||||||
|
num_trans++;
|
||||||
|
}
|
||||||
|
|
||||||
if (flags & UNIVERSAL_NEWLINE) {
|
if (flags & UNIVERSAL_NEWLINE) {
|
||||||
transcoder_entry_t *e = get_transcoder_entry("universal_newline", "");
|
transcoder_entry_t *e = get_transcoder_entry("universal_newline", "");
|
||||||
if (!e)
|
if (!e)
|
||||||
|
@ -1392,4 +1402,6 @@ Init_transcode(void)
|
||||||
rb_define_method(rb_cEncodingConverter, "max_output", econv_max_output, 0);
|
rb_define_method(rb_cEncodingConverter, "max_output", econv_max_output, 0);
|
||||||
rb_define_const(rb_cEncodingConverter, "PARTIAL_INPUT", INT2FIX(PARTIAL_INPUT));
|
rb_define_const(rb_cEncodingConverter, "PARTIAL_INPUT", INT2FIX(PARTIAL_INPUT));
|
||||||
rb_define_const(rb_cEncodingConverter, "UNIVERSAL_NEWLINE", INT2FIX(UNIVERSAL_NEWLINE));
|
rb_define_const(rb_cEncodingConverter, "UNIVERSAL_NEWLINE", INT2FIX(UNIVERSAL_NEWLINE));
|
||||||
|
rb_define_const(rb_cEncodingConverter, "CRLF_NEWLINE", INT2FIX(CRLF_NEWLINE));
|
||||||
|
rb_define_const(rb_cEncodingConverter, "CR_NEWLINE", INT2FIX(CR_NEWLINE));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue