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 | 0fa1e1f5137021d0e7f25ccca034081b21a86b7f (patch) | |
| tree | b342f2f72bb763982d4d89001d4e8dd1d368de03 /transcode.c | |
| parent | f6144761ec56a481d21d194301f7d6ec59632855 (diff) | |
| download | ruby-0fa1e1f5137021d0e7f25ccca034081b21a86b7f.tar.gz ruby-0fa1e1f5137021d0e7f25ccca034081b21a86b7f.tar.xz ruby-0fa1e1f5137021d0e7f25ccca034081b21a86b7f.zip | |
* 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
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 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)); } |
