diff options
Diffstat (limited to 'src/corelib/tools/qbytearray.h')
-rw-r--r-- | src/corelib/tools/qbytearray.h | 54 |
1 files changed, 34 insertions, 20 deletions
diff --git a/src/corelib/tools/qbytearray.h b/src/corelib/tools/qbytearray.h index 0a2f7a9e53..ba7fdbb10a 100644 --- a/src/corelib/tools/qbytearray.h +++ b/src/corelib/tools/qbytearray.h @@ -50,6 +50,8 @@ #include <string.h> #include <stdarg.h> +#include <string> + #ifdef truncate #error qbytearray.h must be included before any header file that defines truncate #endif @@ -247,9 +249,9 @@ public: int count(const char *a) const; int count(const QByteArray &a) const; - QByteArray left(int len) const; - QByteArray right(int len) const; - QByteArray mid(int index, int len = -1) const; + QByteArray left(int len) const Q_REQUIRED_RESULT; + QByteArray right(int len) const Q_REQUIRED_RESULT; + QByteArray mid(int index, int len = -1) const Q_REQUIRED_RESULT; bool startsWith(const QByteArray &a) const; bool startsWith(char c) const; @@ -262,13 +264,13 @@ public: void truncate(int pos); void chop(int n); - QByteArray toLower() const; - QByteArray toUpper() const; + QByteArray toLower() const Q_REQUIRED_RESULT; + QByteArray toUpper() const Q_REQUIRED_RESULT; - QByteArray trimmed() const; - QByteArray simplified() const; - QByteArray leftJustified(int width, char fill = ' ', bool truncate = false) const; - QByteArray rightJustified(int width, char fill = ' ', bool truncate = false) const; + QByteArray trimmed() const Q_REQUIRED_RESULT; + QByteArray simplified() const Q_REQUIRED_RESULT; + QByteArray leftJustified(int width, char fill = ' ', bool truncate = false) const Q_REQUIRED_RESULT; + QByteArray rightJustified(int width, char fill = ' ', bool truncate = false) const Q_REQUIRED_RESULT; QByteArray &prepend(char c); QByteArray &prepend(const char *s); @@ -300,7 +302,7 @@ public: QList<QByteArray> split(char sep) const; - QByteArray repeated(int times) const; + QByteArray repeated(int times) const Q_REQUIRED_RESULT; #ifndef QT_NO_CAST_TO_ASCII QT_ASCII_CAST_WARN QByteArray &append(const QString &s); @@ -349,16 +351,16 @@ public: QByteArray &setNum(double, char f = 'g', int prec = 6); QByteArray &setRawData(const char *a, uint n); // ### Qt 6: use an int - static QByteArray number(int, int base = 10); - static QByteArray number(uint, int base = 10); - static QByteArray number(qlonglong, int base = 10); - static QByteArray number(qulonglong, int base = 10); - static QByteArray number(double, char f = 'g', int prec = 6); - static QByteArray fromRawData(const char *, int size); - static QByteArray fromBase64(const QByteArray &base64, Base64Options options); - static QByteArray fromBase64(const QByteArray &base64); // ### Qt6 merge with previous - static QByteArray fromHex(const QByteArray &hexEncoded); - static QByteArray fromPercentEncoding(const QByteArray &pctEncoded, char percent = '%'); + static QByteArray number(int, int base = 10) Q_REQUIRED_RESULT; + static QByteArray number(uint, int base = 10) Q_REQUIRED_RESULT; + static QByteArray number(qlonglong, int base = 10) Q_REQUIRED_RESULT; + static QByteArray number(qulonglong, int base = 10) Q_REQUIRED_RESULT; + static QByteArray number(double, char f = 'g', int prec = 6) Q_REQUIRED_RESULT; + static QByteArray fromRawData(const char *, int size) Q_REQUIRED_RESULT; + static QByteArray fromBase64(const QByteArray &base64, Base64Options options) Q_REQUIRED_RESULT; + static QByteArray fromBase64(const QByteArray &base64) Q_REQUIRED_RESULT; // ### Qt6 merge with previous + static QByteArray fromHex(const QByteArray &hexEncoded) Q_REQUIRED_RESULT; + static QByteArray fromPercentEncoding(const QByteArray &pctEncoded, char percent = '%') Q_REQUIRED_RESULT; #if defined(Q_OS_MAC) || defined(Q_QDOC) static QByteArray fromCFData(CFDataRef data); @@ -387,8 +389,12 @@ public: const_iterator constEnd() const; // stl compatibility + typedef int size_type; + typedef qptrdiff difference_type; typedef const char & const_reference; typedef char & reference; + typedef char *pointer; + typedef const char *const_pointer; typedef char value_type; void push_back(char c); void push_back(const char *c); @@ -397,6 +403,9 @@ public: void push_front(const char *c); void push_front(const QByteArray &a); + static inline QByteArray fromStdString(const std::string &s); + inline std::string toStdString() const; + inline int count() const { return d->size; } int length() const { return d->size; } bool isNull() const; @@ -620,6 +629,11 @@ inline QByteArray &QByteArray::setNum(uint n, int base) inline QByteArray &QByteArray::setNum(float n, char f, int prec) { return setNum(double(n),f,prec); } +inline std::string QByteArray::toStdString() const +{ return std::string(constData(), length()); } + +inline QByteArray QByteArray::fromStdString(const std::string &s) +{ return QByteArray(s.data(), int(s.size())); } #if !defined(QT_NO_DATASTREAM) || (defined(QT_BOOTSTRAPPED) && !defined(QT_BUILD_QMAKE)) Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QByteArray &); |