diff options
Diffstat (limited to 'enc')
-rw-r--r-- | enc/trans/newline.trans | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/enc/trans/newline.trans b/enc/trans/newline.trans index d62034aa49..a200ec00a7 100644 --- a/enc/trans/newline.trans +++ b/enc/trans/newline.trans @@ -48,26 +48,26 @@ fun_so_universal_newline(void *statep, const unsigned char *s, size_t l, unsigne if (s[0] == '\n') { if (STATE == NORMAL) { NEWLINES_MET |= MET_LF; - o[0] = '\n'; - len = 1; } else { /* JUST_AFTER_CR */ NEWLINES_MET |= MET_CRLF; - len = 0; } + o[0] = '\n'; + len = 1; STATE = NORMAL; } else { - if (STATE == JUST_AFTER_CR) - NEWLINES_MET |= MET_CR; - if (s[0] == '\r') { + len = 0; + if (STATE == JUST_AFTER_CR) { o[0] = '\n'; len = 1; + NEWLINES_MET |= MET_CR; + } + if (s[0] == '\r') { STATE = JUST_AFTER_CR; } else { - o[0] = s[0]; - len = 1; + o[len++] = s[0]; STATE = NORMAL; } } @@ -79,10 +79,14 @@ static ssize_t universal_newline_finish(void *statep, unsigned char *o, size_t osize) { unsigned char *sp = statep; - if (STATE == JUST_AFTER_CR) + int len = 0; + if (STATE == JUST_AFTER_CR) { + o[0] = '\n'; + len = 1; NEWLINES_MET |= MET_CR; + } STATE = NORMAL; - return 0; + return len; } static const rb_transcoder @@ -91,7 +95,7 @@ rb_universal_newline = { TRANSCODE_TABLE_INFO, 1, /* input_unit_length */ 1, /* max_input */ - 1, /* max_output */ + 2, /* max_output */ asciicompat_converter, /* asciicompat_type */ 2, universal_newline_init, universal_newline_init, /* state_size, state_init, state_fini */ NULL, NULL, NULL, fun_so_universal_newline, |