KMime

kmime_charfreq.h
Go to the documentation of this file.
1 /* -*- c++ -*-
2  kmime_charfreq.h
3 
4  KMime, the KDE Internet mail/usenet news message library.
5  Copyright (c) 2001-2002 Marc Mutz <[email protected]>
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public License
18  along with this library; see the file COPYING.LIB. If not, write to
19  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  Boston, MA 02110-1301, USA.
21 */
57 #ifndef __KMIME_CHARFREQ_H__
58 #define __KMIME_CHARFREQ_H__
59 
60 #include <QByteArray>
61 #undef None
62 
63 namespace KMime
64 {
65 
78 class CharFreq
79 {
80 public:
87  explicit CharFreq(const QByteArray &buf);
88 
96  CharFreq(const char *buf, size_t len);
97 
101  enum Type {
102  None = 0,
108  };
109 
113  Q_REQUIRED_RESULT Type type() const;
114 
118  Q_REQUIRED_RESULT bool isEightBitData() const;
119 
123  Q_REQUIRED_RESULT bool isEightBitText() const;
124 
128  Q_REQUIRED_RESULT bool isSevenBitData() const;
129 
133  Q_REQUIRED_RESULT bool isSevenBitText() const;
134 
139  Q_REQUIRED_RESULT bool hasTrailingWhitespace() const;
140 
144  Q_REQUIRED_RESULT bool hasLeadingFrom() const;
145 
150  Q_REQUIRED_RESULT float printableRatio() const;
151 
156  Q_REQUIRED_RESULT float controlCodesRatio() const;
157 
158 private:
159  //@cond PRIVATE
160  uint mNUL; // count of NUL chars
161  uint mCTL; // count of CTLs (incl. DEL, excl. CR, LF, HT)
162  uint mCR; // count of CR chars
163  uint mLF; // count of LF chars
164  uint mCRLF; // count of LFs, preceded by CRs
165  uint mPrintable; // count of printable US-ASCII chars (SPC..~)
166  uint mEightBit; // count of other latin1 chars (those with 8th bit set)
167  uint mTotal; // count of all chars
168  uint mLineMin; // minimum line length
169  uint mLineMax; // maximum line length
170  bool mTrailingWS; // does the buffer contain trailing whitespace?
171  bool mLeadingFrom; // does the buffer contain lines starting with "From "?
172  //@endcond
173 
180  void count(const char *buf, size_t len);
181 };
182 
183 } // namespace KMime
184 
185 #endif /* __KMIME_CHARFREQ_H__ */
bool isEightBitText() const
Returns true if the data Type is EightBitText; false otherwise.
bool isEightBitData() const
Returns true if the data Type is EightBitData; false otherwise.
bool isSevenBitText() const
Returns true if the data Type is SevenBitText; false otherwise.
bool hasTrailingWhitespace() const
Returns true if the data contains trailing whitespace.
Type
The different types of data.
bool isSevenBitData() const
Returns true if the data Type is SevenBitData; false otherwise.
float printableRatio() const
Returns the percentage of printable characters in the data.
CharFreq(const QByteArray &buf)
Constructs a Character Frequency instance for a buffer buf of QByteArray data.
bool hasLeadingFrom() const
Returns true if the data contains a line that starts with "From ".
float controlCodesRatio() const
Returns the percentage of control code characters (CTLs) in the data.
A class for performing basic data typing using frequency count heuristics.
Type type() const
Returns the data Type as derived from the class heuristics.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jul 6 2020 23:11:19 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.