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

void QByteArray::resize ( int  size  ) 

Sets the size of the byte array to size bytes.

If size is greater than the current size, the byte array is extended to make it size bytes with the extra bytes added to the end. The new bytes are uninitialized.

If size is less than the current size, bytes are removed from the end.

See also:
size()

Definition at line 1303 of file qbytearray.cpp.

Referenced by QPatternist::Base64Binary::base64Decode(), chop(), QEucKrCodec::convertFromUnicode(), QSjisCodec::convertFromUnicode(), QGb2312Codec::convertFromUnicode(), QEucJpCodec::convertFromUnicode(), QIsciiCodec::convertFromUnicode(), QTsciiCodec::convertFromUnicode(), QGbkCodec::convertFromUnicode(), QGb18030Codec::convertFromUnicode(), Q3UrlOperator::copyGotData(), Q3IconDrag::encodedData(), QXmlInputSource::fetchData(), fill(), fromBase64(), fromHex(), QPatternist::HexBinary::fromLexical(), fromPercentEncoding(), leftJustified(), Q3CString::leftJustify(), Q3LocalFs::operationGet(), operator>>(), Q3TextStream::operator>>(), QBitArray::QBitArray(), qCompress(), qUncompress(), QHttp::readAll(), Q3Http::readAll(), QIODevice::readAll(), QIODevice::readLine(), remove(), replace(), QBitArray::resize(), rightJustified(), Q3CString::rightJustify(), Q3ColorDrag::setColor(), Q3CString::setExpand(), simplified(), Q3Socket::sn_read(), Q3CString::sprintf(), toBase64(), toHex(), QString::toLatin1(), QString::toUtf8(), truncate(), Q3Socket::writeData(), and Q3Process::writeToStdin().

{
    if (size <= 0) {
        Data *x = &shared_empty;
        x->ref.ref();
        if (!d->ref.deref())
            qFree(d);
        d = x;
    } else if (d == &shared_null) {
        //
        // Optimize the idiom:
        //    QByteArray a;
        //    a.resize(sz);
        //    ...
        // which is used in place of the Qt 3 idiom:
        //    QByteArray a(sz);
        //
        Data *x = static_cast<Data *>(qMalloc(sizeof(Data)+size));
        if (!x)
            return;
        x->ref = 1;
        x->alloc = x->size = size;
        x->data = x->array;
        x->array[size] = '\0';
        (void) d->ref.deref(); // cannot be 0, x points to shared_null
        d = x;
    } else {
        if (d->ref != 1 || size > d->alloc || (size < d->size && size < d->alloc >> 1))
            realloc(qAllocMore(size, sizeof(Data)));
        if (d->alloc >= size) {
            d->size = size;
            if (d->data == d->array) {
                d->array[size] = '\0';
            }
        }
    }
}


Generated by  Doxygen 1.6.0   Back to index