KDECore
KEncodingProber Class Reference
Provides encoding detection(probe) capabilities. More...
#include <kencodingprober.h>
Public Types | |
enum | ProberState { FoundIt, NotMe, Probing } |
enum | ProberType { None, Universal, Arabic, Baltic, CentralEuropean, ChineseSimplified, ChineseTraditional, Cyrillic, Greek, Hebrew, Japanese, Korean, NorthernSaami, Other, SouthEasternEurope, Thai, Turkish, Unicode, WesternEuropean } |
Public Member Functions | |
float | confidence () const |
const char * | encodingName () const |
ProberState | feed (const char *data, int len) |
ProberState | feed (const QByteArray &data) |
KEncodingProber (ProberType proberType=Universal) | |
ProberType | proberType () const |
void | reset () |
void | setProberType (ProberType proberType) |
ProberState | state () const |
~KEncodingProber () | |
Static Public Member Functions | |
static QString | nameForProberType (ProberType proberType) |
static ProberType | proberTypeForName (const QString &lang) |
Detailed Description
Provides encoding detection(probe) capabilities.Probe the encoding of raw data only. In the case it can't find it, return the most possible encoding it guessed.
Always do Unicode probe regardless the ProberType
Feed data to it several times until ProberState changed to FoundIt/NotMe, or the Confidence reach a value you think acceptable.
Intended lifetime of the object: one instance per ProberType.
Typical use:
QByteArray data, moredata; ... KEncodingProber prober(KEncodingProber::Chinese); prober.feed(data); prober.feed(moredata); if (prober.confidence() > 0.6) QString out = QTextCodec::codeForName(prober.encodingName())->toUnicode(data);
at least 256 characters are needed to change the ProberState from Probing to FoundIt. if you don't have so many characters to probe, decide whether to accept the encoding it guessed so far according to the Confidence by yourself.
Guess encoding of char array
Definition at line 67 of file kencodingprober.h.
Member Enumeration Documentation
- Enumerator:
-
FoundIt Sure find the encoding. NotMe Sure not included in current ProberType's all supported encodings. Probing Need more data to make a decision.
Definition at line 71 of file kencodingprober.h.
- Enumerator:
-
None Universal Arabic Baltic CentralEuropean ChineseSimplified ChineseTraditional Cyrillic Greek Hebrew Japanese Korean NorthernSaami Other SouthEasternEurope Thai Turkish Unicode WesternEuropean
Definition at line 77 of file kencodingprober.h.
Constructor & Destructor Documentation
KEncodingProber::KEncodingProber | ( | KEncodingProber::ProberType | proberType = Universal |
) |
Default ProberType is Universal(detect all possibe encodings).
Definition at line 148 of file kencodingprober.cpp.
KEncodingProber::~KEncodingProber | ( | ) |
Definition at line 153 of file kencodingprober.cpp.
Member Function Documentation
float KEncodingProber::confidence | ( | ) | const |
- Returns:
- the confidence(sureness) of encoding it guessed so far (0.0 ~ 0.99), not very reliable for single byte encodings
Definition at line 212 of file kencodingprober.cpp.
const char * KEncodingProber::encodingName | ( | ) | const |
- Returns:
- the name of the best encoding it guessed so far
Definition at line 204 of file kencodingprober.cpp.
KEncodingProber::ProberState KEncodingProber::feed | ( | const char * | data, | |
int | len | |||
) |
Definition at line 169 of file kencodingprober.cpp.
KEncodingProber::ProberState KEncodingProber::feed | ( | const QByteArray & | data | ) |
The main class method.
feed data to the prober
- Returns:
- the ProberState after probe the feedded data
Definition at line 164 of file kencodingprober.cpp.
QString KEncodingProber::nameForProberType | ( | KEncodingProber::ProberType | proberType | ) | [static] |
KEncodingProber::ProberType KEncodingProber::proberType | ( | ) | const |
Definition at line 220 of file kencodingprober.cpp.
KEncodingProber::ProberType KEncodingProber::proberTypeForName | ( | const QString & | lang | ) | [static] |
- Returns:
- the ProberType for lang (eg. proberTypeForName("Chinese Simplified") will return KEncodingProber::ChineseSimplified
Definition at line 231 of file kencodingprober.cpp.
void KEncodingProber::reset | ( | ) |
void KEncodingProber::setProberType | ( | KEncodingProber::ProberType | proberType | ) |
change current prober's ProberType and reset the prober
Definition at line 225 of file kencodingprober.cpp.
KEncodingProber::ProberState KEncodingProber::state | ( | ) | const |
The documentation for this class was generated from the following files: