Qt 4.8
Classes | Functions
qbytearray.h File Reference
#include <QtCore/qatomic.h>
#include <QtCore/qnamespace.h>
#include <string.h>
#include <stdarg.h>

Go to the source code of this file.

Classes

class  QByteArray
 The QByteArray class provides an array of bytes. More...
 
struct  QByteArray::Data
 
class  QByteRef
 
class  QList< T >
 The QList class is a template class that provides lists. More...
 

Functions

bool operator!= (const QByteArray &a1, const QByteArray &a2)
 
bool operator!= (const QByteArray &a1, const char *a2)
 
bool operator!= (const char *a1, const QByteArray &a2)
 
const QByteArray operator+ (const QByteArray &a1, const QByteArray &a2)
 
const QByteArray operator+ (const QByteArray &a1, const char *a2)
 
const QByteArray operator+ (const QByteArray &a1, char a2)
 
const QByteArray operator+ (const char *a1, const QByteArray &a2)
 
const QByteArray operator+ (char a1, const QByteArray &a2)
 
bool operator< (const QByteArray &a1, const QByteArray &a2)
 
bool operator< (const QByteArray &a1, const char *a2)
 
bool operator< (const char *a1, const QByteArray &a2)
 
Q_CORE_EXPORT QDataStreamoperator<< (QDataStream &, const QByteArray &)
 
bool operator<= (const QByteArray &a1, const QByteArray &a2)
 
bool operator<= (const QByteArray &a1, const char *a2)
 
bool operator<= (const char *a1, const QByteArray &a2)
 
bool operator== (const QByteArray &a1, const QByteArray &a2)
 
bool operator== (const QByteArray &a1, const char *a2)
 
bool operator== (const char *a1, const QByteArray &a2)
 
bool operator> (const QByteArray &a1, const QByteArray &a2)
 
bool operator> (const QByteArray &a1, const char *a2)
 
bool operator> (const char *a1, const QByteArray &a2)
 
bool operator>= (const QByteArray &a1, const QByteArray &a2)
 
bool operator>= (const QByteArray &a1, const char *a2)
 
bool operator>= (const char *a1, const QByteArray &a2)
 
Q_CORE_EXPORT QDataStreamoperator>> (QDataStream &, QByteArray &)
 
 Q_DECLARE_TYPEINFO (QByteArray, Q_MOVABLE_TYPE)
 
Q_CORE_EXPORT quint16 qChecksum (const char *s, uint len)
 
Q_CORE_EXPORT QByteArray qCompress (const uchar *data, int nbytes, int compressionLevel=-1)
 
QByteArray qCompress (const QByteArray &data, int compressionLevel=-1)
 
Q_CORE_EXPORT int qsnprintf (char *str, size_t n, const char *fmt,...)
 
Q_CORE_EXPORT int qstrcmp (const char *str1, const char *str2)
 
Q_CORE_EXPORT int qstrcmp (const QByteArray &str1, const QByteArray &str2)
 
Q_CORE_EXPORT int qstrcmp (const QByteArray &str1, const char *str2)
 
static int qstrcmp (const char *str1, const QByteArray &str2)
 
Q_CORE_EXPORT char * qstrcpy (char *dst, const char *src)
 
Q_CORE_EXPORT char * qstrdup (const char *)
 
Q_CORE_EXPORT int qstricmp (const char *, const char *)
 
uint qstrlen (const char *str)
 
int qstrncmp (const char *str1, const char *str2, uint len)
 
Q_CORE_EXPORT char * qstrncpy (char *dst, const char *src, uint len)
 
Q_CORE_EXPORT int qstrnicmp (const char *, const char *, uint len)
 
uint qstrnlen (const char *str, uint maxlen)
 
Q_CORE_EXPORT QByteArray qUncompress (const uchar *data, int nbytes)
 
QByteArray qUncompress (const QByteArray &data)
 
Q_CORE_EXPORT int qvsnprintf (char *str, size_t n, const char *fmt, va_list ap)
 

Function Documentation

◆ operator!=() [1/3]

bool operator!= ( const QByteArray a1,
const QByteArray a2 
)
related

Definition at line 533 of file qbytearray.h.

Referenced by QByteArray::isSharedWith().

534 { return !(a1==a2); }

◆ operator!=() [2/3]

bool operator!= ( const QByteArray a1,
const char *  a2 
)
related

