summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-09-06 11:07:01 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-09-06 11:07:01 +0000
commite4b70ffe43463e8723b692f1bebbdf17750be677 (patch)
tree0f668e956b2efd37d2eb9107b1b2bebdd8216025
parentf88c9f03f7c00402558f5b47331774b8b65fbaaa (diff)
* transcode.c (rb_econv_binmode): check actual transcoders.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19187 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog4
-rw-r--r--transcode.c57
2 files changed, 44 insertions, 17 deletions
diff --git a/ChangeLog b/ChangeLog
index ec8ad6e6f6..2ebc47a1e9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Sat Sep 6 20:06:09 2008 Tanaka Akira <akr@fsij.org>
+
+ * transcode.c (rb_econv_binmode): check actual transcoders.
+
Sat Sep 6 19:54:25 2008 Tanaka Akira <akr@fsij.org>
* transcode.c (rb_econv_open): fix last_tc.
diff --git a/transcode.c b/transcode.c
index e2ea56a3ba..6af3a238b5 100644
--- a/transcode.c
+++ b/transcode.c
@@ -1726,25 +1726,48 @@ rb_econv_str_convert(rb_econv_t *ec, VALUE src, int flags)
void
rb_econv_binmode(rb_econv_t *ec)
{
+ const rb_transcoder *trs[3];
+ int n, i, j;
+ transcoder_entry_t *entry;
+
+ n = 0;
if (ec->flags & ECONV_UNIVERSAL_NEWLINE_DECODER) {
- int i = ec->num_trans-1;
- rb_transcoding_close(ec->elems[i].tc);
- xfree(ec->elems[i].out_buf_start);
- ec->elems[i].tc = NULL;
- ec->elems[i].out_buf_start = NULL;
- ec->elems[i].out_data_start = NULL;
- ec->elems[i].out_data_end = NULL;
- ec->elems[i].out_buf_end = NULL;
- ec->num_trans--;
- ec->flags &= ~ECONV_UNIVERSAL_NEWLINE_DECODER;
- }
- if (ec->flags & (ECONV_CRLF_NEWLINE_ENCODER|ECONV_CR_NEWLINE_ENCODER)) {
- rb_transcoding_close(ec->elems[0].tc);
- xfree(ec->elems[0].out_buf_start);
- MEMMOVE(&ec->elems[0], &ec->elems[1], rb_econv_elem_t, ec->num_trans-1);
- ec->num_trans--;
- ec->flags &= ~(ECONV_CRLF_NEWLINE_ENCODER|ECONV_CR_NEWLINE_ENCODER);
+ entry = get_transcoder_entry("universal_newline", "");
+ if (entry->transcoder)
+ trs[n++] = entry->transcoder;
+ }
+ if (ec->flags & ECONV_CRLF_NEWLINE_ENCODER) {
+ entry = get_transcoder_entry("", "crlf_newline");
+ if (entry->transcoder)
+ trs[n++] = entry->transcoder;
+ }
+ if (ec->flags & ECONV_CR_NEWLINE_ENCODER) {
+ entry = get_transcoder_entry("", "cr_newline");
+ if (entry->transcoder)
+ trs[n++] = entry->transcoder;
+ }
+
+ j = 0;
+ for (i = 0; i < ec->num_trans; i++) {
+ int k;
+ for (k = 0; k < n; k++)
+ if (trs[k] == ec->elems[i].tc->transcoder)
+ break;
+ if (k == n) {
+ if (ec->last_tc == ec->elems[i].tc)
+ ec->last_trans_index = j;
+ ec->elems[j] = ec->elems[i];
+ j++;
+ }
+ else {
+ rb_transcoding_close(ec->elems[i].tc);
+ xfree(ec->elems[i].out_buf_start);
+ ec->num_trans--;
+ }
}
+
+ ec->flags &= ~(ECONV_UNIVERSAL_NEWLINE_DECODER|ECONV_CRLF_NEWLINE_ENCODER|ECONV_CR_NEWLINE_ENCODER);
+
}
static VALUE