libkmime

kmime_charfreq.h
1/*
2 kmime_charfreq.h
3
4 KMime, the KDE internet mail/usenet news message library.
5 Copyright (c) 2001-2002 Marc Mutz <mutz@kde.org>
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11 You should have received a copy of the GNU General Public License
12 along with this program; if not, write to the Free Software Foundation,
13 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, US
14*/
15#ifndef __KMIME_CHARFREQ_H__
16#define __KMIME_CHARFREQ_H__
17
18#include <tqcstring.h>
19#include <tdemacros.h>
20#undef None
21
22namespace KMime {
23
24class TDE_EXPORT CharFreq {
25public:
26 CharFreq( const TQByteArray & buf );
27 CharFreq( const char * buf, size_t len );
28
29 enum Type { None = 0, EightBitData, Binary = EightBitData,
30 SevenBitData, EightBitText, SevenBitText };
31
32 Type type() const;
33 bool isEightBitData() const;
34 bool isEightBitText() const;
35 bool isSevenBitData() const;
36 bool isSevenBitText() const;
39 bool hasTrailingWhitespace() const;
41 bool hasLeadingFrom() const;
44 float printableRatio() const;
47 float controlCodesRatio() const;
48
49protected:
50 uint NUL; // count of NUL chars
51 uint CTL; // count of CTLs (incl. DEL, excl. CR, LF, HT)
52 uint CR, LF; // count of CRs and LFs
53 uint CRLF; // count of LFs, preceded by CRs
54 uint printable; // count of printable US-ASCII chars (SPC..~)
55 uint eightBit; // count of other latin1 chars (those with 8th bit set)
56 uint total;
57 uint lineMin;
58 uint lineMax;
59 bool mTrailingWS; // does the buffer contain trailing whitespace?
60 bool mLeadingFrom; // does the buffer contain lines starting with "From "?
61
62private:
63 void count( const char * buf, size_t len );
64};
65
66} // namespace KMime
67
68#endif /* __KMIME_CHARFREQ_H__ */