-
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
a42ad7d
commit a6fa74a
Showing
9 changed files
with
227 additions
and
5 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,84 @@ | ||
#include "interpret_as_iso_8859_13.h" | ||
#include <QFile> | ||
#include <QDebug> | ||
#include <QPlainTextEdit> | ||
#include "../codeeditor.h" | ||
|
||
// Singleton instance | ||
Interpret_As_ISO_8859_13& Interpret_As_ISO_8859_13::instance() { | ||
static Interpret_As_ISO_8859_13 instance; | ||
return instance; | ||
} | ||
|
||
// ISO-8859-13 to Unicode mapping table (partial, extend as needed) | ||
const QMap<uint8_t, QChar> iso885913ToUnicode = { | ||
{ 0xA1, QChar(0x0104) }, // Ą | ||
{ 0xA2, QChar(0x012E) }, // Į | ||
{ 0xA3, QChar(0x0100) }, // Ā | ||
{ 0xA5, QChar(0x0106) }, // Ć | ||
{ 0xA6, QChar(0x0118) }, // Ę | ||
{ 0xA8, QChar(0x0112) }, // Ē | ||
{ 0xAA, QChar(0x0116) }, // Ė | ||
{ 0xAF, QChar(0x0122) }, // Ģ | ||
{ 0xB3, QChar(0x0101) }, // ā | ||
{ 0xB4, QChar(0x0107) }, // ć | ||
{ 0xB6, QChar(0x0119) }, // ę | ||
{ 0xB8, QChar(0x0113) }, // ē | ||
{ 0xBB, QChar(0x0117) }, // ė | ||
{ 0xBF, QChar(0x0123) }, // ģ | ||
{ 0xC5, QChar(0x0160) }, // Š | ||
{ 0xC6, QChar(0x012A) }, // Ī | ||
{ 0xC9, QChar(0x014C) }, // Ō | ||
{ 0xD3, QChar(0x0161) }, // š | ||
{ 0xD6, QChar(0x012B) }, // ī | ||
{ 0xD9, QChar(0x014D) }, // ō | ||
}; | ||
|
||
// Decode ISO-8859-13 manually | ||
QString Interpret_As_ISO_8859_13::decodeISO885913(const QByteArray& iso885913Data) { | ||
QString result; | ||
|
||
for (char byte : iso885913Data) { | ||
uint8_t isoChar = static_cast<uint8_t>(byte); | ||
if (isoChar < 0x80) { | ||
result.append(QChar(isoChar)); // ASCII characters (Direct mapping) | ||
} else { | ||
// Map ISO-8859-13 specific characters, fallback to original byte | ||
result.append(iso885913ToUnicode.value(isoChar, QChar(isoChar))); | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
|
||
// Execute Interpretation | ||
void Interpret_As_ISO_8859_13::execute(QPlainTextEdit* editor) { | ||
if (!editor) { | ||
qWarning() << "[ERROR] No editor instance."; | ||
return; | ||
} | ||
|
||
CodeEditor* codeEditor = qobject_cast<CodeEditor*>(editor); | ||
if (!codeEditor) { | ||
qWarning() << "[ERROR] Editor is not a CodeEditor."; | ||
return; | ||
} | ||
|
||
QString filePath = codeEditor->filePath(); | ||
QFile file(filePath); | ||
if (!file.open(QIODevice::ReadOnly)) { | ||
qWarning() << "[ERROR] Cannot open file: " << filePath; | ||
return; | ||
} | ||
|
||
QByteArray iso885913Data = file.readAll(); | ||
file.close(); | ||
|
||
// Debugging: Print Raw Bytes | ||
qDebug() << "[DEBUG] Raw Bytes (Hex):" << iso885913Data.toHex(); | ||
|
||
QString decodedText = decodeISO885913(iso885913Data); | ||
editor->setPlainText(decodedText); | ||
|
||
qDebug() << "[DEBUG] ISO-8859-13 Decoding applied for file:" << filePath; | ||
} |
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,18 @@ | ||
#pragma once | ||
|
||
#include <QString> | ||
#include <QPlainTextEdit> | ||
|
||
class Interpret_As_ISO_8859_13 { | ||
public: | ||
static Interpret_As_ISO_8859_13& instance(); | ||
void execute(QPlainTextEdit* editor); | ||
|
||
private: | ||
Interpret_As_ISO_8859_13() = default; | ||
~Interpret_As_ISO_8859_13() = default; | ||
Interpret_As_ISO_8859_13(const Interpret_As_ISO_8859_13&) = delete; | ||
Interpret_As_ISO_8859_13& operator=(const Interpret_As_ISO_8859_13&) = delete; | ||
|
||
QString decodeISO885913(const QByteArray& iso885913Data); | ||
}; |
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,83 @@ | ||
#include "interpret_as_iso_8859_14.h" | ||
#include <QFile> | ||
#include <QDebug> | ||
#include <QPlainTextEdit> | ||
#include "../codeeditor.h" | ||
|
||
// Singleton instance | ||
Interpret_As_ISO_8859_14& Interpret_As_ISO_8859_14::instance() { | ||
static Interpret_As_ISO_8859_14 instance; | ||
return instance; | ||
} | ||
|
||
// ISO-8859-14 to Unicode mapping table (partial, extend as needed) | ||
const QMap<uint8_t, QChar> iso885914ToUnicode = { | ||
{ 0xA1, QChar(0x1E02) }, // Ḃ | ||
{ 0xA2, QChar(0x1E03) }, // ḃ | ||
{ 0xA3, QChar(0x010A) }, // Ċ | ||
{ 0xA4, QChar(0x010B) }, // ċ | ||
{ 0xA5, QChar(0x1E0A) }, // Ḋ | ||
{ 0xA6, QChar(0x1E09) }, // ḋ | ||
{ 0xA7, QChar(0x1E1E) }, // Ḟ | ||
{ 0xA8, QChar(0x1E1F) }, // ḟ | ||
{ 0xA9, QChar(0x0120) }, // Ġ | ||
{ 0xAA, QChar(0x0121) }, // ġ | ||
{ 0xAB, QChar(0x1E40) }, // Ṁ | ||
{ 0xAC, QChar(0x1E41) }, // ṁ | ||
{ 0xAD, QChar(0x1E56) }, // Ṗ | ||
{ 0xAE, QChar(0x1E57) }, // ṗ | ||
{ 0xAF, QChar(0x1E60) }, // Ṡ | ||
{ 0xB0, QChar(0x1E61) }, // ṡ | ||
{ 0xB1, QChar(0x1E6A) }, // Ṫ | ||
{ 0xB2, QChar(0x1E6B) }, // ṫ | ||
{ 0xBB, QChar(0x00BB) }, // » | ||
}; | ||
|
||
// Decode ISO-8859-14 manually | ||
QString Interpret_As_ISO_8859_14::decodeISO885914(const QByteArray& iso885914Data) { | ||
QString result; | ||
|
||
for (char byte : iso885914Data) { | ||
uint8_t isoChar = static_cast<uint8_t>(byte); | ||
if (isoChar < 0x80) { | ||
result.append(QChar(isoChar)); // ASCII characters (Direct mapping) | ||
} else { | ||
// Map ISO-8859-14 specific characters, fallback to original byte | ||
result.append(iso885914ToUnicode.value(isoChar, QChar(isoChar))); | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
|
||
// Execute Interpretation | ||
void Interpret_As_ISO_8859_14::execute(QPlainTextEdit* editor) { | ||
if (!editor) { | ||
qWarning() << "[ERROR] No editor instance."; | ||
return; | ||
} | ||
|
||
CodeEditor* codeEditor = qobject_cast<CodeEditor*>(editor); | ||
if (!codeEditor) { | ||
qWarning() << "[ERROR] Editor is not a CodeEditor."; | ||
return; | ||
} | ||
|
||
QString filePath = codeEditor->filePath(); | ||
QFile file(filePath); | ||
if (!file.open(QIODevice::ReadOnly)) { | ||
qWarning() << "[ERROR] Cannot open file: " << filePath; | ||
return; | ||
} | ||
|
||
QByteArray iso885914Data = file.readAll(); | ||
file.close(); | ||
|
||
// Debugging: Print Raw Bytes | ||
qDebug() << "[DEBUG] Raw Bytes (Hex):" << iso885914Data.toHex(); | ||
|
||
QString decodedText = decodeISO885914(iso885914Data); | ||
editor->setPlainText(decodedText); | ||
|
||
qDebug() << "[DEBUG] ISO-8859-14 Decoding applied for file:" << filePath; | ||
} |
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,18 @@ | ||
#pragma once | ||
|
||
#include <QString> | ||
#include <QPlainTextEdit> | ||
|
||
class Interpret_As_ISO_8859_14 { | ||
public: | ||
static Interpret_As_ISO_8859_14& instance(); | ||
void execute(QPlainTextEdit* editor); | ||
|
||
private: | ||
Interpret_As_ISO_8859_14() = default; | ||
~Interpret_As_ISO_8859_14() = default; | ||
Interpret_As_ISO_8859_14(const Interpret_As_ISO_8859_14&) = delete; | ||
Interpret_As_ISO_8859_14& operator=(const Interpret_As_ISO_8859_14&) = delete; | ||
|
||
QString decodeISO885914(const QByteArray& iso885914Data); | ||
}; |
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