Definition at line 535 of file qbytearray.h.

536 { return a2 ? qstrcmp(a1,a2) != 0 : !a1.isEmpty(); }
int qstrcmp(const char *str1, const char *str2)
A safe strcmp() function.
Definition: qbytearray.cpp:231
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421

◆ operator!=() [3/3]

bool operator!= ( const char *  a1,
const QByteArray a2 
)
related

Definition at line 537 of file qbytearray.h.

538 { return a1 ? qstrcmp(a1,a2) != 0 : !a2.isEmpty(); }
int qstrcmp(const char *str1, const char *str2)
A safe strcmp() function.
Definition: qbytearray.cpp:231
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421

◆ operator+() [1/5]

const QByteArray operator+ ( const QByteArray a1,
const QByteArray a2 
)
related

Definition at line 564 of file qbytearray.h.

565 { return QByteArray(a1) += a2; }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135

◆ operator+() [2/5]

const QByteArray operator+ ( const QByteArray a1,
const char *  a2 
)
related

Definition at line 566 of file qbytearray.h.

567 { return QByteArray(a1) += a2; }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135

◆ operator+() [3/5]

const QByteArray operator+ ( const QByteArray a1,
char  a2 
)
related

Definition at line 568 of file qbytearray.h.

569 { return QByteArray(a1) += a2; }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135

◆ operator+() [4/5]

const QByteArray operator+ ( const char *  a1,
const QByteArray a2 
)
related

Definition at line 570 of file qbytearray.h.

571 { return QByteArray(a1) += a2; }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135

◆ operator+() [5/5]

const QByteArray operator+ ( char  a1,
const QByteArray a2 
)
related

Definition at line 572 of file qbytearray.h.

573 { return QByteArray(&a1, 1) += a2; }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135

◆ operator<() [1/3]

bool operator< ( const QByteArray a1,
const QByteArray a2 
)
related

Definition at line 539 of file qbytearray.h.

Referenced by QByteArray::isSharedWith().

540 { return qstrcmp(a1, a2) < 0; }
int qstrcmp(const char *str1, const char *str2)
A safe strcmp() function.
Definition: qbytearray.cpp:231

◆ operator<() [2/3]

bool operator< ( const QByteArray a1,
const char *  a2 
)
related

Definition at line 541 of file qbytearray.h.

542 { return qstrcmp(a1, a2) < 0; }
int qstrcmp(const char *str1, const char *str2)
A safe strcmp() function.
Definition: qbytearray.cpp:231

◆ operator<() [3/3]

bool operator< ( const char *  a1,
const QByteArray a2 
)
related

Definition at line 543 of file qbytearray.h.

544 { return qstrcmp(a1, a2) < 0; }
int qstrcmp(const char *str1, const char *str2)
A safe strcmp() function.
Definition: qbytearray.cpp:231

◆ operator<<()

Q_CORE_EXPORT QDataStream& operator<< ( QDataStream ,
const QByteArray  
)
related

◆ operator<=() [1/3]

bool operator<= ( const QByteArray a1,
const QByteArray a2 
)
related

Definition at line 545 of file qbytearray.h.

Referenced by QVector< QPoint >::constData(), and QByteArray::isSharedWith().

546 { return qstrcmp(a1, a2) <= 0; }
int qstrcmp(const char *str1, const char *str2)
A safe strcmp() function.
Definition: qbytearray.cpp:231

◆ operator<=() [2/3]

bool operator<= ( const QByteArray a1,
const char *  a2 
)
related

Definition at line 547 of file qbytearray.h.

548 { return qstrcmp(a1, a2) <= 0; }
int qstrcmp(const char *str1, const char *str2)
A safe strcmp() function.
Definition: qbytearray.cpp:231

◆ operator<=() [3/3]

bool operator<= ( const char *  a1,
const QByteArray a2 
)
related

Definition at line 549 of file qbytearray.h.

550 { return qstrcmp(a1, a2) <= 0; }
int qstrcmp(const char *str1, const char *str2)
A safe strcmp() function.
Definition: qbytearray.cpp:231

◆ operator==() [1/3]

bool operator== ( const QByteArray a1,
const QByteArray a2 
)
related

Definition at line 527 of file qbytearray.h.

Referenced by QByteArray::isSharedWith().

