[tested PATCH] let QString::lower() assume lower case input to avoid real_detach()

Harri Porten kde-optimize@mail.kde.org
Fri, 24 Jan 2003 19:42:11 +0100 (CET)


On Fri, 24 Jan 2003, Harri Porten wrote:

> >  If it's tested patch, you could probably send it to qt-bugs@trolltech.com :).
> 
> No need to. I will fix* and improve it a bit and check it into qt-copy for
> everyone to tes^H^H^Henjoy :)

I found an elegant solution done by a colleague to be present in the main
(e.g. HEAD) branch already. Just applied my change that removes the imo
redundant if(p) check:

QString QString::lower() const
{
    int l = length();
    if ( l ) {
	register QChar *p = d->unicode;
	while ( l ) {
	    if ( *p != ::lower(*p) ) {
		QString s( *this );
		s.real_detach();
		p = s.d->unicode + ( p - d->unicode );
		while ( l ) {
		    *p = ::lower( *p );
		    l--;
		    p++;
		}
		return s;
	    }
	    l--;
	    p++;
	}
    }
    return *this;
}

Harri.