21#include "charfreq_p.h"
37 count(buf.data(), buf.size());
41static inline bool isWS(
char ch)
43 return (ch ==
'\t' || ch ==
' ');
46void CharFreq::count(
const char *it,
size_t len)
48 const char *
end = it + len;
49 uint currentLineLength = 0;
53 char prevPrevChar = 0;
55 for (; it !=
end ; ++it) {
58 case '\0': ++mNUL;
break;
59 case '\r': ++mCR;
break;
61 if (prevChar ==
'\r') {
62 --currentLineLength; ++mCRLF;
64 if (currentLineLength >= mLineMax) {
65 mLineMax = currentLineLength - 1;
67 if (currentLineLength <= mLineMin) {
68 mLineMin = currentLineLength - 1;
72 (prevChar ==
'\r' && isWS(prevPrevChar))) {
76 currentLineLength = 0;
80 if (prevChar ==
'\n' && end - it >= 5 &&
81 !qstrncmp(
"From ", it, 5)) {
89 if (c ==
'\t' || (c >=
' ' && c <=
'~')) {
91 }
else if (c == 127 || c <
' ') {
98 prevPrevChar = prevChar;
103 if (currentLineLength >= mLineMax) {
104 mLineMax = currentLineLength;
106 if (currentLineLength <= mLineMin) {
107 mLineMin = currentLineLength;
111 if (isWS(prevChar)) {
118bool CharFreq::isEightBitData()
const
120 return type() == EightBitData;
123bool CharFreq::isEightBitText()
const
125 return type() == EightBitText;
128bool CharFreq::isSevenBitData()
const
130 return type() == SevenBitData;
133bool CharFreq::isSevenBitText()
const
135 return type() == SevenBitText;
138bool CharFreq::hasTrailingWhitespace()
const
143bool CharFreq::hasLeadingFrom()
const
148CharFreq::Type CharFreq::type()
const
151 qCDebug(KMIME_LOG)(
"Total: %d; NUL: %d; CTL: %d;\n"
152 "CR: %d; LF: %d; CRLF: %d;\n"
153 "lineMin: %d; lineMax: %d;\n"
154 "printable: %d; eightBit: %d;\n"
155 "trailing whitespace: %s;\n"
156 "leading 'From ': %s;\n",
157 total, NUL, CTL, CR, LF, CRLF, lineMin, lineMax,
159 mTrailingWS ?
"yes" :
"no" , mLeadingFrom ?
"yes" :
"no");
167 if (mLineMax > 988) {
170 if ((mLF != mCRLF && mCRLF > 0) || mCR != mCRLF || controlCodesRatio() > 0.2) {
177 if (mLineMax > 988) {
180 if ((mLF != mCRLF && mCRLF > 0) || mCR != mCRLF || controlCodesRatio() > 0.2) {
188float CharFreq::printableRatio()
const
191 return float(mPrintable) / float(mTotal);
197float CharFreq::controlCodesRatio()
const
200 return float(mCTL) / float(mTotal);
Type type(const QSqlDatabase &db)
const QList< QKeySequence > & end()
bool isEmpty() const const