528 { return (a1.size() == a2.size()) && (memcmp(a1.constData(), a2.constData(), a1.size())==0); }
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402

◆ operator==() [2/3]

bool operator== ( const QByteArray a1,
const char *  a2 
)
related

Definition at line 529 of file qbytearray.h.

530 { return a2 ? qstrcmp(a1,a2) == 0 : a1.isEmpty(); }
int qstrcmp(const char *str1, const char *str2)
A safe strcmp() function.
Definition: qbytearray.cpp:231
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421

◆ operator==() [3/3]

bool operator== ( const char *  a1,
const QByteArray a2 
)
related

Definition at line 531 of file qbytearray.h.

532 { return a1 ? qstrcmp(a1,a2) == 0 : a2.isEmpty(); }
int qstrcmp(const char *str1, const char *str2)
A safe strcmp() function.
Definition: qbytearray.cpp:231
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421

◆ operator>() [1/3]

bool operator> ( const QByteArray a1,
const QByteArray a2 
)
related

Definition at line 551 of file qbytearray.h.

Referenced by QVector< QPoint >::constData(), QByteArray::isSharedWith(), and QUuid::operator!=().

552 { return qstrcmp(a1, a2) > 0; }
int qstrcmp(const char *str1, const char *str2)
A safe strcmp() function.
Definition: qbytearray.cpp:231

◆ operator>() [2/3]

bool operator> ( const QByteArray a1,
const char *  a2 
)
related

Definition at line 553 of file qbytearray.h.

554 { return qstrcmp(a1, a2) > 0; }
int qstrcmp(const char *str1, const char *str2)
A safe strcmp() function.
Definition: qbytearray.cpp:231

◆ operator>() [3/3]

bool operator> ( const char *  a1,
const QByteArray a2 
)
related

Definition at line 555 of file qbytearray.h.

556 { return qstrcmp(a1, a2) > 0; }
int qstrcmp(const char *str1, const char *str2)
A safe strcmp() function.
Definition: qbytearray.cpp:231

◆ operator>=() [1/3]

bool operator>= ( const QByteArray a1,
const QByteArray a2 
)
related

Definition at line 557 of file qbytearray.h.

Referenced by QVector< QPoint >::constData(), and QByteArray::isSharedWith().

558 { return qstrcmp(a1, a2) >= 0; }
int qstrcmp(const char *str1, const char *str2)
A safe strcmp() function.
Definition: qbytearray.cpp:231

◆ operator>=() [2/3]

bool operator>= ( const QByteArray a1,
const char *  a2 
)
related

Definition at line 559 of file qbytearray.h.

560 { return qstrcmp(a1, a2) >= 0; }
int qstrcmp(const char *str1, const char *str2)
A safe strcmp() function.
Definition: qbytearray.cpp:231

◆ operator>=() [3/3]

bool operator>= ( const char *  a1,
const QByteArray a2 
)
related

Definition at line 561 of file qbytearray.h.

562 { return qstrcmp(a1, a2) >= 0; }
int qstrcmp(const char *str1, const char *str2)
A safe strcmp() function.
Definition: qbytearray.cpp:231

◆ operator>>()

Q_CORE_EXPORT QDataStream& operator>> ( QDataStream ,
QByteArray  
)
related

◆ Q_DECLARE_TYPEINFO()

Q_DECLARE_TYPEINFO ( QByteArray  ,
Q_MOVABLE_TYPE   
)

Referenced by qUncompress().

◆ qChecksum()

Q_CORE_EXPORT quint16 qChecksum ( const char *  s,
uint  len 
)
related

◆ qCompress() [1/2]

Q_CORE_EXPORT QByteArray qCompress ( const uchar data,
int  nbytes,
int  compressionLevel = -1 
)
related

◆ qCompress() [2/2]

QByteArray qCompress ( const QByteArray data,
int  compressionLevel = -1 
)
related

Definition at line 604 of file qbytearray.h.

605 { return qCompress(reinterpret_cast<const uchar *>(data.constData()), data.size(), compressionLevel); }
QByteArray qCompress(const QByteArray &data, int compressionLevel)
Compresses the data byte array and returns the compressed data in a new byte array.
Definition: qbytearray.h:604
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402

◆ qsnprintf()

Q_CORE_EXPORT int qsnprintf ( char *  str,
size_t  n,
const char *  fmt,
  ... 
)
related

◆ qstrcmp() [1/4]

