KCodecs

kcharsets.h
1/*
2 This file is part of the KDE libraries
3 SPDX-FileCopyrightText: 1999 Lars Knoll <knoll@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7#ifndef KCHARSETS_H
8#define KCHARSETS_H
9
10#include <kcodecs_export.h>
11
12#include <QCoreApplication>
13#include <QList>
14#include <QStringList>
15#include <memory>
16
17#include "kcodecs.h"
18
19class KCharsetsPrivate;
20
21class QChar;
22class QString;
23
24/**
25 * @class KCharsets kcharsets.h KCharsets
26 *
27 * Charset font and encoder/decoder handling.
28 *
29 * This is needed, because Qt's encoding name matching in
30 * QTextCodec::codecForName matches only closely-related encoded names
31 * but not alternate names, e.g. found in the reality of the Internet.
32 */
33class KCODECS_EXPORT KCharsets final
34{
35 Q_DECLARE_TR_FUNCTIONS(KCharsets)
36
37protected:
38 /** Protected constructor. If you need the kcharsets object, use
39 KCharsets::charsets() instead.
40 */
41 KCharsets();
42
43public:
44 /**
45 * Destructor.
46 */
48
49 /**
50 * The global charset manager.
51 * @return the global charset manager
52 */
53 static KCharsets *charsets();
54
55 /**
56 * @brief Converts an entity to a character.
57 *
58 * The string must contain only the
59 * entity without the trailing ';'.
60 * @param str the entity
61 * @return QChar::Null if the entity could not be decoded.
62 */
63 static QChar fromEntity(QStringView str);
64
65 /**
66 * Overloaded member function. Tries to find an entity in the
67 * QString str.
68 * @param str the string containing entified
69 * @param len is a return value, that gives the length of the decoded
70 * entity.
71 * @return a decoded entity if one could be found, QChar::null
72 * otherwise
73 */
74 static QChar fromEntity(QStringView str, int &len);
75
76 /**
77 * Converts a QChar to an entity. The returned string does already
78 * contain the leading '&' and the trailing ';'.
79 * @param ch the char to convert
80 * @return the entity
81 */
82 static QString toEntity(const QChar &ch);
83
84 /**
85 * Scans the given string for entities (like &amp;amp;) and resolves them
86 * using fromEntity.
87 * @param text the string containing the entities
88 * @return the clean string
89 */
90 static QString resolveEntities(const QString &text);
91
92 /**
93 * Lists all available encodings as names.
94 * @return the list of all encodings
95 */
96 QStringList availableEncodingNames() const;
97
98 /**
99 * Lists the available encoding names together with a more descriptive language.
100 * @return the list of descriptive encoding names
101 */
102 QStringList descriptiveEncodingNames() const;
103
104 /**
105 * Lists the available encoding names grouped by script (or language that uses them).
106 * @returns the list of lists consisting of description followed by encoding names (i.e. encodingsByScript().at(i).at(0) is a description for
107 * encodingsByScript().at(i).at(k), k>0)
108 */
109 QList<QStringList> encodingsByScript() const;
110
111 /**
112 * @brief Returns a long description for an encoding name.
113 * @param encoding the encoding for the language
114 * @return the long description for the encoding
115 */
116 QString descriptionForEncoding(QStringView encoding) const;
117
118 /**
119 * Returns the encoding for a string obtained with descriptiveEncodingNames().
120 * @param descriptiveName the descriptive name for the encoding
121 * @return the name of the encoding
122 */
123 QString encodingForName(const QString &descriptiveName) const;
124
125private:
126 std::unique_ptr<KCharsetsPrivate> const d;
127 friend struct KCharsetsSingletonPrivate;
128};
129
130#endif
Charset font and encoder/decoder handling.
Definition kcharsets.h:34
~KCharsets()
Destructor.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:59:08 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.