-
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
e66501d
commit 4b0bbe7
Showing
13 changed files
with
535 additions
and
8 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,104 @@ | ||
#include "../codeeditor.h" | ||
#include "interpret_as_ibm_850.h" | ||
#include <QFile> | ||
#include <QDebug> | ||
|
||
// Singleton instance | ||
Interpret_As_IBM_850& Interpret_As_IBM_850::instance() { | ||
static Interpret_As_IBM_850 instance; | ||
return instance; | ||
} | ||
|
||
// EBCDIC to Unicode mapping for IBM-850 (Latin-1) | ||
const std::unordered_map<unsigned char, QChar> Interpret_As_IBM_850::ebcdicTable = { | ||
{0x80, QChar(0x00C7)}, // Ç | ||
{0x81, QChar(0x00FC)}, // ü | ||
{0x82, QChar(0x00E9)}, // é | ||
{0x83, QChar(0x00E2)}, // â | ||
{0x84, QChar(0x00E4)}, // ä | ||
{0x85, QChar(0x00E0)}, // à | ||
{0x86, QChar(0x00E5)}, // å | ||
{0x87, QChar(0x00E7)}, // ç | ||
{0x88, QChar(0x00EA)}, // ê | ||
{0x89, QChar(0x00EB)}, // ë | ||
{0x8A, QChar(0x00E8)}, // è | ||
{0x8B, QChar(0x00EF)}, // ï | ||
{0x8C, QChar(0x00EE)}, // î | ||
{0x8D, QChar(0x00EC)}, // ì | ||
{0x8E, QChar(0x00C4)}, // Ä | ||
{0x8F, QChar(0x00C5)}, // Å | ||
{0x90, QChar(0x00C9)}, // É | ||
{0x91, QChar(0x00E6)}, // æ | ||
{0x92, QChar(0x00C6)}, // Æ | ||
{0x93, QChar(0x00F4)}, // ô | ||
{0x94, QChar(0x00F6)}, // ö | ||
{0x95, QChar(0x00F2)}, // ò | ||
{0x96, QChar(0x00FB)}, // û | ||
{0x97, QChar(0x00F9)}, // ù | ||
{0x98, QChar(0x00FF)}, // ÿ | ||
{0x99, QChar(0x00D6)}, // Ö | ||
{0x9A, QChar(0x00DC)}, // Ü | ||
{0x9B, QChar(0x00A2)}, // ¢ | ||
{0x9C, QChar(0x00A3)}, // £ | ||
{0x9D, QChar(0x00A5)}, // ¥ | ||
{0x9E, QChar(0x20A7)}, // ₧ | ||
{0x9F, QChar(0x0192)}, // ƒ | ||
{0xA0, QChar(0x00E1)}, // á | ||
{0xA1, QChar(0x00ED)}, // í | ||
{0xA2, QChar(0x00F3)}, // ó | ||
{0xA3, QChar(0x00FA)}, // ú | ||
{0xA4, QChar(0x00F1)}, // ñ | ||
{0xA5, QChar(0x00D1)}, // Ñ | ||
{0xA6, QChar(0x00AA)}, // ª | ||
{0xA7, QChar(0x00BA)}, // º | ||
}; | ||
|
||
// Constructor | ||
Interpret_As_IBM_850::Interpret_As_IBM_850() {} | ||
|
||
// Main execution function | ||
void Interpret_As_IBM_850::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 = decodeIBM850(rawData); | ||
editor->setPlainText(decodedText); | ||
qDebug() << "[DEBUG] IBM-850 Decoding applied for file:" << filePath; | ||
} | ||
|
||
// Decode raw data from IBM-850 encoding | ||
QString Interpret_As_IBM_850::decodeIBM850(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_850 { | ||
public: | ||
static Interpret_As_IBM_850& instance(); | ||
void execute(QPlainTextEdit* editor); | ||
|
||
private: | ||
Interpret_As_IBM_850(); | ||
~Interpret_As_IBM_850() = default; | ||
|
||
Interpret_As_IBM_850(const Interpret_As_IBM_850&) = delete; | ||
Interpret_As_IBM_850& operator=(const Interpret_As_IBM_850&) = delete; | ||
|
||
QString decodeIBM850(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,104 @@ | ||
#include "../codeeditor.h" | ||
#include "interpret_as_ibm_852.h" | ||
#include <QFile> | ||
#include <QDebug> | ||
|
||
// Singleton instance | ||
Interpret_As_IBM_852& Interpret_As_IBM_852::instance() { | ||
static Interpret_As_IBM_852 instance; | ||
return instance; | ||
} | ||
|
||
// EBCDIC to Unicode mapping for IBM-852 (Central European) | ||
const std::unordered_map<unsigned char, QChar> Interpret_As_IBM_852::ebcdicTable = { | ||
{0x80, QChar(0x0104)}, // Ą | ||
{0x81, QChar(0x00FC)}, // ü | ||
{0x82, QChar(0x00E9)}, // é | ||
{0x83, QChar(0x0101)}, // ā | ||
{0x84, QChar(0x00E4)}, // ä | ||
{0x85, QChar(0x0123)}, // ģ | ||
{0x86, QChar(0x00E5)}, // å | ||
{0x87, QChar(0x0107)}, // ć | ||
{0x88, QChar(0x0142)}, // ł | ||
{0x89, QChar(0x0113)}, // ē | ||
{0x8A, QChar(0x010D)}, // č | ||
{0x8B, QChar(0x0119)}, // ę | ||
{0x8C, QChar(0x0117)}, // ė | ||
{0x8D, QChar(0x0106)}, // Ć | ||
{0x8E, QChar(0x00C4)}, // Ä | ||
{0x8F, QChar(0x00C5)}, // Å | ||
{0x90, QChar(0x0141)}, // Ł | ||
{0x91, QChar(0x00E6)}, // æ | ||
{0x92, QChar(0x00C6)}, // Æ | ||
{0x93, QChar(0x0112)}, // Ē | ||
{0x94, QChar(0x00F6)}, // ö | ||
{0x95, QChar(0x00F3)}, // ó | ||
{0x96, QChar(0x0144)}, // ń | ||
{0x97, QChar(0x0143)}, // Ń | ||
{0x98, QChar(0x00D6)}, // Ö | ||
{0x99, QChar(0x00DC)}, // Ü | ||
{0x9A, QChar(0x00A2)}, // ¢ | ||
{0x9B, QChar(0x015A)}, // Ś | ||
{0x9C, QChar(0x015B)}, // ś | ||
{0x9D, QChar(0x00D3)}, // Ó | ||
{0x9E, QChar(0x0179)}, // Ź | ||
{0x9F, QChar(0x017A)}, // ź | ||
{0xA0, QChar(0x00E1)}, // á | ||
{0xA1, QChar(0x00ED)}, // í | ||
{0xA2, QChar(0x00F3)}, // ó | ||
{0xA3, QChar(0x00FA)}, // ú | ||
{0xA4, QChar(0x00F1)}, // ñ | ||
{0xA5, QChar(0x00D1)}, // Ñ | ||
{0xA6, QChar(0x015E)}, // Ş | ||
{0xA7, QChar(0x015F)}, // ş | ||
}; | ||
|
||
// Constructor | ||
Interpret_As_IBM_852::Interpret_As_IBM_852() {} | ||
|
||
// Main execution function | ||
void Interpret_As_IBM_852::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 = decodeIBM852(rawData); | ||
editor->setPlainText(decodedText); | ||
qDebug() << "[DEBUG] IBM-852 Decoding applied for file:" << filePath; | ||
} | ||
|
||
// Decode raw data from IBM-852 encoding | ||
QString Interpret_As_IBM_852::decodeIBM852(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_852 { | ||
public: | ||
static Interpret_As_IBM_852& instance(); | ||
void execute(QPlainTextEdit* editor); | ||
|
||
private: | ||
Interpret_As_IBM_852(); | ||
~Interpret_As_IBM_852() = default; | ||
|
||
Interpret_As_IBM_852(const Interpret_As_IBM_852&) = delete; | ||
Interpret_As_IBM_852& operator=(const Interpret_As_IBM_852&) = delete; | ||
|
||
QString decodeIBM852(const QByteArray& rawData); | ||
static const std::unordered_map<unsigned char, QChar> ebcdicTable; | ||
}; |
Oops, something went wrong.