chop!()
public
Processes str as for String#chop, returning str,
or nil if str is the empty string. See also String#chomp!.
Show source
/*
* call-seq:
* str.chop! => str or nil
*
* Processes <i>str</i> as for <code>String
* or <code>nil</code> if <i>str</i> is the empty string. See also
* <code>String
*/
static VALUE
rb_str_chop_bang(str)
VALUE str;
{
if (RSTRING(str)->len > 0) {
rb_str_modify(str);
RSTRING(str)->len--;
if (RSTRING(str)->ptr[RSTRING(str)->len] == '\n') {
if (RSTRING(str)->len > 0 &&
RSTRING(str)->ptr[RSTRING(str)->len-1] == '\r') {
RSTRING(str)->len--;
}
}
RSTRING(str)->ptr[RSTRING(str)->len] = '\0';
return str;
}
return Qnil;
}