void tst_Q3ValueVector::reserve() { QFETCH( QByteArray, ba ); Q3ValueVector<int> vector; QDataStream ds( &ba, IO_ReadWrite ); ds >> vector; Q3ValueVector<int>::size_type cap = vector.capacity(); // should do nothing if( cap > 5 ) vector.reserve( vector.capacity() - 5 ); else vector.reserve( 0 ); QVERIFY( vector.capacity() == cap ); // should make capacity() grow vector.reserve( vector.capacity() + 5 ); QVERIFY( cap < vector.capacity() ); }
QString EQStr::formatMessage(uint32_t formatid, const char* arguments, size_t argsLen) const { QString* formatStringRes = m_messageStrings.find(formatid); QString tempStr; if (formatStringRes == NULL) { tempStr.sprintf( "Unknown: %04x: ", formatid); tempStr += QString::fromUtf8(arguments); size_t totalArgsLen = strlen(arguments) + 1; const char* curMsg; while (totalArgsLen < argsLen) { curMsg = arguments + totalArgsLen; tempStr += QString(", ") + QString::fromUtf8(curMsg); totalArgsLen += strlen(curMsg) + 1; } } else { Q3ValueVector<QString> argList; argList.reserve(5); // reserve space for 5 elements to handle most common sizes // size_t totalArgsLen = 0; const char* curArg; while (totalArgsLen < argsLen) { curArg = arguments + totalArgsLen; // insert argument into the argument list argList.push_back(QString::fromUtf8(curArg)); totalArgsLen += strlen(curArg) + 1; } bool ok; int curPos; size_t substArg; int substArgValue; QString* substFormatStringRes; QString substFormatString; //////////////////////////// // replace template (%T) arguments in formatted string QString formatString = *formatStringRes; QRegExp rxt("%T(\\d{1,3})", true, false); // find first template substitution curPos = rxt.search(formatString, 0); while (curPos != -1) { substFormatStringRes = NULL; substArg = rxt.cap(1).toInt(&ok); if (ok && (substArg <= argList.size())) { substArgValue = argList[substArg-1].toInt(&ok); if (ok) substFormatStringRes = m_messageStrings.find(substArgValue); } // replace template argument with subst string if (substFormatStringRes != NULL) formatString.replace(curPos, rxt.matchedLength(), *substFormatStringRes); else curPos += rxt.matchedLength(); // if no replacement string, skip over // find next substitution curPos = rxt.search(formatString, curPos); } //////////////////////////// // now replace substitution arguments in formatted string // NOTE: not using QString::arg() because not all arguments are always used // and it will do screwy stuff in this situation QRegExp rx("%(\\d{1,3})", true, false); // find first template substitution curPos = rx.search(formatString, 0); while (curPos != -1) { substArg = rx.cap(1).toInt(&ok); // replace substitution argument with argument from list if (ok && (substArg <= argList.size())) formatString.replace(curPos, rx.matchedLength(), argList[substArg-1]); else curPos += rx.matchedLength(); // if no such argument, skip over // find next substitution curPos = rx.search(formatString, curPos); } return formatString; } return tempStr; }