summaryrefslogtreecommitdiffstats
path: root/src/corelib/text
diff options
context:
space:
mode:
authorMårten Nordheim <marten.nordheim@qt.io>2021-04-29 12:34:45 +0200
committerMårten Nordheim <marten.nordheim@qt.io>2021-05-20 17:02:38 +0200
commite8297ba17602475e0fc94e3a67a625dc5bc8c136 (patch)
tree08d32f4258696915e80446ce21d300ed4cc9b84c /src/corelib/text
parent4b09522c23e9efdf83ba8d4af436d8a700ccb66e (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')
-rw-r--r--src/corelib/text/qbytearray.h57
-rw-r--r--src/corelib/text/qbytearrayalgorithms.h53
-rw-r--r--src/corelib/text/qbytearrayview.h7
3 files changed, 60 insertions, 57 deletions
diff --git a/src/corelib/text/qbytearray.h b/src/corelib/text/qbytearray.h
index 91c34747d8..91f50d76c3 100644
--- a/src/corelib/text/qbytearray.h
+++ b/src/corelib/text/qbytearray.h
@@ -72,63 +72,6 @@ Q_FORWARD_DECLARE_OBJC_CLASS(NSData);
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 QDataStream;
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
diff --git a/src/corelib/text/qbytearrayview.h b/src/corelib/text/qbytearrayview.h
index 02ce49613e..367fdb58b2 100644
--- a/src/corelib/text/qbytearrayview.h
+++ b/src/corelib/text/qbytearrayview.h
@@ -320,6 +320,13 @@ template<typename QByteArrayLike,
[[nodiscard]] inline QByteArrayView qToByteArrayViewIgnoringNull(const QByteArrayLike &b) noexcept
{ 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
#endif // QBYTEARRAYVIEW_H