-
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
c16d276
commit 33a0c60
Showing
19 changed files
with
912 additions
and
6 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,97 @@ | ||
#include "../codeeditor.h" | ||
#include "interpret_as_ibm_277.h" | ||
#include <QFile> | ||
#include <QDebug> | ||
|
||
// Singleton instance | ||
Interpret_As_IBM_277& Interpret_As_IBM_277::instance() { | ||
static Interpret_As_IBM_277 instance; | ||
return instance; | ||
} | ||
|
||
// EBCDIC to Unicode mapping for IBM-277 (Danish/Norwegian EBCDIC) | ||
const std::unordered_map<unsigned char, QChar> Interpret_As_IBM_277::ebcdicTable = { | ||
{0x41, QChar(0x0041)}, // A | ||
{0x42, QChar(0x0042)}, // B | ||
{0x43, QChar(0x0043)}, // C | ||
{0x44, QChar(0x0044)}, // D | ||
{0x45, QChar(0x0045)}, // E | ||
{0x46, QChar(0x0046)}, // F | ||
{0x47, QChar(0x0047)}, // G | ||
{0x48, QChar(0x0048)}, // H | ||
{0x49, QChar(0x0049)}, // I | ||
{0x4A, QChar(0x004A)}, // J | ||
{0x4B, QChar(0x004B)}, // K | ||
{0x4C, QChar(0x004C)}, // L | ||
{0x4D, QChar(0x004D)}, // M | ||
{0x4E, QChar(0x004E)}, // N | ||
{0x4F, QChar(0x004F)}, // O | ||
{0x50, QChar(0x0050)}, // P | ||
{0x51, QChar(0x0051)}, // Q | ||
{0x52, QChar(0x0052)}, // R | ||
{0x53, QChar(0x0053)}, // S | ||
{0x54, QChar(0x0054)}, // T | ||
{0x55, QChar(0x0055)}, // U | ||
{0x56, QChar(0x0056)}, // V | ||
{0x57, QChar(0x0057)}, // W | ||
{0x58, QChar(0x0058)}, // X | ||
{0x59, QChar(0x0059)}, // Y | ||
{0x5A, QChar(0x005A)}, // Z | ||
{0x7B, QChar(0x00E6)}, // æ | ||
{0x81, QChar(0x0061)}, // a | ||
{0x85, QChar(0x0065)}, // e | ||
{0x8C, QChar(0x00F8)}, // ø | ||
{0x90, QChar(0x00E5)}, // å | ||
{0xA4, QChar(0x00E9)}, // é | ||
{0xA7, QChar(0x00FC)}, // ü | ||
}; | ||
|
||
// Constructor | ||
Interpret_As_IBM_277::Interpret_As_IBM_277() {} | ||
|
||
// Main execution function | ||
void Interpret_As_IBM_277::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 = decodeIBM277(rawData); | ||
editor->setPlainText(decodedText); | ||
qDebug() << "[DEBUG] IBM-277 Decoding applied for file:" << filePath; | ||
} | ||
|
||
// Decode raw data from IBM-277 encoding | ||
QString Interpret_As_IBM_277::decodeIBM277(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_277 { | ||
public: | ||
static Interpret_As_IBM_277& instance(); | ||
void execute(QPlainTextEdit* editor); | ||
|
||
private: | ||
Interpret_As_IBM_277(); | ||
~Interpret_As_IBM_277() = default; | ||
|
||
Interpret_As_IBM_277(const Interpret_As_IBM_277&) = delete; | ||
Interpret_As_IBM_277& operator=(const Interpret_As_IBM_277&) = delete; | ||
|
||
QString decodeIBM277(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,97 @@ | ||
#include "../codeeditor.h" | ||
#include "interpret_as_ibm_278.h" | ||
#include <QFile> | ||
#include <QDebug> | ||
|
||
// Singleton instance | ||
Interpret_As_IBM_278& Interpret_As_IBM_278::instance() { | ||
static Interpret_As_IBM_278 instance; | ||
return instance; | ||
} | ||
|
||
// EBCDIC to Unicode mapping for IBM-278 (Nordic EBCDIC) | ||
const std::unordered_map<unsigned char, QChar> Interpret_As_IBM_278::ebcdicTable = { | ||
{0x41, QChar(0x0041)}, // A | ||
{0x42, QChar(0x0042)}, // B | ||
{0x43, QChar(0x0043)}, // C | ||
{0x44, QChar(0x0044)}, // D | ||
{0x45, QChar(0x0045)}, // E | ||
{0x46, QChar(0x0046)}, // F | ||
{0x47, QChar(0x0047)}, // G | ||
{0x48, QChar(0x0048)}, // H | ||
{0x49, QChar(0x0049)}, // I | ||
{0x4A, QChar(0x004A)}, // J | ||
{0x4B, QChar(0x004B)}, // K | ||
{0x4C, QChar(0x004C)}, // L | ||
{0x4D, QChar(0x004D)}, // M | ||
{0x4E, QChar(0x004E)}, // N | ||
{0x4F, QChar(0x004F)}, // O | ||
{0x50, QChar(0x0050)}, // P | ||
{0x51, QChar(0x0051)}, // Q | ||
{0x52, QChar(0x0052)}, // R | ||
{0x53, QChar(0x0053)}, // S | ||
{0x54, QChar(0x0054)}, // T | ||
{0x55, QChar(0x0055)}, // U | ||
{0x56, QChar(0x0056)}, // V | ||
{0x57, QChar(0x0057)}, // W | ||
{0x58, QChar(0x0058)}, // X | ||
{0x59, QChar(0x0059)}, // Y | ||
{0x5A, QChar(0x005A)}, // Z | ||
{0x7B, QChar(0x00E4)}, // ä | ||
{0x81, QChar(0x0061)}, // a | ||
{0x85, QChar(0x0065)}, // e | ||
{0x8C, QChar(0x00F6)}, // ö | ||
{0x90, QChar(0x00E5)}, // å | ||
{0xA4, QChar(0x00E9)}, // é | ||
{0xA7, QChar(0x00FC)}, // ü | ||
}; | ||
|
||
// Constructor | ||
Interpret_As_IBM_278::Interpret_As_IBM_278() {} | ||
|
||
// Main execution function | ||
void Interpret_As_IBM_278::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 = decodeIBM278(rawData); | ||
editor->setPlainText(decodedText); | ||
qDebug() << "[DEBUG] IBM-278 Decoding applied for file:" << filePath; | ||
} | ||
|
||
// Decode raw data from IBM-278 encoding | ||
QString Interpret_As_IBM_278::decodeIBM278(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_278 { | ||
public: | ||
static Interpret_As_IBM_278& instance(); | ||
void execute(QPlainTextEdit* editor); | ||
|
||
private: | ||
Interpret_As_IBM_278(); | ||
~Interpret_As_IBM_278() = default; | ||
|
||
Interpret_As_IBM_278(const Interpret_As_IBM_278&) = delete; | ||
Interpret_As_IBM_278& operator=(const Interpret_As_IBM_278&) = delete; | ||
|
||
QString decodeIBM278(const QByteArray& rawData); | ||
static const std::unordered_map<unsigned char, QChar> ebcdicTable; | ||
}; |
Oops, something went wrong.