/*
 *  call-seq:
 *     str.chop!   => str or nil
 *  
 *  Processes <i>str</i> as for <code>String#chop</code>, returning <i>str</i>,
 *  or <code>nil</code> if <i>str</i> is the empty string.  See also
 *  <code>String#chomp!</code>.
 */

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;
}