/*
 *  call-seq:
 *     str.swapcase!   => str or nil
 *  
 *  Equivalent to <code>String#swapcase</code>, but modifies the receiver in
 *  place, returning <i>str</i>, or <code>nil</code> if no changes were made.
 */

static VALUE
rb_str_swapcase_bang(str)
    VALUE str;
{
    char *s, *send;
    int modify = 0;

    rb_str_modify(str);
    s = RSTRING(str)->ptr; send = s + RSTRING(str)->len;
    while (s < send) {
        if (ismbchar(*s)) {
            s+=mbclen(*s) - 1;
        }
        else if (ISUPPER(*s)) {
            *s = tolower(*s);
            modify = 1;
        }
        else if (ISLOWER(*s)) {
            *s = toupper(*s);
            modify = 1;
        }
        s++;
    }

    if (modify) return str;
    return Qnil;
}