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  SPDX-FileCopyrightText: 2001-2002 Marc Mutz <[email protected]>
6 
7  SPDX-License-Identifier: LGPL-2.0-or-later
8 */
44 #ifndef __KMIME_CHARFREQ_H__
45 #define __KMIME_CHARFREQ_H__
46 
47 #include <QByteArray>
48 #undef None
49 
50 namespace KMime
51 {
52 
65 class CharFreq
66 {
67 public:
74  explicit CharFreq(const QByteArray &buf);
75 
83  CharFreq(const char *buf, size_t len);
84 
88  enum Type {
89  None = 0,
95  };
96 
100  Q_REQUIRED_RESULT Type type() const;
101 
105  Q_REQUIRED_RESULT bool isEightBitData() const;
106 
110  Q_REQUIRED_RESULT bool isEightBitText() const;
111 
115  Q_REQUIRED_RESULT bool isSevenBitData() const;
116 
120  Q_REQUIRED_RESULT bool isSevenBitText() const;
121 
126  Q_REQUIRED_RESULT bool hasTrailingWhitespace() const;
127 
131  Q_REQUIRED_RESULT bool hasLeadingFrom() const;
132 
137  Q_REQUIRED_RESULT float printableRatio() const;
138 
143  Q_REQUIRED_RESULT float controlCodesRatio() const;
144 
145 private:
146  //@cond PRIVATE
147  uint mNUL; // count of NUL chars
148  uint mCTL; // count of CTLs (incl. DEL, excl. CR, LF, HT)
149  uint mCR; // count of CR chars
150  uint mLF; // count of LF chars
151  uint mCRLF; // count of LFs, preceded by CRs
152  uint mPrintable; // count of printable US-ASCII chars (SPC..~)
153  uint mEightBit; // count of other latin1 chars (those with 8th bit set)
154  uint mTotal; // count of all chars
155  uint mLineMin; // minimum line length
156  uint mLineMax; // maximum line length
157  bool mTrailingWS = false; // does the buffer contain trailing whitespace?
158  bool mLeadingFrom = false; // does the buffer contain lines starting with "From "?
159  //@endcond
160 
167  void count(const char *buf, size_t len);
168 };
169 
170 } // namespace KMime
171 
172 #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-2021 The KDE developers.
Generated on Wed Jan 20 2021 23:18:47 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.