Logo Search packages:      
Sourcecode: qt4-x11 version File versions

QString QString::trimmed (  )  const

Returns a string that has whitespace removed from the start and the end.

Whitespace means any character for which QChar::isSpace() returns true. This includes the ASCII characters '\t', '\n', '\v', '\f', '\r', and ' '.


snippets/qstring/main.cpp Widget::trimmedFunction() QString str // str == "lots\t of\nwhitespace"

Unlike simplified(), trimmed() leaves internal whitespace alone.

See also:

Definition at line 3579 of file qstring.cpp.

References data(), end(), QChar::isSpace(), and QString().

Referenced by QHttpHeader::contentType(), QSqlQuery::exec(), QDate::fromString(), QMetaEnum::keysToValue(), QHttpHeader::parse(), QHttpHeader::parseLine(), QFtp::rawCommand(), QUrl::setHost(), and QUrl::setUserInfo().

    if (d->size == 0)
        return *this;
    const QChar *s = (const QChar*)d->data;
    if (!s->isSpace() && !s[d->size-1].isSpace())
        return *this;
    int start = 0;
    int end = d->size - 1;
    while (start<=end && s[start].isSpace())  // skip white space from start
    if (start <= end) {                          // only white space
        while (end && s[end].isSpace())           // skip white space from end
    int l = end - start + 1;
    if (l <= 0) {
        return QString(&shared_empty, 0);
    return QString(s + start, l);

Generated by  Doxygen 1.6.0   Back to index