QByteArray: Move some free-functions around

Most of them go to qbytearrayalgorithms.h while the deprecated (inline)
version of qChecksum goes to qbytearrayview.h

In preparation for adding compare to QByteArrayView.

Change-Id: If7f65e9e7cd74838e11ebdb952309b811cef079d
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Mårten Nordheim 2021-04-29 12:34:45 +02:00
parent 4b09522c23
commit e8297ba176
3 changed files with 60 additions and 57 deletions

View File

@ -72,63 +72,6 @@ Q_FORWARD_DECLARE_OBJC_CLASS(NSData);
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
/*****************************************************************************
Safe and portable C string functions; extensions to standard string.h
*****************************************************************************/
Q_CORE_EXPORT char *qstrdup(const char *);
inline size_t qstrlen(const char *str)
{
QT_WARNING_PUSH
#if defined(Q_CC_GNU) && Q_CC_GNU >= 900 && Q_CC_GNU < 1000
// spurious compiler warning (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91490#c6)
// when Q_DECLARE_METATYPE_TEMPLATE_1ARG is used
QT_WARNING_DISABLE_GCC("-Wstringop-overflow")
#endif
return str ? strlen(str) : 0;
QT_WARNING_POP
}
inline size_t qstrnlen(const char *str, size_t maxlen)
{
size_t length = 0;
if (str) {
while (length < maxlen && *str++)
length++;
}
return length;
}
Q_CORE_EXPORT char *qstrcpy(char *dst, const char *src);
Q_CORE_EXPORT char *qstrncpy(char *dst, const char *src, size_t len);
Q_CORE_EXPORT int qstrcmp(const char *str1, const char *str2);
inline int qstrncmp(const char *str1, const char *str2, size_t len)
{
return (str1 && str2) ? strncmp(str1, str2, len)
: (str1 ? 1 : (str2 ? -1 : 0));
}
Q_CORE_EXPORT int qstricmp(const char *, const char *);
Q_CORE_EXPORT int qstrnicmp(const char *, const char *, size_t len);
Q_CORE_EXPORT int qstrnicmp(const char *, qsizetype, const char *, qsizetype = -1);
// implemented in qvsnprintf.cpp
Q_CORE_EXPORT int qvsnprintf(char *str, size_t n, const char *fmt, va_list ap);
Q_CORE_EXPORT int qsnprintf(char *str, size_t n, const char *fmt, ...);
// qChecksum: Internet checksum
Q_CORE_EXPORT quint16 qChecksum(QByteArrayView data, Qt::ChecksumType standard = Qt::ChecksumIso3309);
#if QT_DEPRECATED_SINCE(6, 0)
QT_DEPRECATED_VERSION_X_6_0("Use the QByteArrayView overload.")
inline quint16 qChecksum(const char *s, qsizetype len,
Qt::ChecksumType standard = Qt::ChecksumIso3309)
{ return qChecksum(QByteArrayView(s, len), standard); }
#endif
class QString; class QString;
class QDataStream; class QDataStream;

View File

@ -42,6 +42,9 @@
#include <QtCore/qnamespace.h> #include <QtCore/qnamespace.h>
#include <string.h>
#include <stdarg.h>
#if 0 #if 0
#pragma qt_class(QByteArrayAlgorithms) #pragma qt_class(QByteArrayAlgorithms)
#endif #endif
@ -71,6 +74,56 @@ qsizetype count(QByteArrayView haystack, QByteArrayView needle) noexcept;
} // namespace QtPrivate } // namespace QtPrivate
/*****************************************************************************
Safe and portable C string functions; extensions to standard string.h
*****************************************************************************/
Q_CORE_EXPORT char *qstrdup(const char *);
inline size_t qstrlen(const char *str)
{
QT_WARNING_PUSH
#if defined(Q_CC_GNU) && Q_CC_GNU >= 900 && Q_CC_GNU < 1000
// spurious compiler warning (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91490#c6)
// when Q_DECLARE_METATYPE_TEMPLATE_1ARG is used
QT_WARNING_DISABLE_GCC("-Wstringop-overflow")
#endif
return str ? strlen(str) : 0;
QT_WARNING_POP
}
inline size_t qstrnlen(const char *str, size_t maxlen)
{
size_t length = 0;
if (str) {
while (length < maxlen && *str++)
length++;
}
return length;
}
// implemented in qbytearray.cpp
Q_CORE_EXPORT char *qstrcpy(char *dst, const char *src);
Q_CORE_EXPORT char *qstrncpy(char *dst, const char *src, size_t len);
Q_CORE_EXPORT int qstrcmp(const char *str1, const char *str2);
inline int qstrncmp(const char *str1, const char *str2, size_t len)
{
return (str1 && str2) ? strncmp(str1, str2, len)
: (str1 ? 1 : (str2 ? -1 : 0));
}
Q_CORE_EXPORT int qstricmp(const char *, const char *);
Q_CORE_EXPORT int qstrnicmp(const char *, const char *, size_t len);
Q_CORE_EXPORT int qstrnicmp(const char *, qsizetype, const char *, qsizetype = -1);
// implemented in qvsnprintf.cpp
Q_CORE_EXPORT int qvsnprintf(char *str, size_t n, const char *fmt, va_list ap);
Q_CORE_EXPORT int qsnprintf(char *str, size_t n, const char *fmt, ...);
// qChecksum: Internet checksum
Q_CORE_EXPORT quint16 qChecksum(QByteArrayView data, Qt::ChecksumType standard = Qt::ChecksumIso3309);
QT_END_NAMESPACE QT_END_NAMESPACE
#endif // QBYTEARRAYALGORITHMS_H #endif // QBYTEARRAYALGORITHMS_H

View File

@ -320,6 +320,13 @@ template<typename QByteArrayLike,
[[nodiscard]] inline QByteArrayView qToByteArrayViewIgnoringNull(const QByteArrayLike &b) noexcept [[nodiscard]] inline QByteArrayView qToByteArrayViewIgnoringNull(const QByteArrayLike &b) noexcept
{ return QByteArrayView(b.data(), b.size()); } { return QByteArrayView(b.data(), b.size()); }
#if QT_DEPRECATED_SINCE(6, 0)
QT_DEPRECATED_VERSION_X_6_0("Use the QByteArrayView overload.")
inline quint16 qChecksum(const char *s, qsizetype len,
Qt::ChecksumType standard = Qt::ChecksumIso3309)
{ return qChecksum(QByteArrayView(s, len), standard); }
#endif
QT_END_NAMESPACE QT_END_NAMESPACE
#endif // QBYTEARRAYVIEW_H #endif // QBYTEARRAYVIEW_H