• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

KDECore

Public Types | Public Member Functions | Static Public Member Functions | List of all members
KEncodingProber Class Reference

#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

 KEncodingProber (ProberType proberType=Universal)
 
 ~KEncodingProber ()
 
float confidence () const
 
QByteArray encoding () const
 
const char * encodingName () const
 
ProberState feed (const QByteArray &data)
 
ProberState feed (const char *data, int len)
 
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)
QString out = QTextCodec::codecForName(prober.encoding())->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

enum KEncodingProber::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 71 of file kencodingprober.h.

enum KEncodingProber::ProberType
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 141 of file kencodingprober.cpp.

KEncodingProber::~KEncodingProber ( )

Definition at line 146 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 213 of file kencodingprober.cpp.

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

const char * KEncodingProber::encodingName ( ) const
Returns
the name of the best encoding it has guessed so far
Warning
The returned string is allocated with strdup, so some memory is leaked with every call.
Deprecated:
Use encoding() instead, which returns a QByteArray.

Definition at line 199 of file kencodingprober.cpp.

KEncodingProber::ProberState KEncodingProber::feed ( const QByteArray &  data)

The main class method.

feed data to the prober

Returns
the ProberState after probing the fed data.

Definition at line 157 of file kencodingprober.cpp.

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

Definition at line 162 of file kencodingprober.cpp.

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

map ProberType to language string

Definition at line 268 of file kencodingprober.cpp.

KEncodingProber::ProberType KEncodingProber::proberType ( ) const

Definition at line 221 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 232 of file kencodingprober.cpp.

void KEncodingProber::reset ( )

reset the prober's internal state and data.

Definition at line 151 of file kencodingprober.cpp.

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

change current prober's ProberType and reset the prober

Definition at line 226 of file kencodingprober.cpp.

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

Definition at line 192 of file kencodingprober.cpp.


The documentation for this class was generated from the following files:
  • kencodingprober.h
  • kencodingprober.cpp
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:47:10 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDECore

Skip menu "KDECore"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal