diff --git a/CHANGELOG.md b/CHANGELOG.md index 0764020..c874f34 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ ============ +## 0.0.95 + +- Implemented: +- Encoding Menu -> Interpret as ... IBM-01144, IBM-01143, IBM-01142, IBM-01141, IBM-01140 + ## 0.0.94 - Implemented: diff --git a/CMakeLists.txt b/CMakeLists.txt index 61511bb..76044cd 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -271,6 +271,16 @@ set(PROJECT_SOURCES src/encoding/interpret_as_ibm_01146.h src/encoding/interpret_as_ibm_01145.cpp src/encoding/interpret_as_ibm_01145.h + src/encoding/interpret_as_ibm_01144.cpp + src/encoding/interpret_as_ibm_01144.h + src/encoding/interpret_as_ibm_01143.cpp + src/encoding/interpret_as_ibm_01143.h + src/encoding/interpret_as_ibm_01142.cpp + src/encoding/interpret_as_ibm_01142.h + src/encoding/interpret_as_ibm_01141.cpp + src/encoding/interpret_as_ibm_01141.h + src/encoding/interpret_as_ibm_01140.cpp + src/encoding/interpret_as_ibm_01140.h ${PROJECT_UI} ) diff --git a/CMakeLists.txt.user b/CMakeLists.txt.user index 4913999..a9e50d9 100644 --- a/CMakeLists.txt.user +++ b/CMakeLists.txt.user @@ -1,6 +1,6 @@ - + EnvironmentId @@ -103,14 +103,14 @@ 2 false - -DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} --DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake --DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} + -DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} --DCMAKE_GENERATOR:STRING=Ninja --DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} --DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} +-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} +-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} +-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake +-DCMAKE_GENERATOR:STRING=Ninja /data/Code/Qt/Notepad-- 0 /data/Code/Qt/Notepad--/build/Desktop_Qt_6_8_1-Debug diff --git a/src/encoding/interpret_as_dialog.cpp b/src/encoding/interpret_as_dialog.cpp index d5bfa60..ece2e82 100644 --- a/src/encoding/interpret_as_dialog.cpp +++ b/src/encoding/interpret_as_dialog.cpp @@ -80,7 +80,12 @@ InterpreteAsDialog::InterpreteAsDialog(QWidget* parent) "IBM-01148", "IBM-01147", "IBM-01146", - "IBM-01145" + "IBM-01145", + "IBM-01144", + "IBM-01143", + "IBM-01142", + "IBM-01141", + "IBM-01140" }); // Create OK and Cancel buttons using QDialogButtonBox diff --git a/src/encoding/interpret_as_ibm_01140.cpp b/src/encoding/interpret_as_ibm_01140.cpp new file mode 100644 index 0000000..3f589b2 --- /dev/null +++ b/src/encoding/interpret_as_ibm_01140.cpp @@ -0,0 +1,99 @@ +#include "../codeeditor.h" +#include "interpret_as_ibm_01140.h" +#include +#include + +// Singleton instance +Interpret_As_IBM_01140& Interpret_As_IBM_01140::instance() { + static Interpret_As_IBM_01140 instance; + return instance; +} + +// EBCDIC to Unicode mapping for IBM-01140 (Latin-1 with Euro support) +const std::unordered_map Interpret_As_IBM_01140::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(0x00FC)}, // ü + {0xA4, QChar(0x20AC)}, // € + {0xA6, QChar(0x00E0)}, // à + {0xA8, QChar(0x00E8)}, // è + {0xB2, QChar(0x00E9)}, // é +}; + +// Constructor +Interpret_As_IBM_01140::Interpret_As_IBM_01140() {} + +// Main execution function +void Interpret_As_IBM_01140::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeIBM01140(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] IBM-01140 Decoding applied for file:" << filePath; +} + +// Decode raw data from IBM-01140 encoding +QString Interpret_As_IBM_01140::decodeIBM01140(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; +} diff --git a/src/encoding/interpret_as_ibm_01140.h b/src/encoding/interpret_as_ibm_01140.h new file mode 100644 index 0000000..fff6fce --- /dev/null +++ b/src/encoding/interpret_as_ibm_01140.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_IBM_01140 { +public: + static Interpret_As_IBM_01140& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_IBM_01140(); + ~Interpret_As_IBM_01140() = default; + + Interpret_As_IBM_01140(const Interpret_As_IBM_01140&) = delete; + Interpret_As_IBM_01140& operator=(const Interpret_As_IBM_01140&) = delete; + + QString decodeIBM01140(const QByteArray& rawData); + static const std::unordered_map ebcdicTable; +}; diff --git a/src/encoding/interpret_as_ibm_01141.cpp b/src/encoding/interpret_as_ibm_01141.cpp new file mode 100644 index 0000000..987dccb --- /dev/null +++ b/src/encoding/interpret_as_ibm_01141.cpp @@ -0,0 +1,99 @@ +#include "../codeeditor.h" +#include "interpret_as_ibm_01141.h" +#include +#include + +// Singleton instance +Interpret_As_IBM_01141& Interpret_As_IBM_01141::instance() { + static Interpret_As_IBM_01141 instance; + return instance; +} + +// EBCDIC to Unicode mapping for IBM-01141 (Latin-2 with Euro support for Austria/Germany) +const std::unordered_map Interpret_As_IBM_01141::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(0x010D)}, // č + {0x81, QChar(0x0061)}, // a + {0x85, QChar(0x0065)}, // e + {0x8C, QChar(0x00F6)}, // ö + {0x90, QChar(0x00FC)}, // ü + {0xA4, QChar(0x20AC)}, // € + {0xA6, QChar(0x011B)}, // ě + {0xA8, QChar(0x0161)}, // š + {0xB2, QChar(0x0159)}, // ř +}; + +// Constructor +Interpret_As_IBM_01141::Interpret_As_IBM_01141() {} + +// Main execution function +void Interpret_As_IBM_01141::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeIBM01141(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] IBM-01141 Decoding applied for file:" << filePath; +} + +// Decode raw data from IBM-01141 encoding +QString Interpret_As_IBM_01141::decodeIBM01141(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; +} diff --git a/src/encoding/interpret_as_ibm_01141.h b/src/encoding/interpret_as_ibm_01141.h new file mode 100644 index 0000000..615104e --- /dev/null +++ b/src/encoding/interpret_as_ibm_01141.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_IBM_01141 { +public: + static Interpret_As_IBM_01141& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_IBM_01141(); + ~Interpret_As_IBM_01141() = default; + + Interpret_As_IBM_01141(const Interpret_As_IBM_01141&) = delete; + Interpret_As_IBM_01141& operator=(const Interpret_As_IBM_01141&) = delete; + + QString decodeIBM01141(const QByteArray& rawData); + static const std::unordered_map ebcdicTable; +}; diff --git a/src/encoding/interpret_as_ibm_01142.cpp b/src/encoding/interpret_as_ibm_01142.cpp new file mode 100644 index 0000000..0fd85c7 --- /dev/null +++ b/src/encoding/interpret_as_ibm_01142.cpp @@ -0,0 +1,99 @@ +#include "../codeeditor.h" +#include "interpret_as_ibm_01142.h" +#include +#include + +// Singleton instance +Interpret_As_IBM_01142& Interpret_As_IBM_01142::instance() { + static Interpret_As_IBM_01142 instance; + return instance; +} + +// EBCDIC to Unicode mapping for IBM-01142 (Latin-2 with Euro support for Austria/Germany) +const std::unordered_map Interpret_As_IBM_01142::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(0x010D)}, // č + {0x81, QChar(0x0061)}, // a + {0x85, QChar(0x0065)}, // e + {0x8C, QChar(0x00F6)}, // ö + {0x90, QChar(0x00FC)}, // ü + {0xA4, QChar(0x20AC)}, // € + {0xA6, QChar(0x011B)}, // ě + {0xA8, QChar(0x0161)}, // š + {0xB2, QChar(0x0159)}, // ř +}; + +// Constructor +Interpret_As_IBM_01142::Interpret_As_IBM_01142() {} + +// Main execution function +void Interpret_As_IBM_01142::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeIBM01142(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] IBM-01142 Decoding applied for file:" << filePath; +} + +// Decode raw data from IBM-01142 encoding +QString Interpret_As_IBM_01142::decodeIBM01142(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; +} diff --git a/src/encoding/interpret_as_ibm_01142.h b/src/encoding/interpret_as_ibm_01142.h new file mode 100644 index 0000000..c471c2d --- /dev/null +++ b/src/encoding/interpret_as_ibm_01142.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_IBM_01142 { +public: + static Interpret_As_IBM_01142& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_IBM_01142(); + ~Interpret_As_IBM_01142() = default; + + Interpret_As_IBM_01142(const Interpret_As_IBM_01142&) = delete; + Interpret_As_IBM_01142& operator=(const Interpret_As_IBM_01142&) = delete; + + QString decodeIBM01142(const QByteArray& rawData); + static const std::unordered_map ebcdicTable; +}; diff --git a/src/encoding/interpret_as_ibm_01143.cpp b/src/encoding/interpret_as_ibm_01143.cpp new file mode 100644 index 0000000..584e2d0 --- /dev/null +++ b/src/encoding/interpret_as_ibm_01143.cpp @@ -0,0 +1,99 @@ +#include "../codeeditor.h" +#include "interpret_as_ibm_01143.h" +#include +#include + +// Singleton instance +Interpret_As_IBM_01143& Interpret_As_IBM_01143::instance() { + static Interpret_As_IBM_01143 instance; + return instance; +} + +// EBCDIC to Unicode mapping for IBM-01143 (Latin-2 with Euro support for Austria/Germany) +const std::unordered_map Interpret_As_IBM_01143::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(0x010D)}, // č + {0x81, QChar(0x0061)}, // a + {0x85, QChar(0x0065)}, // e + {0x8C, QChar(0x00F6)}, // ö + {0x90, QChar(0x00FC)}, // ü + {0xA4, QChar(0x20AC)}, // € + {0xA6, QChar(0x011B)}, // ě + {0xA8, QChar(0x0161)}, // š + {0xB2, QChar(0x0159)}, // ř +}; + +// Constructor +Interpret_As_IBM_01143::Interpret_As_IBM_01143() {} + +// Main execution function +void Interpret_As_IBM_01143::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeIBM01143(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] IBM-01143 Decoding applied for file:" << filePath; +} + +// Decode raw data from IBM-01143 encoding +QString Interpret_As_IBM_01143::decodeIBM01143(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; +} diff --git a/src/encoding/interpret_as_ibm_01143.h b/src/encoding/interpret_as_ibm_01143.h new file mode 100644 index 0000000..409909b --- /dev/null +++ b/src/encoding/interpret_as_ibm_01143.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_IBM_01143 { +public: + static Interpret_As_IBM_01143& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_IBM_01143(); + ~Interpret_As_IBM_01143() = default; + + Interpret_As_IBM_01143(const Interpret_As_IBM_01143&) = delete; + Interpret_As_IBM_01143& operator=(const Interpret_As_IBM_01143&) = delete; + + QString decodeIBM01143(const QByteArray& rawData); + static const std::unordered_map ebcdicTable; +}; diff --git a/src/encoding/interpret_as_ibm_01144.cpp b/src/encoding/interpret_as_ibm_01144.cpp new file mode 100644 index 0000000..6a7ee77 --- /dev/null +++ b/src/encoding/interpret_as_ibm_01144.cpp @@ -0,0 +1,99 @@ +#include "../codeeditor.h" +#include "interpret_as_ibm_01144.h" +#include +#include + +// Singleton instance +Interpret_As_IBM_01144& Interpret_As_IBM_01144::instance() { + static Interpret_As_IBM_01144 instance; + return instance; +} + +// EBCDIC to Unicode mapping for IBM-01144 (Latin-2 with Euro support for Austria/Germany) +const std::unordered_map Interpret_As_IBM_01144::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(0x010D)}, // č + {0x81, QChar(0x0061)}, // a + {0x85, QChar(0x0065)}, // e + {0x8C, QChar(0x00F6)}, // ö + {0x90, QChar(0x00FC)}, // ü + {0xA4, QChar(0x20AC)}, // € + {0xA6, QChar(0x011B)}, // ě + {0xA8, QChar(0x0161)}, // š + {0xB2, QChar(0x0159)}, // ř +}; + +// Constructor +Interpret_As_IBM_01144::Interpret_As_IBM_01144() {} + +// Main execution function +void Interpret_As_IBM_01144::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeIBM01144(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] IBM-01144 Decoding applied for file:" << filePath; +} + +// Decode raw data from IBM-01144 encoding +QString Interpret_As_IBM_01144::decodeIBM01144(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; +} diff --git a/src/encoding/interpret_as_ibm_01144.h b/src/encoding/interpret_as_ibm_01144.h new file mode 100644 index 0000000..db15a2e --- /dev/null +++ b/src/encoding/interpret_as_ibm_01144.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_IBM_01144 { +public: + static Interpret_As_IBM_01144& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_IBM_01144(); + ~Interpret_As_IBM_01144() = default; + + Interpret_As_IBM_01144(const Interpret_As_IBM_01144&) = delete; + Interpret_As_IBM_01144& operator=(const Interpret_As_IBM_01144&) = delete; + + QString decodeIBM01144(const QByteArray& rawData); + static const std::unordered_map ebcdicTable; +}; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index c61221b..e302af1 100755 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -98,6 +98,11 @@ #include "encoding/interpret_as_ibm_01147.h" #include "encoding/interpret_as_ibm_01146.h" #include "encoding/interpret_as_ibm_01145.h" +#include "encoding/interpret_as_ibm_01144.h" +#include "encoding/interpret_as_ibm_01143.h" +#include "encoding/interpret_as_ibm_01142.h" +#include "encoding/interpret_as_ibm_01141.h" +#include "encoding/interpret_as_ibm_01140.h" MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), @@ -1080,6 +1085,21 @@ void MainWindow::on_actionInterpret_As_triggered() if (selectedItem == "IBM-01145") { Interpret_As_IBM_01145::instance().execute(editor); } + if (selectedItem == "IBM-01144") { + Interpret_As_IBM_01144::instance().execute(editor); + } + if (selectedItem == "IBM-01143") { + Interpret_As_IBM_01143::instance().execute(editor); + } + if (selectedItem == "IBM-01142") { + Interpret_As_IBM_01142::instance().execute(editor); + } + if (selectedItem == "IBM-01141") { + Interpret_As_IBM_01141::instance().execute(editor); + } + if (selectedItem == "IBM-01140") { + Interpret_As_IBM_01140::instance().execute(editor); + } } }