KCodecs 5.109.0
kencodingprober.h
1/*
2 This file is part of the KDE libraries
3
4 SPDX-FileCopyrightText: 2008 Wang Hoi <zealot.hoi@gmail.com>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8#ifndef KENCODINGPROBER_H
9#define KENCODINGPROBER_H
10
11// enable debug of private probers
12// #define DEBUG_PROBE
13
14#include <kcodecs_export.h>
15
16#ifdef DEBUG_PROBE
17#include <QDebug>
18#endif
19
20#include <QCoreApplication>
21#include <QString>
22#include <memory>
23
24class KEncodingProberPrivate;
25
59class KCODECS_EXPORT KEncodingProber
60{
61 Q_DECLARE_TR_FUNCTIONS(KEncodingProber)
62
63public:
68 };
69
70 enum ProberType {
71 None,
72 Universal,
73 Arabic,
74 Baltic,
75 CentralEuropean,
76 ChineseSimplified,
77 ChineseTraditional,
78 Cyrillic,
79 Greek,
80 Hebrew,
81 Japanese,
82 Korean,
83 NorthernSaami,
84 Other,
85 SouthEasternEurope,
86 Thai,
87 Turkish,
88 Unicode,
89 WesternEuropean,
90 };
91
95 KEncodingProber(ProberType proberType = Universal);
96
98
99 KEncodingProber(const KEncodingProber &) = delete;
100 KEncodingProber &operator=(const KEncodingProber &) = delete;
101
105 void reset();
106
114 ProberState feed(const QByteArray &data);
115 ProberState feed(const char *data, int len);
116
122
127 QByteArray encoding() const;
128
132 float confidence() const;
133
134 ProberType proberType() const;
135
139 void setProberType(ProberType proberType);
140
144 static ProberType proberTypeForName(const QString &lang);
145
149 static QString nameForProberType(ProberType proberType);
150
151private:
152 std::unique_ptr<KEncodingProberPrivate> const d;
153};
154
155#endif
Provides encoding detection(probe) capabilities.
Definition kencodingprober.h:60
void reset()
reset the prober's internal state and data.
static QString nameForProberType(ProberType proberType)
map ProberType to language string
KEncodingProber(ProberType proberType=Universal)
Default ProberType is Universal(detect all possible encodings)
ProberState feed(const QByteArray &data)
The main class method.
ProberState state() const
float confidence() const
void setProberType(ProberType proberType)
change current prober's ProberType and reset the prober
QByteArray encoding() const
static ProberType proberTypeForName(const QString &lang)
ProberState
Definition kencodingprober.h:64
@ Probing
Need more data to make a decision.
Definition kencodingprober.h:67
@ NotMe
Sure not included in current ProberType's all supported encodings
Definition kencodingprober.h:66
@ FoundIt
Sure find the encoding.
Definition kencodingprober.h:65