summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-10-30 08:43:28 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-10-30 08:43:28 +0000
commit54d534f04313a0437a613516169cb243b695ccaf (patch)
tree04fc0c8f6e436dbe5025298e3d61851252820e27 /string.c
parent864bc4f18beb189c07a22e605810bb8d6eef5645 (diff)
* string.c (rb_str_chomp_bang): do smart chomp if $/ == '\n'.
* io.c (rb_io_puts): don't treat Array specially. * bignum.c (rb_big_cmp): should convert bignum to float. * eval.c (rb_f_eval): can't modify untainted binding. * regex.c (re_compile_pattern): should preverve p0 value. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1803 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/string.c b/string.c
index a461222..c57ebb5 100644
--- a/string.c
+++ b/string.c
@@ -2661,15 +2661,37 @@ rb_str_chomp_bang(argc, argv, str)
long len = RSTRING(str)->len;
if (rb_scan_args(argc, argv, "01", &rs) == 0) {
+ if (len == 0) return Qnil;
rs = rb_rs;
+ if (rs == rb_default_rs) {
+ smart_chomp:
+ rb_str_modify(str);
+ if (RSTRING(str)->ptr[len-1] == '\n') {
+ RSTRING(str)->len--;
+ if (RSTRING(str)->len > 0 &&
+ RSTRING(str)->ptr[RSTRING(str)->len-1] == '\r') {
+ RSTRING(str)->len--;
+ }
+ return str;
+ }
+ else if (RSTRING(str)->ptr[len-1] == '\r') {
+ RSTRING(str)->len--;
+ return str;
+ }
+ return Qnil;
+ }
}
if (NIL_P(rs)) return Qnil;
+ if (len == 0) return Qnil;
StringValue(rs);
+ rb_str_modify(str);
rslen = RSTRING(rs)->len;
if (rslen == 0) {
while (len>0 && p[len-1] == '\n') {
len--;
+ if (len>0 && p[len-1] == '\r')
+ len--;
}
if (len < RSTRING(str)->len) {
rb_str_modify(str);
@@ -2681,6 +2703,8 @@ rb_str_chomp_bang(argc, argv, str)
}
if (rslen > len) return Qnil;
newline = RSTRING(rs)->ptr[rslen-1];
+ if (rslen == 1 && newline == '\n')
+ goto smart_chomp;
if (p[len-1] == newline &&
(rslen <= 1 ||