KCharsets

KDE 4.7 PyKDE API Reference

- KDE's Python API

# KCharsets Class Reference

`from PyKDE4.kdecore import *`

## 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.

## Methods
| __init__ (self)
| __init__ (self, KCharsets other)
QStringList | availableEncodingNames (self)
QTextCodec | codecForName (self, QString name)
QTextCodec, bool ok | codecForName2 (self, QString n)
QString | descriptionForEncoding (self, QString encoding)
QStringList | descriptiveEncodingNames (self)
QString | encodingForName (self, QString descriptiveName)
[QStringList] | encodingsByScript (self)
QString | languageForEncoding (self, QString encoding)
## Static Methods
QChar | fromEntity (QString str)
QChar, int len | fromEntity2 (QString str)
QString | resolveEntities (QString text)
QString | toEntity (QChar ch)

## Method Documentation

__init__ | ( |  | self ) |

Protected constructor. If you need the kcharsets object, use KGlobal.charsets() instead.

__init__ | ( | self, |
|  | KCharsets | other
| ) |  |  |

QStringList availableEncodingNames | ( |  | self ) |

Lists all available encodings as names.

Returns:
  the list of all encodings

QTextCodec codecForName | ( | self, |
|  | QString | name
| ) |  |  |

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.

Parameters:

  | n | the name of the codec
  | ok | true 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

QTextCodec, bool ok codecForName2 | ( | self, |
|  | QString | n
| ) |  |  |

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.

Parameters:

  | n | the name of the codec
  | ok | true 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

QString descriptionForEncoding | ( | self, |
|  | QString | encoding
| ) |  |  |

Returns a long description for an encoding name.

Parameters:

  | encoding | the encoding for the language

Returns:
  the long description for the encoding

QStringList descriptiveEncodingNames | ( |  | self ) |

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

Returns:
  the list of descriptive encoding names

QString encodingForName | ( | self, |
|  | QString | descriptiveName
| ) |  |  |

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

Parameters:

  | descriptiveName | the descriptive name for the encoding

Returns:
  the name of the encoding

[QStringList] encodingsByScript | ( |  | self ) |

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)

QString languageForEncoding | ( | self, |
|  | QString | encoding
| ) |  |  |

Returns the language the encoding is used for.

Parameters:

  | encoding | the encoding for the language

Returns:
  the language of the encoding

Deprecated:
  Please use descriptionForEncoding instead. This function will be removed before KDE4 is released.

## Static Method Documentation

QChar fromEntity | ( | QString | str
| ) |  |  |

Overloaded member function. Tries to find an entity in the QString str.

Parameters:

  | 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

QChar, int len fromEntity2 | ( | QString | str
| ) |  |  |

Overloaded member function. Tries to find an entity in the QString str.

Parameters:

  | 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

QString resolveEntities | ( | QString | text
| ) |  |  |

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

Parameters:

  | text | the string containing the entities

Returns:
  the clean string

QString toEntity | ( | QChar | ch
| ) |  |  |

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

Parameters:

  | ch | the char to convert

Returns:
  the entity