diff options
| author | Ahmad Samir <a.samirh78@gmail.com> | 2023-03-15 17:27:21 +0200 |
|---|---|---|
| committer | Ahmad Samir <a.samirh78@gmail.com> | 2023-03-18 12:00:56 +0200 |
| commit | f6b780b58339bbaccd5c981291de5ef462e7aa3a (patch) | |
| tree | 7ae1bbaa96a644e2f9550e06dd3f245809c4f970 /src/corelib/io/qdebug.cpp | |
| parent | d184c66ad5ca90ef93ce1df6012f6cfb4318cf6d (diff) | |
QtMiscUtils: add isAsciiPrintable() helper
- isAsciiPrintable: borrowed the logic from isPrintable(uchar) in
qdebug.cpp, now isPrintable(uchar) calls isAsciiPrintable
- Replace ::isspace() with ascii_isspace() from qlocale_p.h
Functions from ctype.h have a couple of issues:
- they're locale-dependent, which isn't what's required here, the code
is only interested in ASCII
- their args should be representable as uchar or EOF otherwise it's
undefined behavior
An Early-Warning could use something like:
grep -rP "\b(isalnum|isalpha|isblank|iscntrl|isdigit|islower|isgraph|\
"isprint|ispunct|isspace|isupper|isxdigit|tolower|toupper)\b"
Pick-to: 6.5
Task-number: QTBUG-111262
Change-Id: I1f47f41bd56735297078ff0d0ddc2ebf999abf8b
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/io/qdebug.cpp')
| -rw-r--r-- | src/corelib/io/qdebug.cpp | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/src/corelib/io/qdebug.cpp b/src/corelib/io/qdebug.cpp index 22f2c0ce8b1..0a72696a372 100644 --- a/src/corelib/io/qdebug.cpp +++ b/src/corelib/io/qdebug.cpp @@ -14,13 +14,10 @@ #include "qmetaobject.h" #include <private/qtextstream_p.h> #include <private/qtools_p.h> -#include <ctype.h> QT_BEGIN_NAMESPACE -using QtMiscUtils::toHexUpper; -using QtMiscUtils::toHexLower; -using QtMiscUtils::fromHex; +using namespace QtMiscUtils; /* Returns a human readable representation of the first \a maxSize @@ -35,7 +32,7 @@ QByteArray QtDebugUtils::toPrintable(const char *data, qint64 len, qsizetype max QByteArray out; for (qsizetype i = 0; i < qMin(len, maxSize); ++i) { char c = data[i]; - if (isprint(c)) { + if (isAsciiPrintable(c)) { out += c; } else { switch (c) { @@ -198,7 +195,7 @@ void QDebug::putUcs4(uint ucs4) static inline bool isPrintable(char32_t ucs4) { return QChar::isPrint(ucs4); } static inline bool isPrintable(char16_t uc) { return QChar::isPrint(uc); } static inline bool isPrintable(uchar c) -{ return c >= ' ' && c < 0x7f; } +{ return isAsciiPrintable(c); } template <typename Char> static inline void putEscapedString(QTextStreamPrivate *d, const Char *begin, size_t length, bool isUnicode = true) |
