/*
* call-seq:
* str.rstrip! => self or nil
*
* Removes trailing whitespace from <i>str</i>, returning <code>nil</code> if
* no change was made. See also <code>String#lstrip!</code> and
* <code>String#strip!</code>.
*
* " hello ".rstrip #=> " hello"
* "hello".rstrip! #=> nil
*/
static VALUE
rb_str_rstrip_bang(str)
VALUE str;
{
char *s, *t, *e;
s = RSTRING(str)->ptr;
if (!s || RSTRING(str)->len == 0) return Qnil;
e = t = s + RSTRING(str)->len;
/* remove trailing '\0's */
while (s < t && t[-1] == '\0') t--;
/* remove trailing spaces */
while (s < t && ISSPACE(*(t-1))) t--;
if (t < e) {
rb_str_modify(str);
RSTRING(str)->len = t-s;
RSTRING(str)->ptr[RSTRING(str)->len] = '\0';
return str;
}
return Qnil;
}