KCharsets Class

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

Header: #include <KCharsets>
CMake: find_package(KF6 REQUIRED COMPONENTS Codecs)
target_link_libraries(mytarget PRIVATE KF6::Codecs)

Public Functions

QStringList availableEncodingNames() const
QString descriptionForEncoding(QStringView encoding) const
QStringList descriptiveEncodingNames() const
QString encodingForName(const QString &descriptiveName) const
QList<QStringList> encodingsByScript() const

Static Public Members

KCharsets *charsets()
QChar fromEntity(QStringView str)
QChar fromEntity(QStringView str, int &len)
QString resolveEntities(const QString &text)
QString toEntity(const QChar &ch)

Detailed Description

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.

Member Function Documentation

QStringList KCharsets::availableEncodingNames() const

Lists all available encodings as names

[static] KCharsets *KCharsets::charsets()

The global charset manager.

QString KCharsets::descriptionForEncoding(QStringView encoding) const

Returns a long description for an encoding name.

encoding the encoding for the language

QStringList KCharsets::descriptiveEncodingNames() const

Lists the available encoding names together with a more descriptive language

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

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

descriptiveName the descriptive name for the encoding

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)

[static] QChar KCharsets::fromEntity(QStringView str)

Converts an entity to a character.

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

str the entity

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

[static] QChar KCharsets::fromEntity(QStringView str, int &len)

Tries to find an entity in the QString str.

str the string containing entified

len is a return value, that gives the length of the decoded entity.

Returns a decoded entity if one could be found, QChar::null otherwise

This function overloads fromEntity(QStringView).

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

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

text the string containing the entities

Returns the clean string

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

Converts a QChar to an entity. The returned string does already contain the leading '&' and the trailing ';'.

ch the char to convert

Returns the entity