diff options
author | Mårten Nordheim <marten.nordheim@qt.io> | 2021-04-29 12:34:45 +0200 |
---|---|---|
committer | Mårten Nordheim <marten.nordheim@qt.io> | 2021-05-20 17:02:38 +0200 |
commit | e8297ba17602475e0fc94e3a67a625dc5bc8c136 (patch) | |
tree | 08d32f4258696915e80446ce21d300ed4cc9b84c /src/corelib/text/qbytearrayalgorithms.h | |
parent | 4b09522c23e9efdf83ba8d4af436d8a700ccb66e (diff) |
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>
Diffstat (limited to 'src/corelib/text/qbytearrayalgorithms.h')
-rw-r--r-- | src/corelib/text/qbytearrayalgorithms.h | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/corelib/text/qbytearrayalgorithms.h b/src/corelib/text/qbytearrayalgorithms.h index fdcd00a8c1..be1e6cc953 100644 --- a/src/corelib/text/qbytearrayalgorithms.h +++ b/src/corelib/text/qbytearrayalgorithms.h @@ -42,6 +42,9 @@ #include <QtCore/qnamespace.h> +#include <string.h> +#include <stdarg.h> + #if 0 #pragma qt_class(QByteArrayAlgorithms) #endif @@ -71,6 +74,56 @@ qsizetype count(QByteArrayView haystack, QByteArrayView needle) noexcept; } // 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 #endif // QBYTEARRAYALGORITHMS_H |