The code is shamelessly borrowed from kdelibs4support implementation:
https://cgit.kde.org/kdelibs4support.git/tree/src/kdecore/kmimetype.cpp
Personally, I do not know if there is a better way to implement this check without libmagic. Please help.
broulik |
KDE Applications |
The code is shamelessly borrowed from kdelibs4support implementation:
https://cgit.kde.org/kdelibs4support.git/tree/src/kdecore/kmimetype.cpp
Personally, I do not know if there is a better way to implement this check without libmagic. Please help.
Lint Skipped |
Unit Tests Skipped |
The question was raised previously here:
https://mail.kde.org/pipermail/kde-frameworks-devel/2015-January/021254.html
I guess that this is the second user of isBinaryData...
Better ask @dfaure
("KDE Applications" is not meant to be used as tag for reviews, it's used to collect the projects; the last one who did significant changes to kfind is @broulik )
src/kquery.cpp | ||
---|---|---|
451 | Actually, that's 128 bytes nowadays. static inline bool isTextFile(const QByteArray &data) { // UTF16 byte order marks static const char bigEndianBOM[] = "\xFE\xFF"; static const char littleEndianBOM[] = "\xFF\xFE"; if (data.startsWith(bigEndianBOM) || data.startsWith(littleEndianBOM)) return true; // Check the first 128 bytes (see shared-mime spec) const char *p = data.constData(); const char *e = p + qMin(128, data.size()); for ( ; p < e; ++p) { if ((unsigned char)(*p) < 32 && *p != 9 && *p !=10 && *p != 13) return false; } return true; } But yeah I'm not sure it's worth its own public method in QMimeDatabase, it's just some inexact heuristic for last-chance fallback... |