diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-13 05:48:57 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-13 05:48:57 +0000 |
commit | a14d5eb09bc791b7ada7897a8fdb6a243babbb78 (patch) | |
tree | b342f2f72bb763982d4d89001d4e8dd1d368de03 /transcode.c | |
parent | 74a2a7bdbfbf70febab024354fe0b7fb26300704 (diff) | |
download | ruby-a14d5eb09bc791b7ada7897a8fdb6a243babbb78.tar.gz |
* 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
Diffstat (limited to 'transcode.c')
-rw-r--r-- | transcode.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/transcode.c b/transcode.c index 507e1b0b9e..62e11c7551 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)); } |