rstrip!()
public
Removes trailing whitespace from str, returning nil if no change
was made. See also String#lstrip! and
String#strip!.
Refer to strip for the definition of
whitespace.
" hello ".rstrip!
" hello".rstrip!
"hello".rstrip!
Show source
static VALUE
rb_str_rstrip_bang(VALUE str)
{
rb_encoding *enc;
char *start;
long olen, roffset;
str_modify_keep_cr(str);
enc = STR_ENC_GET(str);
RSTRING_GETMEM(str, start, olen);
roffset = rstrip_offset(str, start, start+olen, enc);
if (roffset > 0) {
long len = olen - roffset;
STR_SET_LEN(str, len);
TERM_FILL(start+len, rb_enc_mbminlen(enc));
return str;
}
return Qnil;
}