-
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
e7263f0
commit fb0dc84
Showing
27 changed files
with
467 additions
and
351 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
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,79 @@ | ||
#include "interpret_as_koi8_r.h" | ||
#include <QFile> | ||
#include <QDebug> | ||
#include <QPlainTextEdit> | ||
#include "../codeeditor.h" | ||
|
||
// Singleton instance | ||
Interpret_As_KOI8_R& Interpret_As_KOI8_R::instance() { | ||
static Interpret_As_KOI8_R instance; | ||
return instance; | ||
} | ||
|
||
// KOI8-R to Unicode mapping (with explicit casting) | ||
const QMap<uint8_t, QChar> koi8rToUnicode = { | ||
{ uint8_t(0xC0), QChar(0x0410) }, { uint8_t(0xC1), QChar(0x0411) }, | ||
{ uint8_t(0xC2), QChar(0x0412) }, { uint8_t(0xC3), QChar(0x0413) }, | ||
{ uint8_t(0xC4), QChar(0x0414) }, { uint8_t(0xC5), QChar(0x0415) }, | ||
{ uint8_t(0xC6), QChar(0x0416) }, { uint8_t(0xC7), QChar(0x0417) }, | ||
{ uint8_t(0xC8), QChar(0x0418) }, { uint8_t(0xC9), QChar(0x0419) }, | ||
{ uint8_t(0xCA), QChar(0x041A) }, { uint8_t(0xCB), QChar(0x041B) }, | ||
{ uint8_t(0xCC), QChar(0x041C) }, { uint8_t(0xCD), QChar(0x041D) }, | ||
{ uint8_t(0xCE), QChar(0x041E) }, { uint8_t(0xCF), QChar(0x041F) }, | ||
{ uint8_t(0xD0), QChar(0x0420) }, { uint8_t(0xD1), QChar(0x0421) }, | ||
{ uint8_t(0xD2), QChar(0x0422) }, { uint8_t(0xD3), QChar(0x0423) }, | ||
{ uint8_t(0xD4), QChar(0x0424) }, { uint8_t(0xD5), QChar(0x0425) }, | ||
{ uint8_t(0xD6), QChar(0x0426) }, { uint8_t(0xD7), QChar(0x0427) }, | ||
{ uint8_t(0xD8), QChar(0x0428) }, { uint8_t(0xD9), QChar(0x0429) }, | ||
{ uint8_t(0xDA), QChar(0x042A) }, { uint8_t(0xDB), QChar(0x042B) }, | ||
{ uint8_t(0xDC), QChar(0x042C) }, { uint8_t(0xDD), QChar(0x042D) }, | ||
{ uint8_t(0xDE), QChar(0x042E) }, { uint8_t(0xDF), QChar(0x042F) }, | ||
|
||
{ uint8_t(0xE0), QChar(0x0430) }, { uint8_t(0xE1), QChar(0x0431) }, | ||
{ uint8_t(0xE2), QChar(0x0432) }, { uint8_t(0xE3), QChar(0x0433) }, | ||
{ uint8_t(0xE4), QChar(0x0434) }, { uint8_t(0xE5), QChar(0x0435) }, | ||
{ uint8_t(0xE6), QChar(0x0436) }, { uint8_t(0xE7), QChar(0x0437) }, | ||
{ uint8_t(0xE8), QChar(0x0438) }, { uint8_t(0xE9), QChar(0x0439) }, | ||
{ uint8_t(0xEA), QChar(0x043A) }, { uint8_t(0xEB), QChar(0x043B) }, | ||
{ uint8_t(0xEC), QChar(0x043C) }, { uint8_t(0xED), QChar(0x043D) }, | ||
{ uint8_t(0xEE), QChar(0x043E) }, { uint8_t(0xEF), QChar(0x043F) }, | ||
{ uint8_t(0xF0), QChar(0x0440) }, { uint8_t(0xF1), QChar(0x0441) }, | ||
{ uint8_t(0xF2), QChar(0x0442) }, { uint8_t(0xF3), QChar(0x0443) }, | ||
{ uint8_t(0xF4), QChar(0x0444) }, { uint8_t(0xF5), QChar(0x0445) }, | ||
{ uint8_t(0xF6), QChar(0x0446) }, { uint8_t(0xF7), QChar(0x0447) }, | ||
{ uint8_t(0xF8), QChar(0x0448) }, { uint8_t(0xF9), QChar(0x0449) }, | ||
{ uint8_t(0xFA), QChar(0x044A) }, { uint8_t(0xFB), QChar(0x044B) }, | ||
{ uint8_t(0xFC), QChar(0x044C) }, { uint8_t(0xFD), QChar(0x044D) }, | ||
{ uint8_t(0xFE), QChar(0x044E) }, { uint8_t(0xFF), QChar(0x044F) } | ||
}; | ||
|
||
// KOI8-R Decoding Logic | ||
QString Interpret_As_KOI8_R::decodeKOI8R(const QByteArray& koi8Data) { | ||
QString result; | ||
for (char byte : koi8Data) { | ||
uint8_t koi8Char = static_cast<uint8_t>(byte); | ||
result.append(koi8rToUnicode.value(koi8Char, QChar(0xFFFD))); // U+FFFD for unmapped bytes | ||
} | ||
return result; | ||
} | ||
|
||
// Execute KOI8-R Interpretation | ||
void Interpret_As_KOI8_R::execute(QPlainTextEdit* editor) { | ||
if (!editor) return; | ||
|
||
CodeEditor* codeEditor = qobject_cast<CodeEditor*>(editor); | ||
QString filePath = codeEditor->filePath(); | ||
|
||
QFile file(filePath); | ||
if (!file.open(QIODevice::ReadOnly)) { | ||
qWarning() << "[ERROR] Cannot open file: " << filePath; | ||
return; | ||
} | ||
|
||
QByteArray koi8Data = file.readAll(); | ||
file.close(); | ||
|
||
QString decodedText = decodeKOI8R(koi8Data); | ||
codeEditor->setPlainText(decodedText); | ||
qDebug() << "[DEBUG] KOI8-R Decoding Applied to 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,24 @@ | ||
#pragma once | ||
|
||
#include <QString> | ||
#include <QByteArray> | ||
#include <QPlainTextEdit> | ||
|
||
// Singleton class to interpret files as KOI8-R | ||
class Interpret_As_KOI8_R { | ||
public: | ||
static Interpret_As_KOI8_R& instance(); | ||
|
||
// Main decoding method | ||
QString decodeKOI8R(const QByteArray& koi8Data); | ||
|
||
// Executes KOI8-R interpretation for the given editor | ||
void execute(QPlainTextEdit* editor); | ||
|
||
private: | ||
Interpret_As_KOI8_R() = default; | ||
~Interpret_As_KOI8_R() = default; | ||
|
||
Interpret_As_KOI8_R(const Interpret_As_KOI8_R&) = delete; | ||
Interpret_As_KOI8_R& operator=(const Interpret_As_KOI8_R&) = delete; | ||
}; |
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 |
---|---|---|
@@ -1,60 +1,50 @@ | ||
#include "interpret_as_tis_620.h" | ||
#include <QStringDecoder> | ||
#include <QFile> | ||
#include <QDebug> | ||
#include "interpret_as_tis_620.h" | ||
#include "../codeeditor.h" | ||
|
||
// Singleton instance | ||
// Singleton instance definition | ||
Interpret_As_TIS_620& Interpret_As_TIS_620::instance() { | ||
static Interpret_As_TIS_620 instance; | ||
return instance; | ||
} | ||
|
||
// TIS-620 to Unicode mapping | ||
uint32_t Interpret_As_TIS_620::tis620ToUnicode(uint8_t tis620Char) { | ||
if (tis620Char < 0x80) { | ||
return tis620Char; // ASCII range | ||
} else if (tis620Char >= 0xA1 && tis620Char <= 0xDA) { | ||
return 0x0E01 + (tis620Char - 0xA1); // Thai characters | ||
} else if (tis620Char >= 0xDF && tis620Char <= 0xFB) { | ||
return 0x0E3F + (tis620Char - 0xDF); // Thai punctuation and symbols | ||
} | ||
return 0xFFFD; // Replacement character for invalid mappings | ||
} | ||
|
||
// Decode the TIS-620 data | ||
QString Interpret_As_TIS_620::decodeTIS620(const QByteArray& tis620Data) { | ||
QString result; | ||
|
||
for (char byte : tis620Data) { | ||
uint32_t unicodeChar = tis620ToUnicode(static_cast<uint8_t>(byte)); | ||
result.append(QChar(unicodeChar)); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
// Execute the TIS-620 interpretation | ||
void Interpret_As_TIS_620::execute(QPlainTextEdit* editor) { | ||
if (!editor) { | ||
qWarning() << "[ERROR] No editor instance provided."; | ||
return; | ||
} | ||
|
||
QString filePath = editor->property("filePath").toString(); | ||
CodeEditor* codeEditor = qobject_cast<CodeEditor*>(editor); | ||
if (!codeEditor) { | ||
qWarning() << "[ERROR] Editor is not a 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; | ||
qWarning() << "[ERROR] Cannot open file: " << filePath; | ||
return; | ||
} | ||
|
||
QByteArray tis620Data = file.readAll(); | ||
file.close(); | ||
|
||
QString decodedText = decodeTIS620(tis620Data); | ||
editor->setPlainText(decodedText); | ||
} | ||
// Use QStringDecoder to decode TIS-620 | ||
QStringDecoder decoder("TIS-620"); | ||
|
||
// Decode TIS-620 data to QString | ||
QString decodedText = decoder.decode(tis620Data); | ||
|
||
// Replace the text in the editor with the correctly decoded text | ||
codeEditor->setPlainText(decodedText); | ||
|
||
qDebug() << "[DEBUG] Successfully reloaded and decoded as TIS-620:" << filePath; | ||
} |
Oops, something went wrong.