-
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
57632c7
commit e7263f0
Showing
8 changed files
with
339 additions
and
2 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,58 @@ | ||
#include "interpret_as_koi8_u.h" | ||
#include <QFile> | ||
#include <QDebug> | ||
|
||
// Singleton instance | ||
Interpret_As_KOI8_U& Interpret_As_KOI8_U::instance() { | ||
static Interpret_As_KOI8_U instance; | ||
return instance; | ||
} | ||
|
||
// KOI8-U to Unicode mapping | ||
QChar Interpret_As_KOI8_U::koi8uToUnicode(uint8_t koi8uChar) { | ||
// ASCII range (0x00-0x7F remains unchanged) | ||
if (koi8uChar < 0x80) { | ||
return QChar(koi8uChar); | ||
} | ||
|
||
// Mapping for KOI8-U specific characters (0x80-0xFF) | ||
static const uint16_t koi8uToUnicodeTable[128] = { | ||
0x2500, 0x2502, 0x250C, 0x2510, 0x2514, 0x2518, 0x251C, 0x2524, // 0x80-0x87 | ||
0x252C, 0x2534, 0x253C, 0x2580, 0x2584, 0x2588, 0x258C, 0x2590, // 0x88-0x8F | ||
// Add the remaining KOI8-U mappings (refer to the KOI8-U standard table) | ||
// ... | ||
0xFFFD // Placeholder for unmapped characters | ||
}; | ||
|
||
return QChar(koi8uToUnicodeTable[koi8uChar - 0x80]); | ||
} | ||
|
||
// Decode the KOI8-U data | ||
QString Interpret_As_KOI8_U::decodeKOI8U(const QByteArray& koi8uData) { | ||
QString result; | ||
|
||
for (char byte : koi8uData) { | ||
QChar unicodeChar = koi8uToUnicode(static_cast<uint8_t>(byte)); | ||
result.append(unicodeChar); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
// Execute the KOI8-U interpretation | ||
void Interpret_As_KOI8_U::execute(QPlainTextEdit* editor) { | ||
if (!editor) { | ||
qWarning() << "[ERROR] No editor instance provided."; | ||
return; | ||
} | ||
|
||
// Access the raw QByteArray from the editor's document | ||
QTextDocument* doc = editor->document(); | ||
QByteArray rawBytes = doc->toRawText().toLocal8Bit(); | ||
|
||
// Decode KOI8-U from raw bytes | ||
QString decodedText = decodeKOI8U(rawBytes); | ||
|
||
// Replace the text in the editor with the decoded text | ||
editor->setPlainText(decodedText); | ||
} |
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,25 @@ | ||
#pragma once | ||
|
||
#include <QString> | ||
#include <QByteArray> | ||
#include <QPlainTextEdit> | ||
|
||
class Interpret_As_KOI8_U { | ||
public: | ||
static Interpret_As_KOI8_U& instance(); | ||
|
||
// Main decoding method | ||
QString decodeKOI8U(const QByteArray& koi8uData); | ||
|
||
// Executes the KOI8-U interpretation for a given editor | ||
void execute(QPlainTextEdit* editor); | ||
|
||
private: | ||
Interpret_As_KOI8_U() = default; | ||
~Interpret_As_KOI8_U() = default; | ||
|
||
Interpret_As_KOI8_U(const Interpret_As_KOI8_U&) = delete; | ||
Interpret_As_KOI8_U& operator=(const Interpret_As_KOI8_U&) = delete; | ||
|
||
QChar koi8uToUnicode(uint8_t koi8uChar); | ||
}; |
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