-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4b0bbe7
commit c16d276
Showing
15 changed files
with
651 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#include "../codeeditor.h" | ||
#include "interpret_as_ibm_420.h" | ||
#include <QFile> | ||
#include <QDebug> | ||
|
||
// Singleton instance | ||
Interpret_As_IBM_420& Interpret_As_IBM_420::instance() { | ||
static Interpret_As_IBM_420 instance; | ||
return instance; | ||
} | ||
|
||
// EBCDIC to Unicode mapping for IBM-420 (Arabic EBCDIC) | ||
const std::unordered_map<unsigned char, QChar> Interpret_As_IBM_420::ebcdicTable = { | ||
{0x80, QChar(0x0627)}, // ا (Alef) | ||
{0x81, QChar(0x0628)}, // ب (Beh) | ||
{0x82, QChar(0x062A)}, // ت (Teh) | ||
{0x83, QChar(0x062B)}, // ث (Theh) | ||
{0x84, QChar(0x062C)}, // ج (Jeem) | ||
{0x85, QChar(0x062D)}, // ح (Hah) | ||
{0x86, QChar(0x062E)}, // خ (Khah) | ||
{0x87, QChar(0x062F)}, // د (Dal) | ||
{0x88, QChar(0x0630)}, // ذ (Thal) | ||
{0x89, QChar(0x0631)}, // ر (Reh) | ||
{0x8A, QChar(0x0632)}, // ز (Zain) | ||
{0x8B, QChar(0x0633)}, // س (Seen) | ||
{0x8C, QChar(0x0634)}, // ش (Sheen) | ||
{0x8D, QChar(0x0635)}, // ص (Sad) | ||
{0x8E, QChar(0x0636)}, // ض (Dad) | ||
{0x8F, QChar(0x0637)}, // ط (Tah) | ||
{0x90, QChar(0x0638)}, // ظ (Zah) | ||
{0x91, QChar(0x0639)}, // ع (Ain) | ||
{0x92, QChar(0x063A)}, // غ (Ghain) | ||
{0x93, QChar(0x0641)}, // ف (Feh) | ||
{0x94, QChar(0x0642)}, // ق (Qaf) | ||
{0x95, QChar(0x0643)}, // ك (Kaf) | ||
{0x96, QChar(0x0644)}, // ل (Lam) | ||
{0x97, QChar(0x0645)}, // م (Meem) | ||
{0x98, QChar(0x0646)}, // ن (Noon) | ||
{0x99, QChar(0x0647)}, // ه (Heh) | ||
{0x9A, QChar(0x0648)}, // و (Waw) | ||
{0x9B, QChar(0x064A)}, // ي (Yeh) | ||
}; | ||
|
||
// Constructor | ||
Interpret_As_IBM_420::Interpret_As_IBM_420() {} | ||
|
||
// Main execution function | ||
void Interpret_As_IBM_420::execute(QPlainTextEdit* editor) { | ||
if (!editor) { | ||
qWarning() << "[ERROR] No editor instance provided."; | ||
return; | ||
} | ||
|
||
CodeEditor* codeEditor = qobject_cast<CodeEditor*>(editor); | ||
if (!codeEditor) { | ||
qWarning() << "[ERROR] Invalid CodeEditor instance."; | ||
return; | ||
} | ||
|
||
QString filePath = codeEditor->filePath(); | ||
if (filePath.isEmpty()) { | ||
qWarning() << "[ERROR] No file path associated with the editor."; | ||
return; | ||
} | ||
|
||
QFile file(filePath); | ||
if (!file.open(QIODevice::ReadOnly)) { | ||
qWarning() << "[ERROR] Cannot open file:" << filePath; | ||
return; | ||
} | ||
|
||
QByteArray rawData = file.readAll(); | ||
file.close(); | ||
|
||
QString decodedText = decodeIBM420(rawData); | ||
editor->setPlainText(decodedText); | ||
qDebug() << "[DEBUG] IBM-420 Decoding applied for file:" << filePath; | ||
} | ||
|
||
// Decode raw data from IBM-420 encoding | ||
QString Interpret_As_IBM_420::decodeIBM420(const QByteArray& rawData) { | ||
QString result; | ||
|
||
for (unsigned char byte : rawData) { | ||
if (ebcdicTable.contains(byte)) { | ||
result.append(ebcdicTable.at(byte)); | ||
} else { | ||
result.append(QChar(0xFFFD)); // Fallback for unmapped characters | ||
} | ||
} | ||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#pragma once | ||
|
||
#include <QPlainTextEdit> | ||
#include <QString> | ||
#include <QByteArray> | ||
#include <unordered_map> | ||
|
||
class Interpret_As_IBM_420 { | ||
public: | ||
static Interpret_As_IBM_420& instance(); | ||
void execute(QPlainTextEdit* editor); | ||
|
||
private: | ||
Interpret_As_IBM_420(); | ||
~Interpret_As_IBM_420() = default; | ||
|
||
Interpret_As_IBM_420(const Interpret_As_IBM_420&) = delete; | ||
Interpret_As_IBM_420& operator=(const Interpret_As_IBM_420&) = delete; | ||
|
||
QString decodeIBM420(const QByteArray& rawData); | ||
static const std::unordered_map<unsigned char, QChar> ebcdicTable; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
#include "../codeeditor.h" | ||
#include "interpret_as_ibm_424.h" | ||
#include <QFile> | ||
#include <QDebug> | ||
|
||
// Singleton instance | ||
Interpret_As_IBM_424& Interpret_As_IBM_424::instance() { | ||
static Interpret_As_IBM_424 instance; | ||
return instance; | ||
} | ||
|
||
// EBCDIC to Unicode mapping for IBM-424 (Hebrew EBCDIC) | ||
const std::unordered_map<unsigned char, QChar> Interpret_As_IBM_424::ebcdicTable = { | ||
{0x80, QChar(0x05D0)}, // א (Alef) | ||
{0x81, QChar(0x05D1)}, // ב (Bet) | ||
{0x82, QChar(0x05D2)}, // ג (Gimel) | ||
{0x83, QChar(0x05D3)}, // ד (Dalet) | ||
{0x84, QChar(0x05D4)}, // ה (He) | ||
{0x85, QChar(0x05D5)}, // ו (Vav) | ||
{0x86, QChar(0x05D6)}, // ז (Zayin) | ||
{0x87, QChar(0x05D7)}, // ח (Het) | ||
{0x88, QChar(0x05D8)}, // ט (Tet) | ||
{0x89, QChar(0x05D9)}, // י (Yod) | ||
{0x8A, QChar(0x05DA)}, // ך (Final Kaf) | ||
{0x8B, QChar(0x05DB)}, // כ (Kaf) | ||
{0x8C, QChar(0x05DC)}, // ל (Lamed) | ||
{0x8D, QChar(0x05DD)}, // ם (Final Mem) | ||
{0x8E, QChar(0x05DE)}, // מ (Mem) | ||
{0x8F, QChar(0x05DF)}, // ן (Final Nun) | ||
{0x90, QChar(0x05E0)}, // נ (Nun) | ||
{0x91, QChar(0x05E1)}, // ס (Samekh) | ||
{0x92, QChar(0x05E2)}, // ע (Ayin) | ||
{0x93, QChar(0x05E3)}, // ף (Final Pe) | ||
{0x94, QChar(0x05E4)}, // פ (Pe) | ||
{0x95, QChar(0x05E5)}, // ץ (Final Tsadi) | ||
{0x96, QChar(0x05E6)}, // צ (Tsadi) | ||
{0x97, QChar(0x05E7)}, // ק (Qof) | ||
{0x98, QChar(0x05E8)}, // ר (Resh) | ||
{0x99, QChar(0x05E9)}, // ש (Shin) | ||
{0x9A, QChar(0x05EA)}, // ת (Tav) | ||
}; | ||
|
||
// Constructor | ||
Interpret_As_IBM_424::Interpret_As_IBM_424() {} | ||
|
||
// Main execution function | ||
void Interpret_As_IBM_424::execute(QPlainTextEdit* editor) { | ||
if (!editor) { | ||
qWarning() << "[ERROR] No editor instance provided."; | ||
return; | ||
} | ||
|
||
CodeEditor* codeEditor = qobject_cast<CodeEditor*>(editor); | ||
if (!codeEditor) { | ||
qWarning() << "[ERROR] Invalid CodeEditor instance."; | ||
return; | ||
} | ||
|
||
QString filePath = codeEditor->filePath(); | ||
if (filePath.isEmpty()) { | ||
qWarning() << "[ERROR] No file path associated with the editor."; | ||
return; | ||
} | ||
|
||
QFile file(filePath); | ||
if (!file.open(QIODevice::ReadOnly)) { | ||
qWarning() << "[ERROR] Cannot open file:" << filePath; | ||
return; | ||
} | ||
|
||
QByteArray rawData = file.readAll(); | ||
file.close(); | ||
|
||
QString decodedText = decodeIBM424(rawData); | ||
editor->setPlainText(decodedText); | ||
qDebug() << "[DEBUG] IBM-424 Decoding applied for file:" << filePath; | ||
} | ||
|
||
// Decode raw data from IBM-424 encoding | ||
QString Interpret_As_IBM_424::decodeIBM424(const QByteArray& rawData) { | ||
QString result; | ||
|
||
for (unsigned char byte : rawData) { | ||
if (ebcdicTable.contains(byte)) { | ||
result.append(ebcdicTable.at(byte)); | ||
} else { | ||
result.append(QChar(0xFFFD)); // Fallback for unmapped characters | ||
} | ||
} | ||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#pragma once | ||
|
||
#include <QPlainTextEdit> | ||
#include <QString> | ||
#include <QByteArray> | ||
#include <unordered_map> | ||
|
||
class Interpret_As_IBM_424 { | ||
public: | ||
static Interpret_As_IBM_424& instance(); | ||
void execute(QPlainTextEdit* editor); | ||
|
||
private: | ||
Interpret_As_IBM_424(); | ||
~Interpret_As_IBM_424() = default; | ||
|
||
Interpret_As_IBM_424(const Interpret_As_IBM_424&) = delete; | ||
Interpret_As_IBM_424& operator=(const Interpret_As_IBM_424&) = delete; | ||
|
||
QString decodeIBM424(const QByteArray& rawData); | ||
static const std::unordered_map<unsigned char, QChar> ebcdicTable; | ||
}; |
Oops, something went wrong.