Q_CORE_EXPORT int qstrcmp ( const char *  str1,
const char *  str2 
)
related

◆ qstrcmp() [2/4]

Q_CORE_EXPORT int qstrcmp ( const QByteArray str1,
const QByteArray str2 
)
Warning
This function is not part of the public interface.

Definition at line 363 of file qbytearray.cpp.

364 {
365  int l1 = str1.length();
366  int l2 = str2.length();
367  int ret = memcmp(str1, str2, qMin(l1, l2));
368  if (ret != 0)
369  return ret;
370 
371  // they matched qMin(l1, l2) bytes
372  // so the longer one is lexically after the shorter one
373  return l1 - l2;
374 }
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
int length() const
Same as size().
Definition: qbytearray.h:356

◆ qstrcmp() [3/4]

Q_CORE_EXPORT int qstrcmp ( const QByteArray str1,
const char *  str2 
)
Warning
This function is not part of the public interface.

Definition at line 336 of file qbytearray.cpp.

Referenced by QAccessibleObjectPrivate::actionList(), QDBusAdaptorConnector::addAdaptor(), QPrintPropertiesDialog::addItemToOptions(), QAudioDeviceInfoInternal::availableDevices(), QLocalePrivate::bytearrayToDouble(), QMetaObject::checkConnectArgs(), QCUPSSupport::collectMarkedOptionsHelper(), QPSQLDriver::commitTransaction(), QTest::compare_string_helper(), QFutureWatcherBase::connectNotify(), QNetworkSession::connectNotify(), QDBusAbstractInterface::connectNotify(), QAxClass< T >::createObject(), QDeclarativeVisualDataModelDataMetaObject::createProperty(), QScript::QMetaObjectWrapperObject::deleteProperty(), QFutureWatcherBase::disconnectNotify(), QNetworkSession::disconnectNotify(), QProxyStylePrivate::ensureBaseStyle(), QScript::QMetaObjectWrapperObject::getOwnPropertyDescriptor(), QScript::QMetaObjectWrapperObject::getOwnPropertySlot(), getStyle(), QObject::inherits(), QDeclarativeJS::integerFromString(), QScript::integerFromString(), QMetaMethod::invoke(), isProcessBeingDebugged(), QObject::killTimer(), QStyleSheetStyle::nativeFrameWidth(), QStyleSheetStyleSelector::nodeNameEquals(), QStyleSheetStyleSelector::nodeNames(), operator!=(), operator<(), operator<=(), operator==(), operator>(), operator>=(), QCUPSSupport::pageRect(), QCUPSSupport::paperRect(), parentWidget(), QPPDOptionsModel::parseChoices(), QCUPSSupport::ppdOption(), QApplicationPrivate::process_cmdline(), QVideoSurfaceFormat::property(), QScript::QMetaObjectWrapperObject::put(), QTest::qExec(), QTest::qInvokeTestMethod(), QRenderRule::QRenderRule(), QSQLite2DriverPrivate::QSQLite2DriverPrivate(), qt_check_if_internal_widget(), qt_init(), QAxObject::qt_metacast(), QAxWidget::qt_metacast(), QAxHostWidget::qt_metacast(), qt_parseEtcLpPrinters(), QBBSystemLocaleData::readHourFormat(), QBBSystemLocaleData::readMeasurementSystem(), QCUPSSupport::saveOptions(), QWizard::setDefaultProperty(), QFontDialogPrivate::setFont(), QObject::setObjectName(), QVideoSurfaceFormat::setProperty(), QDBusConnectionInterface::unregisterService(), and QAccessible::updateAccessibility().

337 {
338  if (!str2)
339  return str1.isEmpty() ? 0 : +1;
340 
341  const char *str1data = str1.constData();
342  const char *str1end = str1data + str1.length();
343  for ( ; str1data < str1end && *str2; ++str1data, ++str2) {
344  register int diff = int(uchar(*str1data)) - uchar(*str2);
345  if (diff)
346  // found a difference
347  return diff;
348  }
349 
350  // Why did we stop?
351  if (*str2 != '\0')
352  // not the null, so we stopped because str1 is shorter
353  return -1;
354  if (str1data < str1end)
355  // we haven't reached the end, so str1 must be longer
356  return +1;
357  return 0;
358 }
unsigned char uchar
Definition: qglobal.h:994
static Bigint * diff(Bigint *a, Bigint *b)
int length() const
Same as size().
Definition: qbytearray.h:356
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421

