1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* enc/trans/newline.trans (fun_so_universal_newline): generate \n

after \r\n detection instead of just after \r.
  [ruby-list:45988] [ruby-core:25881] [ruby-core:26788]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25883 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2009-11-22 19:15:55 +00:00
parent 5181fa2a55
commit cc128e3ecf
4 changed files with 37 additions and 15 deletions

View file

@ -1,3 +1,9 @@
Mon Nov 23 04:12:00 2009 Tanaka Akira <akr@fsij.org>
* enc/trans/newline.trans (fun_so_universal_newline): generate \n
after \r\n detection instead of just after \r.
[ruby-list:45988] [ruby-core:25881] [ruby-core:26788]
Sat Nov 21 18:48:35 2009 Tanaka Akira <akr@fsij.org>
* vm_eval.c (rb_search_method_entry): show flags and klass value in

View file

@ -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,

View file

@ -399,7 +399,7 @@ class TestEncodingConverter < Test::Unit::TestCase
src << "abc\r\ndef"; check_ec("abc\ndef", "", :source_buffer_empty, *a)
src << "ghi\njkl"; check_ec("abc\ndefghi\njkl", "", :source_buffer_empty, *a)
src << "mno\rpqr"; check_ec("abc\ndefghi\njklmno\npqr", "", :source_buffer_empty, *a)
src << "stu\r"; check_ec("abc\ndefghi\njklmno\npqrstu\n", "", :source_buffer_empty, *a)
src << "stu\r"; check_ec("abc\ndefghi\njklmno\npqrstu", "", :source_buffer_empty, *a)
src << "\nvwx"; check_ec("abc\ndefghi\njklmno\npqrstu\nvwx", "", :source_buffer_empty, *a)
src << "\nyz"; check_ec("abc\ndefghi\njklmno\npqrstu\nvwx\nyz", "", :source_buffer_empty, *a)
end
@ -410,11 +410,25 @@ class TestEncodingConverter < Test::Unit::TestCase
src << "abc\r\ndef"; check_ec("abc\ndef", "", :source_buffer_empty, *a)
src << "ghi\njkl"; check_ec("abc\ndefghi\njkl", "", :source_buffer_empty, *a)
src << "mno\rpqr"; check_ec("abc\ndefghi\njklmno\npqr", "", :source_buffer_empty, *a)
src << "stu\r"; check_ec("abc\ndefghi\njklmno\npqrstu\n", "", :source_buffer_empty, *a)
src << "stu\r"; check_ec("abc\ndefghi\njklmno\npqrstu", "", :source_buffer_empty, *a)
src << "\nvwx"; check_ec("abc\ndefghi\njklmno\npqrstu\nvwx", "", :source_buffer_empty, *a)
src << "\nyz"; check_ec("abc\ndefghi\njklmno\npqrstu\nvwx\nyz", "", :source_buffer_empty, *a)
end
def test_universal_newline3
ec = Encoding::Converter.new("", "", universal_newline: true)
a = ["", src="", ec, nil, 50, :partial_input=>true]
src << "abc\r\ndef"; check_ec("abc\ndef", "", :source_buffer_empty, *a)
src << "ghi\njkl"; check_ec("abc\ndefghi\njkl", "", :source_buffer_empty, *a)
src << "mno\rpqr"; check_ec("abc\ndefghi\njklmno\npqr", "", :source_buffer_empty, *a)
src << "stu\r"; check_ec("abc\ndefghi\njklmno\npqrstu", "", :source_buffer_empty, *a)
src << "\nvwx"; check_ec("abc\ndefghi\njklmno\npqrstu\nvwx", "", :source_buffer_empty, *a)
src << "\nyz"; check_ec("abc\ndefghi\njklmno\npqrstu\nvwx\nyz", "", :source_buffer_empty, *a)
src << "\r"; check_ec("abc\ndefghi\njklmno\npqrstu\nvwx\nyz", "", :source_buffer_empty, *a)
a[-1] = nil
src << ""; check_ec("abc\ndefghi\njklmno\npqrstu\nvwx\nyz\n", "", :finished, *a)
end
def test_crlf_newline
ec = Encoding::Converter.new("UTF-8", "EUC-JP", crlf_newline: true)
assert_econv("abc\r\ndef", :finished, 50, ec, "abc\ndef", "")

View file

@ -1511,7 +1511,6 @@ EOT
assert_equal("a", f.getc)
assert_equal("\n", f.getc)
f.binmode
assert_equal("\n", f.getc)
assert_equal("b", f.getc)
assert_equal("\r", f.getc)
assert_equal("\n", f.getc)
@ -1531,7 +1530,6 @@ EOT
assert_equal("a", f.getc)
assert_equal("\n", f.getc)
f.binmode
assert_equal("\n", f.getc)
assert_equal("b", f.getc)
assert_equal("\r", f.getc)
assert_equal("\n", f.getc)