umbrello 26.07.70-c53146a Umbrello UML Modeller is a Unified Modelling Language (UML) diagram program based on KDE Technology

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

encodinghelper.h
Go to the documentation of this file.
1/*
2 SPDX-FileCopyrightText: 2025 Umbrello UML Modeller Authors <umbrello-devel@kde.org>
3 SPDX-License-Identifier: GPL-2.0-or-later
4*/
5
6#pragma once
7
8#include <QString>
9#include <QTextStream>
10
11#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
12#include <QStringConverter>
13#else
14#include <QTextCodec>
15#endif
16
17 class EncodingHelper {
18 public:
19 static bool setEncoding(QTextStream &stream, const QString &encodingName) {
20#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
21 auto enc = QStringConverter::encodingForName(encodingName);
22 if (!enc.has_value()) {
23 return false;
24 }
25 stream.setEncoding(enc.value());
26 return true;
27#else
28 QTextCodec *codec = QTextCodec::codecForName(encodingName.toUtf8());
29 if (!codec) {
30 return false;
31 }
32 stream.setCodec(codec);
33 return true;
34#endif
35 }
36
37 static bool setEncodingByCharsetNum(QTextStream &stream, int charSetNum) {
38 switch (charSetNum) {
39 case 0: // ASCII
40 case 1: // Default
41 return setEncoding(stream, QStringLiteral("System"));
42 case 2: // Symbol
43 return false; // No known codec
44 case 77:
45 return setEncoding(stream, QStringLiteral("macintosh"));
46 case 128:
47 return setEncoding(stream, QStringLiteral("Shift_JIS"));
48 case 129:
49 case 130:
50 return setEncoding(stream, QStringLiteral("EUC-KR"));
51 case 134:
52 return setEncoding(stream, QStringLiteral("GB18030"));
53 case 136:
54 return setEncoding(stream, QStringLiteral("Big5"));
55 case 161:
56 return setEncoding(stream, QStringLiteral("windows-1253"));
57 case 162:
58 return setEncoding(stream, QStringLiteral("windows-1254"));
59 case 163:
60 return setEncoding(stream, QStringLiteral("windows-1258"));
61 case 177:
62 return setEncoding(stream, QStringLiteral("windows-1255"));
63 case 178:
64 return setEncoding(stream, QStringLiteral("windows-1256"));
65 case 186:
66 return setEncoding(stream, QStringLiteral("windows-1257"));
67 case 204:
68 return setEncoding(stream, QStringLiteral("windows-1251"));
69 case 222:
70 return setEncoding(stream, QStringLiteral("TIS-620"));
71 case 238:
72 return setEncoding(stream, QStringLiteral("windows-1250"));
73 case 255:
74 return setEncoding(stream, QStringLiteral("windows-1252"));
75 default:
76 return false; // unknown charset
77 }
78 }
79};
EncodingHelper
Definition: encodinghelper.h:17
EncodingHelper::setEncodingByCharsetNum
static bool setEncodingByCharsetNum(QTextStream &stream, int charSetNum)
Definition: encodinghelper.h:37
EncodingHelper::setEncoding
static bool setEncoding(QTextStream &stream, const QString &encodingName)
Definition: encodinghelper.h:19