◆ qstrcmp() [4/4]

static int qstrcmp ( const char *  str1,
const QByteArray str2 
)
inlinestatic

Definition at line 98 of file qbytearray.h.

99 { return -qstrcmp(str2, str1); }
int qstrcmp(const char *str1, const char *str2)
A safe strcmp() function.
Definition: qbytearray.cpp:231

◆ qstrcpy()

Q_CORE_EXPORT char* qstrcpy ( char *  dst,
const char *  src 
)
related

◆ qstrdup()

Q_CORE_EXPORT char* qstrdup ( const char *  )
related

◆ qstricmp()

Q_CORE_EXPORT int qstricmp ( const char *  ,
const char *   
)
related

◆ qstrlen()

uint qstrlen ( const char *  str)
related

Definition at line 79 of file qbytearray.h.

Referenced by _qdtoa(), QPatternist::XQueryTokenizer::aheadEquals(), QString::append(), QMetaObject::checkConnectArgs(), QGLShader::compileSourceCode(), QObject::connect(), QMetaObject::connectSlotsByName(), QWindowsMimeText::convertToMime(), QObject::disconnect(), QTextHtmlExporter::emitCharFormatStyle(), QTextHtmlExporter::emitFragment(), QTextHtmlExporter::emitFrameStyle(), extract_location(), QString::fromAscii_helper(), QHashableLatin1Literal::fromData(), QString::fromLatin1_helper(), QString::fromLocal8Bit(), QString::fromUtf8(), QString::insert(), intValueHelper(), QMetaMethod::invoke(), QMetaObject::invokeMethod(), QTest::isValidSlot(), QMetaEnum::keysToValue(), QMetaEnum::keyToValue(), QString::lastIndexOf(), QStringRef::lastIndexOf(), QDBusMessagePrivate::makeLocal(), QGLExtensionMatcher::match(), QMetaObject::newInstance(), QMetaObject::normalizedType(), QDataStream::operator<<(), qt_ends_with(), qt_fillFontDef(), qt_find_latin1_string(), qt_mac_execute_apple_script(), qt_parse_pattern(), qt_starts_with(), QXIMInputContext::QXIMInputContext(), QFSFileEnginePrivate::readLineFdFh(), QCss::Declaration::realValue(), QString::replace(), MetaObjectGenerator::replacePrototype(), QObjectPrivate::signalSignature(), QConcatenable< QLatin1String >::size(), QConcatenable< const char * >::size(), QTextCodec::toUnicode(), QMetaType::type(), and QIODevice::write().

80 { return str ? uint(strlen(str)) : 0; }
unsigned int uint
Definition: qglobal.h:996

◆ qstrncmp()

int qstrncmp ( const char *  str1,
const char *  str2,
uint  len 
)
related

◆ qstrncpy()

Q_CORE_EXPORT char* qstrncpy ( char *  dst,
const char *  src,
uint  len 
)
related

◆ qstrnicmp()

Q_CORE_EXPORT int qstrnicmp ( const char *  ,
const char *  ,
uint  len 
)
related

◆ qstrnlen()

uint qstrnlen ( const char *  str,
uint  maxlen 
)
related

Definition at line 82 of file qbytearray.h.

Referenced by QString::append(), operator+(), QString::operator+=(), QString::operator=(), and QString::prepend().

83 {
84  uint length = 0;
85  if (str) {
86  while (length < maxlen && *str++)
87  length++;
88  }
89  return length;
90 }
unsigned int uint
Definition: qglobal.h:996

◆ qUncompress() [1/2]

Q_CORE_EXPORT QByteArray qUncompress ( const uchar data,
int  nbytes 
)

◆ qUncompress() [2/2]

QByteArray qUncompress ( const QByteArray data)
related

Definition at line 606 of file qbytearray.h.

607 { return qUncompress(reinterpret_cast<const uchar*>(data.constData()), data.size()); }
QByteArray qUncompress(const QByteArray &data)
Uncompresses the data byte array and returns a new byte array with the uncompressed data...
Definition: qbytearray.h:606
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402

◆ qvsnprintf()

Q_CORE_EXPORT int qvsnprintf ( char *  str,
size_t  n,
const char *  fmt,
va_list  ap 
)
related