From 0fa1e1f5137021d0e7f25ccca034081b21a86b7f Mon Sep 17 00:00:00 2001 From: akr Date: Wed, 13 Aug 2008 05:48:57 +0000 Subject: * 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: http://svn.ruby-lang.org/repos/ruby/trunk@18557 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- transcode.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'transcode.c') diff --git a/transcode.c b/transcode.c index 507e1b0b9..62e11c755 100644 --- a/transcode.c +++ b/transcode.c @@ -683,7 +683,7 @@ trans_open_i(const char *from, const char *to, int depth, void *arg) transcoder_entry_t **entries; if (!*entries_ptr) { - entries = ALLOC_N(transcoder_entry_t *, depth+1+1); + entries = ALLOC_N(transcoder_entry_t *, depth+1+2); *entries_ptr = entries; } else { @@ -704,6 +704,16 @@ rb_trans_open(const char *from, const char *to, int flags) if (num_trans < 0 || !entries) 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) { transcoder_entry_t *e = get_transcoder_entry("universal_newline", ""); if (!e) @@ -1392,4 +1402,6 @@ Init_transcode(void) 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, "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)); } -- cgit