KCodecs 5.109.0
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
KCharsets

Charset font and encoder/decoder handling. More...

#include <KCharsets>

Public Member Functions

virtual ~KCharsets ()
 Destructor.
 
QStringList availableEncodingNames () const
 Lists all available encodings as names.
 
QTextCodec * codecForName (const QString &n, bool &ok) const
 Tries to find a QTextCodec to convert the given encoding from and to Unicode.
 
QTextCodec * codecForName (const QString &name) const
 Provided for compatibility.
 
QString descriptionForEncoding (const QString &encoding) const
 Returns a long description for an encoding name.
 
QStringList descriptiveEncodingNames () const
 Lists the available encoding names together with a more descriptive language.
 
QString encodingForName (const QString &descriptiveName) const
 Returns the encoding for a string obtained with descriptiveEncodingNames().
 
QList< QStringList > encodingsByScript () const
 Lists the available encoding names grouped by script (or language that uses them).
 

Static Public Member Functions

static KCharsetscharsets ()
 The global charset manager.
 
static QChar fromEntity (const QString &str)
 Converts an entity to a character.
 
static QChar fromEntity (const QString &str, int &len)
 Overloaded member function.
 
static QString resolveEntities (const QString &text)
 Scans the given string for entities (like &amp;) and resolves them using fromEntity.
 
static QString toEntity (const QChar &ch)
 Converts a QChar to an entity.
 

Protected Member Functions

 KCharsets ()
 Protected constructor.
 

Detailed Description

Charset font and encoder/decoder handling.

This is needed, because Qt's encoding name matching in QTextCodec::codecForName matches only closely-related encoded names but not alternate names, e.g. found in the reality of the Internet.

Constructor & Destructor Documentation

◆ KCharsets()

KCharsets::KCharsets ( )
protected

Protected constructor.

If you need the kcharsets object, use KCharsets::charsets() instead.

◆ ~KCharsets()

virtual KCharsets::~KCharsets ( )
virtual

Destructor.

Member Function Documentation

◆ availableEncodingNames()

QStringList KCharsets::availableEncodingNames ( ) const

Lists all available encodings as names.

Returns
the list of all encodings

◆ charsets()

static KCharsets * KCharsets::charsets ( )
static

The global charset manager.

Returns
the global charset manager

◆ codecForName() [1/2]

QTextCodec * KCharsets::codecForName ( const QString &  n,
bool &  ok 
) const

Tries to find a QTextCodec to convert the given encoding from and to Unicode.

If no codec could be found, the ISO 8859-1 codec will be returned an and ok will be set to false.

Deprecated:
apps should use QTextCodec::codecForName in Qt5 or Qt5Compat in Qt6 or port to QStringEncoder
Parameters
nthe name of the codec
oktrue if a matching codec has been found, false if not
Returns
the QTextCodec. If the desired codec could not be found, it returns a default (ISO 8859-1) codec

◆ codecForName() [2/2]

QTextCodec * KCharsets::codecForName ( const QString &  name) const

Provided for compatibility.

Parameters
namethe name of the codec
Returns
the QTextCodec. If the desired codec could not be found, it returns a default (ISO 8859-1) codec
Deprecated:
since 5.101 apps should use QTextCodec::codecForName in Qt5 or Qt5Compat in Qt6 or port to QStringEncoder

◆ descriptionForEncoding()

QString KCharsets::descriptionForEncoding ( const QString &  encoding) const

Returns a long description for an encoding name.

Parameters
encodingthe encoding for the language
Returns
the long description for the encoding

◆ descriptiveEncodingNames()

QStringList KCharsets::descriptiveEncodingNames ( ) const

Lists the available encoding names together with a more descriptive language.

Returns
the list of descriptive encoding names

◆ encodingForName()

QString KCharsets::encodingForName ( const QString &  descriptiveName) const

Returns the encoding for a string obtained with descriptiveEncodingNames().

Parameters
descriptiveNamethe descriptive name for the encoding
Returns
the name of the encoding

◆ encodingsByScript()

QList< QStringList > KCharsets::encodingsByScript ( ) const

Lists the available encoding names grouped by script (or language that uses them).

Returns
the list of lists consisting of description followed by encoding names (i.e. encodingsByScript().at(i).at(0) is a description for encodingsByScript().at(i).at(k), k>0)

◆ fromEntity() [1/2]

static QChar KCharsets::fromEntity ( const QString &  str)
static

Converts an entity to a character.

The string must contain only the entity without the trailing ';'.

Parameters
strthe entity
Returns
QChar::Null if the entity could not be decoded.

◆ fromEntity() [2/2]

static QChar KCharsets::fromEntity ( const QString &  str,
int &  len 
)
static

Overloaded member function.

Tries to find an entity in the QString str.

Parameters
strthe string containing entified
lenis a return value, that gives the length of the decoded entity.
Returns
a decoded entity if one could be found, QChar::null otherwise

◆ resolveEntities()

static QString KCharsets::resolveEntities ( const QString &  text)
static

Scans the given string for entities (like &amp;) and resolves them using fromEntity.

Parameters
textthe string containing the entities
Returns
the clean string

◆ toEntity()

static QString KCharsets::toEntity ( const QChar &  ch)
static

Converts a QChar to an entity.

The returned string does already contain the leading '&' and the trailing ';'.

Parameters
chthe char to convert
Returns
the entity