Skip to content

Commit dfa17cf

Browse files
committed
v0.0.96
1 parent 30dba52 commit dfa17cf

12 files changed

+567
-2
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
## 0.0.96
77

88
- Implemented:
9-
- Encoding Menu -> Interpret as ... IBM-00858, IBM-Thai, HZ-GB-2312, GBK, GH18030, EUC-JP, CESU-8
9+
- Encoding Menu -> Interpret as ... IBM-00858, IBM-Thai, HZ-GB-2312, GBK, GH18030, EUC-JP, CESU-8, Big5-HKSCS, Big5, BOCU-1, Adobe-Standard-Encoding
1010

1111
## 0.0.95
1212

CMakeLists.txt

+8
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,14 @@ set(PROJECT_SOURCES
295295
src/decoding/interpret_as_euc_jp.h
296296
src/decoding/interpret_as_cesu_8.cpp
297297
src/decoding/interpret_as_cesu_8.h
298+
src/decoding/interpret_as_big5_hkscs.cpp
299+
src/decoding/interpret_as_big5_hkscs.h
300+
src/decoding/interpret_as_big5.cpp
301+
src/decoding/interpret_as_big5.h
302+
src/decoding/interpret_as_bocu_1.cpp
303+
src/decoding/interpret_as_bocu_1.h
304+
src/decoding/interpret_as_adobe_standard_encoding.cpp
305+
src/decoding/interpret_as_adobe_standard_encoding.h
298306
${PROJECT_UI}
299307
)
300308

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
#include "../codeeditor.h"
2+
#include "interpret_as_adobe_standard_encoding.h"
3+
#include <QFile>
4+
#include <QDebug>
5+
6+
// Singleton instance
7+
Interpret_As_Adobe_Standard_Encoding& Interpret_As_Adobe_Standard_Encoding::instance() {
8+
static Interpret_As_Adobe_Standard_Encoding instance;
9+
return instance;
10+
}
11+
12+
// Constructor
13+
Interpret_As_Adobe_Standard_Encoding::Interpret_As_Adobe_Standard_Encoding() {}
14+
15+
// Main execution function
16+
void Interpret_As_Adobe_Standard_Encoding::execute(QPlainTextEdit* editor) {
17+
if (!editor) {
18+
qWarning() << "[ERROR] No editor instance provided.";
19+
return;
20+
}
21+
22+
CodeEditor* codeEditor = qobject_cast<CodeEditor*>(editor);
23+
if (!codeEditor) {
24+
qWarning() << "[ERROR] Invalid CodeEditor instance.";
25+
return;
26+
}
27+
28+
QString filePath = codeEditor->filePath();
29+
if (filePath.isEmpty()) {
30+
qWarning() << "[ERROR] No file path associated with the editor.";
31+
return;
32+
}
33+
34+
QFile file(filePath);
35+
if (!file.open(QIODevice::ReadOnly)) {
36+
qWarning() << "[ERROR] Cannot open file:" << filePath;
37+
return;
38+
}
39+
40+
QByteArray rawData = file.readAll();
41+
file.close();
42+
43+
QString decodedText = decodeAdobeStandardEncoding(rawData);
44+
editor->setPlainText(decodedText);
45+
qDebug() << "[DEBUG] Adobe-Standard-Encoding applied for file:" << filePath;
46+
}
47+
48+
// Decode Adobe-Standard-Encoding encoded data
49+
QString Interpret_As_Adobe_Standard_Encoding::decodeAdobeStandardEncoding(const QByteArray& rawData) {
50+
QString result;
51+
52+
for (unsigned char byte : rawData) {
53+
auto it = adobeStandardEncodingTable.find(byte);
54+
if (it != adobeStandardEncodingTable.end()) {
55+
result.append(it->second);
56+
} else {
57+
result.append(QChar(0xFFFD)); // Replacement character for unknown bytes
58+
}
59+
}
60+
61+
return result;
62+
}
63+
64+
// Adobe Standard Encoding table
65+
const std::unordered_map<unsigned char, QChar> Interpret_As_Adobe_Standard_Encoding::adobeStandardEncodingTable = {
66+
{0x20, QChar(' ')},
67+
{0x21, QChar('!')},
68+
{0x22, QChar('"')},
69+
{0x23, QChar('#')},
70+
{0x24, QChar('$')},
71+
{0x25, QChar('%')},
72+
{0x26, QChar('&')},
73+
{0x27, QChar('\'')},
74+
{0x28, QChar('(')},
75+
{0x29, QChar(')')},
76+
{0x2A, QChar('*')},
77+
{0x2B, QChar('+')},
78+
{0x2C, QChar(',')},
79+
{0x2D, QChar('-')},
80+
{0x2E, QChar('.')},
81+
{0x2F, QChar('/')},
82+
{0x30, QChar('0')},
83+
{0x31, QChar('1')},
84+
{0x32, QChar('2')},
85+
{0x33, QChar('3')},
86+
{0x34, QChar('4')},
87+
{0x35, QChar('5')},
88+
{0x36, QChar('6')},
89+
{0x37, QChar('7')},
90+
{0x38, QChar('8')},
91+
{0x39, QChar('9')},
92+
{0x3A, QChar(':')},
93+
{0x3B, QChar(';')},
94+
{0x3C, QChar('<')},
95+
{0x3D, QChar('=')},
96+
{0x3E, QChar('>')},
97+
{0x3F, QChar('?')},
98+
{0x40, QChar('@')},
99+
{0x41, QChar('A')},
100+
{0x42, QChar('B')},
101+
{0x43, QChar('C')},
102+
{0x44, QChar('D')},
103+
{0x45, QChar('E')},
104+
{0x46, QChar('F')},
105+
{0x47, QChar('G')},
106+
{0x48, QChar('H')},
107+
{0x49, QChar('I')},
108+
{0x4A, QChar('J')},
109+
{0x4B, QChar('K')},
110+
{0x4C, QChar('L')},
111+
{0x4D, QChar('M')},
112+
{0x4E, QChar('N')},
113+
{0x4F, QChar('O')},
114+
{0x50, QChar('P')},
115+
{0x51, QChar('Q')},
116+
{0x52, QChar('R')},
117+
{0x53, QChar('S')},
118+
{0x54, QChar('T')},
119+
{0x55, QChar('U')},
120+
{0x56, QChar('V')},
121+
{0x57, QChar('W')},
122+
{0x58, QChar('X')},
123+
{0x59, QChar('Y')},
124+
{0x5A, QChar('Z')},
125+
{0x5B, QChar('[')},
126+
{0x5C, QChar('\\')},
127+
{0x5D, QChar(']')},
128+
{0x5E, QChar('^')},
129+
{0x5F, QChar('_')},
130+
{0x60, QChar('`')},
131+
{0x61, QChar('a')},
132+
{0x62, QChar('b')},
133+
{0x63, QChar('c')},
134+
{0x64, QChar('d')},
135+
{0x65, QChar('e')},
136+
{0x66, QChar('f')},
137+
{0x67, QChar('g')},
138+
{0x68, QChar('h')},
139+
{0x69, QChar('i')},
140+
{0x6A, QChar('j')},
141+
{0x6B, QChar('k')},
142+
{0x6C, QChar('l')},
143+
{0x6D, QChar('m')},
144+
{0x6E, QChar('n')},
145+
{0x6F, QChar('o')},
146+
{0x70, QChar('p')},
147+
{0x71, QChar('q')},
148+
{0x72, QChar('r')},
149+
{0x73, QChar('s')},
150+
{0x74, QChar('t')},
151+
{0x75, QChar('u')},
152+
{0x76, QChar('v')},
153+
{0x77, QChar('w')},
154+
{0x78, QChar('x')},
155+
{0x79, QChar('y')},
156+
{0x7A, QChar('z')},
157+
{0x7B, QChar('{')},
158+
{0x7C, QChar('|')},
159+
{0x7D, QChar('}')},
160+
{0x7E, QChar('~')},
161+
{0xA1, QChar(0x00A1)}, // Inverted Exclamation Mark
162+
{0xA2, QChar(0x00A2)}, // Cent Sign
163+
{0xA3, QChar(0x00A3)}, // Pound Sign
164+
{0xA4, QChar(0x00A4)}, // Currency Sign
165+
{0xA5, QChar(0x00A5)}, // Yen Sign
166+
{0xA6, QChar(0x00A6)}, // Broken Bar
167+
{0xA7, QChar(0x00A7)}, // Section Sign
168+
{0xA8, QChar(0x00A8)}, // Diaeresis
169+
{0xA9, QChar(0x00A9)}, // Copyright Sign
170+
{0xAA, QChar(0x00AA)}, // Feminine Ordinal Indicator
171+
{0xAB, QChar(0x00AB)}, // Left-Pointing Double Angle Quotation Mark
172+
{0xAC, QChar(0x00AC)}, // Not Sign
173+
{0xAD, QChar(0x00AD)}, // Soft Hyphen
174+
{0xAE, QChar(0x00AE)}, // Registered Sign
175+
{0xAF, QChar(0x00AF)}, // Macron
176+
{0xB0, QChar(0x00B0)}, // Degree Sign
177+
{0xB1, QChar(0x00B1)}, // Plus-Minus Sign
178+
{0xB2, QChar(0x00B2)}, // Superscript Two
179+
{0xB3, QChar(0x00B3)}, // Superscript Three
180+
{0xB4, QChar(0x00B4)}, // Acute Accent
181+
{0xB5, QChar(0x00B5)}, // Micro Sign
182+
{0xB6, QChar(0x00B6)}, // Pilcrow Sign
183+
{0xB7, QChar(0x00B7)}, // Middle Dot
184+
{0xB8, QChar(0x00B8)}, // Cedilla
185+
{0xB9, QChar(0x00B9)}, // Superscript One
186+
{0xBA, QChar(0x00BA)}, // Masculine Ordinal Indicator
187+
{0xBB, QChar(0x00BB)}, // Right-Pointing Double Angle Quotation Mark
188+
{0xBC, QChar(0x00BC)}, // Vulgar Fraction One Quarter
189+
{0xBD, QChar(0x00BD)}, // Vulgar Fraction One Half
190+
{0xBE, QChar(0x00BE)}, // Vulgar Fraction Three Quarters
191+
{0xBF, QChar(0x00BF)}, // Inverted Question Mark
192+
{0xC0, QChar(0x00C0)}, // À
193+
{0xC1, QChar(0x00C1)}, // Á
194+
{0xC2, QChar(0x00C2)}, // Â
195+
{0xC3, QChar(0x00C3)}, // Ã
196+
{0xC4, QChar(0x00C4)}, // Ä
197+
{0xC5, QChar(0x00C5)}, // Å
198+
{0xC6, QChar(0x00C6)}, // Æ
199+
{0xC7, QChar(0x00C7)}, // Ç
200+
{0xC8, QChar(0x00C8)}, // È
201+
{0xC9, QChar(0x00C9)}, // É
202+
{0xCA, QChar(0x00CA)}, // Ê
203+
{0xCB, QChar(0x00CB)}, // Ë
204+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#pragma once
2+
3+
#include <QPlainTextEdit>
4+
#include <QString>
5+
#include <QByteArray>
6+
#include <unordered_map>
7+
8+
class Interpret_As_Adobe_Standard_Encoding {
9+
public:
10+
// Singleton instance access
11+
static Interpret_As_Adobe_Standard_Encoding& instance();
12+
13+
// Execute decoding for the provided editor
14+
void execute(QPlainTextEdit* editor);
15+
16+
private:
17+
// Private constructor for Singleton pattern
18+
Interpret_As_Adobe_Standard_Encoding();
19+
~Interpret_As_Adobe_Standard_Encoding() = default;
20+
21+
// Disable copy construction and assignment
22+
Interpret_As_Adobe_Standard_Encoding(const Interpret_As_Adobe_Standard_Encoding&) = delete;
23+
Interpret_As_Adobe_Standard_Encoding& operator=(const Interpret_As_Adobe_Standard_Encoding&) = delete;
24+
25+
// Decoding method for Adobe-Standard-Encoding data
26+
QString decodeAdobeStandardEncoding(const QByteArray& rawData);
27+
28+
// Adobe Standard Encoding table
29+
static const std::unordered_map<unsigned char, QChar> adobeStandardEncodingTable;
30+
};

src/decoding/interpret_as_big5.cpp

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#include "../codeeditor.h"
2+
#include "interpret_as_big5.h"
3+
#include <QFile>
4+
#include <QDebug>
5+
#include <QStringDecoder>
6+
7+
// Singleton instance
8+
Interpret_As_Big5& Interpret_As_Big5::instance() {
9+
static Interpret_As_Big5 instance;
10+
return instance;
11+
}
12+
13+
// Constructor
14+
Interpret_As_Big5::Interpret_As_Big5() {}
15+
16+
// Main execution function
17+
void Interpret_As_Big5::execute(QPlainTextEdit* editor) {
18+
if (!editor) {
19+
qWarning() << "[ERROR] No editor instance provided.";
20+
return;
21+
}
22+
23+
CodeEditor* codeEditor = qobject_cast<CodeEditor*>(editor);
24+
if (!codeEditor) {
25+
qWarning() << "[ERROR] Invalid CodeEditor instance.";
26+
return;
27+
}
28+
29+
QString filePath = codeEditor->filePath();
30+
if (filePath.isEmpty()) {
31+
qWarning() << "[ERROR] No file path associated with the editor.";
32+
return;
33+
}
34+
35+
QFile file(filePath);
36+
if (!file.open(QIODevice::ReadOnly)) {
37+
qWarning() << "[ERROR] Cannot open file:" << filePath;
38+
return;
39+
}
40+
41+
QByteArray rawData = file.readAll();
42+
file.close();
43+
44+
QString decodedText = decodeBig5(rawData);
45+
editor->setPlainText(decodedText);
46+
qDebug() << "[DEBUG] Big5 Decoding applied for file:" << filePath;
47+
}
48+
49+
// Decode Big5 encoded data
50+
QString Interpret_As_Big5::decodeBig5(const QByteArray& rawData) {
51+
QStringDecoder decoder("Big5");
52+
53+
if (!decoder.isValid()) {
54+
qWarning() << "[ERROR] Big5 decoder is invalid.";
55+
return QString();
56+
}
57+
58+
return decoder.decode(rawData);
59+
}

src/decoding/interpret_as_big5.h

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#pragma once
2+
3+
#include <QPlainTextEdit>
4+
#include <QString>
5+
#include <QByteArray>
6+
7+
class Interpret_As_Big5 {
8+
public:
9+
// Singleton instance access
10+
static Interpret_As_Big5& instance();
11+
12+
// Execute decoding for the provided editor
13+
void execute(QPlainTextEdit* editor);
14+
15+
private:
16+
// Private constructor for Singleton pattern
17+
Interpret_As_Big5();
18+
~Interpret_As_Big5() = default;
19+
20+
// Disable copy construction and assignment
21+
Interpret_As_Big5(const Interpret_As_Big5&) = delete;
22+
Interpret_As_Big5& operator=(const Interpret_As_Big5&) = delete;
23+
24+
// Decoding method for Big5 data
25+
QString decodeBig5(const QByteArray& rawData);
26+
};

0 commit comments

Comments
 (0)