-
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
943c144
commit a42ad7d
Showing
9 changed files
with
188 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,53 @@ | ||
#include "interpret_as_iso_8859_1.h" | ||
#include <QFile> | ||
#include <QDebug> | ||
#include <QPlainTextEdit> | ||
#include "../codeeditor.h" | ||
|
||
// Singleton instance | ||
Interpret_As_ISO_8859_1& Interpret_As_ISO_8859_1::instance() { | ||
static Interpret_As_ISO_8859_1 instance; | ||
return instance; | ||
} | ||
|
||
// Decode ISO-8859-1 manually (1:1 mapping for 0xA0 to 0xFF) | ||
QString Interpret_As_ISO_8859_1::decodeISO88591(const QByteArray& iso88591Data) { | ||
QString result; | ||
for (char byte : iso88591Data) { | ||
uint8_t isoChar = static_cast<uint8_t>(byte); | ||
result.append(QChar(isoChar)); // Direct 1:1 mapping | ||
} | ||
return result; | ||
} | ||
|
||
// Execute Interpretation | ||
void Interpret_As_ISO_8859_1::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 iso88591Data = file.readAll(); | ||
file.close(); | ||
|
||
// Debugging: Print Raw Bytes | ||
qDebug() << "[DEBUG] Raw Bytes (Hex):" << iso88591Data.toHex(); | ||
|
||
QString decodedText = decodeISO88591(iso88591Data); | ||
editor->setPlainText(decodedText); | ||
|
||
qDebug() << "[DEBUG] 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_1 { | ||
public: | ||
static Interpret_As_ISO_8859_1& instance(); | ||
void execute(QPlainTextEdit* editor); | ||
|
||
private: | ||
Interpret_As_ISO_8859_1() = default; | ||
~Interpret_As_ISO_8859_1() = default; | ||
Interpret_As_ISO_8859_1(const Interpret_As_ISO_8859_1&) = delete; | ||
Interpret_As_ISO_8859_1& operator=(const Interpret_As_ISO_8859_1&) = delete; | ||
|
||
QString decodeISO88591(const QByteArray& iso88591Data); | ||
}; |
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,72 @@ | ||
#include "interpret_as_iso_8859_15.h" | ||
#include <QFile> | ||
#include <QDebug> | ||
#include <QPlainTextEdit> | ||
#include "../codeeditor.h" | ||
|
||
// Singleton instance | ||
Interpret_As_ISO_8859_15& Interpret_As_ISO_8859_15::instance() { | ||
static Interpret_As_ISO_8859_15 instance; | ||
return instance; | ||
} | ||
|
||
// ISO-8859-15 to Unicode mapping table for differences from ISO-8859-1 | ||
const QMap<uint8_t, QChar> iso885915ToUnicode = { | ||
{ 0xA4, QChar(0x20AC) }, // € - Euro Sign | ||
{ 0xA6, QChar(0x0160) }, // Š - Latin Capital Letter S with Caron | ||
{ 0xA8, QChar(0x0161) }, // š - Latin Small Letter S with Caron | ||
{ 0xB4, QChar(0x017D) }, // Ž - Latin Capital Letter Z with Caron | ||
{ 0xB8, QChar(0x017E) }, // ž - Latin Small Letter Z with Caron | ||
{ 0xBC, QChar(0x0152) }, // Œ - Latin Capital Ligature OE | ||
{ 0xBD, QChar(0x0153) }, // œ - Latin Small Ligature OE | ||
{ 0xBE, QChar(0x0178) }, // Ÿ - Latin Capital Letter Y with Diaeresis | ||
}; | ||
|
||
// Decode ISO-8859-15 manually | ||
QString Interpret_As_ISO_8859_15::decodeISO885915(const QByteArray& iso885915Data) { | ||
QString result; | ||
|
||
for (char byte : iso885915Data) { | ||
uint8_t isoChar = static_cast<uint8_t>(byte); | ||
if (isoChar < 0x80) { | ||
result.append(QChar(isoChar)); // ASCII characters (Direct mapping) | ||
} else { | ||
// Map ISO-8859-15 specific characters, fallback to original byte | ||
result.append(iso885915ToUnicode.value(isoChar, QChar(isoChar))); | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
|
||
// Execute Interpretation | ||
void Interpret_As_ISO_8859_15::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 iso885915Data = file.readAll(); | ||
file.close(); | ||
|
||
// Debugging: Print Raw Bytes | ||
qDebug() << "[DEBUG] Raw Bytes (Hex):" << iso885915Data.toHex(); | ||
|
||
QString decodedText = decodeISO885915(iso885915Data); | ||
editor->setPlainText(decodedText); | ||
|
||
qDebug() << "[DEBUG] ISO-8859-15 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_15 { | ||
public: | ||
static Interpret_As_ISO_8859_15& instance(); | ||
void execute(QPlainTextEdit* editor); | ||
|
||
private: | ||
Interpret_As_ISO_8859_15() = default; | ||
~Interpret_As_ISO_8859_15() = default; | ||
Interpret_As_ISO_8859_15(const Interpret_As_ISO_8859_15&) = delete; | ||
Interpret_As_ISO_8859_15& operator=(const Interpret_As_ISO_8859_15&) = delete; | ||
|
||
QString decodeISO885915(const QByteArray& iso885915Data); | ||
}; |
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