KEncodingProber

Search for usage in LXR

#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)
 
float confidence () const
 
QByteArray encoding () const
 
ProberState feed (const char *data, qsizetype len)
 
ProberState feed (QByteArrayView data)
 
KEncodingProberoperator= (const KEncodingProber &)=delete
 
ProberType proberType () const
 
void reset ()
 
void setProberType (ProberType proberType)
 
ProberState state () const
 

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 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:

QByteArray data, moredata;
...
KEncodingProber prober(KEncodingProber::Chinese);
prober.feed(data);
prober.feed(moredata);
if (prober.confidence() > 0.6)
encoding = prober.encoding();
QByteArray encoding() const

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 59 of file kencodingprober.h.

Member Enumeration Documentation

◆ ProberState

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 64 of file kencodingprober.h.

◆ ProberType

enum KEncodingProber::ProberType

Definition at line 70 of file kencodingprober.h.

Constructor & Destructor Documentation

◆ KEncodingProber()

KEncodingProber::KEncodingProber ( KEncodingProber::ProberType proberType = Universal)

Default ProberType is Universal(detect all possible encodings)

Definition at line 138 of file kencodingprober.cpp.

Member Function Documentation

◆ confidence()

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 197 of file kencodingprober.cpp.

◆ encoding()

QByteArray KEncodingProber::encoding ( ) const
Returns
a QByteArray with the name of the best encoding it has guessed so far
Since
4.2.2

Definition at line 188 of file kencodingprober.cpp.

◆ feed() [1/2]

ProberState KEncodingProber::feed ( const char * data,
qsizetype len )
inline

Definition at line 116 of file kencodingprober.h.

◆ feed() [2/2]

KEncodingProber::ProberState KEncodingProber::feed ( QByteArrayView data)

The main class method.

feed data to the prober

Returns
the ProberState after probing the fed data.

Definition at line 152 of file kencodingprober.cpp.

◆ nameForProberType()

QString KEncodingProber::nameForProberType ( KEncodingProber::ProberType proberType)
static

map ProberType to language string

Definition at line 258 of file kencodingprober.cpp.

◆ proberType()

KEncodingProber::ProberType KEncodingProber::proberType ( ) const

Definition at line 206 of file kencodingprober.cpp.

◆ proberTypeForName()

KEncodingProber::ProberType KEncodingProber::proberTypeForName ( const QString & lang)
static
Returns
the ProberType for lang (e.g. proberTypeForName("Chinese Simplified") will return KEncodingProber::ChineseSimplified

Definition at line 217 of file kencodingprober.cpp.

◆ reset()

void KEncodingProber::reset ( )

reset the prober's internal state and data.

Definition at line 146 of file kencodingprober.cpp.

◆ setProberType()

void KEncodingProber::setProberType ( KEncodingProber::ProberType proberType)

change current prober's ProberType and reset the prober

Definition at line 211 of file kencodingprober.cpp.

◆ state()

KEncodingProber::ProberState KEncodingProber::state ( ) const
Returns
the prober's current ProberState

Definition at line 183 of file kencodingprober.cpp.


The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:08:36 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.