KCodecs 5.109.0
|
Provides encoding detection(probe) capabilities. More...
#include <KEncodingProber>
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 | |
KEncodingProber (const KEncodingProber &)=delete | |
KEncodingProber (ProberType proberType=Universal) | |
Default ProberType is Universal(detect all possible encodings) | |
float | confidence () const |
QByteArray | encoding () const |
ProberState | feed (const char *data, int len) |
ProberState | feed (const QByteArray &data) |
The main class method. | |
KEncodingProber & | operator= (const KEncodingProber &)=delete |
ProberType | proberType () const |
void | reset () |
reset the prober's internal state and data. | |
void | setProberType (ProberType proberType) |
change current prober's ProberType and reset the prober | |
ProberState | state () const |
Static Public Member Functions | |
static QString | nameForProberType (ProberType proberType) |
map ProberType to language string | |
static ProberType | proberTypeForName (const QString &lang) |
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 with feed() until ProberState changes to FoundIt/NotMe, or confidence() returns a value you find acceptable.
Intended lifetime of the object: one instance per ProberType.
Typical use:
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
KEncodingProber::KEncodingProber | ( | ProberType | proberType = Universal | ) |
Default ProberType is Universal(detect all possible encodings)
float KEncodingProber::confidence | ( | ) | const |
QByteArray KEncodingProber::encoding | ( | ) | const |
ProberState KEncodingProber::feed | ( | const QByteArray & | data | ) |
The main class method.
feed data to the prober
|
static |
map ProberType to language string
|
static |
void KEncodingProber::reset | ( | ) |
reset the prober's internal state and data.
void KEncodingProber::setProberType | ( | ProberType | proberType | ) |
change current prober's ProberType and reset the prober
ProberState KEncodingProber::state | ( | ) | const |