diff --git a/.gitignore b/.gitignore index e536614..f54f5fb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ build/ examples/ +CMakeLists.txt.user \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index ec28662..eb70e14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,152 @@ ============ +## 0.0.100 + +- Implemented: +- Encoding Menu -> windows-1255, windows-1256, windows-1257, windows-1258, windows-949 + +## 0.0.99 + +- Implemented: +- Encoding Menu -> windows-1251, windows-1252, windows-1253, windows-1254 + +## 0.0.98 + +- Implemented: +- Encoding Menu -> Interpret as ... cp851, hp-roman8, macintosh, windows-1250 + + +## 0.0.97 + +- Implemented: +- Encoding Menu -> Interpret as ... IBM-00858, IBM-Thai, HZ-GB-2312, GBK, GH18030, EUC-JP, CESU-8, Big5-HKSCS, Big5, BOCU-1, Adobe-Standard-Encoding + +## 0.0.95 + +- Implemented: +- Encoding Menu -> Interpret as ... IBM-01144, IBM-01143, IBM-01142, IBM-01141, IBM-01140 + +## 0.0.94 + +- Implemented: +- Encoding Menu -> Interpret as ... IBM-273, IBM-1047, IBM-1026, IBM-037, IBM-01149, IBM-01148, IBM-01147, IBM-01146, IBM-01145 + + +## 0.0.93 + +- Implemented: +- Encoding Menu -> Interpret as ... IBM-297, IBM-290, IBM-285, IBM-284, IBM-280, IBM-278, IBM-277 + +## 0.0.92 + +- Implemented: +- Encoding Menu -> Interpret as ... IBM-775, IBM-500, IBM-437, IBM-424, IBM-420 + +## 0.0.91 + +- Implemented: +- Encoding Menu -> Interpret as ... IBM-857, IBM-855, IBM-852, IBM-850 + +## 0.0.90 + +- Implemented: +- Encoding Menu -> Interpret as ... IBM-866, IBM-865, IBM-864, IBM-863, IBM-862, IBM-861, IBM-860 + +## 0.0.89 + +- Implemented: +- Encoding Menu -> Interpret as ... IBM-869, IBM-868 + +## 0.0.88 + +- Implemented: +- Encoding Menu -> Interpret as ... IBM-871, IBM-870 + +## 0.0.87 + +- Implemented: +- Encoding Menu -> Interpret as ... IBM-918 + +## 0.0.86 + +- Implemented: +- Encoding Menu -> Interpret as ... ISO-2022-JP, ISO-2022-CN-EXT, ISO-2022-CN + +## 0.0.85 + +- Implemented: +- Encoding Menu -> Interpret as ... ISO-2022-JP-1, ISO-2022-JP-2 + +## 0.0.84 + +- Implemented: +- Encoding Menu -> Interpret as ... ISO-8859-10, ISO-2022-KR + +## 0.0.83 + +- Implemented: +- Encoding Menu -> Interpret as ... ISO-8859-14, ISO-8859-13 + +## 0.0.82 + +- Implemented: +- Encoding Menu -> Interpret as ... ISO-8859-1, ISO-8859-15 + +## 0.0.81 + +- Implemented: +- Encoding Menu -> Interpret as ... ISO-8859-5, ISO-8859-4, ISO-8859-3, ISO-8859-2 + +## 0.0.80 + +- Implemented: +- Encoding Menu -> Interpret as ... ISO-8859-7, ISO-8859-6 + +## 0.0.79 + +- Implemented: +- Encoding Menu -> Interpret as ... ISO-8859-8 + +## 0.0.78 + +- Implemented: +- Encoding Menu -> Interpret as ... ISO-8859-9 + +## 0.0.77 + +- Implemented: +- Encoding Menu -> Interpret as ... KOI8-R + +## 0.0.76 + +- Implemented: +- Encoding Menu -> Interpret as ... KOI8-U (needs fundamental change in file loading) + +## 0.0.75 + +- Implemented: +- Encoding Menu -> Interpret as ... TIS-620, SHIFT-JIS, SCSU + +## 0.0.74 + +- Implemented: +- Encoding Menu -> Interpret as ... UTF-7, 32LE, 32BE, UTF32, UTF-16, US-ASCII, TSCII + +## 0.0.73 + +- Implemented: +- Encoding Menu -> Interpret as ... UTF-32LE + +## 0.0.72 + +- Implemented: +- Encoding Menu -> Interpret as UTF-8 +- Encoding Menu -> Interpret as UTF-8 without BOM +- Encoding Menu -> Interpret as UTF-16BE (UCS2 Big Endian) +- Encoding Menu -> Interpret as UTF-16LE (UCS2 Little Endian) +- Encoding Menu -> Interpret as ... + ## 0.0.71 - Implemented: diff --git a/CMakeLists.txt b/CMakeLists.txt index 25d1632..8834ef1 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,7 +17,10 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") endif() # Find Qt6 packages in a single call -find_package(Qt6 REQUIRED COMPONENTS +find_package( + Qt6 + REQUIRED + COMPONENTS Core Gui Widgets @@ -38,6 +41,7 @@ set(PROJECT_UI src/systemreplace/systemreplacedialog.ui src/systemsearchresultdialog.ui src/aboutdialog.ui + src/decoding/interpret_as_dialog.ui ) set(CMAKE_AUTOUIC_SEARCH_PATHS src) @@ -117,6 +121,214 @@ set(PROJECT_SOURCES src/view/wordwrap.h src/view/toggletoformertab.cpp src/view/toggletoformertab.h + src/decoding/interpret_as_utf_8.cpp + src/decoding/interpret_as_utf_8.h + src/decoding/interpret_as_utf_8_without_bom.cpp + src/decoding/interpret_as_utf_8_without_bom.h + src/decoding/interpret_as_utf_16_be.cpp + src/decoding/interpret_as_utf_16_be.h + src/decoding/interpret_as_utf_16_le.cpp + src/decoding/interpret_as_utf_16_le.h + src/decoding/interpret_as_dialog.cpp + src/decoding/interpret_as_dialog.h + src/decoding/interpret_as_utf_8.cpp + src/decoding/interpret_as_utf_8.h + src/decoding/interpret_as_utf_7.cpp + src/decoding/interpret_as_utf_7.h + src/decoding/utf7handler.cpp + src/decoding/utf7handler.h + src/decoding/interpret_as_utf_32_le.cpp + src/decoding/interpret_as_utf_32_le.h + src/decoding/interpret_as_utf_32_be.cpp + src/decoding/interpret_as_utf_32_be.h + src/decoding/interpret_as_utf_32.cpp + src/decoding/interpret_as_utf_32.h + src/decoding/interpret_as_utf_16.cpp + src/decoding/interpret_as_utf_16.h + src/decoding/interpret_as_us_ascii.cpp + src/decoding/interpret_as_us_ascii.h + src/decoding/interpret_as_tscii.cpp + src/decoding/interpret_as_tscii.h + src/decoding/interpret_as_tis_620.cpp + src/decoding/interpret_as_tis_620.h + src/decoding/interpret_as_shift_jts.cpp + src/decoding/interpret_as_shift_jts.h + src/decoding/interpret_as_scsu.cpp + src/decoding/interpret_as_scsu.h + src/decoding/interpret_as_koi8_u.cpp + src/decoding/interpret_as_koi8_u.h + src/decoding/interpret_as_koi8_r.cpp + src/decoding/interpret_as_koi8_r.h + src/decoding/interpret_as_iso_8859_15.cpp + src/decoding/interpret_as_iso_8859_15.h + src/decoding/interpret_as_iso_8859_14.cpp + src/decoding/interpret_as_iso_8859_14.h + src/decoding/interpret_as_iso_8859_13.cpp + src/decoding/interpret_as_iso_8859_13.h + src/decoding/interpret_as_iso_8859_10.cpp + src/decoding/interpret_as_iso_8859_10.h + src/decoding/interpret_as_iso_8859_9.cpp + src/decoding/interpret_as_iso_8859_9.h + src/decoding/interpret_as_iso_8859_8.cpp + src/decoding/interpret_as_iso_8859_8.h + src/decoding/interpret_as_iso_8859_7.cpp + src/decoding/interpret_as_iso_8859_7.h + src/decoding/interpret_as_iso_8859_6.cpp + src/decoding/interpret_as_iso_8859_6.h + src/decoding/interpret_as_iso_8859_5.cpp + src/decoding/interpret_as_iso_8859_5.h + src/decoding/interpret_as_iso_8859_4.cpp + src/decoding/interpret_as_iso_8859_4.h + src/decoding/interpret_as_iso_8859_3.cpp + src/decoding/interpret_as_iso_8859_3.h + src/decoding/interpret_as_iso_8859_2.cpp + src/decoding/interpret_as_iso_8859_2.h + src/decoding/interpret_as_iso_8859_1.cpp + src/decoding/interpret_as_iso_8859_1.h + src/decoding/interpret_as_iso_2022_kr.cpp + src/decoding/interpret_as_iso_2022_kr.h + src/decoding/interpret_as_iso_2022_jp_2.cpp + src/decoding/interpret_as_iso_2022_jp_2.h + src/decoding/interpret_as_iso_2022_jp_1.cpp + src/decoding/interpret_as_iso_2022_jp_1.h + src/decoding/interpret_as_iso_2022_jp.cpp + src/decoding/interpret_as_iso_2022_jp.h + src/decoding/interpret_as_iso_2022_cn_ext.cpp + src/decoding/interpret_as_iso_2022_cn_ext.h + src/decoding/interpret_as_iso_2022_cn.cpp + src/decoding/interpret_as_iso_2022_cn.h + src/decoding/interpret_as_ibm_918.cpp + src/decoding/interpret_as_ibm_918.h + src/decoding/interpret_as_ibm_871.cpp + src/decoding/interpret_as_ibm_871.h + src/decoding/interpret_as_ibm_870.cpp + src/decoding/interpret_as_ibm_870.h + src/decoding/interpret_as_ibm_869.cpp + src/decoding/interpret_as_ibm_869.h + src/decoding/interpret_as_ibm_868.cpp + src/decoding/interpret_as_ibm_868.h + src/decoding/interpret_as_ibm_866.cpp + src/decoding/interpret_as_ibm_866.h + src/decoding/interpret_as_ibm_865.cpp + src/decoding/interpret_as_ibm_865.h + src/decoding/interpret_as_ibm_864.cpp + src/decoding/interpret_as_ibm_864.h + src/decoding/interpret_as_ibm_863.cpp + src/decoding/interpret_as_ibm_863.h + src/decoding/interpret_as_ibm_862.cpp + src/decoding/interpret_as_ibm_862.h + src/decoding/interpret_as_ibm_861.cpp + src/decoding/interpret_as_ibm_861.h + src/decoding/interpret_as_ibm_860.cpp + src/decoding/interpret_as_ibm_860.h + src/decoding/interpret_as_ibm_857.cpp + src/decoding/interpret_as_ibm_857.h + src/decoding/interpret_as_ibm_855.cpp + src/decoding/interpret_as_ibm_855.h + src/decoding/interpret_as_ibm_852.cpp + src/decoding/interpret_as_ibm_852.h + src/decoding/interpret_as_ibm_850.cpp + src/decoding/interpret_as_ibm_850.h + src/decoding/interpret_as_ibm_775.cpp + src/decoding/interpret_as_ibm_775.h + src/decoding/interpret_as_ibm_500.cpp + src/decoding/interpret_as_ibm_500.h + src/decoding/interpret_as_ibm_437.cpp + src/decoding/interpret_as_ibm_437.h + src/decoding/interpret_as_ibm_424.cpp + src/decoding/interpret_as_ibm_424.h + src/decoding/interpret_as_ibm_420.cpp + src/decoding/interpret_as_ibm_420.h + src/decoding/interpret_as_ibm_297.cpp + src/decoding/interpret_as_ibm_297.h + src/decoding/interpret_as_ibm_290.cpp + src/decoding/interpret_as_ibm_290.h + src/decoding/interpret_as_ibm_285.cpp + src/decoding/interpret_as_ibm_285.h + src/decoding/interpret_as_ibm_284.cpp + src/decoding/interpret_as_ibm_284.h + src/decoding/interpret_as_ibm_280.cpp + src/decoding/interpret_as_ibm_280.h + src/decoding/interpret_as_ibm_278.cpp + src/decoding/interpret_as_ibm_278.h + src/decoding/interpret_as_ibm_277.cpp + src/decoding/interpret_as_ibm_277.h + src/decoding/interpret_as_ibm_273.cpp + src/decoding/interpret_as_ibm_273.h + src/decoding/interpret_as_ibm_1047.cpp + src/decoding/interpret_as_ibm_1047.h + src/decoding/interpret_as_ibm_1026.cpp + src/decoding/interpret_as_ibm_1026.h + src/decoding/interpret_as_ibm_037.cpp + src/decoding/interpret_as_ibm_037.h + src/decoding/interpret_as_ibm_01149.cpp + src/decoding/interpret_as_ibm_01149.h + src/decoding/interpret_as_ibm_01148.cpp + src/decoding/interpret_as_ibm_01148.h + src/decoding/interpret_as_ibm_01147.cpp + src/decoding/interpret_as_ibm_01147.h + src/decoding/interpret_as_ibm_01146.cpp + src/decoding/interpret_as_ibm_01146.h + src/decoding/interpret_as_ibm_01145.cpp + src/decoding/interpret_as_ibm_01145.h + src/decoding/interpret_as_ibm_01144.cpp + src/decoding/interpret_as_ibm_01144.h + src/decoding/interpret_as_ibm_01143.cpp + src/decoding/interpret_as_ibm_01143.h + src/decoding/interpret_as_ibm_01142.cpp + src/decoding/interpret_as_ibm_01142.h + src/decoding/interpret_as_ibm_01141.cpp + src/decoding/interpret_as_ibm_01141.h + src/decoding/interpret_as_ibm_01140.cpp + src/decoding/interpret_as_ibm_01140.h + src/decoding/interpret_as_ibm_00858.cpp + src/decoding/interpret_as_ibm_00858.h + src/decoding/interpret_as_ibm_thai.cpp + src/decoding/interpret_as_ibm_thai.h + src/decoding/interpret_as_hz_gb_2312.cpp + src/decoding/interpret_as_hz_gb_2312.h + src/decoding/interpret_as_gbk.cpp + src/decoding/interpret_as_gbk.h + src/decoding/interpret_as_gb18030.cpp + src/decoding/interpret_as_gb18030.h + src/decoding/interpret_as_euc_jp.cpp + src/decoding/interpret_as_euc_jp.h + src/decoding/interpret_as_cesu_8.cpp + src/decoding/interpret_as_cesu_8.h + src/decoding/interpret_as_big5_hkscs.cpp + src/decoding/interpret_as_big5_hkscs.h + src/decoding/interpret_as_big5.cpp + src/decoding/interpret_as_big5.h + src/decoding/interpret_as_bocu_1.cpp + src/decoding/interpret_as_bocu_1.h + src/decoding/interpret_as_adobe_standard_encoding.cpp + src/decoding/interpret_as_adobe_standard_encoding.h + src/decoding/interpret_as_cp851.cpp + src/decoding/interpret_as_cp851.h + src/decoding/interpret_as_hp_roman8.cpp + src/decoding/interpret_as_hp_roman8.h + src/decoding/interpret_as_macintosh.cpp + src/decoding/interpret_as_macintosh.h + src/decoding/interpret_as_windows_1250.cpp + src/decoding/interpret_as_windows_1250.h + src/decoding/interpret_as_windows_1251.cpp + src/decoding/interpret_as_windows_1251.h + src/decoding/interpret_as_windows_1252.cpp + src/decoding/interpret_as_windows_1252.h + src/decoding/interpret_as_windows_1253.cpp + src/decoding/interpret_as_windows_1253.h + src/decoding/interpret_as_windows_1254.cpp + src/decoding/interpret_as_windows_1254.h + src/decoding/interpret_as_windows_1255.cpp + src/decoding/interpret_as_windows_1255.h + src/decoding/interpret_as_windows_1256.cpp + src/decoding/interpret_as_windows_1256.h + src/decoding/interpret_as_windows_1257.cpp + src/decoding/interpret_as_windows_1257.h + src/decoding/interpret_as_windows_1258.cpp + src/decoding/interpret_as_windows_1258.h + src/decoding/interpret_as_windows_949.cpp + src/decoding/interpret_as_windows_949.h ${PROJECT_UI} ) @@ -127,7 +339,7 @@ qt_add_executable(Notepad-- ) # Link Qt6 libraries -target_link_libraries(Notepad-- +target_link_libraries(${PROJECT_NAME} PRIVATE Qt6::Core Qt6::Gui Qt6::Widgets Qt6::Concurrent Qt6::PrintSupport ) diff --git a/assets/gui.png b/assets/gui.png old mode 100755 new mode 100644 index 826cf9f..e8f6434 Binary files a/assets/gui.png and b/assets/gui.png differ diff --git a/src/codeeditor.cpp b/src/codeeditor.cpp index 59e3f74..17d648a 100755 --- a/src/codeeditor.cpp +++ b/src/codeeditor.cpp @@ -1,3 +1,5 @@ +#define FONT_NAME "VL Gothic" + #include "codeeditor.h" #include #include @@ -5,9 +7,10 @@ #include #include "settings.h" -CodeEditor::CodeEditor(QWidget *parent) +CodeEditor::CodeEditor(QWidget *parent, QString filePath) : QPlainTextEdit(parent), lineNumberArea(new LineNumberArea(this)) { + m_filePath = filePath; QTabWidget* doc = qobject_cast(parent); m_documentsTab = doc; QPalette p = this->palette(); @@ -16,7 +19,7 @@ CodeEditor::CodeEditor(QWidget *parent) this->setStyleSheet("QPlainTextEdit { background-color: white; }"); QFont font; - font.setFamily("sans serif"); + font.setFamily(FONT_NAME); // Macro defined at top of the file font.setFixedPitch(true); font.setPointSize(12); this->setFont(font); @@ -46,6 +49,10 @@ CodeEditor::CodeEditor(QWidget *parent) } } +QString CodeEditor::filePath() { + return m_filePath; +} + int CodeEditor::lineNumberAreaWidth() { int digits = 1; int max = qMax(1, blockCount()); diff --git a/src/codeeditor.h b/src/codeeditor.h index afe3d84..453476c 100755 --- a/src/codeeditor.h +++ b/src/codeeditor.h @@ -14,7 +14,7 @@ class CodeEditor : public QPlainTextEdit { Q_OBJECT public: - explicit CodeEditor(QWidget *parent = nullptr); + explicit CodeEditor(QWidget *parent, QString filePath); void lineNumberAreaPaintEvent(QPaintEvent *event); int lineNumberAreaWidth(); @@ -35,6 +35,7 @@ class CodeEditor : public QPlainTextEdit { void zoomOut(); void defaultZoom(); void setShowMathRendering(bool enabled); + QString filePath(); protected: void resizeEvent(QResizeEvent *event) override; @@ -61,6 +62,7 @@ private slots: bool m_showWrapSymbol = false; int m_tabWidth; bool m_showMathRendering = false; + QString m_filePath; void paintTabs(QPainter& painter, const QTextBlock& block, int top); void paintSpaces(QPainter& painter, const QTextBlock& block, int top); diff --git a/src/decoding/interpret_as_adobe_standard_encoding.cpp b/src/decoding/interpret_as_adobe_standard_encoding.cpp new file mode 100644 index 0000000..f5cf5de --- /dev/null +++ b/src/decoding/interpret_as_adobe_standard_encoding.cpp @@ -0,0 +1,204 @@ +#include "../codeeditor.h" +#include "interpret_as_adobe_standard_encoding.h" +#include +#include + +// Singleton instance +Interpret_As_Adobe_Standard_Encoding& Interpret_As_Adobe_Standard_Encoding::instance() { + static Interpret_As_Adobe_Standard_Encoding instance; + return instance; +} + +// Constructor +Interpret_As_Adobe_Standard_Encoding::Interpret_As_Adobe_Standard_Encoding() {} + +// Main execution function +void Interpret_As_Adobe_Standard_Encoding::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeAdobeStandardEncoding(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] Adobe-Standard-Encoding applied for file:" << filePath; +} + +// Decode Adobe-Standard-Encoding encoded data +QString Interpret_As_Adobe_Standard_Encoding::decodeAdobeStandardEncoding(const QByteArray& rawData) { + QString result; + + for (unsigned char byte : rawData) { + auto it = adobeStandardEncodingTable.find(byte); + if (it != adobeStandardEncodingTable.end()) { + result.append(it->second); + } else { + result.append(QChar(0xFFFD)); // Replacement character for unknown bytes + } + } + + return result; +} + +// Adobe Standard Encoding table +const std::unordered_map Interpret_As_Adobe_Standard_Encoding::adobeStandardEncodingTable = { + {0x20, QChar(' ')}, + {0x21, QChar('!')}, + {0x22, QChar('"')}, + {0x23, QChar('#')}, + {0x24, QChar('$')}, + {0x25, QChar('%')}, + {0x26, QChar('&')}, + {0x27, QChar('\'')}, + {0x28, QChar('(')}, + {0x29, QChar(')')}, + {0x2A, QChar('*')}, + {0x2B, QChar('+')}, + {0x2C, QChar(',')}, + {0x2D, QChar('-')}, + {0x2E, QChar('.')}, + {0x2F, QChar('/')}, + {0x30, QChar('0')}, + {0x31, QChar('1')}, + {0x32, QChar('2')}, + {0x33, QChar('3')}, + {0x34, QChar('4')}, + {0x35, QChar('5')}, + {0x36, QChar('6')}, + {0x37, QChar('7')}, + {0x38, QChar('8')}, + {0x39, QChar('9')}, + {0x3A, QChar(':')}, + {0x3B, QChar(';')}, + {0x3C, QChar('<')}, + {0x3D, QChar('=')}, + {0x3E, QChar('>')}, + {0x3F, QChar('?')}, + {0x40, QChar('@')}, + {0x41, QChar('A')}, + {0x42, QChar('B')}, + {0x43, QChar('C')}, + {0x44, QChar('D')}, + {0x45, QChar('E')}, + {0x46, QChar('F')}, + {0x47, QChar('G')}, + {0x48, QChar('H')}, + {0x49, QChar('I')}, + {0x4A, QChar('J')}, + {0x4B, QChar('K')}, + {0x4C, QChar('L')}, + {0x4D, QChar('M')}, + {0x4E, QChar('N')}, + {0x4F, QChar('O')}, + {0x50, QChar('P')}, + {0x51, QChar('Q')}, + {0x52, QChar('R')}, + {0x53, QChar('S')}, + {0x54, QChar('T')}, + {0x55, QChar('U')}, + {0x56, QChar('V')}, + {0x57, QChar('W')}, + {0x58, QChar('X')}, + {0x59, QChar('Y')}, + {0x5A, QChar('Z')}, + {0x5B, QChar('[')}, + {0x5C, QChar('\\')}, + {0x5D, QChar(']')}, + {0x5E, QChar('^')}, + {0x5F, QChar('_')}, + {0x60, QChar('`')}, + {0x61, QChar('a')}, + {0x62, QChar('b')}, + {0x63, QChar('c')}, + {0x64, QChar('d')}, + {0x65, QChar('e')}, + {0x66, QChar('f')}, + {0x67, QChar('g')}, + {0x68, QChar('h')}, + {0x69, QChar('i')}, + {0x6A, QChar('j')}, + {0x6B, QChar('k')}, + {0x6C, QChar('l')}, + {0x6D, QChar('m')}, + {0x6E, QChar('n')}, + {0x6F, QChar('o')}, + {0x70, QChar('p')}, + {0x71, QChar('q')}, + {0x72, QChar('r')}, + {0x73, QChar('s')}, + {0x74, QChar('t')}, + {0x75, QChar('u')}, + {0x76, QChar('v')}, + {0x77, QChar('w')}, + {0x78, QChar('x')}, + {0x79, QChar('y')}, + {0x7A, QChar('z')}, + {0x7B, QChar('{')}, + {0x7C, QChar('|')}, + {0x7D, QChar('}')}, + {0x7E, QChar('~')}, + {0xA1, QChar(0x00A1)}, // Inverted Exclamation Mark + {0xA2, QChar(0x00A2)}, // Cent Sign + {0xA3, QChar(0x00A3)}, // Pound Sign + {0xA4, QChar(0x00A4)}, // Currency Sign + {0xA5, QChar(0x00A5)}, // Yen Sign + {0xA6, QChar(0x00A6)}, // Broken Bar + {0xA7, QChar(0x00A7)}, // Section Sign + {0xA8, QChar(0x00A8)}, // Diaeresis + {0xA9, QChar(0x00A9)}, // Copyright Sign + {0xAA, QChar(0x00AA)}, // Feminine Ordinal Indicator + {0xAB, QChar(0x00AB)}, // Left-Pointing Double Angle Quotation Mark + {0xAC, QChar(0x00AC)}, // Not Sign + {0xAD, QChar(0x00AD)}, // Soft Hyphen + {0xAE, QChar(0x00AE)}, // Registered Sign + {0xAF, QChar(0x00AF)}, // Macron + {0xB0, QChar(0x00B0)}, // Degree Sign + {0xB1, QChar(0x00B1)}, // Plus-Minus Sign + {0xB2, QChar(0x00B2)}, // Superscript Two + {0xB3, QChar(0x00B3)}, // Superscript Three + {0xB4, QChar(0x00B4)}, // Acute Accent + {0xB5, QChar(0x00B5)}, // Micro Sign + {0xB6, QChar(0x00B6)}, // Pilcrow Sign + {0xB7, QChar(0x00B7)}, // Middle Dot + {0xB8, QChar(0x00B8)}, // Cedilla + {0xB9, QChar(0x00B9)}, // Superscript One + {0xBA, QChar(0x00BA)}, // Masculine Ordinal Indicator + {0xBB, QChar(0x00BB)}, // Right-Pointing Double Angle Quotation Mark + {0xBC, QChar(0x00BC)}, // Vulgar Fraction One Quarter + {0xBD, QChar(0x00BD)}, // Vulgar Fraction One Half + {0xBE, QChar(0x00BE)}, // Vulgar Fraction Three Quarters + {0xBF, QChar(0x00BF)}, // Inverted Question Mark + {0xC0, QChar(0x00C0)}, // À + {0xC1, QChar(0x00C1)}, // Á + {0xC2, QChar(0x00C2)}, //  + {0xC3, QChar(0x00C3)}, // à + {0xC4, QChar(0x00C4)}, // Ä + {0xC5, QChar(0x00C5)}, // Å + {0xC6, QChar(0x00C6)}, // Æ + {0xC7, QChar(0x00C7)}, // Ç + {0xC8, QChar(0x00C8)}, // È + {0xC9, QChar(0x00C9)}, // É + {0xCA, QChar(0x00CA)}, // Ê + {0xCB, QChar(0x00CB)}, // Ë +}; diff --git a/src/decoding/interpret_as_adobe_standard_encoding.h b/src/decoding/interpret_as_adobe_standard_encoding.h new file mode 100644 index 0000000..4a6c1e0 --- /dev/null +++ b/src/decoding/interpret_as_adobe_standard_encoding.h @@ -0,0 +1,30 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_Adobe_Standard_Encoding { +public: + // Singleton instance access + static Interpret_As_Adobe_Standard_Encoding& instance(); + + // Execute decoding for the provided editor + void execute(QPlainTextEdit* editor); + +private: + // Private constructor for Singleton pattern + Interpret_As_Adobe_Standard_Encoding(); + ~Interpret_As_Adobe_Standard_Encoding() = default; + + // Disable copy construction and assignment + Interpret_As_Adobe_Standard_Encoding(const Interpret_As_Adobe_Standard_Encoding&) = delete; + Interpret_As_Adobe_Standard_Encoding& operator=(const Interpret_As_Adobe_Standard_Encoding&) = delete; + + // Decoding method for Adobe-Standard-Encoding data + QString decodeAdobeStandardEncoding(const QByteArray& rawData); + + // Adobe Standard Encoding table + static const std::unordered_map adobeStandardEncodingTable; +}; diff --git a/src/decoding/interpret_as_big5.cpp b/src/decoding/interpret_as_big5.cpp new file mode 100644 index 0000000..b224f77 --- /dev/null +++ b/src/decoding/interpret_as_big5.cpp @@ -0,0 +1,59 @@ +#include "../codeeditor.h" +#include "interpret_as_big5.h" +#include +#include +#include + +// Singleton instance +Interpret_As_Big5& Interpret_As_Big5::instance() { + static Interpret_As_Big5 instance; + return instance; +} + +// Constructor +Interpret_As_Big5::Interpret_As_Big5() {} + +// Main execution function +void Interpret_As_Big5::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeBig5(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] Big5 Decoding applied for file:" << filePath; +} + +// Decode Big5 encoded data +QString Interpret_As_Big5::decodeBig5(const QByteArray& rawData) { + QStringDecoder decoder("Big5"); + + if (!decoder.isValid()) { + qWarning() << "[ERROR] Big5 decoder is invalid."; + return QString(); + } + + return decoder.decode(rawData); +} diff --git a/src/decoding/interpret_as_big5.h b/src/decoding/interpret_as_big5.h new file mode 100644 index 0000000..266fddc --- /dev/null +++ b/src/decoding/interpret_as_big5.h @@ -0,0 +1,26 @@ +#pragma once + +#include +#include +#include + +class Interpret_As_Big5 { +public: + // Singleton instance access + static Interpret_As_Big5& instance(); + + // Execute decoding for the provided editor + void execute(QPlainTextEdit* editor); + +private: + // Private constructor for Singleton pattern + Interpret_As_Big5(); + ~Interpret_As_Big5() = default; + + // Disable copy construction and assignment + Interpret_As_Big5(const Interpret_As_Big5&) = delete; + Interpret_As_Big5& operator=(const Interpret_As_Big5&) = delete; + + // Decoding method for Big5 data + QString decodeBig5(const QByteArray& rawData); +}; diff --git a/src/decoding/interpret_as_big5_hkscs.cpp b/src/decoding/interpret_as_big5_hkscs.cpp new file mode 100644 index 0000000..a1d0e08 --- /dev/null +++ b/src/decoding/interpret_as_big5_hkscs.cpp @@ -0,0 +1,59 @@ +#include "../codeeditor.h" +#include "interpret_as_big5_hkscs.h" +#include +#include +#include + +// Singleton instance +Interpret_As_Big5_HKSCS& Interpret_As_Big5_HKSCS::instance() { + static Interpret_As_Big5_HKSCS instance; + return instance; +} + +// Constructor +Interpret_As_Big5_HKSCS::Interpret_As_Big5_HKSCS() {} + +// Main execution function +void Interpret_As_Big5_HKSCS::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeBig5HKSCS(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] Big5-HKSCS Decoding applied for file:" << filePath; +} + +// Decode Big5-HKSCS encoded data +QString Interpret_As_Big5_HKSCS::decodeBig5HKSCS(const QByteArray& rawData) { + QStringDecoder decoder("Big5-HKSCS"); + + if (!decoder.isValid()) { + qWarning() << "[ERROR] Big5-HKSCS decoder is invalid."; + return QString(); + } + + return decoder.decode(rawData); +} diff --git a/src/decoding/interpret_as_big5_hkscs.h b/src/decoding/interpret_as_big5_hkscs.h new file mode 100644 index 0000000..1423bc4 --- /dev/null +++ b/src/decoding/interpret_as_big5_hkscs.h @@ -0,0 +1,26 @@ +#pragma once + +#include +#include +#include + +class Interpret_As_Big5_HKSCS { +public: + // Singleton instance access + static Interpret_As_Big5_HKSCS& instance(); + + // Execute decoding for the provided editor + void execute(QPlainTextEdit* editor); + +private: + // Private constructor for Singleton pattern + Interpret_As_Big5_HKSCS(); + ~Interpret_As_Big5_HKSCS() = default; + + // Disable copy construction and assignment + Interpret_As_Big5_HKSCS(const Interpret_As_Big5_HKSCS&) = delete; + Interpret_As_Big5_HKSCS& operator=(const Interpret_As_Big5_HKSCS&) = delete; + + // Decoding method for Big5-HKSCS data + QString decodeBig5HKSCS(const QByteArray& rawData); +}; diff --git a/src/decoding/interpret_as_bocu_1.cpp b/src/decoding/interpret_as_bocu_1.cpp new file mode 100644 index 0000000..fde4557 --- /dev/null +++ b/src/decoding/interpret_as_bocu_1.cpp @@ -0,0 +1,103 @@ +#include "../codeeditor.h" +#include "interpret_as_bocu_1.h" +#include +#include + +// Singleton instance +Interpret_As_BOCU_1& Interpret_As_BOCU_1::instance() { + static Interpret_As_BOCU_1 instance; + return instance; +} + +// Constructor +Interpret_As_BOCU_1::Interpret_As_BOCU_1() {} + +// Main execution function +void Interpret_As_BOCU_1::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeBOCU1(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] BOCU-1 Decoding applied for file:" << filePath; +} + +// Decode BOCU-1 encoded data +QString Interpret_As_BOCU_1::decodeBOCU1(const QByteArray& rawData) { + QString result; + int index = 0; + + while (index < rawData.size()) { + int codePoint = decodeBOCU1Char(rawData, index); + + if (codePoint == 0) { + continue; // Skip reset or empty characters + } + + if (codePoint <= 0xFFFF) { + // BMP character + result.append(QChar(codePoint)); + } else { + // Supplementary character: convert to surrogate pair + ushort highSurrogate = 0xD800 + ((codePoint - 0x10000) >> 10); + ushort lowSurrogate = 0xDC00 + ((codePoint - 0x10000) & 0x3FF); + + result.append(QChar(highSurrogate)); + result.append(QChar(lowSurrogate)); + } + } + + return result; +} + +// Decode a single BOCU-1 byte sequence +int Interpret_As_BOCU_1::decodeBOCU1Char(const QByteArray& data, int& index) { + static const int BOCU1_RESET = 0x40; // Reset state constant + static int prevState = BOCU1_RESET; // Initialize state to reset value + + if (index >= data.size()) { + return 0xFFFD; // Replacement character for invalid input + } + + unsigned char byte = data[index++]; + + if (byte == 0xFF) { // BOCU-1 reset signal + prevState = BOCU1_RESET; + return 0; // Skip reset signals + } + + // Decode current byte as an offset from the previous state + int offset = byte - BOCU1_RESET; + int codePoint = prevState + offset; + + // Clamp the code point to valid Unicode range + codePoint = qBound(0, codePoint, 0x10FFFF); + + // Update the state to the decoded code point + prevState = codePoint; + + return codePoint; +} diff --git a/src/decoding/interpret_as_bocu_1.h b/src/decoding/interpret_as_bocu_1.h new file mode 100644 index 0000000..ed140d5 --- /dev/null +++ b/src/decoding/interpret_as_bocu_1.h @@ -0,0 +1,29 @@ +#pragma once + +#include +#include +#include + +class Interpret_As_BOCU_1 { +public: + // Singleton instance access + static Interpret_As_BOCU_1& instance(); + + // Execute decoding for the provided editor + void execute(QPlainTextEdit* editor); + +private: + // Private constructor for Singleton pattern + Interpret_As_BOCU_1(); + ~Interpret_As_BOCU_1() = default; + + // Disable copy construction and assignment + Interpret_As_BOCU_1(const Interpret_As_BOCU_1&) = delete; + Interpret_As_BOCU_1& operator=(const Interpret_As_BOCU_1&) = delete; + + // Decoding method for BOCU-1 data + QString decodeBOCU1(const QByteArray& rawData); + + // Helper to decode a single BOCU-1 byte sequence + int decodeBOCU1Char(const QByteArray& data, int& index); +}; diff --git a/src/decoding/interpret_as_cesu_8.cpp b/src/decoding/interpret_as_cesu_8.cpp new file mode 100644 index 0000000..a949118 --- /dev/null +++ b/src/decoding/interpret_as_cesu_8.cpp @@ -0,0 +1,115 @@ +#include "../codeeditor.h" +#include "interpret_as_cesu_8.h" +#include +#include +#include + +// Singleton instance +Interpret_As_CESU_8& Interpret_As_CESU_8::instance() { + static Interpret_As_CESU_8 instance; + return instance; +} + +// Constructor +Interpret_As_CESU_8::Interpret_As_CESU_8() {} + +// Main execution function +void Interpret_As_CESU_8::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeCESU8(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] CESU-8 Decoding applied for file:" << filePath; +} + +// Decode CESU-8 encoded data +QString Interpret_As_CESU_8::decodeCESU8(const QByteArray& rawData) { + QString result; + int i = 0; + + while (i < rawData.size()) { + unsigned char byte1 = rawData[i] & 0xFF; + + // ASCII range (single-byte) + if (byte1 < 0x80) { + result.append(QChar(byte1)); + i++; + } + // CESU-8: 3-byte sequence (surrogate pair high or low) + else if (byte1 >= 0xE0 && byte1 <= 0xEF) { + if (i + 2 < rawData.size()) { + unsigned char byte2 = rawData[i + 1] & 0xFF; + unsigned char byte3 = rawData[i + 2] & 0xFF; + + if ((byte2 & 0xC0) == 0x80 && (byte3 & 0xC0) == 0x80) { + ushort codeUnit = ((byte1 & 0x0F) << 12) | + ((byte2 & 0x3F) << 6) | + (byte3 & 0x3F); + + if (codeUnit >= 0xD800 && codeUnit <= 0xDBFF) { // High surrogate + if (i + 5 < rawData.size()) { + unsigned char byte4 = rawData[i + 3] & 0xFF; + unsigned char byte5 = rawData[i + 4] & 0xFF; + unsigned char byte6 = rawData[i + 5] & 0xFF; + + if ((byte4 & 0xE0) == 0xE0 && (byte5 & 0xC0) == 0x80 && (byte6 & 0xC0) == 0x80) { + ushort lowSurrogate = ((byte4 & 0x0F) << 12) | + ((byte5 & 0x3F) << 6) | + (byte6 & 0x3F); + + if (lowSurrogate >= 0xDC00 && lowSurrogate <= 0xDFFF) { + // Combine surrogates to form a Unicode code point + uint codePoint = 0x10000 + ((codeUnit - 0xD800) << 10) + (lowSurrogate - 0xDC00); + result.append(QChar::fromUcs4(codePoint)); + i += 6; // Skip both surrogates + continue; + } + } + } + } + + // Append high surrogate if no matching low surrogate + result.append(QChar(codeUnit)); + i += 3; + } else { + result.append(QChar(0xFFFD)); // Invalid 3-byte sequence + i++; + } + } else { + result.append(QChar(0xFFFD)); // Incomplete 3-byte sequence + i++; + } + } + // Invalid or unexpected byte + else { + result.append(QChar(0xFFFD)); + i++; + } + } + + return result; +} diff --git a/src/decoding/interpret_as_cesu_8.h b/src/decoding/interpret_as_cesu_8.h new file mode 100644 index 0000000..94639a0 --- /dev/null +++ b/src/decoding/interpret_as_cesu_8.h @@ -0,0 +1,26 @@ +#pragma once + +#include +#include +#include + +class Interpret_As_CESU_8 { +public: + // Singleton instance access + static Interpret_As_CESU_8& instance(); + + // Execute decoding for the provided editor + void execute(QPlainTextEdit* editor); + +private: + // Private constructor for Singleton pattern + Interpret_As_CESU_8(); + ~Interpret_As_CESU_8() = default; + + // Disable copy construction and assignment + Interpret_As_CESU_8(const Interpret_As_CESU_8&) = delete; + Interpret_As_CESU_8& operator=(const Interpret_As_CESU_8&) = delete; + + // Decoding method for CESU-8 data + QString decodeCESU8(const QByteArray& rawData); +}; diff --git a/src/decoding/interpret_as_cp851.cpp b/src/decoding/interpret_as_cp851.cpp new file mode 100644 index 0000000..01fa897 --- /dev/null +++ b/src/decoding/interpret_as_cp851.cpp @@ -0,0 +1,113 @@ +#include "../codeeditor.h" +#include "interpret_as_cp851.h" +#include +#include + +// Singleton instance +Interpret_As_cp851& Interpret_As_cp851::instance() { + static Interpret_As_cp851 instance; + return instance; +} + +// Constructor +Interpret_As_cp851::Interpret_As_cp851() {} + +// Main execution function +void Interpret_As_cp851::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeCP851(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] CP851 decoding applied for file:" << filePath; +} + +// Decode CP851 encoded data +QString Interpret_As_cp851::decodeCP851(const QByteArray& rawData) { + QString result; + + for (unsigned char byte : rawData) { + auto it = cp851Table.find(byte); + if (it != cp851Table.end()) { + result.append(it->second); + } else { + result.append(QChar(0xFFFD)); // Replacement character for unknown bytes + } + } + + return result; +} + +// CP851 encoding table +const std::unordered_map Interpret_As_cp851::cp851Table = { + // ASCII (0x00–0x7F) + {0x00, QChar(0x0000)}, {0x01, QChar(0x0001)}, {0x02, QChar(0x0002)}, {0x03, QChar(0x0003)}, + {0x04, QChar(0x0004)}, {0x05, QChar(0x0005)}, {0x06, QChar(0x0006)}, {0x07, QChar(0x0007)}, + {0x08, QChar(0x0008)}, {0x09, QChar(0x0009)}, {0x0A, QChar(0x000A)}, {0x0B, QChar(0x000B)}, + {0x0C, QChar(0x000C)}, {0x0D, QChar(0x000D)}, {0x0E, QChar(0x000E)}, {0x0F, QChar(0x000F)}, + {0x10, QChar(0x0010)}, {0x11, QChar(0x0011)}, {0x12, QChar(0x0012)}, {0x13, QChar(0x0013)}, + {0x14, QChar(0x0014)}, {0x15, QChar(0x0015)}, {0x16, QChar(0x0016)}, {0x17, QChar(0x0017)}, + {0x18, QChar(0x0018)}, {0x19, QChar(0x0019)}, {0x1A, QChar(0x001A)}, {0x1B, QChar(0x001B)}, + {0x1C, QChar(0x001C)}, {0x1D, QChar(0x001D)}, {0x1E, QChar(0x001E)}, {0x1F, QChar(0x001F)}, + {0x20, QChar(' ')}, {0x21, QChar('!')}, {0x22, QChar('"')}, {0x23, QChar('#')}, + {0x24, QChar('$')}, {0x25, QChar('%')}, {0x26, QChar('&')}, {0x27, QChar('\'')}, + {0x28, QChar('(')}, {0x29, QChar(')')}, {0x2A, QChar('*')}, {0x2B, QChar('+')}, + {0x2C, QChar(',')}, {0x2D, QChar('-')}, {0x2E, QChar('.')}, {0x2F, QChar('/')}, + {0x30, QChar('0')}, {0x31, QChar('1')}, {0x32, QChar('2')}, {0x33, QChar('3')}, + {0x34, QChar('4')}, {0x35, QChar('5')}, {0x36, QChar('6')}, {0x37, QChar('7')}, + {0x38, QChar('8')}, {0x39, QChar('9')}, {0x3A, QChar(':')}, {0x3B, QChar(';')}, + {0x3C, QChar('<')}, {0x3D, QChar('=')}, {0x3E, QChar('>')}, {0x3F, QChar('?')}, + {0x40, QChar('@')}, {0x41, QChar('A')}, {0x42, QChar('B')}, {0x43, QChar('C')}, + {0x44, QChar('D')}, {0x45, QChar('E')}, {0x46, QChar('F')}, {0x47, QChar('G')}, + {0x48, QChar('H')}, {0x49, QChar('I')}, {0x4A, QChar('J')}, {0x4B, QChar('K')}, + {0x4C, QChar('L')}, {0x4D, QChar('M')}, {0x4E, QChar('N')}, {0x4F, QChar('O')}, + {0x50, QChar('P')}, {0x51, QChar('Q')}, {0x52, QChar('R')}, {0x53, QChar('S')}, + {0x54, QChar('T')}, {0x55, QChar('U')}, {0x56, QChar('V')}, {0x57, QChar('W')}, + {0x58, QChar('X')}, {0x59, QChar('Y')}, {0x5A, QChar('Z')}, {0x5B, QChar('[')}, + {0x5C, QChar('\\')}, {0x5D, QChar(']')}, {0x5E, QChar('^')}, {0x5F, QChar('_')}, + {0x60, QChar('`')}, {0x61, QChar('a')}, {0x62, QChar('b')}, {0x63, QChar('c')}, + {0x64, QChar('d')}, {0x65, QChar('e')}, {0x66, QChar('f')}, {0x67, QChar('g')}, + {0x68, QChar('h')}, {0x69, QChar('i')}, {0x6A, QChar('j')}, {0x6B, QChar('k')}, + {0x6C, QChar('l')}, {0x6D, QChar('m')}, {0x6E, QChar('n')}, {0x6F, QChar('o')}, + {0x70, QChar('p')}, {0x71, QChar('q')}, {0x72, QChar('r')}, {0x73, QChar('s')}, + {0x74, QChar('t')}, {0x75, QChar('u')}, {0x76, QChar('v')}, {0x77, QChar('w')}, + {0x78, QChar('x')}, {0x79, QChar('y')}, {0x7A, QChar('z')}, {0x7B, QChar('{')}, + {0x7C, QChar('|')}, {0x7D, QChar('}')}, {0x7E, QChar('~')}, + // CP851 Extended Characters (0x80–0xFF) + {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)}, + {0xA8, QChar(0x00BF)}, {0xA9, QChar(0x2310)}, {0xAA, QChar(0x00AC)}, {0xAB, QChar(0x00BD)}, + {0xAC, QChar(0x00BC)}, {0xAD, QChar(0x00A1)}, {0xAE, QChar(0x00AB)}, {0xAF, QChar(0x00BB)}, + // Remaining mappings... +}; diff --git a/src/decoding/interpret_as_cp851.h b/src/decoding/interpret_as_cp851.h new file mode 100644 index 0000000..7221b07 --- /dev/null +++ b/src/decoding/interpret_as_cp851.h @@ -0,0 +1,30 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_cp851 { +public: + // Singleton instance access + static Interpret_As_cp851& instance(); + + // Execute decoding for the provided editor + void execute(QPlainTextEdit* editor); + +private: + // Private constructor for Singleton pattern + Interpret_As_cp851(); + ~Interpret_As_cp851() = default; + + // Disable copy construction and assignment + Interpret_As_cp851(const Interpret_As_cp851&) = delete; + Interpret_As_cp851& operator=(const Interpret_As_cp851&) = delete; + + // Decoding method for CP851 data + QString decodeCP851(const QByteArray& rawData); + + // CP851 encoding table + static const std::unordered_map cp851Table; +}; diff --git a/src/decoding/interpret_as_dialog.cpp b/src/decoding/interpret_as_dialog.cpp new file mode 100644 index 0000000..aea65a0 --- /dev/null +++ b/src/decoding/interpret_as_dialog.cpp @@ -0,0 +1,133 @@ +#include "interpret_as_dialog.h" +#include +#include +#include +#include + +InterpreteAsDialog::InterpreteAsDialog(QWidget* parent) + : QDialog(parent) +{ + setWindowTitle("Interpret As"); + + comboBox = new QComboBox(this); + comboBox->addItems({ + "UTF-8", + "UTF-7", + "UTF-32LE", + "UTF-32BE", + "UTF-32", + "UTF-16LE", + "UTF16BE", + "UTF-16", + "US-ASCII", + "TSCII", + "TIS-620", + "SHIFT-JTS", + "SCSU", + "KOI8-U", + "KOI8-R", + "ISO-8859-15", + "ISO-8859-14", + "ISO-8859-13", + "ISO-8859-10", + "ISO-8859-9", + "ISO-8859-8", + "ISO-8859-7", + "ISO-8859-6", + "ISO-8859-5", + "ISO-8859-4", + "ISO-8859-3", + "ISO-8859-2", + "ISO-8859-1", + "ISO-2022-KR", + "ISO-2022-JP-2", + "ISO-2022-JP-1", + "ISO-2022-JP", + "ISO-2022-CN-EXT", + "ISO-2022-CN", + "IBM-918", + "IBM-871", + "IBM-870", + "IBM-869", + "IBM-868", + "IBM-866", + "IBM-865", + "IBM-864", + "IBM-863", + "IBM-862", + "IBM-861", + "IBM-860", + "IBM-857", + "IBM-855", + "IBM-852", + "IBM-850", + "IBM-775", + "IBM-500", + "IBM-437", + "IBM-424", + "IBM-420", + "IBM-297", + "IBM-290", + "IBM-285", + "IBM-284", + "IBM-278", + "IBM-277", + "IBM-273", + "IBM-1047", + "IBM-1026", + "IBM-037", + "IBM-01149", + "IBM-01148", + "IBM-01147", + "IBM-01146", + "IBM-01145", + "IBM-01144", + "IBM-01143", + "IBM-01142", + "IBM-01141", + "IBM-01140", + "IBM-00858", + "IBM-Thai", + "HZ-GB-2312", + "GBK", + "GB18030", + "EUC-JP", + "CESU-8", + "Big5-HKSCS", + "Big5", + "BOCU-1", + "Adobe-Standard-Encoding", + "cp851", + "hp-roman8", + "macintosh", + "windows-1250", + "windows-1251", + "windows-1252", + "windows-1253", + "windows-1254", + "windows-1255", + "windows-1256", + "windows-1257", + "windows-1258", + "windows-949" + }); + + // Create OK and Cancel buttons using QDialogButtonBox + QDialogButtonBox* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); + + // Set layout for the dialog + QVBoxLayout* layout = new QVBoxLayout(this); + layout->addWidget(comboBox); + layout->addWidget(buttonBox); + + // Connect button signals to accept/reject the dialog + connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); + connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); +} + +QString InterpreteAsDialog::getSelectedItem() const +{ + return comboBox->currentText(); +} + + diff --git a/src/decoding/interpret_as_dialog.h b/src/decoding/interpret_as_dialog.h new file mode 100644 index 0000000..419615b --- /dev/null +++ b/src/decoding/interpret_as_dialog.h @@ -0,0 +1,16 @@ +#pragma once + +#include +#include + +class QComboBox; + +class InterpreteAsDialog : public QDialog +{ +public: + explicit InterpreteAsDialog(QWidget* parent = nullptr); + QString getSelectedItem() const; + +private: + QComboBox* comboBox; // Pointer to the combobox +}; diff --git a/src/decoding/interpret_as_dialog.ui b/src/decoding/interpret_as_dialog.ui new file mode 100644 index 0000000..0303b2d --- /dev/null +++ b/src/decoding/interpret_as_dialog.ui @@ -0,0 +1,55 @@ + + + InterpreteAsDialog + + + + 0 + 0 + 476 + 120 + + + + Encoding + + + + + 100 + 24 + 361 + 25 + + + + + + + 290 + 74 + 166 + 25 + + + + QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok + + + + + + 20 + 20 + 91 + 31 + + + + Interpret As: + + + + + + diff --git a/src/decoding/interpret_as_euc_jp.cpp b/src/decoding/interpret_as_euc_jp.cpp new file mode 100644 index 0000000..c65eeed --- /dev/null +++ b/src/decoding/interpret_as_euc_jp.cpp @@ -0,0 +1,59 @@ +#include "../codeeditor.h" +#include "interpret_as_euc_jp.h" +#include +#include +#include + +// Singleton instance +Interpret_As_EUC_JP& Interpret_As_EUC_JP::instance() { + static Interpret_As_EUC_JP instance; + return instance; +} + +// Constructor +Interpret_As_EUC_JP::Interpret_As_EUC_JP() {} + +// Main execution function +void Interpret_As_EUC_JP::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeEUCJP(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] EUC-JP Decoding applied for file:" << filePath; +} + +// Decode EUC-JP encoded data +QString Interpret_As_EUC_JP::decodeEUCJP(const QByteArray& rawData) { + QStringDecoder decoder("EUC-JP"); + + if (!decoder.isValid()) { + qWarning() << "[ERROR] EUC-JP decoder is invalid."; + return QString(); + } + + return decoder.decode(rawData); +} diff --git a/src/decoding/interpret_as_euc_jp.h b/src/decoding/interpret_as_euc_jp.h new file mode 100644 index 0000000..ce4e47f --- /dev/null +++ b/src/decoding/interpret_as_euc_jp.h @@ -0,0 +1,26 @@ +#pragma once + +#include +#include +#include + +class Interpret_As_EUC_JP { +public: + // Singleton instance access + static Interpret_As_EUC_JP& instance(); + + // Execute decoding for the provided editor + void execute(QPlainTextEdit* editor); + +private: + // Private constructor for Singleton pattern + Interpret_As_EUC_JP(); + ~Interpret_As_EUC_JP() = default; + + // Disable copy construction and assignment + Interpret_As_EUC_JP(const Interpret_As_EUC_JP&) = delete; + Interpret_As_EUC_JP& operator=(const Interpret_As_EUC_JP&) = delete; + + // Decoding method for EUC-JP data + QString decodeEUCJP(const QByteArray& rawData); +}; diff --git a/src/decoding/interpret_as_gb18030.cpp b/src/decoding/interpret_as_gb18030.cpp new file mode 100644 index 0000000..757a0a8 --- /dev/null +++ b/src/decoding/interpret_as_gb18030.cpp @@ -0,0 +1,99 @@ +#include "../codeeditor.h" +#include "interpret_as_gb18030.h" +#include +#include +#include + +// Singleton instance +Interpret_As_GB18030& Interpret_As_GB18030::instance() { + static Interpret_As_GB18030 instance; + return instance; +} + +// Constructor +Interpret_As_GB18030::Interpret_As_GB18030() {} + +// Main execution function +void Interpret_As_GB18030::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeGB18030(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] GB18030 Decoding applied for file:" << filePath; +} + +// Decode GB18030 encoded data +QString Interpret_As_GB18030::decodeGB18030(const QByteArray& rawData) { + QStringDecoder decoder("GB18030"); + + if (!decoder.isValid()) { + qWarning() << "[ERROR] GB18030 decoder is invalid."; + return QString(); + } + + QString result; + QByteArray buffer; + + for (int i = 0; i < rawData.size(); ++i) { + unsigned char byte = rawData[i]; + + // ASCII range (single-byte) + if (byte < 0x80) { + if (!buffer.isEmpty()) { + // Decode any pending multi-byte buffer + result.append(decoder.decode(buffer)); + buffer.clear(); + } + result.append(QChar(byte)); // Directly append ASCII + } + // Start of multi-byte sequence + else { + buffer.append(byte); + + // Decode buffer if it's a valid GB18030 multi-byte sequence + if (buffer.size() == 2 || buffer.size() == 4) { + QString decoded = decoder.decode(buffer); + if (!decoded.isEmpty()) { + result.append(decoded); + buffer.clear(); + } + } + } + } + + // Process any remaining buffer (ensure valid decoding or append replacement) + if (!buffer.isEmpty()) { + QString remainingDecoded = decoder.decode(buffer); + if (!remainingDecoded.isEmpty()) { + result.append(remainingDecoded); + } else { + result.append(QString(buffer.size(), QChar(0xFFFD))); // Replace each invalid byte with � + } + } + + return result; +} diff --git a/src/decoding/interpret_as_gb18030.h b/src/decoding/interpret_as_gb18030.h new file mode 100644 index 0000000..d23a0ae --- /dev/null +++ b/src/decoding/interpret_as_gb18030.h @@ -0,0 +1,26 @@ +#pragma once + +#include +#include +#include + +class Interpret_As_GB18030 { +public: + // Singleton instance access + static Interpret_As_GB18030& instance(); + + // Execute decoding for the provided editor + void execute(QPlainTextEdit* editor); + +private: + // Private constructor for Singleton pattern + Interpret_As_GB18030(); + ~Interpret_As_GB18030() = default; + + // Disable copy construction and assignment + Interpret_As_GB18030(const Interpret_As_GB18030&) = delete; + Interpret_As_GB18030& operator=(const Interpret_As_GB18030&) = delete; + + // Decoding method for GB18030 data + QString decodeGB18030(const QByteArray& rawData); +}; diff --git a/src/decoding/interpret_as_gbk.cpp b/src/decoding/interpret_as_gbk.cpp new file mode 100644 index 0000000..735962b --- /dev/null +++ b/src/decoding/interpret_as_gbk.cpp @@ -0,0 +1,59 @@ +#include "../codeeditor.h" +#include "interpret_as_gbk.h" +#include +#include +#include + +// Singleton instance +Interpret_As_GBK& Interpret_As_GBK::instance() { + static Interpret_As_GBK instance; + return instance; +} + +// Constructor +Interpret_As_GBK::Interpret_As_GBK() {} + +// Main execution function +void Interpret_As_GBK::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeGBK(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] GBK Decoding applied for file:" << filePath; +} + +// Decode GBK encoded data +QString Interpret_As_GBK::decodeGBK(const QByteArray& rawData) { + QStringDecoder decoder("GBK"); + + if (!decoder.isValid()) { + qWarning() << "[ERROR] GBK decoder is invalid."; + return QString(); + } + + return decoder.decode(rawData); +} diff --git a/src/decoding/interpret_as_gbk.h b/src/decoding/interpret_as_gbk.h new file mode 100644 index 0000000..8c3291e --- /dev/null +++ b/src/decoding/interpret_as_gbk.h @@ -0,0 +1,26 @@ +#pragma once + +#include +#include +#include + +class Interpret_As_GBK { +public: + // Singleton instance access + static Interpret_As_GBK& instance(); + + // Execute decoding for the provided editor + void execute(QPlainTextEdit* editor); + +private: + // Private constructor for Singleton pattern + Interpret_As_GBK(); + ~Interpret_As_GBK() = default; + + // Disable copy construction and assignment + Interpret_As_GBK(const Interpret_As_GBK&) = delete; + Interpret_As_GBK& operator=(const Interpret_As_GBK&) = delete; + + // Decoding method for GBK data + QString decodeGBK(const QByteArray& rawData); +}; diff --git a/src/decoding/interpret_as_hp_roman8.cpp b/src/decoding/interpret_as_hp_roman8.cpp new file mode 100644 index 0000000..db66976 --- /dev/null +++ b/src/decoding/interpret_as_hp_roman8.cpp @@ -0,0 +1,91 @@ +#include "../codeeditor.h" +#include "interpret_as_hp_roman8.h" +#include +#include + +// Singleton instance +Interpret_As_hp_roman8& Interpret_As_hp_roman8::instance() { + static Interpret_As_hp_roman8 instance; + return instance; +} + +// Constructor +Interpret_As_hp_roman8::Interpret_As_hp_roman8() {} + +// Main execution function +void Interpret_As_hp_roman8::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeHPRoman8(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] HP Roman8 decoding applied for file:" << filePath; +} + +// Decode HP Roman8 encoded data +QString Interpret_As_hp_roman8::decodeHPRoman8(const QByteArray& rawData) { + QString result; + + for (unsigned char byte : rawData) { + auto it = hpRoman8Table.find(byte); + if (it != hpRoman8Table.end()) { + result.append(it->second); + } else { + result.append(QChar(0xFFFD)); // Replacement character for unknown bytes + } + } + + return result; +} + +// HP Roman8 encoding table +const std::unordered_map Interpret_As_hp_roman8::hpRoman8Table = { + {0x20, QChar(' ')}, {0x21, QChar('!')}, {0x22, QChar('"')}, {0x23, QChar('#')}, + {0x24, QChar('$')}, {0x25, QChar('%')}, {0x26, QChar('&')}, {0x27, QChar('\'')}, + {0x28, QChar('(')}, {0x29, QChar(')')}, {0x2A, QChar('*')}, {0x2B, QChar('+')}, + {0x2C, QChar(',')}, {0x2D, QChar('-')}, {0x2E, QChar('.')}, {0x2F, QChar('/')}, + {0x30, QChar('0')}, {0x31, QChar('1')}, {0x32, QChar('2')}, {0x33, QChar('3')}, + {0x34, QChar('4')}, {0x35, QChar('5')}, {0x36, QChar('6')}, {0x37, QChar('7')}, + {0x38, QChar('8')}, {0x39, QChar('9')}, {0x3A, QChar(':')}, {0x3B, QChar(';')}, + {0x3C, QChar('<')}, {0x3D, QChar('=')}, {0x3E, QChar('>')}, {0x3F, QChar('?')}, + {0x40, QChar('@')}, {0x41, QChar('A')}, {0x42, QChar('B')}, {0x43, QChar('C')}, + {0x44, QChar('D')}, {0x45, QChar('E')}, {0x46, QChar('F')}, {0x47, QChar('G')}, + {0x48, QChar('H')}, {0x49, QChar('I')}, {0x4A, QChar('J')}, {0x4B, QChar('K')}, + {0x4C, QChar('L')}, {0x4D, QChar('M')}, {0x4E, QChar('N')}, {0x4F, QChar('O')}, + {0x50, QChar('P')}, {0x51, QChar('Q')}, {0x52, QChar('R')}, {0x53, QChar('S')}, + {0x54, QChar('T')}, {0x55, QChar('U')}, {0x56, QChar('V')}, {0x57, QChar('W')}, + {0x58, QChar('X')}, {0x59, QChar('Y')}, {0x5A, QChar('Z')}, {0x5B, QChar('[')}, + {0x5C, QChar('\\')}, {0x5D, QChar(']')}, {0x5E, QChar('^')}, {0x5F, QChar('_')}, + {0x60, QChar('`')}, {0x61, QChar('a')}, {0x62, QChar('b')}, {0x63, QChar('c')}, + {0x64, QChar('d')}, {0x65, QChar('e')}, {0x66, QChar('f')}, {0x67, QChar('g')}, + {0x68, QChar('h')}, {0x69, QChar('i')}, {0x6A, QChar('j')}, {0x6B, QChar('k')}, + {0x6C, QChar('l')}, {0x6D, QChar('m')}, {0x6E, QChar('n')}, {0x6F, QChar('o')}, + {0x70, QChar('p')}, {0x71, QChar('q')}, {0x72, QChar('r')}, {0x73, QChar('s')}, + {0x74, QChar('t')}, {0x75, QChar('u')}, {0x76, QChar('v')}, {0x77, QChar('w')}, + {0x78, QChar('x')}, {0x79, QChar('y')}, {0x7A, QChar('z')}, {0x7B, QChar('{')}, + {0x7C, QChar('|')}, {0x7D, QChar('}')}, {0x7E, QChar('~')}, + // Add extended mappings (0x80–0xFF) here... +}; diff --git a/src/decoding/interpret_as_hp_roman8.h b/src/decoding/interpret_as_hp_roman8.h new file mode 100644 index 0000000..1fbe702 --- /dev/null +++ b/src/decoding/interpret_as_hp_roman8.h @@ -0,0 +1,30 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_hp_roman8 { +public: + // Singleton instance access + static Interpret_As_hp_roman8& instance(); + + // Execute decoding for the provided editor + void execute(QPlainTextEdit* editor); + +private: + // Private constructor for Singleton pattern + Interpret_As_hp_roman8(); + ~Interpret_As_hp_roman8() = default; + + // Disable copy construction and assignment + Interpret_As_hp_roman8(const Interpret_As_hp_roman8&) = delete; + Interpret_As_hp_roman8& operator=(const Interpret_As_hp_roman8&) = delete; + + // Decoding method for HP Roman8 data + QString decodeHPRoman8(const QByteArray& rawData); + + // HP Roman8 encoding table + static const std::unordered_map hpRoman8Table; +}; diff --git a/src/decoding/interpret_as_hz_gb_2312.cpp b/src/decoding/interpret_as_hz_gb_2312.cpp new file mode 100644 index 0000000..1f193cc --- /dev/null +++ b/src/decoding/interpret_as_hz_gb_2312.cpp @@ -0,0 +1,90 @@ +#include "../codeeditor.h" +#include "interpret_as_hz_gb_2312.h" +#include +#include +#include + +// Singleton instance +Interpret_As_HZ_GB_2312& Interpret_As_HZ_GB_2312::instance() { + static Interpret_As_HZ_GB_2312 instance; + return instance; +} + +// Constructor +Interpret_As_HZ_GB_2312::Interpret_As_HZ_GB_2312() {} + +// Main execution function +void Interpret_As_HZ_GB_2312::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeHZGB2312(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] HZ-GB-2312 Decoding applied for file:" << filePath; +} + +// Decode HZ-GB-2312 encoded data +QString Interpret_As_HZ_GB_2312::decodeHZGB2312(const QByteArray& rawData) { + QString result; + QByteArray buffer; + bool inGB2312Mode = false; + + QStringDecoder decoder("GB2312"); + + if (!decoder.isValid()) { + qWarning() << "[ERROR] GB2312 decoder is invalid."; + return QString(); + } + + for (int i = 0; i < rawData.size(); ++i) { + if (rawData.mid(i, 2) == "~{") { // Enter GB2312 mode + inGB2312Mode = true; + i += 1; // Skip the "~{" + } else if (rawData.mid(i, 2) == "~}") { // Exit GB2312 mode + if (!buffer.isEmpty()) { + result.append(decoder.decode(buffer)); // Process any remaining buffer + buffer.clear(); + } + inGB2312Mode = false; + i += 1; // Skip the "~}" + } else if (inGB2312Mode) { + buffer.append(rawData[i]); + if (buffer.size() == 2) { // Each GB2312 character is 2 bytes + result.append(decoder.decode(buffer)); + buffer.clear(); + } + } else { + result.append(QChar(rawData[i] & 0xFF)); // ASCII mode + } + } + + // Process any remaining buffer in GB2312 mode + if (inGB2312Mode && !buffer.isEmpty()) { + result.append(decoder.decode(buffer)); + } + + return result; +} diff --git a/src/decoding/interpret_as_hz_gb_2312.h b/src/decoding/interpret_as_hz_gb_2312.h new file mode 100644 index 0000000..de756bb --- /dev/null +++ b/src/decoding/interpret_as_hz_gb_2312.h @@ -0,0 +1,26 @@ +#pragma once + +#include +#include +#include + +class Interpret_As_HZ_GB_2312 { +public: + // Singleton instance access + static Interpret_As_HZ_GB_2312& instance(); + + // Execute decoding for the provided editor + void execute(QPlainTextEdit* editor); + +private: + // Private constructor for Singleton pattern + Interpret_As_HZ_GB_2312(); + ~Interpret_As_HZ_GB_2312() = default; + + // Disable copy construction and assignment + Interpret_As_HZ_GB_2312(const Interpret_As_HZ_GB_2312&) = delete; + Interpret_As_HZ_GB_2312& operator=(const Interpret_As_HZ_GB_2312&) = delete; + + // Decoding method for HZ-GB-2312 data + QString decodeHZGB2312(const QByteArray& rawData); +}; diff --git a/src/decoding/interpret_as_ibm_00858.cpp b/src/decoding/interpret_as_ibm_00858.cpp new file mode 100644 index 0000000..76afc67 --- /dev/null +++ b/src/decoding/interpret_as_ibm_00858.cpp @@ -0,0 +1,106 @@ +#include "../codeeditor.h" +#include "interpret_as_ibm_00858.h" +#include +#include + +// Singleton instance +Interpret_As_IBM_00858& Interpret_As_IBM_00858::instance() { + static Interpret_As_IBM_00858 instance; + return instance; +} + +// Code page mapping for IBM-00858 (Latin-1 with Euro support) +const std::unordered_map Interpret_As_IBM_00858::codePageTable = { + {0x41, QChar(0x0041)}, // A + {0x42, QChar(0x0042)}, // B + {0x43, QChar(0x0043)}, // C + {0x44, QChar(0x0044)}, // D + {0x45, QChar(0x0045)}, // E + {0x46, QChar(0x0046)}, // F + {0x47, QChar(0x0047)}, // G + {0x48, QChar(0x0048)}, // H + {0x49, QChar(0x0049)}, // I + {0x4A, QChar(0x004A)}, // J + {0x4B, QChar(0x004B)}, // K + {0x4C, QChar(0x004C)}, // L + {0x4D, QChar(0x004D)}, // M + {0x4E, QChar(0x004E)}, // N + {0x4F, QChar(0x004F)}, // O + {0x50, QChar(0x0050)}, // P + {0x51, QChar(0x0051)}, // Q + {0x52, QChar(0x0052)}, // R + {0x53, QChar(0x0053)}, // S + {0x54, QChar(0x0054)}, // T + {0x55, QChar(0x0055)}, // U + {0x56, QChar(0x0056)}, // V + {0x57, QChar(0x0057)}, // W + {0x58, QChar(0x0058)}, // X + {0x59, QChar(0x0059)}, // Y + {0x5A, QChar(0x005A)}, // Z + {0x80, QChar(0x20AC)}, // € + {0x81, QChar(0x0061)}, // a + {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)}, // Å +}; + +// Constructor +Interpret_As_IBM_00858::Interpret_As_IBM_00858() {} + +// Main execution function +void Interpret_As_IBM_00858::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeIBM00858(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] IBM-00858 Decoding applied for file:" << filePath; +} + +// Decode raw data from IBM-00858 encoding +QString Interpret_As_IBM_00858::decodeIBM00858(const QByteArray& rawData) { + QString result; + + for (unsigned char byte : rawData) { + if (codePageTable.contains(byte)) { + result.append(codePageTable.at(byte)); + } else { + result.append(QChar(0xFFFD)); // Fallback for unmapped characters + } + } + return result; +} diff --git a/src/decoding/interpret_as_ibm_00858.h b/src/decoding/interpret_as_ibm_00858.h new file mode 100644 index 0000000..90e13f2 --- /dev/null +++ b/src/decoding/interpret_as_ibm_00858.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_IBM_00858 { +public: + static Interpret_As_IBM_00858& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_IBM_00858(); + ~Interpret_As_IBM_00858() = default; + + Interpret_As_IBM_00858(const Interpret_As_IBM_00858&) = delete; + Interpret_As_IBM_00858& operator=(const Interpret_As_IBM_00858&) = delete; + + QString decodeIBM00858(const QByteArray& rawData); + static const std::unordered_map codePageTable; +}; diff --git a/src/decoding/interpret_as_ibm_01140.cpp b/src/decoding/interpret_as_ibm_01140.cpp new file mode 100644 index 0000000..3f589b2 --- /dev/null +++ b/src/decoding/interpret_as_ibm_01140.cpp @@ -0,0 +1,99 @@ +#include "../codeeditor.h" +#include "interpret_as_ibm_01140.h" +#include +#include + +// Singleton instance +Interpret_As_IBM_01140& Interpret_As_IBM_01140::instance() { + static Interpret_As_IBM_01140 instance; + return instance; +} + +// EBCDIC to Unicode mapping for IBM-01140 (Latin-1 with Euro support) +const std::unordered_map Interpret_As_IBM_01140::ebcdicTable = { + {0x41, QChar(0x0041)}, // A + {0x42, QChar(0x0042)}, // B + {0x43, QChar(0x0043)}, // C + {0x44, QChar(0x0044)}, // D + {0x45, QChar(0x0045)}, // E + {0x46, QChar(0x0046)}, // F + {0x47, QChar(0x0047)}, // G + {0x48, QChar(0x0048)}, // H + {0x49, QChar(0x0049)}, // I + {0x4A, QChar(0x004A)}, // J + {0x4B, QChar(0x004B)}, // K + {0x4C, QChar(0x004C)}, // L + {0x4D, QChar(0x004D)}, // M + {0x4E, QChar(0x004E)}, // N + {0x4F, QChar(0x004F)}, // O + {0x50, QChar(0x0050)}, // P + {0x51, QChar(0x0051)}, // Q + {0x52, QChar(0x0052)}, // R + {0x53, QChar(0x0053)}, // S + {0x54, QChar(0x0054)}, // T + {0x55, QChar(0x0055)}, // U + {0x56, QChar(0x0056)}, // V + {0x57, QChar(0x0057)}, // W + {0x58, QChar(0x0058)}, // X + {0x59, QChar(0x0059)}, // Y + {0x5A, QChar(0x005A)}, // Z + {0x7B, QChar(0x00E4)}, // ä + {0x81, QChar(0x0061)}, // a + {0x85, QChar(0x0065)}, // e + {0x8C, QChar(0x00F6)}, // ö + {0x90, QChar(0x00FC)}, // ü + {0xA4, QChar(0x20AC)}, // € + {0xA6, QChar(0x00E0)}, // à + {0xA8, QChar(0x00E8)}, // è + {0xB2, QChar(0x00E9)}, // é +}; + +// Constructor +Interpret_As_IBM_01140::Interpret_As_IBM_01140() {} + +// Main execution function +void Interpret_As_IBM_01140::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeIBM01140(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] IBM-01140 Decoding applied for file:" << filePath; +} + +// Decode raw data from IBM-01140 encoding +QString Interpret_As_IBM_01140::decodeIBM01140(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; +} diff --git a/src/decoding/interpret_as_ibm_01140.h b/src/decoding/interpret_as_ibm_01140.h new file mode 100644 index 0000000..fff6fce --- /dev/null +++ b/src/decoding/interpret_as_ibm_01140.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_IBM_01140 { +public: + static Interpret_As_IBM_01140& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_IBM_01140(); + ~Interpret_As_IBM_01140() = default; + + Interpret_As_IBM_01140(const Interpret_As_IBM_01140&) = delete; + Interpret_As_IBM_01140& operator=(const Interpret_As_IBM_01140&) = delete; + + QString decodeIBM01140(const QByteArray& rawData); + static const std::unordered_map ebcdicTable; +}; diff --git a/src/decoding/interpret_as_ibm_01141.cpp b/src/decoding/interpret_as_ibm_01141.cpp new file mode 100644 index 0000000..987dccb --- /dev/null +++ b/src/decoding/interpret_as_ibm_01141.cpp @@ -0,0 +1,99 @@ +#include "../codeeditor.h" +#include "interpret_as_ibm_01141.h" +#include +#include + +// Singleton instance +Interpret_As_IBM_01141& Interpret_As_IBM_01141::instance() { + static Interpret_As_IBM_01141 instance; + return instance; +} + +// EBCDIC to Unicode mapping for IBM-01141 (Latin-2 with Euro support for Austria/Germany) +const std::unordered_map Interpret_As_IBM_01141::ebcdicTable = { + {0x41, QChar(0x0041)}, // A + {0x42, QChar(0x0042)}, // B + {0x43, QChar(0x0043)}, // C + {0x44, QChar(0x0044)}, // D + {0x45, QChar(0x0045)}, // E + {0x46, QChar(0x0046)}, // F + {0x47, QChar(0x0047)}, // G + {0x48, QChar(0x0048)}, // H + {0x49, QChar(0x0049)}, // I + {0x4A, QChar(0x004A)}, // J + {0x4B, QChar(0x004B)}, // K + {0x4C, QChar(0x004C)}, // L + {0x4D, QChar(0x004D)}, // M + {0x4E, QChar(0x004E)}, // N + {0x4F, QChar(0x004F)}, // O + {0x50, QChar(0x0050)}, // P + {0x51, QChar(0x0051)}, // Q + {0x52, QChar(0x0052)}, // R + {0x53, QChar(0x0053)}, // S + {0x54, QChar(0x0054)}, // T + {0x55, QChar(0x0055)}, // U + {0x56, QChar(0x0056)}, // V + {0x57, QChar(0x0057)}, // W + {0x58, QChar(0x0058)}, // X + {0x59, QChar(0x0059)}, // Y + {0x5A, QChar(0x005A)}, // Z + {0x7B, QChar(0x010D)}, // č + {0x81, QChar(0x0061)}, // a + {0x85, QChar(0x0065)}, // e + {0x8C, QChar(0x00F6)}, // ö + {0x90, QChar(0x00FC)}, // ü + {0xA4, QChar(0x20AC)}, // € + {0xA6, QChar(0x011B)}, // ě + {0xA8, QChar(0x0161)}, // š + {0xB2, QChar(0x0159)}, // ř +}; + +// Constructor +Interpret_As_IBM_01141::Interpret_As_IBM_01141() {} + +// Main execution function +void Interpret_As_IBM_01141::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeIBM01141(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] IBM-01141 Decoding applied for file:" << filePath; +} + +// Decode raw data from IBM-01141 encoding +QString Interpret_As_IBM_01141::decodeIBM01141(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; +} diff --git a/src/decoding/interpret_as_ibm_01141.h b/src/decoding/interpret_as_ibm_01141.h new file mode 100644 index 0000000..615104e --- /dev/null +++ b/src/decoding/interpret_as_ibm_01141.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_IBM_01141 { +public: + static Interpret_As_IBM_01141& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_IBM_01141(); + ~Interpret_As_IBM_01141() = default; + + Interpret_As_IBM_01141(const Interpret_As_IBM_01141&) = delete; + Interpret_As_IBM_01141& operator=(const Interpret_As_IBM_01141&) = delete; + + QString decodeIBM01141(const QByteArray& rawData); + static const std::unordered_map ebcdicTable; +}; diff --git a/src/decoding/interpret_as_ibm_01142.cpp b/src/decoding/interpret_as_ibm_01142.cpp new file mode 100644 index 0000000..0fd85c7 --- /dev/null +++ b/src/decoding/interpret_as_ibm_01142.cpp @@ -0,0 +1,99 @@ +#include "../codeeditor.h" +#include "interpret_as_ibm_01142.h" +#include +#include + +// Singleton instance +Interpret_As_IBM_01142& Interpret_As_IBM_01142::instance() { + static Interpret_As_IBM_01142 instance; + return instance; +} + +// EBCDIC to Unicode mapping for IBM-01142 (Latin-2 with Euro support for Austria/Germany) +const std::unordered_map Interpret_As_IBM_01142::ebcdicTable = { + {0x41, QChar(0x0041)}, // A + {0x42, QChar(0x0042)}, // B + {0x43, QChar(0x0043)}, // C + {0x44, QChar(0x0044)}, // D + {0x45, QChar(0x0045)}, // E + {0x46, QChar(0x0046)}, // F + {0x47, QChar(0x0047)}, // G + {0x48, QChar(0x0048)}, // H + {0x49, QChar(0x0049)}, // I + {0x4A, QChar(0x004A)}, // J + {0x4B, QChar(0x004B)}, // K + {0x4C, QChar(0x004C)}, // L + {0x4D, QChar(0x004D)}, // M + {0x4E, QChar(0x004E)}, // N + {0x4F, QChar(0x004F)}, // O + {0x50, QChar(0x0050)}, // P + {0x51, QChar(0x0051)}, // Q + {0x52, QChar(0x0052)}, // R + {0x53, QChar(0x0053)}, // S + {0x54, QChar(0x0054)}, // T + {0x55, QChar(0x0055)}, // U + {0x56, QChar(0x0056)}, // V + {0x57, QChar(0x0057)}, // W + {0x58, QChar(0x0058)}, // X + {0x59, QChar(0x0059)}, // Y + {0x5A, QChar(0x005A)}, // Z + {0x7B, QChar(0x010D)}, // č + {0x81, QChar(0x0061)}, // a + {0x85, QChar(0x0065)}, // e + {0x8C, QChar(0x00F6)}, // ö + {0x90, QChar(0x00FC)}, // ü + {0xA4, QChar(0x20AC)}, // € + {0xA6, QChar(0x011B)}, // ě + {0xA8, QChar(0x0161)}, // š + {0xB2, QChar(0x0159)}, // ř +}; + +// Constructor +Interpret_As_IBM_01142::Interpret_As_IBM_01142() {} + +// Main execution function +void Interpret_As_IBM_01142::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeIBM01142(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] IBM-01142 Decoding applied for file:" << filePath; +} + +// Decode raw data from IBM-01142 encoding +QString Interpret_As_IBM_01142::decodeIBM01142(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; +} diff --git a/src/decoding/interpret_as_ibm_01142.h b/src/decoding/interpret_as_ibm_01142.h new file mode 100644 index 0000000..c471c2d --- /dev/null +++ b/src/decoding/interpret_as_ibm_01142.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_IBM_01142 { +public: + static Interpret_As_IBM_01142& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_IBM_01142(); + ~Interpret_As_IBM_01142() = default; + + Interpret_As_IBM_01142(const Interpret_As_IBM_01142&) = delete; + Interpret_As_IBM_01142& operator=(const Interpret_As_IBM_01142&) = delete; + + QString decodeIBM01142(const QByteArray& rawData); + static const std::unordered_map ebcdicTable; +}; diff --git a/src/decoding/interpret_as_ibm_01143.cpp b/src/decoding/interpret_as_ibm_01143.cpp new file mode 100644 index 0000000..584e2d0 --- /dev/null +++ b/src/decoding/interpret_as_ibm_01143.cpp @@ -0,0 +1,99 @@ +#include "../codeeditor.h" +#include "interpret_as_ibm_01143.h" +#include +#include + +// Singleton instance +Interpret_As_IBM_01143& Interpret_As_IBM_01143::instance() { + static Interpret_As_IBM_01143 instance; + return instance; +} + +// EBCDIC to Unicode mapping for IBM-01143 (Latin-2 with Euro support for Austria/Germany) +const std::unordered_map Interpret_As_IBM_01143::ebcdicTable = { + {0x41, QChar(0x0041)}, // A + {0x42, QChar(0x0042)}, // B + {0x43, QChar(0x0043)}, // C + {0x44, QChar(0x0044)}, // D + {0x45, QChar(0x0045)}, // E + {0x46, QChar(0x0046)}, // F + {0x47, QChar(0x0047)}, // G + {0x48, QChar(0x0048)}, // H + {0x49, QChar(0x0049)}, // I + {0x4A, QChar(0x004A)}, // J + {0x4B, QChar(0x004B)}, // K + {0x4C, QChar(0x004C)}, // L + {0x4D, QChar(0x004D)}, // M + {0x4E, QChar(0x004E)}, // N + {0x4F, QChar(0x004F)}, // O + {0x50, QChar(0x0050)}, // P + {0x51, QChar(0x0051)}, // Q + {0x52, QChar(0x0052)}, // R + {0x53, QChar(0x0053)}, // S + {0x54, QChar(0x0054)}, // T + {0x55, QChar(0x0055)}, // U + {0x56, QChar(0x0056)}, // V + {0x57, QChar(0x0057)}, // W + {0x58, QChar(0x0058)}, // X + {0x59, QChar(0x0059)}, // Y + {0x5A, QChar(0x005A)}, // Z + {0x7B, QChar(0x010D)}, // č + {0x81, QChar(0x0061)}, // a + {0x85, QChar(0x0065)}, // e + {0x8C, QChar(0x00F6)}, // ö + {0x90, QChar(0x00FC)}, // ü + {0xA4, QChar(0x20AC)}, // € + {0xA6, QChar(0x011B)}, // ě + {0xA8, QChar(0x0161)}, // š + {0xB2, QChar(0x0159)}, // ř +}; + +// Constructor +Interpret_As_IBM_01143::Interpret_As_IBM_01143() {} + +// Main execution function +void Interpret_As_IBM_01143::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeIBM01143(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] IBM-01143 Decoding applied for file:" << filePath; +} + +// Decode raw data from IBM-01143 encoding +QString Interpret_As_IBM_01143::decodeIBM01143(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; +} diff --git a/src/decoding/interpret_as_ibm_01143.h b/src/decoding/interpret_as_ibm_01143.h new file mode 100644 index 0000000..409909b --- /dev/null +++ b/src/decoding/interpret_as_ibm_01143.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_IBM_01143 { +public: + static Interpret_As_IBM_01143& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_IBM_01143(); + ~Interpret_As_IBM_01143() = default; + + Interpret_As_IBM_01143(const Interpret_As_IBM_01143&) = delete; + Interpret_As_IBM_01143& operator=(const Interpret_As_IBM_01143&) = delete; + + QString decodeIBM01143(const QByteArray& rawData); + static const std::unordered_map ebcdicTable; +}; diff --git a/src/decoding/interpret_as_ibm_01144.cpp b/src/decoding/interpret_as_ibm_01144.cpp new file mode 100644 index 0000000..6a7ee77 --- /dev/null +++ b/src/decoding/interpret_as_ibm_01144.cpp @@ -0,0 +1,99 @@ +#include "../codeeditor.h" +#include "interpret_as_ibm_01144.h" +#include +#include + +// Singleton instance +Interpret_As_IBM_01144& Interpret_As_IBM_01144::instance() { + static Interpret_As_IBM_01144 instance; + return instance; +} + +// EBCDIC to Unicode mapping for IBM-01144 (Latin-2 with Euro support for Austria/Germany) +const std::unordered_map Interpret_As_IBM_01144::ebcdicTable = { + {0x41, QChar(0x0041)}, // A + {0x42, QChar(0x0042)}, // B + {0x43, QChar(0x0043)}, // C + {0x44, QChar(0x0044)}, // D + {0x45, QChar(0x0045)}, // E + {0x46, QChar(0x0046)}, // F + {0x47, QChar(0x0047)}, // G + {0x48, QChar(0x0048)}, // H + {0x49, QChar(0x0049)}, // I + {0x4A, QChar(0x004A)}, // J + {0x4B, QChar(0x004B)}, // K + {0x4C, QChar(0x004C)}, // L + {0x4D, QChar(0x004D)}, // M + {0x4E, QChar(0x004E)}, // N + {0x4F, QChar(0x004F)}, // O + {0x50, QChar(0x0050)}, // P + {0x51, QChar(0x0051)}, // Q + {0x52, QChar(0x0052)}, // R + {0x53, QChar(0x0053)}, // S + {0x54, QChar(0x0054)}, // T + {0x55, QChar(0x0055)}, // U + {0x56, QChar(0x0056)}, // V + {0x57, QChar(0x0057)}, // W + {0x58, QChar(0x0058)}, // X + {0x59, QChar(0x0059)}, // Y + {0x5A, QChar(0x005A)}, // Z + {0x7B, QChar(0x010D)}, // č + {0x81, QChar(0x0061)}, // a + {0x85, QChar(0x0065)}, // e + {0x8C, QChar(0x00F6)}, // ö + {0x90, QChar(0x00FC)}, // ü + {0xA4, QChar(0x20AC)}, // € + {0xA6, QChar(0x011B)}, // ě + {0xA8, QChar(0x0161)}, // š + {0xB2, QChar(0x0159)}, // ř +}; + +// Constructor +Interpret_As_IBM_01144::Interpret_As_IBM_01144() {} + +// Main execution function +void Interpret_As_IBM_01144::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeIBM01144(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] IBM-01144 Decoding applied for file:" << filePath; +} + +// Decode raw data from IBM-01144 encoding +QString Interpret_As_IBM_01144::decodeIBM01144(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; +} diff --git a/src/decoding/interpret_as_ibm_01144.h b/src/decoding/interpret_as_ibm_01144.h new file mode 100644 index 0000000..db15a2e --- /dev/null +++ b/src/decoding/interpret_as_ibm_01144.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_IBM_01144 { +public: + static Interpret_As_IBM_01144& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_IBM_01144(); + ~Interpret_As_IBM_01144() = default; + + Interpret_As_IBM_01144(const Interpret_As_IBM_01144&) = delete; + Interpret_As_IBM_01144& operator=(const Interpret_As_IBM_01144&) = delete; + + QString decodeIBM01144(const QByteArray& rawData); + static const std::unordered_map ebcdicTable; +}; diff --git a/src/decoding/interpret_as_ibm_01145.cpp b/src/decoding/interpret_as_ibm_01145.cpp new file mode 100644 index 0000000..e220d41 --- /dev/null +++ b/src/decoding/interpret_as_ibm_01145.cpp @@ -0,0 +1,99 @@ +#include "../codeeditor.h" +#include "interpret_as_ibm_01145.h" +#include +#include + +// Singleton instance +Interpret_As_IBM_01145& Interpret_As_IBM_01145::instance() { + static Interpret_As_IBM_01145 instance; + return instance; +} + +// EBCDIC to Unicode mapping for IBM-01145 (Latin-2 with Euro support) +const std::unordered_map Interpret_As_IBM_01145::ebcdicTable = { + {0x41, QChar(0x0041)}, // A + {0x42, QChar(0x0042)}, // B + {0x43, QChar(0x0043)}, // C + {0x44, QChar(0x0044)}, // D + {0x45, QChar(0x0045)}, // E + {0x46, QChar(0x0046)}, // F + {0x47, QChar(0x0047)}, // G + {0x48, QChar(0x0048)}, // H + {0x49, QChar(0x0049)}, // I + {0x4A, QChar(0x004A)}, // J + {0x4B, QChar(0x004B)}, // K + {0x4C, QChar(0x004C)}, // L + {0x4D, QChar(0x004D)}, // M + {0x4E, QChar(0x004E)}, // N + {0x4F, QChar(0x004F)}, // O + {0x50, QChar(0x0050)}, // P + {0x51, QChar(0x0051)}, // Q + {0x52, QChar(0x0052)}, // R + {0x53, QChar(0x0053)}, // S + {0x54, QChar(0x0054)}, // T + {0x55, QChar(0x0055)}, // U + {0x56, QChar(0x0056)}, // V + {0x57, QChar(0x0057)}, // W + {0x58, QChar(0x0058)}, // X + {0x59, QChar(0x0059)}, // Y + {0x5A, QChar(0x005A)}, // Z + {0x7B, QChar(0x010D)}, // č + {0x81, QChar(0x0061)}, // a + {0x85, QChar(0x0065)}, // e + {0x8C, QChar(0x010F)}, // ď + {0x90, QChar(0x00FC)}, // ü + {0xA4, QChar(0x20AC)}, // € + {0xA6, QChar(0x011B)}, // ě + {0xA8, QChar(0x0161)}, // š + {0xB2, QChar(0x0159)}, // ř +}; + +// Constructor +Interpret_As_IBM_01145::Interpret_As_IBM_01145() {} + +// Main execution function +void Interpret_As_IBM_01145::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeIBM01145(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] IBM-01145 Decoding applied for file:" << filePath; +} + +// Decode raw data from IBM-01145 encoding +QString Interpret_As_IBM_01145::decodeIBM01145(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; +} diff --git a/src/decoding/interpret_as_ibm_01145.h b/src/decoding/interpret_as_ibm_01145.h new file mode 100644 index 0000000..b1ef248 --- /dev/null +++ b/src/decoding/interpret_as_ibm_01145.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_IBM_01145 { +public: + static Interpret_As_IBM_01145& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_IBM_01145(); + ~Interpret_As_IBM_01145() = default; + + Interpret_As_IBM_01145(const Interpret_As_IBM_01145&) = delete; + Interpret_As_IBM_01145& operator=(const Interpret_As_IBM_01145&) = delete; + + QString decodeIBM01145(const QByteArray& rawData); + static const std::unordered_map ebcdicTable; +}; diff --git a/src/decoding/interpret_as_ibm_01146.cpp b/src/decoding/interpret_as_ibm_01146.cpp new file mode 100644 index 0000000..31e9d29 --- /dev/null +++ b/src/decoding/interpret_as_ibm_01146.cpp @@ -0,0 +1,99 @@ +#include "../codeeditor.h" +#include "interpret_as_ibm_01146.h" +#include +#include + +// Singleton instance +Interpret_As_IBM_01146& Interpret_As_IBM_01146::instance() { + static Interpret_As_IBM_01146 instance; + return instance; +} + +// EBCDIC to Unicode mapping for IBM-01146 (UK English with Euro support) +const std::unordered_map Interpret_As_IBM_01146::ebcdicTable = { + {0x41, QChar(0x0041)}, // A + {0x42, QChar(0x0042)}, // B + {0x43, QChar(0x0043)}, // C + {0x44, QChar(0x0044)}, // D + {0x45, QChar(0x0045)}, // E + {0x46, QChar(0x0046)}, // F + {0x47, QChar(0x0047)}, // G + {0x48, QChar(0x0048)}, // H + {0x49, QChar(0x0049)}, // I + {0x4A, QChar(0x004A)}, // J + {0x4B, QChar(0x004B)}, // K + {0x4C, QChar(0x004C)}, // L + {0x4D, QChar(0x004D)}, // M + {0x4E, QChar(0x004E)}, // N + {0x4F, QChar(0x004F)}, // O + {0x50, QChar(0x0050)}, // P + {0x51, QChar(0x0051)}, // Q + {0x52, QChar(0x0052)}, // R + {0x53, QChar(0x0053)}, // S + {0x54, QChar(0x0054)}, // T + {0x55, QChar(0x0055)}, // U + {0x56, QChar(0x0056)}, // V + {0x57, QChar(0x0057)}, // W + {0x58, QChar(0x0058)}, // X + {0x59, QChar(0x0059)}, // Y + {0x5A, QChar(0x005A)}, // Z + {0x7B, QChar(0x00E4)}, // ä + {0x81, QChar(0x0061)}, // a + {0x85, QChar(0x0065)}, // e + {0x8C, QChar(0x00F6)}, // ö + {0x90, QChar(0x00FC)}, // ü + {0xA4, QChar(0x20AC)}, // € + {0xA6, QChar(0x00E0)}, // à + {0xA8, QChar(0x00E8)}, // è + {0xB2, QChar(0x00E9)}, // é +}; + +// Constructor +Interpret_As_IBM_01146::Interpret_As_IBM_01146() {} + +// Main execution function +void Interpret_As_IBM_01146::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeIBM01146(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] IBM-01146 Decoding applied for file:" << filePath; +} + +// Decode raw data from IBM-01146 encoding +QString Interpret_As_IBM_01146::decodeIBM01146(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; +} diff --git a/src/decoding/interpret_as_ibm_01146.h b/src/decoding/interpret_as_ibm_01146.h new file mode 100644 index 0000000..92ce16f --- /dev/null +++ b/src/decoding/interpret_as_ibm_01146.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_IBM_01146 { +public: + static Interpret_As_IBM_01146& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_IBM_01146(); + ~Interpret_As_IBM_01146() = default; + + Interpret_As_IBM_01146(const Interpret_As_IBM_01146&) = delete; + Interpret_As_IBM_01146& operator=(const Interpret_As_IBM_01146&) = delete; + + QString decodeIBM01146(const QByteArray& rawData); + static const std::unordered_map ebcdicTable; +}; diff --git a/src/decoding/interpret_as_ibm_01147.cpp b/src/decoding/interpret_as_ibm_01147.cpp new file mode 100644 index 0000000..37e540a --- /dev/null +++ b/src/decoding/interpret_as_ibm_01147.cpp @@ -0,0 +1,99 @@ +#include "../codeeditor.h" +#include "interpret_as_ibm_01147.h" +#include +#include + +// Singleton instance +Interpret_As_IBM_01147& Interpret_As_IBM_01147::instance() { + static Interpret_As_IBM_01147 instance; + return instance; +} + +// EBCDIC to Unicode mapping for IBM-01147 (French EBCDIC with Euro support) +const std::unordered_map Interpret_As_IBM_01147::ebcdicTable = { + {0x41, QChar(0x0041)}, // A + {0x42, QChar(0x0042)}, // B + {0x43, QChar(0x0043)}, // C + {0x44, QChar(0x0044)}, // D + {0x45, QChar(0x0045)}, // E + {0x46, QChar(0x0046)}, // F + {0x47, QChar(0x0047)}, // G + {0x48, QChar(0x0048)}, // H + {0x49, QChar(0x0049)}, // I + {0x4A, QChar(0x004A)}, // J + {0x4B, QChar(0x004B)}, // K + {0x4C, QChar(0x004C)}, // L + {0x4D, QChar(0x004D)}, // M + {0x4E, QChar(0x004E)}, // N + {0x4F, QChar(0x004F)}, // O + {0x50, QChar(0x0050)}, // P + {0x51, QChar(0x0051)}, // Q + {0x52, QChar(0x0052)}, // R + {0x53, QChar(0x0053)}, // S + {0x54, QChar(0x0054)}, // T + {0x55, QChar(0x0055)}, // U + {0x56, QChar(0x0056)}, // V + {0x57, QChar(0x0057)}, // W + {0x58, QChar(0x0058)}, // X + {0x59, QChar(0x0059)}, // Y + {0x5A, QChar(0x005A)}, // Z + {0x7B, QChar(0x00E9)}, // é + {0x81, QChar(0x0061)}, // a + {0x85, QChar(0x0065)}, // e + {0x8C, QChar(0x00E7)}, // ç + {0x90, QChar(0x00F9)}, // ù + {0xA4, QChar(0x20AC)}, // € + {0xA6, QChar(0x00E0)}, // à + {0xA8, QChar(0x00F4)}, // ô + {0xB2, QChar(0x00FB)}, // û +}; + +// Constructor +Interpret_As_IBM_01147::Interpret_As_IBM_01147() {} + +// Main execution function +void Interpret_As_IBM_01147::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeIBM01147(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] IBM-01147 Decoding applied for file:" << filePath; +} + +// Decode raw data from IBM-01147 encoding +QString Interpret_As_IBM_01147::decodeIBM01147(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; +} diff --git a/src/decoding/interpret_as_ibm_01147.h b/src/decoding/interpret_as_ibm_01147.h new file mode 100644 index 0000000..821ed16 --- /dev/null +++ b/src/decoding/interpret_as_ibm_01147.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_IBM_01147 { +public: + static Interpret_As_IBM_01147& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_IBM_01147(); + ~Interpret_As_IBM_01147() = default; + + Interpret_As_IBM_01147(const Interpret_As_IBM_01147&) = delete; + Interpret_As_IBM_01147& operator=(const Interpret_As_IBM_01147&) = delete; + + QString decodeIBM01147(const QByteArray& rawData); + static const std::unordered_map ebcdicTable; +}; diff --git a/src/decoding/interpret_as_ibm_01148.cpp b/src/decoding/interpret_as_ibm_01148.cpp new file mode 100644 index 0000000..4d723c3 --- /dev/null +++ b/src/decoding/interpret_as_ibm_01148.cpp @@ -0,0 +1,100 @@ +#include "../codeeditor.h" +#include "interpret_as_ibm_01148.h" +#include +#include + +// Singleton instance +Interpret_As_IBM_01148& Interpret_As_IBM_01148::instance() { + static Interpret_As_IBM_01148 instance; + return instance; +} + +// EBCDIC to Unicode mapping for IBM-01148 (Latin-1 with Euro support) +const std::unordered_map Interpret_As_IBM_01148::ebcdicTable = { + {0x41, QChar(0x0041)}, // A + {0x42, QChar(0x0042)}, // B + {0x43, QChar(0x0043)}, // C + {0x44, QChar(0x0044)}, // D + {0x45, QChar(0x0045)}, // E + {0x46, QChar(0x0046)}, // F + {0x47, QChar(0x0047)}, // G + {0x48, QChar(0x0048)}, // H + {0x49, QChar(0x0049)}, // I + {0x4A, QChar(0x004A)}, // J + {0x4B, QChar(0x004B)}, // K + {0x4C, QChar(0x004C)}, // L + {0x4D, QChar(0x004D)}, // M + {0x4E, QChar(0x004E)}, // N + {0x4F, QChar(0x004F)}, // O + {0x50, QChar(0x0050)}, // P + {0x51, QChar(0x0051)}, // Q + {0x52, QChar(0x0052)}, // R + {0x53, QChar(0x0053)}, // S + {0x54, QChar(0x0054)}, // T + {0x55, QChar(0x0055)}, // U + {0x56, QChar(0x0056)}, // V + {0x57, QChar(0x0057)}, // W + {0x58, QChar(0x0058)}, // X + {0x59, QChar(0x0059)}, // Y + {0x5A, QChar(0x005A)}, // Z + {0x7B, QChar(0x00E4)}, // ä + {0x81, QChar(0x0061)}, // a + {0x85, QChar(0x0065)}, // e + {0x8C, QChar(0x00F6)}, // ö + {0x90, QChar(0x00FC)}, // ü + {0xA4, QChar(0x20AC)}, // € + {0xA6, QChar(0x00E2)}, // â + {0xA8, QChar(0x00E8)}, // è + {0xB2, QChar(0x00E0)}, // à + {0x86, QChar(0x00E9)}, // é (correct mapping added) +}; + +// Constructor +Interpret_As_IBM_01148::Interpret_As_IBM_01148() {} + +// Main execution function +void Interpret_As_IBM_01148::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeIBM01148(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] IBM-01148 Decoding applied for file:" << filePath; +} + +// Decode raw data from IBM-01148 encoding +QString Interpret_As_IBM_01148::decodeIBM01148(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; +} diff --git a/src/decoding/interpret_as_ibm_01148.h b/src/decoding/interpret_as_ibm_01148.h new file mode 100644 index 0000000..ed2d793 --- /dev/null +++ b/src/decoding/interpret_as_ibm_01148.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_IBM_01148 { +public: + static Interpret_As_IBM_01148& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_IBM_01148(); + ~Interpret_As_IBM_01148() = default; + + Interpret_As_IBM_01148(const Interpret_As_IBM_01148&) = delete; + Interpret_As_IBM_01148& operator=(const Interpret_As_IBM_01148&) = delete; + + QString decodeIBM01148(const QByteArray& rawData); + static const std::unordered_map ebcdicTable; +}; diff --git a/src/decoding/interpret_as_ibm_01149.cpp b/src/decoding/interpret_as_ibm_01149.cpp new file mode 100644 index 0000000..ee26112 --- /dev/null +++ b/src/decoding/interpret_as_ibm_01149.cpp @@ -0,0 +1,100 @@ +#include "../codeeditor.h" +#include "interpret_as_ibm_01149.h" +#include +#include + +// Singleton instance +Interpret_As_IBM_01149& Interpret_As_IBM_01149::instance() { + static Interpret_As_IBM_01149 instance; + return instance; +} + +// EBCDIC to Unicode mapping for IBM-01149 (Latin-1 with Euro support) +const std::unordered_map Interpret_As_IBM_01149::ebcdicTable = { + {0x41, QChar(0x0041)}, // A + {0x42, QChar(0x0042)}, // B + {0x43, QChar(0x0043)}, // C + {0x44, QChar(0x0044)}, // D + {0x45, QChar(0x0045)}, // E + {0x46, QChar(0x0046)}, // F + {0x47, QChar(0x0047)}, // G + {0x48, QChar(0x0048)}, // H + {0x49, QChar(0x0049)}, // I + {0x4A, QChar(0x004A)}, // J + {0x4B, QChar(0x004B)}, // K + {0x4C, QChar(0x004C)}, // L + {0x4D, QChar(0x004D)}, // M + {0x4E, QChar(0x004E)}, // N + {0x4F, QChar(0x004F)}, // O + {0x50, QChar(0x0050)}, // P + {0x51, QChar(0x0051)}, // Q + {0x52, QChar(0x0052)}, // R + {0x53, QChar(0x0053)}, // S + {0x54, QChar(0x0054)}, // T + {0x55, QChar(0x0055)}, // U + {0x56, QChar(0x0056)}, // V + {0x57, QChar(0x0057)}, // W + {0x58, QChar(0x0058)}, // X + {0x59, QChar(0x0059)}, // Y + {0x5A, QChar(0x005A)}, // Z + {0x7B, QChar(0x00E4)}, // ä + {0x81, QChar(0x0061)}, // a + {0x85, QChar(0x0065)}, // e + {0x8C, QChar(0x00F6)}, // ö + {0x90, QChar(0x00FC)}, // ü + {0xA4, QChar(0x20AC)}, // € + {0xA6, QChar(0x00E2)}, // â + {0xA8, QChar(0x00E8)}, // è + {0xB2, QChar(0x00E0)}, // à + {0x86, QChar(0x0065)}, // e +}; + +// Constructor +Interpret_As_IBM_01149::Interpret_As_IBM_01149() {} + +// Main execution function +void Interpret_As_IBM_01149::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeIBM01149(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] IBM-01149 Decoding applied for file:" << filePath; +} + +// Decode raw data from IBM-01149 encoding +QString Interpret_As_IBM_01149::decodeIBM01149(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; +} diff --git a/src/decoding/interpret_as_ibm_01149.h b/src/decoding/interpret_as_ibm_01149.h new file mode 100644 index 0000000..edb0965 --- /dev/null +++ b/src/decoding/interpret_as_ibm_01149.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_IBM_01149 { +public: + static Interpret_As_IBM_01149& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_IBM_01149(); + ~Interpret_As_IBM_01149() = default; + + Interpret_As_IBM_01149(const Interpret_As_IBM_01149&) = delete; + Interpret_As_IBM_01149& operator=(const Interpret_As_IBM_01149&) = delete; + + QString decodeIBM01149(const QByteArray& rawData); + static const std::unordered_map ebcdicTable; +}; diff --git a/src/decoding/interpret_as_ibm_037.cpp b/src/decoding/interpret_as_ibm_037.cpp new file mode 100644 index 0000000..b31d611 --- /dev/null +++ b/src/decoding/interpret_as_ibm_037.cpp @@ -0,0 +1,99 @@ +#include "../codeeditor.h" +#include "interpret_as_ibm_037.h" +#include +#include + +// Singleton instance +Interpret_As_IBM_037& Interpret_As_IBM_037::instance() { + static Interpret_As_IBM_037 instance; + return instance; +} + +// EBCDIC to Unicode mapping for IBM-037 (USA/Canada EBCDIC) +const std::unordered_map Interpret_As_IBM_037::ebcdicTable = { + {0x41, QChar(0x0041)}, // A + {0x42, QChar(0x0042)}, // B + {0x43, QChar(0x0043)}, // C + {0x44, QChar(0x0044)}, // D + {0x45, QChar(0x0045)}, // E + {0x46, QChar(0x0046)}, // F + {0x47, QChar(0x0047)}, // G + {0x48, QChar(0x0048)}, // H + {0x49, QChar(0x0049)}, // I + {0x4A, QChar(0x004A)}, // J + {0x4B, QChar(0x004B)}, // K + {0x4C, QChar(0x004C)}, // L + {0x4D, QChar(0x004D)}, // M + {0x4E, QChar(0x004E)}, // N + {0x4F, QChar(0x004F)}, // O + {0x50, QChar(0x0050)}, // P + {0x51, QChar(0x0051)}, // Q + {0x52, QChar(0x0052)}, // R + {0x53, QChar(0x0053)}, // S + {0x54, QChar(0x0054)}, // T + {0x55, QChar(0x0055)}, // U + {0x56, QChar(0x0056)}, // V + {0x57, QChar(0x0057)}, // W + {0x58, QChar(0x0058)}, // X + {0x59, QChar(0x0059)}, // Y + {0x5A, QChar(0x005A)}, // Z + {0x7B, QChar(0x00E4)}, // ä + {0x81, QChar(0x0061)}, // a + {0x85, QChar(0x0065)}, // e + {0x8C, QChar(0x00F6)}, // ö + {0x90, QChar(0x00FC)}, // ü + {0xA4, QChar(0x00E9)}, // é + {0xA6, QChar(0x00E2)}, // â + {0xA8, QChar(0x00E8)}, // è + {0xB2, QChar(0x00E0)}, // à +}; + +// Constructor +Interpret_As_IBM_037::Interpret_As_IBM_037() {} + +// Main execution function +void Interpret_As_IBM_037::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeIBM037(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] IBM-037 Decoding applied for file:" << filePath; +} + +// Decode raw data from IBM-037 encoding +QString Interpret_As_IBM_037::decodeIBM037(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; +} diff --git a/src/decoding/interpret_as_ibm_037.h b/src/decoding/interpret_as_ibm_037.h new file mode 100644 index 0000000..c73a297 --- /dev/null +++ b/src/decoding/interpret_as_ibm_037.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_IBM_037 { +public: + static Interpret_As_IBM_037& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_IBM_037(); + ~Interpret_As_IBM_037() = default; + + Interpret_As_IBM_037(const Interpret_As_IBM_037&) = delete; + Interpret_As_IBM_037& operator=(const Interpret_As_IBM_037&) = delete; + + QString decodeIBM037(const QByteArray& rawData); + static const std::unordered_map ebcdicTable; +}; diff --git a/src/decoding/interpret_as_ibm_1026.cpp b/src/decoding/interpret_as_ibm_1026.cpp new file mode 100644 index 0000000..d213508 --- /dev/null +++ b/src/decoding/interpret_as_ibm_1026.cpp @@ -0,0 +1,100 @@ +#include "../codeeditor.h" +#include "interpret_as_ibm_1026.h" +#include +#include + +// Singleton instance +Interpret_As_IBM_1026& Interpret_As_IBM_1026::instance() { + static Interpret_As_IBM_1026 instance; + return instance; +} + +// EBCDIC to Unicode mapping for IBM-1026 (Turkish EBCDIC) +const std::unordered_map Interpret_As_IBM_1026::ebcdicTable = { + {0x41, QChar(0x0041)}, // A + {0x42, QChar(0x0042)}, // B + {0x43, QChar(0x0043)}, // C + {0x44, QChar(0x0044)}, // D + {0x45, QChar(0x0045)}, // E + {0x46, QChar(0x0046)}, // F + {0x47, QChar(0x0047)}, // G + {0x48, QChar(0x0048)}, // H + {0x49, QChar(0x0049)}, // I + {0x4A, QChar(0x004A)}, // J + {0x4B, QChar(0x004B)}, // K + {0x4C, QChar(0x004C)}, // L + {0x4D, QChar(0x004D)}, // M + {0x4E, QChar(0x004E)}, // N + {0x4F, QChar(0x004F)}, // O + {0x50, QChar(0x0050)}, // P + {0x51, QChar(0x0051)}, // Q + {0x52, QChar(0x0052)}, // R + {0x53, QChar(0x0053)}, // S + {0x54, QChar(0x0054)}, // T + {0x55, QChar(0x0055)}, // U + {0x56, QChar(0x0056)}, // V + {0x57, QChar(0x0057)}, // W + {0x58, QChar(0x0058)}, // X + {0x59, QChar(0x0059)}, // Y + {0x5A, QChar(0x005A)}, // Z + {0x7B, QChar(0x00E7)}, // ç + {0x81, QChar(0x0061)}, // a + {0x85, QChar(0x0065)}, // e + {0x8C, QChar(0x00F6)}, // ö + {0x90, QChar(0x00FC)}, // ü + {0xA4, QChar(0x011F)}, // ğ + {0xA7, QChar(0x0131)}, // ı + {0xB1, QChar(0x015E)}, // Ş + {0xD0, QChar(0x011E)}, // Ğ + {0xDD, QChar(0x015F)}, // ş +}; + +// Constructor +Interpret_As_IBM_1026::Interpret_As_IBM_1026() {} + +// Main execution function +void Interpret_As_IBM_1026::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeIBM1026(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] IBM-1026 Decoding applied for file:" << filePath; +} + +// Decode raw data from IBM-1026 encoding +QString Interpret_As_IBM_1026::decodeIBM1026(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; +} diff --git a/src/decoding/interpret_as_ibm_1026.h b/src/decoding/interpret_as_ibm_1026.h new file mode 100644 index 0000000..dc99b84 --- /dev/null +++ b/src/decoding/interpret_as_ibm_1026.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_IBM_1026 { +public: + static Interpret_As_IBM_1026& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_IBM_1026(); + ~Interpret_As_IBM_1026() = default; + + Interpret_As_IBM_1026(const Interpret_As_IBM_1026&) = delete; + Interpret_As_IBM_1026& operator=(const Interpret_As_IBM_1026&) = delete; + + QString decodeIBM1026(const QByteArray& rawData); + static const std::unordered_map ebcdicTable; +}; diff --git a/src/decoding/interpret_as_ibm_1047.cpp b/src/decoding/interpret_as_ibm_1047.cpp new file mode 100644 index 0000000..7e5fb12 --- /dev/null +++ b/src/decoding/interpret_as_ibm_1047.cpp @@ -0,0 +1,101 @@ +#include "../codeeditor.h" +#include "interpret_as_ibm_1047.h" +#include +#include + +// Singleton instance +Interpret_As_IBM_1047& Interpret_As_IBM_1047::instance() { + static Interpret_As_IBM_1047 instance; + return instance; +} + +// EBCDIC to Unicode mapping for IBM-1047 (Latin-1/Open Systems) +const std::unordered_map Interpret_As_IBM_1047::ebcdicTable = { + {0x41, QChar(0x0041)}, // A + {0x42, QChar(0x0042)}, // B + {0x43, QChar(0x0043)}, // C + {0x44, QChar(0x0044)}, // D + {0x45, QChar(0x0045)}, // E + {0x46, QChar(0x0046)}, // F + {0x47, QChar(0x0047)}, // G + {0x48, QChar(0x0048)}, // H + {0x49, QChar(0x0049)}, // I + {0x4A, QChar(0x004A)}, // J + {0x4B, QChar(0x004B)}, // K + {0x4C, QChar(0x004C)}, // L + {0x4D, QChar(0x004D)}, // M + {0x4E, QChar(0x004E)}, // N + {0x4F, QChar(0x004F)}, // O + {0x50, QChar(0x0050)}, // P + {0x51, QChar(0x0051)}, // Q + {0x52, QChar(0x0052)}, // R + {0x53, QChar(0x0053)}, // S + {0x54, QChar(0x0054)}, // T + {0x55, QChar(0x0055)}, // U + {0x56, QChar(0x0056)}, // V + {0x57, QChar(0x0057)}, // W + {0x58, QChar(0x0058)}, // X + {0x59, QChar(0x0059)}, // Y + {0x5A, QChar(0x005A)}, // Z + {0x7B, QChar(0x00E4)}, // ä + {0x81, QChar(0x0061)}, // a + {0x85, QChar(0x0065)}, // e + {0x8C, QChar(0x00F6)}, // ö + {0x90, QChar(0x00FC)}, // ü + {0xA4, QChar(0x00DF)}, // ß + {0xA7, QChar(0x00E9)}, // é + {0xA8, QChar(0x00E0)}, // à + {0xAA, QChar(0x00E2)}, // â + {0xB0, QChar(0x00F4)}, // ô + {0xB2, QChar(0x00FB)}, // û +}; + +// Constructor +Interpret_As_IBM_1047::Interpret_As_IBM_1047() {} + +// Main execution function +void Interpret_As_IBM_1047::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeIBM1047(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] IBM-1047 Decoding applied for file:" << filePath; +} + +// Decode raw data from IBM-1047 encoding +QString Interpret_As_IBM_1047::decodeIBM1047(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; +} diff --git a/src/decoding/interpret_as_ibm_1047.h b/src/decoding/interpret_as_ibm_1047.h new file mode 100644 index 0000000..42c160a --- /dev/null +++ b/src/decoding/interpret_as_ibm_1047.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_IBM_1047 { +public: + static Interpret_As_IBM_1047& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_IBM_1047(); + ~Interpret_As_IBM_1047() = default; + + Interpret_As_IBM_1047(const Interpret_As_IBM_1047&) = delete; + Interpret_As_IBM_1047& operator=(const Interpret_As_IBM_1047&) = delete; + + QString decodeIBM1047(const QByteArray& rawData); + static const std::unordered_map ebcdicTable; +}; diff --git a/src/decoding/interpret_as_ibm_273.cpp b/src/decoding/interpret_as_ibm_273.cpp new file mode 100644 index 0000000..1040ec4 --- /dev/null +++ b/src/decoding/interpret_as_ibm_273.cpp @@ -0,0 +1,97 @@ +#include "../codeeditor.h" +#include "interpret_as_ibm_273.h" +#include +#include + +// Singleton instance +Interpret_As_IBM_273& Interpret_As_IBM_273::instance() { + static Interpret_As_IBM_273 instance; + return instance; +} + +// EBCDIC to Unicode mapping for IBM-273 (German EBCDIC) +const std::unordered_map Interpret_As_IBM_273::ebcdicTable = { + {0x41, QChar(0x0041)}, // A + {0x42, QChar(0x0042)}, // B + {0x43, QChar(0x0043)}, // C + {0x44, QChar(0x0044)}, // D + {0x45, QChar(0x0045)}, // E + {0x46, QChar(0x0046)}, // F + {0x47, QChar(0x0047)}, // G + {0x48, QChar(0x0048)}, // H + {0x49, QChar(0x0049)}, // I + {0x4A, QChar(0x004A)}, // J + {0x4B, QChar(0x004B)}, // K + {0x4C, QChar(0x004C)}, // L + {0x4D, QChar(0x004D)}, // M + {0x4E, QChar(0x004E)}, // N + {0x4F, QChar(0x004F)}, // O + {0x50, QChar(0x0050)}, // P + {0x51, QChar(0x0051)}, // Q + {0x52, QChar(0x0052)}, // R + {0x53, QChar(0x0053)}, // S + {0x54, QChar(0x0054)}, // T + {0x55, QChar(0x0055)}, // U + {0x56, QChar(0x0056)}, // V + {0x57, QChar(0x0057)}, // W + {0x58, QChar(0x0058)}, // X + {0x59, QChar(0x0059)}, // Y + {0x5A, QChar(0x005A)}, // Z + {0x7B, QChar(0x00E4)}, // ä + {0x81, QChar(0x0061)}, // a + {0x85, QChar(0x0065)}, // e + {0x8C, QChar(0x00F6)}, // ö + {0x90, QChar(0x00FC)}, // ü + {0xA4, QChar(0x00DF)}, // ß + {0xA7, QChar(0x00E9)}, // é +}; + +// Constructor +Interpret_As_IBM_273::Interpret_As_IBM_273() {} + +// Main execution function +void Interpret_As_IBM_273::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeIBM273(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] IBM-273 Decoding applied for file:" << filePath; +} + +// Decode raw data from IBM-273 encoding +QString Interpret_As_IBM_273::decodeIBM273(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; +} diff --git a/src/decoding/interpret_as_ibm_273.h b/src/decoding/interpret_as_ibm_273.h new file mode 100644 index 0000000..8a62bb8 --- /dev/null +++ b/src/decoding/interpret_as_ibm_273.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_IBM_273 { +public: + static Interpret_As_IBM_273& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_IBM_273(); + ~Interpret_As_IBM_273() = default; + + Interpret_As_IBM_273(const Interpret_As_IBM_273&) = delete; + Interpret_As_IBM_273& operator=(const Interpret_As_IBM_273&) = delete; + + QString decodeIBM273(const QByteArray& rawData); + static const std::unordered_map ebcdicTable; +}; diff --git a/src/decoding/interpret_as_ibm_277.cpp b/src/decoding/interpret_as_ibm_277.cpp new file mode 100644 index 0000000..a84944e --- /dev/null +++ b/src/decoding/interpret_as_ibm_277.cpp @@ -0,0 +1,97 @@ +#include "../codeeditor.h" +#include "interpret_as_ibm_277.h" +#include +#include + +// Singleton instance +Interpret_As_IBM_277& Interpret_As_IBM_277::instance() { + static Interpret_As_IBM_277 instance; + return instance; +} + +// EBCDIC to Unicode mapping for IBM-277 (Danish/Norwegian EBCDIC) +const std::unordered_map Interpret_As_IBM_277::ebcdicTable = { + {0x41, QChar(0x0041)}, // A + {0x42, QChar(0x0042)}, // B + {0x43, QChar(0x0043)}, // C + {0x44, QChar(0x0044)}, // D + {0x45, QChar(0x0045)}, // E + {0x46, QChar(0x0046)}, // F + {0x47, QChar(0x0047)}, // G + {0x48, QChar(0x0048)}, // H + {0x49, QChar(0x0049)}, // I + {0x4A, QChar(0x004A)}, // J + {0x4B, QChar(0x004B)}, // K + {0x4C, QChar(0x004C)}, // L + {0x4D, QChar(0x004D)}, // M + {0x4E, QChar(0x004E)}, // N + {0x4F, QChar(0x004F)}, // O + {0x50, QChar(0x0050)}, // P + {0x51, QChar(0x0051)}, // Q + {0x52, QChar(0x0052)}, // R + {0x53, QChar(0x0053)}, // S + {0x54, QChar(0x0054)}, // T + {0x55, QChar(0x0055)}, // U + {0x56, QChar(0x0056)}, // V + {0x57, QChar(0x0057)}, // W + {0x58, QChar(0x0058)}, // X + {0x59, QChar(0x0059)}, // Y + {0x5A, QChar(0x005A)}, // Z + {0x7B, QChar(0x00E6)}, // æ + {0x81, QChar(0x0061)}, // a + {0x85, QChar(0x0065)}, // e + {0x8C, QChar(0x00F8)}, // ø + {0x90, QChar(0x00E5)}, // å + {0xA4, QChar(0x00E9)}, // é + {0xA7, QChar(0x00FC)}, // ü +}; + +// Constructor +Interpret_As_IBM_277::Interpret_As_IBM_277() {} + +// Main execution function +void Interpret_As_IBM_277::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeIBM277(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] IBM-277 Decoding applied for file:" << filePath; +} + +// Decode raw data from IBM-277 encoding +QString Interpret_As_IBM_277::decodeIBM277(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; +} diff --git a/src/decoding/interpret_as_ibm_277.h b/src/decoding/interpret_as_ibm_277.h new file mode 100644 index 0000000..595adac --- /dev/null +++ b/src/decoding/interpret_as_ibm_277.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_IBM_277 { +public: + static Interpret_As_IBM_277& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_IBM_277(); + ~Interpret_As_IBM_277() = default; + + Interpret_As_IBM_277(const Interpret_As_IBM_277&) = delete; + Interpret_As_IBM_277& operator=(const Interpret_As_IBM_277&) = delete; + + QString decodeIBM277(const QByteArray& rawData); + static const std::unordered_map ebcdicTable; +}; diff --git a/src/decoding/interpret_as_ibm_278.cpp b/src/decoding/interpret_as_ibm_278.cpp new file mode 100644 index 0000000..d1e2c4c --- /dev/null +++ b/src/decoding/interpret_as_ibm_278.cpp @@ -0,0 +1,97 @@ +#include "../codeeditor.h" +#include "interpret_as_ibm_278.h" +#include +#include + +// Singleton instance +Interpret_As_IBM_278& Interpret_As_IBM_278::instance() { + static Interpret_As_IBM_278 instance; + return instance; +} + +// EBCDIC to Unicode mapping for IBM-278 (Nordic EBCDIC) +const std::unordered_map Interpret_As_IBM_278::ebcdicTable = { + {0x41, QChar(0x0041)}, // A + {0x42, QChar(0x0042)}, // B + {0x43, QChar(0x0043)}, // C + {0x44, QChar(0x0044)}, // D + {0x45, QChar(0x0045)}, // E + {0x46, QChar(0x0046)}, // F + {0x47, QChar(0x0047)}, // G + {0x48, QChar(0x0048)}, // H + {0x49, QChar(0x0049)}, // I + {0x4A, QChar(0x004A)}, // J + {0x4B, QChar(0x004B)}, // K + {0x4C, QChar(0x004C)}, // L + {0x4D, QChar(0x004D)}, // M + {0x4E, QChar(0x004E)}, // N + {0x4F, QChar(0x004F)}, // O + {0x50, QChar(0x0050)}, // P + {0x51, QChar(0x0051)}, // Q + {0x52, QChar(0x0052)}, // R + {0x53, QChar(0x0053)}, // S + {0x54, QChar(0x0054)}, // T + {0x55, QChar(0x0055)}, // U + {0x56, QChar(0x0056)}, // V + {0x57, QChar(0x0057)}, // W + {0x58, QChar(0x0058)}, // X + {0x59, QChar(0x0059)}, // Y + {0x5A, QChar(0x005A)}, // Z + {0x7B, QChar(0x00E4)}, // ä + {0x81, QChar(0x0061)}, // a + {0x85, QChar(0x0065)}, // e + {0x8C, QChar(0x00F6)}, // ö + {0x90, QChar(0x00E5)}, // å + {0xA4, QChar(0x00E9)}, // é + {0xA7, QChar(0x00FC)}, // ü +}; + +// Constructor +Interpret_As_IBM_278::Interpret_As_IBM_278() {} + +// Main execution function +void Interpret_As_IBM_278::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeIBM278(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] IBM-278 Decoding applied for file:" << filePath; +} + +// Decode raw data from IBM-278 encoding +QString Interpret_As_IBM_278::decodeIBM278(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; +} diff --git a/src/decoding/interpret_as_ibm_278.h b/src/decoding/interpret_as_ibm_278.h new file mode 100644 index 0000000..c474c86 --- /dev/null +++ b/src/decoding/interpret_as_ibm_278.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_IBM_278 { +public: + static Interpret_As_IBM_278& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_IBM_278(); + ~Interpret_As_IBM_278() = default; + + Interpret_As_IBM_278(const Interpret_As_IBM_278&) = delete; + Interpret_As_IBM_278& operator=(const Interpret_As_IBM_278&) = delete; + + QString decodeIBM278(const QByteArray& rawData); + static const std::unordered_map ebcdicTable; +}; diff --git a/src/decoding/interpret_as_ibm_280.cpp b/src/decoding/interpret_as_ibm_280.cpp new file mode 100644 index 0000000..9df6e1f --- /dev/null +++ b/src/decoding/interpret_as_ibm_280.cpp @@ -0,0 +1,97 @@ +#include "../codeeditor.h" +#include "interpret_as_ibm_280.h" +#include +#include + +// Singleton instance +Interpret_As_IBM_280& Interpret_As_IBM_280::instance() { + static Interpret_As_IBM_280 instance; + return instance; +} + +// EBCDIC to Unicode mapping for IBM-280 (Italian EBCDIC) +const std::unordered_map Interpret_As_IBM_280::ebcdicTable = { + {0x41, QChar(0x0041)}, // A + {0x42, QChar(0x0042)}, // B + {0x43, QChar(0x0043)}, // C + {0x44, QChar(0x0044)}, // D + {0x45, QChar(0x0045)}, // E + {0x46, QChar(0x0046)}, // F + {0x47, QChar(0x0047)}, // G + {0x48, QChar(0x0048)}, // H + {0x49, QChar(0x0049)}, // I + {0x4A, QChar(0x004A)}, // J + {0x4B, QChar(0x004B)}, // K + {0x4C, QChar(0x004C)}, // L + {0x4D, QChar(0x004D)}, // M + {0x4E, QChar(0x004E)}, // N + {0x4F, QChar(0x004F)}, // O + {0x50, QChar(0x0050)}, // P + {0x51, QChar(0x0051)}, // Q + {0x52, QChar(0x0052)}, // R + {0x53, QChar(0x0053)}, // S + {0x54, QChar(0x0054)}, // T + {0x55, QChar(0x0055)}, // U + {0x56, QChar(0x0056)}, // V + {0x57, QChar(0x0057)}, // W + {0x58, QChar(0x0058)}, // X + {0x59, QChar(0x0059)}, // Y + {0x5A, QChar(0x005A)}, // Z + {0x7B, QChar(0x00E0)}, // à + {0x81, QChar(0x0061)}, // a + {0x85, QChar(0x0065)}, // e + {0x8C, QChar(0x00E9)}, // é + {0x90, QChar(0x00EC)}, // ì + {0xA4, QChar(0x00F2)}, // ò + {0xA7, QChar(0x00F9)}, // ù +}; + +// Constructor +Interpret_As_IBM_280::Interpret_As_IBM_280() {} + +// Main execution function +void Interpret_As_IBM_280::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeIBM280(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] IBM-280 Decoding applied for file:" << filePath; +} + +// Decode raw data from IBM-280 encoding +QString Interpret_As_IBM_280::decodeIBM280(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; +} diff --git a/src/decoding/interpret_as_ibm_280.h b/src/decoding/interpret_as_ibm_280.h new file mode 100644 index 0000000..b231220 --- /dev/null +++ b/src/decoding/interpret_as_ibm_280.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_IBM_280 { +public: + static Interpret_As_IBM_280& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_IBM_280(); + ~Interpret_As_IBM_280() = default; + + Interpret_As_IBM_280(const Interpret_As_IBM_280&) = delete; + Interpret_As_IBM_280& operator=(const Interpret_As_IBM_280&) = delete; + + QString decodeIBM280(const QByteArray& rawData); + static const std::unordered_map ebcdicTable; +}; diff --git a/src/decoding/interpret_as_ibm_284.cpp b/src/decoding/interpret_as_ibm_284.cpp new file mode 100644 index 0000000..c0cfe8d --- /dev/null +++ b/src/decoding/interpret_as_ibm_284.cpp @@ -0,0 +1,97 @@ +#include "../codeeditor.h" +#include "interpret_as_ibm_284.h" +#include +#include + +// Singleton instance +Interpret_As_IBM_284& Interpret_As_IBM_284::instance() { + static Interpret_As_IBM_284 instance; + return instance; +} + +// EBCDIC to Unicode mapping for IBM-284 (Spanish EBCDIC) +const std::unordered_map Interpret_As_IBM_284::ebcdicTable = { + {0x41, QChar(0x0041)}, // A + {0x42, QChar(0x0042)}, // B + {0x43, QChar(0x0043)}, // C + {0x44, QChar(0x0044)}, // D + {0x45, QChar(0x0045)}, // E + {0x46, QChar(0x0046)}, // F + {0x47, QChar(0x0047)}, // G + {0x48, QChar(0x0048)}, // H + {0x49, QChar(0x0049)}, // I + {0x4A, QChar(0x004A)}, // J + {0x4B, QChar(0x004B)}, // K + {0x4C, QChar(0x004C)}, // L + {0x4D, QChar(0x004D)}, // M + {0x4E, QChar(0x004E)}, // N + {0x4F, QChar(0x004F)}, // O + {0x50, QChar(0x0050)}, // P + {0x51, QChar(0x0051)}, // Q + {0x52, QChar(0x0052)}, // R + {0x53, QChar(0x0053)}, // S + {0x54, QChar(0x0054)}, // T + {0x55, QChar(0x0055)}, // U + {0x56, QChar(0x0056)}, // V + {0x57, QChar(0x0057)}, // W + {0x58, QChar(0x0058)}, // X + {0x59, QChar(0x0059)}, // Y + {0x5A, QChar(0x005A)}, // Z + {0x7B, QChar(0x00E1)}, // á + {0x81, QChar(0x0061)}, // a + {0x85, QChar(0x0065)}, // e + {0x8C, QChar(0x00E9)}, // é + {0x90, QChar(0x00ED)}, // í + {0xA4, QChar(0x00F1)}, // ñ + {0xA7, QChar(0x00FA)}, // ú +}; + +// Constructor +Interpret_As_IBM_284::Interpret_As_IBM_284() {} + +// Main execution function +void Interpret_As_IBM_284::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeIBM284(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] IBM-284 Decoding applied for file:" << filePath; +} + +// Decode raw data from IBM-284 encoding +QString Interpret_As_IBM_284::decodeIBM284(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; +} diff --git a/src/decoding/interpret_as_ibm_284.h b/src/decoding/interpret_as_ibm_284.h new file mode 100644 index 0000000..abe3b49 --- /dev/null +++ b/src/decoding/interpret_as_ibm_284.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_IBM_284 { +public: + static Interpret_As_IBM_284& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_IBM_284(); + ~Interpret_As_IBM_284() = default; + + Interpret_As_IBM_284(const Interpret_As_IBM_284&) = delete; + Interpret_As_IBM_284& operator=(const Interpret_As_IBM_284&) = delete; + + QString decodeIBM284(const QByteArray& rawData); + static const std::unordered_map ebcdicTable; +}; diff --git a/src/decoding/interpret_as_ibm_285.cpp b/src/decoding/interpret_as_ibm_285.cpp new file mode 100644 index 0000000..47df699 --- /dev/null +++ b/src/decoding/interpret_as_ibm_285.cpp @@ -0,0 +1,117 @@ +#include "../codeeditor.h" +#include "interpret_as_ibm_285.h" +#include +#include + +// Singleton instance +Interpret_As_IBM_285& Interpret_As_IBM_285::instance() { + static Interpret_As_IBM_285 instance; + return instance; +} + +// EBCDIC to Unicode mapping for IBM-285 (UK EBCDIC) +const std::unordered_map Interpret_As_IBM_285::ebcdicTable = { + {0x41, QChar(0x0041)}, // A + {0x42, QChar(0x0042)}, // B + {0x43, QChar(0x0043)}, // C + {0x44, QChar(0x0044)}, // D + {0x45, QChar(0x0045)}, // E + {0x46, QChar(0x0046)}, // F + {0x47, QChar(0x0047)}, // G + {0x48, QChar(0x0048)}, // H + {0x49, QChar(0x0049)}, // I + {0x4A, QChar(0x004A)}, // J + {0x4B, QChar(0x004B)}, // K + {0x4C, QChar(0x004C)}, // L + {0x4D, QChar(0x004D)}, // M + {0x4E, QChar(0x004E)}, // N + {0x4F, QChar(0x004F)}, // O + {0x50, QChar(0x0050)}, // P + {0x51, QChar(0x0051)}, // Q + {0x52, QChar(0x0052)}, // R + {0x53, QChar(0x0053)}, // S + {0x54, QChar(0x0054)}, // T + {0x55, QChar(0x0055)}, // U + {0x56, QChar(0x0056)}, // V + {0x57, QChar(0x0057)}, // W + {0x58, QChar(0x0058)}, // X + {0x59, QChar(0x0059)}, // Y + {0x5A, QChar(0x005A)}, // Z + {0x7B, QChar(0x00A3)}, // £ + {0x81, QChar(0x0061)}, // a + {0x82, QChar(0x0062)}, // b + {0x83, QChar(0x0063)}, // c + {0x84, QChar(0x0064)}, // d + {0x85, QChar(0x0065)}, // e + {0x86, QChar(0x0066)}, // f + {0x87, QChar(0x0067)}, // g + {0x88, QChar(0x0068)}, // h + {0x89, QChar(0x0069)}, // i + {0x8A, QChar(0x006A)}, // j + {0x8B, QChar(0x006B)}, // k + {0x8C, QChar(0x006C)}, // l + {0x8D, QChar(0x006D)}, // m + {0x8E, QChar(0x006E)}, // n + {0x8F, QChar(0x006F)}, // o + {0x90, QChar(0x0070)}, // p + {0x91, QChar(0x0071)}, // q + {0x92, QChar(0x0072)}, // r + {0x93, QChar(0x0073)}, // s + {0x94, QChar(0x0074)}, // t + {0x95, QChar(0x0075)}, // u + {0x96, QChar(0x0076)}, // v + {0x97, QChar(0x0077)}, // w + {0x98, QChar(0x0078)}, // x + {0x99, QChar(0x0079)}, // y + {0x9A, QChar(0x007A)}, // z +}; + +// Constructor +Interpret_As_IBM_285::Interpret_As_IBM_285() {} + +// Main execution function +void Interpret_As_IBM_285::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeIBM285(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] IBM-285 Decoding applied for file:" << filePath; +} + +// Decode raw data from IBM-285 encoding +QString Interpret_As_IBM_285::decodeIBM285(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; +} diff --git a/src/decoding/interpret_as_ibm_285.h b/src/decoding/interpret_as_ibm_285.h new file mode 100644 index 0000000..95bfbc6 --- /dev/null +++ b/src/decoding/interpret_as_ibm_285.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_IBM_285 { +public: + static Interpret_As_IBM_285& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_IBM_285(); + ~Interpret_As_IBM_285() = default; + + Interpret_As_IBM_285(const Interpret_As_IBM_285&) = delete; + Interpret_As_IBM_285& operator=(const Interpret_As_IBM_285&) = delete; + + QString decodeIBM285(const QByteArray& rawData); + static const std::unordered_map ebcdicTable; +}; diff --git a/src/decoding/interpret_as_ibm_290.cpp b/src/decoding/interpret_as_ibm_290.cpp new file mode 100644 index 0000000..7af4fc1 --- /dev/null +++ b/src/decoding/interpret_as_ibm_290.cpp @@ -0,0 +1,90 @@ +#include "../codeeditor.h" +#include "interpret_as_ibm_290.h" +#include +#include + +// Singleton instance +Interpret_As_IBM_290& Interpret_As_IBM_290::instance() { + static Interpret_As_IBM_290 instance; + return instance; +} + +// EBCDIC to Unicode mapping for IBM-290 (Japanese Katakana Extended) +const std::unordered_map Interpret_As_IBM_290::ebcdicTable = { + {0x41, QChar(0x30A1)}, // ァ (small a) + {0x42, QChar(0x30A2)}, // ア (a) + {0x43, QChar(0x30A3)}, // ィ (small i) + {0x44, QChar(0x30A4)}, // イ (i) + {0x45, QChar(0x30A5)}, // ゥ (small u) + {0x46, QChar(0x30A6)}, // ウ (u) + {0x47, QChar(0x30A7)}, // ェ (small e) + {0x48, QChar(0x30A8)}, // エ (e) + {0x49, QChar(0x30A9)}, // ォ (small o) + {0x4A, QChar(0x30AA)}, // オ (o) + {0x4B, QChar(0x30AB)}, // カ (ka) + {0x4C, QChar(0x30AC)}, // ガ (ga) + {0x4D, QChar(0x30AD)}, // キ (ki) + {0x4E, QChar(0x30AE)}, // ギ (gi) + {0x4F, QChar(0x30AF)}, // ク (ku) + {0x50, QChar(0x30B0)}, // グ (gu) + {0x51, QChar(0x30B1)}, // ケ (ke) + {0x52, QChar(0x30B2)}, // ゲ (ge) + {0x53, QChar(0x30B3)}, // コ (ko) + {0x54, QChar(0x30B4)}, // ゴ (go) + {0x55, QChar(0x30B5)}, // サ (sa) + {0x56, QChar(0x30B6)}, // ザ (za) + {0x57, QChar(0x30B7)}, // シ (shi) + {0x58, QChar(0x30B8)}, // ジ (ji) + {0x59, QChar(0x30B9)}, // ス (su) + {0x5A, QChar(0x30BA)}, // ズ (zu) +}; + +// Constructor +Interpret_As_IBM_290::Interpret_As_IBM_290() {} + +// Main execution function +void Interpret_As_IBM_290::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeIBM290(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] IBM-290 Decoding applied for file:" << filePath; +} + +// Decode raw data from IBM-290 encoding +QString Interpret_As_IBM_290::decodeIBM290(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; +} diff --git a/src/decoding/interpret_as_ibm_290.h b/src/decoding/interpret_as_ibm_290.h new file mode 100644 index 0000000..fc76dcf --- /dev/null +++ b/src/decoding/interpret_as_ibm_290.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_IBM_290 { +public: + static Interpret_As_IBM_290& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_IBM_290(); + ~Interpret_As_IBM_290() = default; + + Interpret_As_IBM_290(const Interpret_As_IBM_290&) = delete; + Interpret_As_IBM_290& operator=(const Interpret_As_IBM_290&) = delete; + + QString decodeIBM290(const QByteArray& rawData); + static const std::unordered_map ebcdicTable; +}; diff --git a/src/decoding/interpret_as_ibm_297.cpp b/src/decoding/interpret_as_ibm_297.cpp new file mode 100644 index 0000000..76d0a2a --- /dev/null +++ b/src/decoding/interpret_as_ibm_297.cpp @@ -0,0 +1,104 @@ +#include "../codeeditor.h" +#include "interpret_as_ibm_297.h" +#include +#include + +// Singleton instance +Interpret_As_IBM_297& Interpret_As_IBM_297::instance() { + static Interpret_As_IBM_297 instance; + return instance; +} + +// EBCDIC to Unicode mapping for IBM-297 (French EBCDIC) +const std::unordered_map Interpret_As_IBM_297::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_297::Interpret_As_IBM_297() {} + +// Main execution function +void Interpret_As_IBM_297::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeIBM297(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] IBM-297 Decoding applied for file:" << filePath; +} + +// Decode raw data from IBM-297 encoding +QString Interpret_As_IBM_297::decodeIBM297(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; +} diff --git a/src/decoding/interpret_as_ibm_297.h b/src/decoding/interpret_as_ibm_297.h new file mode 100644 index 0000000..402bd67 --- /dev/null +++ b/src/decoding/interpret_as_ibm_297.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_IBM_297 { +public: + static Interpret_As_IBM_297& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_IBM_297(); + ~Interpret_As_IBM_297() = default; + + Interpret_As_IBM_297(const Interpret_As_IBM_297&) = delete; + Interpret_As_IBM_297& operator=(const Interpret_As_IBM_297&) = delete; + + QString decodeIBM297(const QByteArray& rawData); + static const std::unordered_map ebcdicTable; +}; diff --git a/src/decoding/interpret_as_ibm_420.cpp b/src/decoding/interpret_as_ibm_420.cpp new file mode 100644 index 0000000..896d1e8 --- /dev/null +++ b/src/decoding/interpret_as_ibm_420.cpp @@ -0,0 +1,92 @@ +#include "../codeeditor.h" +#include "interpret_as_ibm_420.h" +#include +#include + +// Singleton instance +Interpret_As_IBM_420& Interpret_As_IBM_420::instance() { + static Interpret_As_IBM_420 instance; + return instance; +} + +// EBCDIC to Unicode mapping for IBM-420 (Arabic EBCDIC) +const std::unordered_map Interpret_As_IBM_420::ebcdicTable = { + {0x80, QChar(0x0627)}, // ا (Alef) + {0x81, QChar(0x0628)}, // ب (Beh) + {0x82, QChar(0x062A)}, // ت (Teh) + {0x83, QChar(0x062B)}, // ث (Theh) + {0x84, QChar(0x062C)}, // ج (Jeem) + {0x85, QChar(0x062D)}, // ح (Hah) + {0x86, QChar(0x062E)}, // خ (Khah) + {0x87, QChar(0x062F)}, // د (Dal) + {0x88, QChar(0x0630)}, // ذ (Thal) + {0x89, QChar(0x0631)}, // ر (Reh) + {0x8A, QChar(0x0632)}, // ز (Zain) + {0x8B, QChar(0x0633)}, // س (Seen) + {0x8C, QChar(0x0634)}, // ش (Sheen) + {0x8D, QChar(0x0635)}, // ص (Sad) + {0x8E, QChar(0x0636)}, // ض (Dad) + {0x8F, QChar(0x0637)}, // ط (Tah) + {0x90, QChar(0x0638)}, // ظ (Zah) + {0x91, QChar(0x0639)}, // ع (Ain) + {0x92, QChar(0x063A)}, // غ (Ghain) + {0x93, QChar(0x0641)}, // ف (Feh) + {0x94, QChar(0x0642)}, // ق (Qaf) + {0x95, QChar(0x0643)}, // ك (Kaf) + {0x96, QChar(0x0644)}, // ل (Lam) + {0x97, QChar(0x0645)}, // م (Meem) + {0x98, QChar(0x0646)}, // ن (Noon) + {0x99, QChar(0x0647)}, // ه (Heh) + {0x9A, QChar(0x0648)}, // و (Waw) + {0x9B, QChar(0x064A)}, // ي (Yeh) +}; + +// Constructor +Interpret_As_IBM_420::Interpret_As_IBM_420() {} + +// Main execution function +void Interpret_As_IBM_420::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeIBM420(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] IBM-420 Decoding applied for file:" << filePath; +} + +// Decode raw data from IBM-420 encoding +QString Interpret_As_IBM_420::decodeIBM420(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; +} diff --git a/src/decoding/interpret_as_ibm_420.h b/src/decoding/interpret_as_ibm_420.h new file mode 100644 index 0000000..004287f --- /dev/null +++ b/src/decoding/interpret_as_ibm_420.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_IBM_420 { +public: + static Interpret_As_IBM_420& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_IBM_420(); + ~Interpret_As_IBM_420() = default; + + Interpret_As_IBM_420(const Interpret_As_IBM_420&) = delete; + Interpret_As_IBM_420& operator=(const Interpret_As_IBM_420&) = delete; + + QString decodeIBM420(const QByteArray& rawData); + static const std::unordered_map ebcdicTable; +}; diff --git a/src/decoding/interpret_as_ibm_424.cpp b/src/decoding/interpret_as_ibm_424.cpp new file mode 100644 index 0000000..f84df96 --- /dev/null +++ b/src/decoding/interpret_as_ibm_424.cpp @@ -0,0 +1,91 @@ +#include "../codeeditor.h" +#include "interpret_as_ibm_424.h" +#include +#include + +// Singleton instance +Interpret_As_IBM_424& Interpret_As_IBM_424::instance() { + static Interpret_As_IBM_424 instance; + return instance; +} + +// EBCDIC to Unicode mapping for IBM-424 (Hebrew EBCDIC) +const std::unordered_map Interpret_As_IBM_424::ebcdicTable = { + {0x80, QChar(0x05D0)}, // א (Alef) + {0x81, QChar(0x05D1)}, // ב (Bet) + {0x82, QChar(0x05D2)}, // ג (Gimel) + {0x83, QChar(0x05D3)}, // ד (Dalet) + {0x84, QChar(0x05D4)}, // ה (He) + {0x85, QChar(0x05D5)}, // ו (Vav) + {0x86, QChar(0x05D6)}, // ז (Zayin) + {0x87, QChar(0x05D7)}, // ח (Het) + {0x88, QChar(0x05D8)}, // ט (Tet) + {0x89, QChar(0x05D9)}, // י (Yod) + {0x8A, QChar(0x05DA)}, // ך (Final Kaf) + {0x8B, QChar(0x05DB)}, // כ (Kaf) + {0x8C, QChar(0x05DC)}, // ל (Lamed) + {0x8D, QChar(0x05DD)}, // ם (Final Mem) + {0x8E, QChar(0x05DE)}, // מ (Mem) + {0x8F, QChar(0x05DF)}, // ן (Final Nun) + {0x90, QChar(0x05E0)}, // נ (Nun) + {0x91, QChar(0x05E1)}, // ס (Samekh) + {0x92, QChar(0x05E2)}, // ע (Ayin) + {0x93, QChar(0x05E3)}, // ף (Final Pe) + {0x94, QChar(0x05E4)}, // פ (Pe) + {0x95, QChar(0x05E5)}, // ץ (Final Tsadi) + {0x96, QChar(0x05E6)}, // צ (Tsadi) + {0x97, QChar(0x05E7)}, // ק (Qof) + {0x98, QChar(0x05E8)}, // ר (Resh) + {0x99, QChar(0x05E9)}, // ש (Shin) + {0x9A, QChar(0x05EA)}, // ת (Tav) +}; + +// Constructor +Interpret_As_IBM_424::Interpret_As_IBM_424() {} + +// Main execution function +void Interpret_As_IBM_424::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeIBM424(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] IBM-424 Decoding applied for file:" << filePath; +} + +// Decode raw data from IBM-424 encoding +QString Interpret_As_IBM_424::decodeIBM424(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; +} diff --git a/src/decoding/interpret_as_ibm_424.h b/src/decoding/interpret_as_ibm_424.h new file mode 100644 index 0000000..059925c --- /dev/null +++ b/src/decoding/interpret_as_ibm_424.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_IBM_424 { +public: + static Interpret_As_IBM_424& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_IBM_424(); + ~Interpret_As_IBM_424() = default; + + Interpret_As_IBM_424(const Interpret_As_IBM_424&) = delete; + Interpret_As_IBM_424& operator=(const Interpret_As_IBM_424&) = delete; + + QString decodeIBM424(const QByteArray& rawData); + static const std::unordered_map ebcdicTable; +}; diff --git a/src/decoding/interpret_as_ibm_437.cpp b/src/decoding/interpret_as_ibm_437.cpp new file mode 100644 index 0000000..8c969bf --- /dev/null +++ b/src/decoding/interpret_as_ibm_437.cpp @@ -0,0 +1,104 @@ +#include "../codeeditor.h" +#include "interpret_as_ibm_437.h" +#include +#include + +// Singleton instance +Interpret_As_IBM_437& Interpret_As_IBM_437::instance() { + static Interpret_As_IBM_437 instance; + return instance; +} + +// ASCII to Unicode mapping for IBM-437 +const std::unordered_map Interpret_As_IBM_437::asciiTable = { + {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_437::Interpret_As_IBM_437() {} + +// Main execution function +void Interpret_As_IBM_437::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeIBM437(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] IBM-437 Decoding applied for file:" << filePath; +} + +// Decode raw data from IBM-437 encoding +QString Interpret_As_IBM_437::decodeIBM437(const QByteArray& rawData) { + QString result; + + for (unsigned char byte : rawData) { + if (asciiTable.contains(byte)) { + result.append(asciiTable.at(byte)); + } else { + result.append(QChar(0xFFFD)); // Fallback for unmapped characters + } + } + return result; +} diff --git a/src/decoding/interpret_as_ibm_437.h b/src/decoding/interpret_as_ibm_437.h new file mode 100644 index 0000000..17510ba --- /dev/null +++ b/src/decoding/interpret_as_ibm_437.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_IBM_437 { +public: + static Interpret_As_IBM_437& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_IBM_437(); + ~Interpret_As_IBM_437() = default; + + Interpret_As_IBM_437(const Interpret_As_IBM_437&) = delete; + Interpret_As_IBM_437& operator=(const Interpret_As_IBM_437&) = delete; + + QString decodeIBM437(const QByteArray& rawData); + static const std::unordered_map asciiTable; +}; diff --git a/src/decoding/interpret_as_ibm_500.cpp b/src/decoding/interpret_as_ibm_500.cpp new file mode 100644 index 0000000..a53d2e5 --- /dev/null +++ b/src/decoding/interpret_as_ibm_500.cpp @@ -0,0 +1,104 @@ +#include "../codeeditor.h" +#include "interpret_as_ibm_500.h" +#include +#include + +// Singleton instance +Interpret_As_IBM_500& Interpret_As_IBM_500::instance() { + static Interpret_As_IBM_500 instance; + return instance; +} + +// EBCDIC to Unicode mapping for IBM-500 (International Latin-1) +const std::unordered_map Interpret_As_IBM_500::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_500::Interpret_As_IBM_500() {} + +// Main execution function +void Interpret_As_IBM_500::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeIBM500(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] IBM-500 Decoding applied for file:" << filePath; +} + +// Decode raw data from IBM-500 encoding +QString Interpret_As_IBM_500::decodeIBM500(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; +} diff --git a/src/decoding/interpret_as_ibm_500.h b/src/decoding/interpret_as_ibm_500.h new file mode 100644 index 0000000..d068025 --- /dev/null +++ b/src/decoding/interpret_as_ibm_500.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_IBM_500 { +public: + static Interpret_As_IBM_500& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_IBM_500(); + ~Interpret_As_IBM_500() = default; + + Interpret_As_IBM_500(const Interpret_As_IBM_500&) = delete; + Interpret_As_IBM_500& operator=(const Interpret_As_IBM_500&) = delete; + + QString decodeIBM500(const QByteArray& rawData); + static const std::unordered_map ebcdicTable; +}; diff --git a/src/decoding/interpret_as_ibm_775.cpp b/src/decoding/interpret_as_ibm_775.cpp new file mode 100644 index 0000000..d25b8d5 --- /dev/null +++ b/src/decoding/interpret_as_ibm_775.cpp @@ -0,0 +1,103 @@ +#include "../codeeditor.h" +#include "interpret_as_ibm_775.h" +#include +#include + +// Singleton instance +Interpret_As_IBM_775& Interpret_As_IBM_775::instance() { + static Interpret_As_IBM_775 instance; + return instance; +} + +// EBCDIC to Unicode mapping for IBM-775 (Baltic languages) +const std::unordered_map Interpret_As_IBM_775::ebcdicTable = { + {0x80, QChar(0x0104)}, // Ą + {0x81, QChar(0x0138)}, // ĸ + {0x82, QChar(0x0156)}, // Ŗ + {0x83, QChar(0x00E4)}, // ä + {0x84, QChar(0x0128)}, // Ĩ + {0x85, QChar(0x013B)}, // Ļ + {0x86, QChar(0x00E5)}, // å + {0x87, QChar(0x0112)}, // Ē + {0x88, QChar(0x0122)}, // Ģ + {0x89, QChar(0x0166)}, // Ŧ + {0x8A, QChar(0x0157)}, // ŗ + {0x8B, QChar(0x014A)}, // Ŋ + {0x8C, QChar(0x00C4)}, // Ä + {0x8D, QChar(0x00C5)}, // Å + {0x8E, QChar(0x00C9)}, // É + {0x8F, QChar(0x00E6)}, // æ + {0x90, QChar(0x00C6)}, // Æ + {0x91, QChar(0x014D)}, // ō + {0x92, QChar(0x00F4)}, // ô + {0x93, QChar(0x00F6)}, // ö + {0x94, QChar(0x00F3)}, // ó + {0x95, QChar(0x0168)}, // Ũ + {0x96, QChar(0x00DC)}, // Ü + {0x97, QChar(0x016A)}, // Ū + {0x98, QChar(0x00A2)}, // ¢ + {0x99, QChar(0x00A3)}, // £ + {0x9A, QChar(0x00A5)}, // ¥ + {0x9B, QChar(0x20A7)}, // ₧ + {0x9C, QChar(0x0192)}, // ƒ + {0x9D, QChar(0x00E1)}, // á + {0x9E, QChar(0x00ED)}, // í + {0x9F, QChar(0x00F3)}, // ó + {0xA0, QChar(0x00FA)}, // ú + {0xA1, QChar(0x017D)}, // Ž + {0xA2, QChar(0x017E)}, // ž + {0xA3, QChar(0x00F1)}, // ñ + {0xA4, QChar(0x00D1)}, // Ñ + {0xA5, QChar(0x015A)}, // Ś + {0xA6, QChar(0x015B)}, // ś +}; + +// Constructor +Interpret_As_IBM_775::Interpret_As_IBM_775() {} + +// Main execution function +void Interpret_As_IBM_775::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeIBM775(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] IBM-775 Decoding applied for file:" << filePath; +} + +// Decode raw data from IBM-775 encoding +QString Interpret_As_IBM_775::decodeIBM775(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; +} diff --git a/src/decoding/interpret_as_ibm_775.h b/src/decoding/interpret_as_ibm_775.h new file mode 100644 index 0000000..ee79d7e --- /dev/null +++ b/src/decoding/interpret_as_ibm_775.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_IBM_775 { +public: + static Interpret_As_IBM_775& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_IBM_775(); + ~Interpret_As_IBM_775() = default; + + Interpret_As_IBM_775(const Interpret_As_IBM_775&) = delete; + Interpret_As_IBM_775& operator=(const Interpret_As_IBM_775&) = delete; + + QString decodeIBM775(const QByteArray& rawData); + static const std::unordered_map ebcdicTable; +}; diff --git a/src/decoding/interpret_as_ibm_850.cpp b/src/decoding/interpret_as_ibm_850.cpp new file mode 100644 index 0000000..0f247ef --- /dev/null +++ b/src/decoding/interpret_as_ibm_850.cpp @@ -0,0 +1,104 @@ +#include "../codeeditor.h" +#include "interpret_as_ibm_850.h" +#include +#include + +// 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 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(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; +} diff --git a/src/decoding/interpret_as_ibm_850.h b/src/decoding/interpret_as_ibm_850.h new file mode 100644 index 0000000..919b687 --- /dev/null +++ b/src/decoding/interpret_as_ibm_850.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include + +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 ebcdicTable; +}; diff --git a/src/decoding/interpret_as_ibm_852.cpp b/src/decoding/interpret_as_ibm_852.cpp new file mode 100644 index 0000000..af88676 --- /dev/null +++ b/src/decoding/interpret_as_ibm_852.cpp @@ -0,0 +1,104 @@ +#include "../codeeditor.h" +#include "interpret_as_ibm_852.h" +#include +#include + +// 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 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(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; +} diff --git a/src/decoding/interpret_as_ibm_852.h b/src/decoding/interpret_as_ibm_852.h new file mode 100644 index 0000000..ba6b844 --- /dev/null +++ b/src/decoding/interpret_as_ibm_852.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include + +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 ebcdicTable; +}; diff --git a/src/decoding/interpret_as_ibm_855.cpp b/src/decoding/interpret_as_ibm_855.cpp new file mode 100644 index 0000000..4672b93 --- /dev/null +++ b/src/decoding/interpret_as_ibm_855.cpp @@ -0,0 +1,94 @@ +#include "../codeeditor.h" +#include "interpret_as_ibm_855.h" +#include +#include + +// Singleton instance +Interpret_As_IBM_855& Interpret_As_IBM_855::instance() { + static Interpret_As_IBM_855 instance; + return instance; +} + +// EBCDIC to Unicode mapping for IBM-855 (Cyrillic EBCDIC) +const std::unordered_map Interpret_As_IBM_855::ebcdicTable = { + {0x80, QChar(0x0452)}, // ђ + {0x81, QChar(0x0453)}, // ғ + {0x82, QChar(0x0451)}, // ё + {0x83, QChar(0x0454)}, // є + {0x84, QChar(0x0455)}, // ї + {0x85, QChar(0x0456)}, // і + {0x86, QChar(0x0457)}, // ґ + {0x87, QChar(0x0458)}, // ј + {0x88, QChar(0x0459)}, // љ + {0x89, QChar(0x045A)}, // њ + {0x8A, QChar(0x045B)}, // ћ + {0x8B, QChar(0x045C)}, // ќ + {0x8C, QChar(0x045E)}, // ў + {0x8D, QChar(0x045F)}, // дз + {0x8E, QChar(0x2116)}, // № + {0x8F, QChar(0x0450)}, // ѐ + {0x90, QChar(0x0401)}, // Ё + {0x91, QChar(0x0402)}, // Ђ + {0x92, QChar(0x0403)}, // Ѓ + {0x93, QChar(0x0404)}, // Є + {0x94, QChar(0x0405)}, // Ѕ + {0x95, QChar(0x0406)}, // І + {0x96, QChar(0x0407)}, // Ї + {0x97, QChar(0x0408)}, // Ј + {0x98, QChar(0x0409)}, // Љ + {0x99, QChar(0x040A)}, // Њ + {0x9A, QChar(0x040B)}, // Ћ + {0x9B, QChar(0x040C)}, // Ќ + {0x9C, QChar(0x040E)}, // Ў + {0x9D, QChar(0x040F)}, // Џ +}; + +// Constructor +Interpret_As_IBM_855::Interpret_As_IBM_855() {} + +// Main execution function +void Interpret_As_IBM_855::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeIBM855(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] IBM-855 Decoding applied for file:" << filePath; +} + +// Decode raw data from IBM-855 encoding +QString Interpret_As_IBM_855::decodeIBM855(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; +} diff --git a/src/decoding/interpret_as_ibm_855.h b/src/decoding/interpret_as_ibm_855.h new file mode 100644 index 0000000..96b2b8d --- /dev/null +++ b/src/decoding/interpret_as_ibm_855.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_IBM_855 { +public: + static Interpret_As_IBM_855& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_IBM_855(); + ~Interpret_As_IBM_855() = default; + + Interpret_As_IBM_855(const Interpret_As_IBM_855&) = delete; + Interpret_As_IBM_855& operator=(const Interpret_As_IBM_855&) = delete; + + QString decodeIBM855(const QByteArray& rawData); + static const std::unordered_map ebcdicTable; +}; diff --git a/src/decoding/interpret_as_ibm_857.cpp b/src/decoding/interpret_as_ibm_857.cpp new file mode 100644 index 0000000..a3ee411 --- /dev/null +++ b/src/decoding/interpret_as_ibm_857.cpp @@ -0,0 +1,104 @@ +#include "../codeeditor.h" +#include "interpret_as_ibm_857.h" +#include +#include + +// Singleton instance +Interpret_As_IBM_857& Interpret_As_IBM_857::instance() { + static Interpret_As_IBM_857 instance; + return instance; +} + +// EBCDIC to Unicode mapping for IBM-857 (Turkish EBCDIC) +const std::unordered_map Interpret_As_IBM_857::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(0x0131)}, // ı (Dotless i) + {0x99, QChar(0x00D6)}, // Ö + {0x9A, QChar(0x00DC)}, // Ü + {0x9B, QChar(0x011E)}, // Ğ (Uppercase G with Breve) + {0x9C, QChar(0x011F)}, // ğ (Lowercase g with Breve) + {0x9D, QChar(0x0130)}, // İ (Uppercase I with dot) + {0x9E, QChar(0x015E)}, // Ş (Uppercase S with Cedilla) + {0x9F, QChar(0x015F)}, // ş (Lowercase s with Cedilla) + {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_857::Interpret_As_IBM_857() {} + +// Main execution function +void Interpret_As_IBM_857::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeIBM857(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] IBM-857 Decoding applied for file:" << filePath; +} + +// Decode raw data from IBM-857 encoding +QString Interpret_As_IBM_857::decodeIBM857(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; +} diff --git a/src/decoding/interpret_as_ibm_857.h b/src/decoding/interpret_as_ibm_857.h new file mode 100644 index 0000000..5a2a62f --- /dev/null +++ b/src/decoding/interpret_as_ibm_857.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_IBM_857 { +public: + static Interpret_As_IBM_857& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_IBM_857(); + ~Interpret_As_IBM_857() = default; + + Interpret_As_IBM_857(const Interpret_As_IBM_857&) = delete; + Interpret_As_IBM_857& operator=(const Interpret_As_IBM_857&) = delete; + + QString decodeIBM857(const QByteArray& rawData); + static const std::unordered_map ebcdicTable; +}; diff --git a/src/decoding/interpret_as_ibm_860.cpp b/src/decoding/interpret_as_ibm_860.cpp new file mode 100644 index 0000000..445c6d4 --- /dev/null +++ b/src/decoding/interpret_as_ibm_860.cpp @@ -0,0 +1,104 @@ +#include "../codeeditor.h" +#include "interpret_as_ibm_860.h" +#include +#include + +// Singleton instance +Interpret_As_IBM_860& Interpret_As_IBM_860::instance() { + static Interpret_As_IBM_860 instance; + return instance; +} + +// EBCDIC to Unicode mapping for IBM-860 (Portuguese EBCDIC) +const std::unordered_map Interpret_As_IBM_860::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_860::Interpret_As_IBM_860() {} + +// Main execution function +void Interpret_As_IBM_860::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeIBM860(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] IBM-860 Decoding applied for file:" << filePath; +} + +// Decode raw data from IBM-860 encoding +QString Interpret_As_IBM_860::decodeIBM860(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; +} diff --git a/src/decoding/interpret_as_ibm_860.h b/src/decoding/interpret_as_ibm_860.h new file mode 100644 index 0000000..a51cc15 --- /dev/null +++ b/src/decoding/interpret_as_ibm_860.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_IBM_860 { +public: + static Interpret_As_IBM_860& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_IBM_860(); + ~Interpret_As_IBM_860() = default; + + Interpret_As_IBM_860(const Interpret_As_IBM_860&) = delete; + Interpret_As_IBM_860& operator=(const Interpret_As_IBM_860&) = delete; + + QString decodeIBM860(const QByteArray& rawData); + static const std::unordered_map ebcdicTable; +}; diff --git a/src/decoding/interpret_as_ibm_861.cpp b/src/decoding/interpret_as_ibm_861.cpp new file mode 100644 index 0000000..f046d08 --- /dev/null +++ b/src/decoding/interpret_as_ibm_861.cpp @@ -0,0 +1,104 @@ +#include "../codeeditor.h" +#include "interpret_as_ibm_861.h" +#include +#include + +// Singleton instance +Interpret_As_IBM_861& Interpret_As_IBM_861::instance() { + static Interpret_As_IBM_861 instance; + return instance; +} + +// EBCDIC to Unicode mapping for IBM-861 (Icelandic EBCDIC) +const std::unordered_map Interpret_As_IBM_861::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_861::Interpret_As_IBM_861() {} + +// Main execution function +void Interpret_As_IBM_861::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeIBM861(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] IBM-861 Decoding applied for file:" << filePath; +} + +// Decode raw data from IBM-861 encoding +QString Interpret_As_IBM_861::decodeIBM861(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; +} diff --git a/src/decoding/interpret_as_ibm_861.h b/src/decoding/interpret_as_ibm_861.h new file mode 100644 index 0000000..2869b22 --- /dev/null +++ b/src/decoding/interpret_as_ibm_861.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_IBM_861 { +public: + static Interpret_As_IBM_861& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_IBM_861(); + ~Interpret_As_IBM_861() = default; + + Interpret_As_IBM_861(const Interpret_As_IBM_861&) = delete; + Interpret_As_IBM_861& operator=(const Interpret_As_IBM_861&) = delete; + + QString decodeIBM861(const QByteArray& rawData); + static const std::unordered_map ebcdicTable; +}; diff --git a/src/decoding/interpret_as_ibm_862.cpp b/src/decoding/interpret_as_ibm_862.cpp new file mode 100644 index 0000000..03a732f --- /dev/null +++ b/src/decoding/interpret_as_ibm_862.cpp @@ -0,0 +1,96 @@ +#include "../codeeditor.h" +#include "interpret_as_ibm_862.h" +#include +#include + +// Singleton instance +Interpret_As_IBM_862& Interpret_As_IBM_862::instance() { + static Interpret_As_IBM_862 instance; + return instance; +} + +// EBCDIC to Unicode mapping for IBM-862 (Hebrew EBCDIC) +const std::unordered_map Interpret_As_IBM_862::ebcdicTable = { + {0x80, QChar(0x05D0)}, // א (Alef) + {0x81, QChar(0x05D1)}, // ב (Bet) + {0x82, QChar(0x05D2)}, // ג (Gimel) + {0x83, QChar(0x05D3)}, // ד (Dalet) + {0x84, QChar(0x05D4)}, // ה (He) + {0x85, QChar(0x05D5)}, // ו (Vav) + {0x86, QChar(0x05D6)}, // ז (Zayin) + {0x87, QChar(0x05D7)}, // ח (Het) + {0x88, QChar(0x05D8)}, // ט (Tet) + {0x89, QChar(0x05D9)}, // י (Yod) + {0x8A, QChar(0x05DA)}, // ך (Final Kaf) + {0x8B, QChar(0x05DB)}, // כ (Kaf) + {0x8C, QChar(0x05DC)}, // ל (Lamed) + {0x8D, QChar(0x05DD)}, // ם (Final Mem) + {0x8E, QChar(0x05DE)}, // מ (Mem) + {0x8F, QChar(0x05DF)}, // ן (Final Nun) + {0x90, QChar(0x05E0)}, // נ (Nun) + {0x91, QChar(0x05E1)}, // ס (Samekh) + {0x92, QChar(0x05E2)}, // ע (Ayin) + {0x93, QChar(0x05E3)}, // ף (Final Pe) + {0x94, QChar(0x05E4)}, // פ (Pe) + {0x95, QChar(0x05E5)}, // ץ (Final Tsadi) + {0x96, QChar(0x05E6)}, // צ (Tsadi) + {0x97, QChar(0x05E7)}, // ק (Qof) + {0x98, QChar(0x05E8)}, // ר (Resh) + {0x99, QChar(0x05E9)}, // ש (Shin) + {0x9A, QChar(0x05EA)}, // ת (Tav) + {0x9B, QChar(0x0020)}, // Space + {0x9C, QChar(0x002E)}, // . (Period) + {0x9D, QChar(0x002C)}, // , (Comma) + {0x9E, QChar(0x003A)}, // : (Colon) + {0x9F, QChar(0x003B)}, // ; (Semicolon) +}; + +// Constructor +Interpret_As_IBM_862::Interpret_As_IBM_862() {} + +// Main execution function +void Interpret_As_IBM_862::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeIBM862(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] IBM-862 Decoding applied for file:" << filePath; +} + +// Decode raw data from IBM-862 encoding +QString Interpret_As_IBM_862::decodeIBM862(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; +} diff --git a/src/decoding/interpret_as_ibm_862.h b/src/decoding/interpret_as_ibm_862.h new file mode 100644 index 0000000..7f296da --- /dev/null +++ b/src/decoding/interpret_as_ibm_862.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_IBM_862 { +public: + static Interpret_As_IBM_862& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_IBM_862(); + ~Interpret_As_IBM_862() = default; + + Interpret_As_IBM_862(const Interpret_As_IBM_862&) = delete; + Interpret_As_IBM_862& operator=(const Interpret_As_IBM_862&) = delete; + + QString decodeIBM862(const QByteArray& rawData); + static const std::unordered_map ebcdicTable; +}; diff --git a/src/decoding/interpret_as_ibm_863.cpp b/src/decoding/interpret_as_ibm_863.cpp new file mode 100644 index 0000000..8f26540 --- /dev/null +++ b/src/decoding/interpret_as_ibm_863.cpp @@ -0,0 +1,104 @@ +#include "../codeeditor.h" +#include "interpret_as_ibm_863.h" +#include +#include + +// Singleton instance +Interpret_As_IBM_863& Interpret_As_IBM_863::instance() { + static Interpret_As_IBM_863 instance; + return instance; +} + +// EBCDIC to Unicode mapping for IBM-863 (French Canadian EBCDIC) +const std::unordered_map Interpret_As_IBM_863::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_863::Interpret_As_IBM_863() {} + +// Main execution function +void Interpret_As_IBM_863::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeIBM863(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] IBM-863 Decoding applied for file:" << filePath; +} + +// Decode raw data from IBM-863 encoding +QString Interpret_As_IBM_863::decodeIBM863(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; +} diff --git a/src/decoding/interpret_as_ibm_863.h b/src/decoding/interpret_as_ibm_863.h new file mode 100644 index 0000000..58f8554 --- /dev/null +++ b/src/decoding/interpret_as_ibm_863.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_IBM_863 { +public: + static Interpret_As_IBM_863& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_IBM_863(); + ~Interpret_As_IBM_863() = default; + + Interpret_As_IBM_863(const Interpret_As_IBM_863&) = delete; + Interpret_As_IBM_863& operator=(const Interpret_As_IBM_863&) = delete; + + QString decodeIBM863(const QByteArray& rawData); + static const std::unordered_map ebcdicTable; +}; diff --git a/src/decoding/interpret_as_ibm_864.cpp b/src/decoding/interpret_as_ibm_864.cpp new file mode 100644 index 0000000..2049594 --- /dev/null +++ b/src/decoding/interpret_as_ibm_864.cpp @@ -0,0 +1,105 @@ +#include "../codeeditor.h" +#include "interpret_as_ibm_864.h" +#include +#include + +// Singleton instance +Interpret_As_IBM_864& Interpret_As_IBM_864::instance() { + static Interpret_As_IBM_864 instance; + return instance; +} + +// EBCDIC to Unicode mapping for IBM-864 (Arabic EBCDIC) +const std::unordered_map Interpret_As_IBM_864::ebcdicTable = { + {0x40, QChar(0x0020)}, // Space + {0x4A, QChar(0x060C)}, // ، (Arabic Comma) + {0x5A, QChar(0x061B)}, // ؛ (Arabic Semicolon) + {0x5F, QChar(0x061F)}, // ؟ (Arabic Question Mark) + {0x61, QChar(0x0621)}, // ء (Hamza) + {0x62, QChar(0x0622)}, // آ (Alef with Madda) + {0x63, QChar(0x0623)}, // أ (Alef with Hamza Above) + {0x64, QChar(0x0624)}, // ؤ (Waw with Hamza Above) + {0x65, QChar(0x0625)}, // إ (Alef with Hamza Below) + {0x66, QChar(0x0626)}, // ئ (Yeh with Hamza Above) + {0x67, QChar(0x0627)}, // ا (Alef) + {0x68, QChar(0x0628)}, // ب (Beh) + {0x69, QChar(0x0629)}, // ة (Teh Marbuta) + {0x6A, QChar(0x062A)}, // ت (Teh) + {0x6B, QChar(0x062B)}, // ث (Theh) + {0x6C, QChar(0x062C)}, // ج (Jeem) + {0x6D, QChar(0x062D)}, // ح (Hah) + {0x6E, QChar(0x062E)}, // خ (Khah) + {0x6F, QChar(0x062F)}, // د (Dal) + {0x70, QChar(0x0630)}, // ذ (Thal) + {0x71, QChar(0x0631)}, // ر (Reh) + {0x72, QChar(0x0632)}, // ز (Zain) + {0x73, QChar(0x0633)}, // س (Seen) + {0x74, QChar(0x0634)}, // ش (Sheen) + {0x75, QChar(0x0635)}, // ص (Sad) + {0x76, QChar(0x0636)}, // ض (Dad) + {0x77, QChar(0x0637)}, // ط (Tah) + {0x78, QChar(0x0638)}, // ظ (Zah) + {0x79, QChar(0x0639)}, // ع (Ain) + {0x7A, QChar(0x063A)}, // غ (Ghain) + {0x7B, QChar(0x0640)}, // ـ (Tatweel) + {0x7C, QChar(0x0641)}, // ف (Feh) + {0x7D, QChar(0x0642)}, // ق (Qaf) + {0x7E, QChar(0x0643)}, // ك (Kaf) + {0x7F, QChar(0x0644)}, // ل (Lam) + {0x80, QChar(0x0645)}, // م (Meem) + {0x81, QChar(0x0646)}, // ن (Noon) + {0x82, QChar(0x0647)}, // ه (Heh) + {0x83, QChar(0x0648)}, // و (Waw) + {0x84, QChar(0x0649)}, // ى (Alef Maksura) + {0x85, QChar(0x064A)}, // ي (Yeh) +}; + +// Constructor +Interpret_As_IBM_864::Interpret_As_IBM_864() {} + +// Main execution function +void Interpret_As_IBM_864::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeIBM864(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] IBM-864 Decoding applied for file:" << filePath; +} + +// Decode raw data from IBM-864 encoding +QString Interpret_As_IBM_864::decodeIBM864(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; +} diff --git a/src/decoding/interpret_as_ibm_864.h b/src/decoding/interpret_as_ibm_864.h new file mode 100644 index 0000000..dc2a86d --- /dev/null +++ b/src/decoding/interpret_as_ibm_864.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_IBM_864 { +public: + static Interpret_As_IBM_864& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_IBM_864(); + ~Interpret_As_IBM_864() = default; + + Interpret_As_IBM_864(const Interpret_As_IBM_864&) = delete; + Interpret_As_IBM_864& operator=(const Interpret_As_IBM_864&) = delete; + + QString decodeIBM864(const QByteArray& rawData); + static const std::unordered_map ebcdicTable; +}; diff --git a/src/decoding/interpret_as_ibm_865.cpp b/src/decoding/interpret_as_ibm_865.cpp new file mode 100644 index 0000000..238ed87 --- /dev/null +++ b/src/decoding/interpret_as_ibm_865.cpp @@ -0,0 +1,104 @@ +#include "../codeeditor.h" +#include "interpret_as_ibm_865.h" +#include +#include + +// Singleton instance +Interpret_As_IBM_865& Interpret_As_IBM_865::instance() { + static Interpret_As_IBM_865 instance; + return instance; +} + +// EBCDIC to Unicode mapping for IBM-865 (Nordic EBCDIC) +const std::unordered_map Interpret_As_IBM_865::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_865::Interpret_As_IBM_865() {} + +// Main execution function +void Interpret_As_IBM_865::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeIBM865(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] IBM-865 Decoding applied for file:" << filePath; +} + +// Decode raw data from IBM-865 encoding +QString Interpret_As_IBM_865::decodeIBM865(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; +} diff --git a/src/decoding/interpret_as_ibm_865.h b/src/decoding/interpret_as_ibm_865.h new file mode 100644 index 0000000..888fd94 --- /dev/null +++ b/src/decoding/interpret_as_ibm_865.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_IBM_865 { +public: + static Interpret_As_IBM_865& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_IBM_865(); + ~Interpret_As_IBM_865() = default; + + Interpret_As_IBM_865(const Interpret_As_IBM_865&) = delete; + Interpret_As_IBM_865& operator=(const Interpret_As_IBM_865&) = delete; + + QString decodeIBM865(const QByteArray& rawData); + static const std::unordered_map ebcdicTable; +}; diff --git a/src/decoding/interpret_as_ibm_866.cpp b/src/decoding/interpret_as_ibm_866.cpp new file mode 100644 index 0000000..37aa2a8 --- /dev/null +++ b/src/decoding/interpret_as_ibm_866.cpp @@ -0,0 +1,112 @@ +#include "../codeeditor.h" +#include "interpret_as_ibm_866.h" +#include +#include + +// Singleton instance +Interpret_As_IBM_866& Interpret_As_IBM_866::instance() { + static Interpret_As_IBM_866 instance; + return instance; +} + +// EBCDIC to Unicode mapping for IBM-866 (Cyrillic EBCDIC) +const std::unordered_map Interpret_As_IBM_866::ebcdicTable = { + {0x80, QChar(0x0410)}, // А + {0x81, QChar(0x0411)}, // Б + {0x82, QChar(0x0412)}, // В + {0x83, QChar(0x0413)}, // Г + {0x84, QChar(0x0414)}, // Д + {0x85, QChar(0x0415)}, // Е + {0x86, QChar(0x0416)}, // Ж + {0x87, QChar(0x0417)}, // З + {0x88, QChar(0x0418)}, // И + {0x89, QChar(0x0419)}, // Й + {0x8A, QChar(0x041A)}, // К + {0x8B, QChar(0x041B)}, // Л + {0x8C, QChar(0x041C)}, // М + {0x8D, QChar(0x041D)}, // Н + {0x8E, QChar(0x041E)}, // О + {0x8F, QChar(0x041F)}, // П + {0x90, QChar(0x0420)}, // Р + {0x91, QChar(0x0421)}, // С + {0x92, QChar(0x0422)}, // Т + {0x93, QChar(0x0423)}, // У + {0x94, QChar(0x0424)}, // Ф + {0x95, QChar(0x0425)}, // Х + {0x96, QChar(0x0426)}, // Ц + {0x97, QChar(0x0427)}, // Ч + {0x98, QChar(0x0428)}, // Ш + {0x99, QChar(0x0429)}, // Щ + {0x9A, QChar(0x042A)}, // Ъ + {0x9B, QChar(0x042B)}, // Ы + {0x9C, QChar(0x042C)}, // Ь + {0x9D, QChar(0x042D)}, // Э + {0x9E, QChar(0x042E)}, // Ю + {0x9F, QChar(0x042F)}, // Я + {0xA0, QChar(0x0430)}, // а + {0xA1, QChar(0x0431)}, // б + {0xA2, QChar(0x0432)}, // в + {0xA3, QChar(0x0433)}, // г + {0xA4, QChar(0x0434)}, // д + {0xA5, QChar(0x0435)}, // е + {0xA6, QChar(0x0436)}, // ж + {0xA7, QChar(0x0437)}, // з + {0xA8, QChar(0x0438)}, // и + {0xA9, QChar(0x0439)}, // й + {0xAA, QChar(0x043A)}, // к + {0xAB, QChar(0x043B)}, // л + {0xAC, QChar(0x043C)}, // м + {0xAD, QChar(0x043D)}, // н + {0xAE, QChar(0x043E)}, // о + {0xAF, QChar(0x043F)}, // п +}; + +// Constructor +Interpret_As_IBM_866::Interpret_As_IBM_866() {} + +// Main execution function +void Interpret_As_IBM_866::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeIBM866(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] IBM-866 Decoding applied for file:" << filePath; +} + +// Decode raw data from IBM-866 encoding +QString Interpret_As_IBM_866::decodeIBM866(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; +} diff --git a/src/decoding/interpret_as_ibm_866.h b/src/decoding/interpret_as_ibm_866.h new file mode 100644 index 0000000..762b298 --- /dev/null +++ b/src/decoding/interpret_as_ibm_866.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_IBM_866 { +public: + static Interpret_As_IBM_866& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_IBM_866(); + ~Interpret_As_IBM_866() = default; + + Interpret_As_IBM_866(const Interpret_As_IBM_866&) = delete; + Interpret_As_IBM_866& operator=(const Interpret_As_IBM_866&) = delete; + + QString decodeIBM866(const QByteArray& rawData); + static const std::unordered_map ebcdicTable; +}; diff --git a/src/decoding/interpret_as_ibm_868.cpp b/src/decoding/interpret_as_ibm_868.cpp new file mode 100644 index 0000000..afe1287 --- /dev/null +++ b/src/decoding/interpret_as_ibm_868.cpp @@ -0,0 +1,99 @@ +#include "../codeeditor.h" +#include "interpret_as_ibm_868.h" +#include +#include + +// Singleton instance +Interpret_As_IBM_868& Interpret_As_IBM_868::instance() { + static Interpret_As_IBM_868 instance; + return instance; +} + +// EBCDIC to Unicode mapping for IBM-868 (Arabic EBCDIC) +const std::unordered_map Interpret_As_IBM_868::ebcdicTable = { + {0x40, QChar(0x0020)}, // Space + {0x4A, QChar(0x060C)}, // ، (Arabic Comma) + {0x5A, QChar(0x061B)}, // ؛ (Arabic Semicolon) + {0x5F, QChar(0x061F)}, // ؟ (Arabic Question Mark) + {0x61, QChar(0x0621)}, // ء (Hamza) + {0x62, QChar(0x0622)}, // آ (Alef with Madda) + {0x63, QChar(0x0623)}, // أ (Alef with Hamza Above) + {0x64, QChar(0x0624)}, // ؤ (Waw with Hamza Above) + {0x65, QChar(0x0625)}, // إ (Alef with Hamza Below) + {0x66, QChar(0x0626)}, // ئ (Yeh with Hamza Above) + {0x67, QChar(0x0627)}, // ا (Alef) + {0x68, QChar(0x0628)}, // ب (Beh) + {0x69, QChar(0x0629)}, // ة (Teh Marbuta) + {0x6A, QChar(0x062A)}, // ت (Teh) + {0x6B, QChar(0x062B)}, // ث (Theh) + {0x6C, QChar(0x062C)}, // ج (Jeem) + {0x6D, QChar(0x062D)}, // ح (Hah) + {0x6E, QChar(0x062E)}, // خ (Khah) + {0x6F, QChar(0x062F)}, // د (Dal) + {0x70, QChar(0x0630)}, // ذ (Thal) + {0x71, QChar(0x0631)}, // ر (Reh) + {0x72, QChar(0x0632)}, // ز (Zain) + {0x73, QChar(0x0633)}, // س (Seen) + {0x74, QChar(0x0634)}, // ش (Sheen) + {0x75, QChar(0x0635)}, // ص (Sad) + {0x76, QChar(0x0636)}, // ض (Dad) + {0x77, QChar(0x0637)}, // ط (Tah) + {0x78, QChar(0x0638)}, // ظ (Zah) + {0x79, QChar(0x0639)}, // ع (Ain) + {0x7A, QChar(0x063A)}, // غ (Ghain) + {0x7B, QChar(0x0640)}, // ـ (Tatweel) + {0x7C, QChar(0x0641)}, // ف (Feh) + {0x7D, QChar(0x0642)}, // ق (Qaf) + {0x7E, QChar(0x0643)}, // ك (Kaf) + {0x7F, QChar(0x0644)}, // ل (Lam) +}; + +// Constructor +Interpret_As_IBM_868::Interpret_As_IBM_868() {} + +// Main execution function +void Interpret_As_IBM_868::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeIBM868(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] IBM-868 Decoding applied for file:" << filePath; +} + +// Decode raw data from IBM-868 encoding +QString Interpret_As_IBM_868::decodeIBM868(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; +} diff --git a/src/decoding/interpret_as_ibm_868.h b/src/decoding/interpret_as_ibm_868.h new file mode 100644 index 0000000..d3863b8 --- /dev/null +++ b/src/decoding/interpret_as_ibm_868.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_IBM_868 { +public: + static Interpret_As_IBM_868& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_IBM_868(); + ~Interpret_As_IBM_868() = default; + + Interpret_As_IBM_868(const Interpret_As_IBM_868&) = delete; + Interpret_As_IBM_868& operator=(const Interpret_As_IBM_868&) = delete; + + QString decodeIBM868(const QByteArray& rawData); + static const std::unordered_map ebcdicTable; +}; diff --git a/src/decoding/interpret_as_ibm_869.cpp b/src/decoding/interpret_as_ibm_869.cpp new file mode 100644 index 0000000..5b67ccc --- /dev/null +++ b/src/decoding/interpret_as_ibm_869.cpp @@ -0,0 +1,99 @@ +#include "../codeeditor.h" +#include "interpret_as_ibm_869.h" +#include +#include + +// Singleton instance +Interpret_As_IBM_869& Interpret_As_IBM_869::instance() { + static Interpret_As_IBM_869 instance; + return instance; +} + +// EBCDIC to Unicode mapping for IBM-869 (Greek EBCDIC) +const std::unordered_map Interpret_As_IBM_869::ebcdicTable = { + {0x40, QChar(0x0020)}, // Space + {0x4A, QChar(0x0384)}, // ΄ (Greek Tonos) + {0x5A, QChar(0x003B)}, // ; (Semicolon) + {0x5F, QChar(0x0387)}, // · (Greek Ano Teleia) + {0x61, QChar(0x0391)}, // Α (Alpha) + {0x62, QChar(0x0392)}, // Β (Beta) + {0x63, QChar(0x0393)}, // Γ (Gamma) + {0x64, QChar(0x0394)}, // Δ (Delta) + {0x65, QChar(0x0395)}, // Ε (Epsilon) + {0x66, QChar(0x0396)}, // Ζ (Zeta) + {0x67, QChar(0x0397)}, // Η (Eta) + {0x68, QChar(0x0398)}, // Θ (Theta) + {0x69, QChar(0x0399)}, // Ι (Iota) + {0x6A, QChar(0x039A)}, // Κ (Kappa) + {0x6B, QChar(0x039B)}, // Λ (Lambda) + {0x6C, QChar(0x039C)}, // Μ (Mu) + {0x6D, QChar(0x039D)}, // Ν (Nu) + {0x6E, QChar(0x039E)}, // Ξ (Xi) + {0x6F, QChar(0x039F)}, // Ο (Omicron) + {0x70, QChar(0x03A0)}, // Π (Pi) + {0x71, QChar(0x03A1)}, // Ρ (Rho) + {0x72, QChar(0x03A3)}, // Σ (Sigma) + {0x73, QChar(0x03A4)}, // Τ (Tau) + {0x74, QChar(0x03A5)}, // Υ (Upsilon) + {0x75, QChar(0x03A6)}, // Φ (Phi) + {0x76, QChar(0x03A7)}, // Χ (Chi) + {0x77, QChar(0x03A8)}, // Ψ (Psi) + {0x78, QChar(0x03A9)}, // Ω (Omega) + {0x79, QChar(0x03B1)}, // α (alpha) + {0x7A, QChar(0x03B2)}, // β (beta) + {0x7B, QChar(0x03B3)}, // γ (gamma) + {0x7C, QChar(0x03B4)}, // δ (delta) + {0x7D, QChar(0x03B5)}, // ε (epsilon) + {0x7E, QChar(0x03B6)}, // ζ (zeta) + {0x7F, QChar(0x03B7)}, // η (eta) +}; + +// Constructor +Interpret_As_IBM_869::Interpret_As_IBM_869() {} + +// Main execution function +void Interpret_As_IBM_869::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeIBM869(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] IBM-869 Decoding applied for file:" << filePath; +} + +// Decode raw data from IBM-869 encoding +QString Interpret_As_IBM_869::decodeIBM869(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; +} diff --git a/src/decoding/interpret_as_ibm_869.h b/src/decoding/interpret_as_ibm_869.h new file mode 100644 index 0000000..da18091 --- /dev/null +++ b/src/decoding/interpret_as_ibm_869.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_IBM_869 { +public: + static Interpret_As_IBM_869& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_IBM_869(); + ~Interpret_As_IBM_869() = default; + + Interpret_As_IBM_869(const Interpret_As_IBM_869&) = delete; + Interpret_As_IBM_869& operator=(const Interpret_As_IBM_869&) = delete; + + QString decodeIBM869(const QByteArray& rawData); + static const std::unordered_map ebcdicTable; +}; diff --git a/src/decoding/interpret_as_ibm_870.cpp b/src/decoding/interpret_as_ibm_870.cpp new file mode 100644 index 0000000..d2d1acb --- /dev/null +++ b/src/decoding/interpret_as_ibm_870.cpp @@ -0,0 +1,87 @@ +#include "../codeeditor.h" +#include "interpret_as_ibm_870.h" +#include +#include + +// Singleton instance +Interpret_As_IBM_870& Interpret_As_IBM_870::instance() { + static Interpret_As_IBM_870 instance; + return instance; +} + +// EBCDIC to Unicode mapping for IBM-870 (Eastern European EBCDIC) +const std::unordered_map Interpret_As_IBM_870::ebcdicTable = { + {0x40, QChar(0x0020)}, // Space + {0x4A, QChar(0x002E)}, // . (Full Stop) + {0x5A, QChar(0x00A7)}, // § (Section Sign) + {0x5F, QChar(0x0021)}, // ! (Exclamation Mark) + {0x61, QChar(0x0104)}, // Ą (A with Ogonek) + {0x62, QChar(0x00C1)}, // Á (A with Acute) + {0x63, QChar(0x00C2)}, //  (A with Circumflex) + {0x64, QChar(0x0106)}, // Ć (C with Acute) + {0x65, QChar(0x00C4)}, // Ä (A with Diaeresis) + {0x66, QChar(0x00C5)}, // Å (A with Ring) + {0x67, QChar(0x00C7)}, // Ç (C with Cedilla) + {0x68, QChar(0x00C9)}, // É (E with Acute) + {0x69, QChar(0x00D3)}, // Ó (O with Acute) + {0x6A, QChar(0x0141)}, // Ł (L with Stroke) + {0x6B, QChar(0x0143)}, // Ń (N with Acute) + {0x6C, QChar(0x00D6)}, // Ö (O with Diaeresis) + {0x6D, QChar(0x00DC)}, // Ü (U with Diaeresis) + {0x6E, QChar(0x00D8)}, // Ø (O with Stroke) + {0x7A, QChar(0x0118)}, // Ę (E with Ogonek) + {0x7B, QChar(0x011A)}, // Ě (E with Caron) + {0x7C, QChar(0x00DE)}, // Þ (Thorn) + {0x7D, QChar(0x00D0)}, // Ð (Eth) + {0x7E, QChar(0x00F0)}, // ð (eth) +}; + +// Constructor +Interpret_As_IBM_870::Interpret_As_IBM_870() {} + +// Main execution function +void Interpret_As_IBM_870::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeIBM870(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] IBM-870 Decoding applied for file:" << filePath; +} + +// Decode raw data from IBM-870 encoding +QString Interpret_As_IBM_870::decodeIBM870(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; +} diff --git a/src/decoding/interpret_as_ibm_870.h b/src/decoding/interpret_as_ibm_870.h new file mode 100644 index 0000000..79450a5 --- /dev/null +++ b/src/decoding/interpret_as_ibm_870.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_IBM_870 { +public: + static Interpret_As_IBM_870& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_IBM_870(); + ~Interpret_As_IBM_870() = default; + + Interpret_As_IBM_870(const Interpret_As_IBM_870&) = delete; + Interpret_As_IBM_870& operator=(const Interpret_As_IBM_870&) = delete; + + QString decodeIBM870(const QByteArray& rawData); + static const std::unordered_map ebcdicTable; +}; diff --git a/src/decoding/interpret_as_ibm_871.cpp b/src/decoding/interpret_as_ibm_871.cpp new file mode 100644 index 0000000..266625f --- /dev/null +++ b/src/decoding/interpret_as_ibm_871.cpp @@ -0,0 +1,92 @@ +#include "../codeeditor.h" +#include "interpret_as_ibm_871.h" +#include +#include + +// Singleton instance +Interpret_As_IBM_871& Interpret_As_IBM_871::instance() { + static Interpret_As_IBM_871 instance; + return instance; +} + +// EBCDIC to Unicode mapping for IBM-871 (Icelandic EBCDIC) +const std::unordered_map Interpret_As_IBM_871::ebcdicTable = { + {0x40, QChar(0x0020)}, // Space + {0x41, QChar(0x00C1)}, // Á + {0x42, QChar(0x00C2)}, //  + {0x43, QChar(0x00C9)}, // É + {0x44, QChar(0x00CD)}, // Í + {0x45, QChar(0x00D3)}, // Ó + {0x46, QChar(0x00DA)}, // Ú + {0x47, QChar(0x00DD)}, // Ý + {0x48, QChar(0x00E1)}, // á + {0x49, QChar(0x00E2)}, // â + {0x4A, QChar(0x00E9)}, // é + {0x4B, QChar(0x00ED)}, // í + {0x4C, QChar(0x00F3)}, // ó + {0x4D, QChar(0x00FA)}, // ú + {0x4E, QChar(0x00FD)}, // ý + {0x4F, QChar(0x00FE)}, // þ + {0x50, QChar(0x00D0)}, // Ð + {0x51, QChar(0x00F0)}, // ð + {0x5A, QChar(0x00C0)}, // À + {0x5B, QChar(0x00C3)}, // à + {0x5C, QChar(0x00E3)}, // ã + {0x5F, QChar(0x00DF)}, // ß + {0x6A, QChar(0x00F6)}, // ö + {0x7A, QChar(0x00D6)}, // Ö + {0x7B, QChar(0x00C4)}, // Ä + {0x7C, QChar(0x00E4)}, // ä + {0x7E, QChar(0x00DC)}, // Ü + {0x7F, QChar(0x00FC)}, // ü +}; + +// Constructor +Interpret_As_IBM_871::Interpret_As_IBM_871() {} + +// Main execution function +void Interpret_As_IBM_871::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeIBM871(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] IBM-871 Decoding applied for file:" << filePath; +} + +// Decode raw data from IBM-871 encoding +QString Interpret_As_IBM_871::decodeIBM871(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; +} diff --git a/src/decoding/interpret_as_ibm_871.h b/src/decoding/interpret_as_ibm_871.h new file mode 100644 index 0000000..c2ba119 --- /dev/null +++ b/src/decoding/interpret_as_ibm_871.h @@ -0,0 +1,21 @@ +#pragma once +#include +#include +#include +#include + +class Interpret_As_IBM_871 { +public: + static Interpret_As_IBM_871& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_IBM_871(); + ~Interpret_As_IBM_871() = default; + + Interpret_As_IBM_871(const Interpret_As_IBM_871&) = delete; + Interpret_As_IBM_871& operator=(const Interpret_As_IBM_871&) = delete; + + QString decodeIBM871(const QByteArray& rawData); + static const std::unordered_map ebcdicTable; +}; diff --git a/src/decoding/interpret_as_ibm_918.cpp b/src/decoding/interpret_as_ibm_918.cpp new file mode 100644 index 0000000..4eea80f --- /dev/null +++ b/src/decoding/interpret_as_ibm_918.cpp @@ -0,0 +1,131 @@ +#include "../codeeditor.h" +#include "interpret_as_ibm_918.h" +#include +#include + +// Singleton instance +Interpret_As_IBM_918& Interpret_As_IBM_918::instance() { + static Interpret_As_IBM_918 instance; + return instance; +} + +// EBCDIC to Unicode mapping for IBM-918 (Limited Arabic subset) +const std::unordered_map Interpret_As_IBM_918::ebcdicTable = { + // Control Characters and Punctuation + {0x40, QChar(0x0020)}, // Space + {0x4A, QChar(0x060C)}, // ، (Arabic Comma) + {0x5A, QChar(0x061B)}, // ؛ (Arabic Semicolon) + {0x5F, QChar(0x061F)}, // ؟ (Arabic Question Mark) + + // Core Arabic Letters (آأؤإئ) + {0xC1, QChar(0x0622)}, // آ (Alef with Madda) + {0xC2, QChar(0x0623)}, // أ (Alef with Hamza Above) + {0xC3, QChar(0x0624)}, // ؤ (Waw with Hamza Above) + {0xC4, QChar(0x0625)}, // إ (Alef with Hamza Below) + {0xC5, QChar(0x0626)}, // ئ (Yeh with Hamza Above) + {0x66, QChar(0x0627)}, // ا (Alef) + {0x67, QChar(0x0628)}, // ب (Beh) + {0x68, QChar(0x0629)}, // ة (Teh Marbuta) + {0x69, QChar(0x062A)}, // ت (Teh) + {0x6A, QChar(0x062B)}, // ث (Theh) + {0x6B, QChar(0x062C)}, // ج (Jeem) + {0x6C, QChar(0x062D)}, // ح (Hah) + {0x6D, QChar(0x062E)}, // خ (Khah) + {0x6E, QChar(0x062F)}, // د (Dal) + {0x6F, QChar(0x0630)}, // ذ (Thal) + {0x70, QChar(0x0631)}, // ر (Reh) + {0x71, QChar(0x0632)}, // ز (Zain) + {0x72, QChar(0x0633)}, // س (Seen) + {0x73, QChar(0x0634)}, // ش (Sheen) + {0x74, QChar(0x0635)}, // ص (Sad) + {0x75, QChar(0x0636)}, // ض (Dad) + {0x76, QChar(0x0637)}, // ط (Tah) + {0x77, QChar(0x0638)}, // ظ (Zah) + {0x78, QChar(0x0639)}, // ع (Ain) + {0x79, QChar(0x063A)}, // غ (Ghain) + + // Arabic Tatweel and Digits + {0x80, QChar(0x0640)}, // ـ (Tatweel) + {0x81, QChar(0x0641)}, // ف (Feh) + {0x82, QChar(0x0642)}, // ق (Qaf) + {0x83, QChar(0x0643)}, // ك (Kaf) + {0x84, QChar(0x0644)}, // ل (Lam) + {0x85, QChar(0x0645)}, // م (Meem) + {0x86, QChar(0x0646)}, // ن (Noon) + {0x87, QChar(0x0647)}, // ه (Heh) + {0x88, QChar(0x0648)}, // و (Waw) + {0x89, QChar(0x0649)}, // ى (Alef Maksura) + {0x8A, QChar(0x064A)}, // ي (Yeh) + + // Tashkeel (Diacritics) + {0x8B, QChar(0x064B)}, // ً (Fathatan) + {0x8C, QChar(0x064C)}, // ٌ (Dammatan) + {0x8D, QChar(0x064D)}, // ٍ (Kasratan) + {0x8E, QChar(0x064E)}, // َ (Fatha) + {0x8F, QChar(0x064F)}, // ُ (Damma) + {0x90, QChar(0x0650)}, // ِ (Kasra) + {0x91, QChar(0x0651)}, // ّ (Shadda) + {0x92, QChar(0x0652)}, // ْ (Sukun) + + // Arabic-Indic Digits + {0xA1, QChar(0x0660)}, // ٠ (Zero) + {0xA2, QChar(0x0661)}, // ١ (One) + {0xA3, QChar(0x0662)}, // ٢ (Two) + {0xA4, QChar(0x0663)}, // ٣ (Three) + {0xA5, QChar(0x0664)}, // ٤ (Four) + {0xA6, QChar(0x0665)}, // ٥ (Five) + {0xA7, QChar(0x0666)}, // ٦ (Six) + {0xA8, QChar(0x0667)}, // ٧ (Seven) + {0xA9, QChar(0x0668)}, // ٨ (Eight) + {0xAA, QChar(0x0669)}, // ٩ (Nine) +}; + +// Constructor +Interpret_As_IBM_918::Interpret_As_IBM_918() {} + +// Main execution function +void Interpret_As_IBM_918::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeIBM918(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] IBM-918 Decoding applied for file:" << filePath; +} + +// Decode raw data from IBM-918 encoding +QString Interpret_As_IBM_918::decodeIBM918(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; +} diff --git a/src/decoding/interpret_as_ibm_918.h b/src/decoding/interpret_as_ibm_918.h new file mode 100644 index 0000000..166e754 --- /dev/null +++ b/src/decoding/interpret_as_ibm_918.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_IBM_918 { +public: + static Interpret_As_IBM_918& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_IBM_918(); + ~Interpret_As_IBM_918() = default; + + Interpret_As_IBM_918(const Interpret_As_IBM_918&) = delete; + Interpret_As_IBM_918& operator=(const Interpret_As_IBM_918&) = delete; + + QString decodeIBM918(const QByteArray& rawData); + static const std::unordered_map ebcdicTable; +}; diff --git a/src/decoding/interpret_as_ibm_thai.cpp b/src/decoding/interpret_as_ibm_thai.cpp new file mode 100644 index 0000000..722897b --- /dev/null +++ b/src/decoding/interpret_as_ibm_thai.cpp @@ -0,0 +1,137 @@ +#include "../codeeditor.h" +#include "interpret_as_ibm_thai.h" +#include +#include + +// Singleton instance +Interpret_As_IBM_Thai& Interpret_As_IBM_Thai::instance() { + static Interpret_As_IBM_Thai instance; + return instance; +} + +// IBM Thai Code Page mapping +const std::unordered_map Interpret_As_IBM_Thai::codePageTable = { + {0x41, QChar(0x0041)}, // A + {0x42, QChar(0x0042)}, // B + {0x43, QChar(0x0043)}, // C + {0x44, QChar(0x0044)}, // D + {0x45, QChar(0x0045)}, // E + {0x46, QChar(0x0046)}, // F + {0x47, QChar(0x0047)}, // G + {0x48, QChar(0x0048)}, // H + {0x49, QChar(0x0049)}, // I + {0x4A, QChar(0x004A)}, // J + {0x4B, QChar(0x004B)}, // K + {0x4C, QChar(0x004C)}, // L + {0x4D, QChar(0x004D)}, // M + {0x4E, QChar(0x004E)}, // N + {0x4F, QChar(0x004F)}, // O + {0x50, QChar(0x0050)}, // P + {0x51, QChar(0x0051)}, // Q + {0x52, QChar(0x0052)}, // R + {0x53, QChar(0x0053)}, // S + {0x54, QChar(0x0054)}, // T + {0x55, QChar(0x0055)}, // U + {0x56, QChar(0x0056)}, // V + {0x57, QChar(0x0057)}, // W + {0x58, QChar(0x0058)}, // X + {0x59, QChar(0x0059)}, // Y + {0x5A, QChar(0x005A)}, // Z + {0xA1, QChar(0x0E01)}, // ก + {0xA2, QChar(0x0E02)}, // ข + {0xA3, QChar(0x0E03)}, // ฃ + {0xA4, QChar(0x0E04)}, // ค + {0xA5, QChar(0x0E05)}, // ฅ + {0xA6, QChar(0x0E06)}, // ฆ + {0xA7, QChar(0x0E07)}, // ง + {0xA8, QChar(0x0E08)}, // จ + {0xA9, QChar(0x0E09)}, // ฉ + {0xAA, QChar(0x0E0A)}, // ช + {0xAB, QChar(0x0E0B)}, // ซ + {0xAC, QChar(0x0E0C)}, // ฌ + {0xAD, QChar(0x0E0D)}, // ญ + {0xAE, QChar(0x0E0E)}, // ฎ + {0xAF, QChar(0x0E0F)}, // ฏ + {0xB0, QChar(0x0E10)}, // ฐ + {0xB1, QChar(0x0E11)}, // ฑ + {0xB2, QChar(0x0E12)}, // ฒ + {0xB3, QChar(0x0E13)}, // ณ + {0xB4, QChar(0x0E14)}, // ด + {0xB5, QChar(0x0E15)}, // ต + {0xB6, QChar(0x0E16)}, // ถ + {0xB7, QChar(0x0E17)}, // ท + {0xB8, QChar(0x0E18)}, // ธ + {0xB9, QChar(0x0E19)}, // น + {0xBA, QChar(0x0E1A)}, // บ + {0xBB, QChar(0x0E1B)}, // ป + {0xBC, QChar(0x0E1C)}, // ผ + {0xBD, QChar(0x0E1D)}, // ฝ + {0xBE, QChar(0x0E1E)}, // พ + {0xBF, QChar(0x0E1F)}, // ฟ + {0xC0, QChar(0x0E20)}, // ภ + {0xC1, QChar(0x0E21)}, // ม + {0xC2, QChar(0x0E22)}, // ย + {0xC3, QChar(0x0E23)}, // ร + {0xC4, QChar(0x0E24)}, // ฤ + {0xC5, QChar(0x0E25)}, // ล + {0xC6, QChar(0x0E26)}, // ฦ + {0xC7, QChar(0x0E27)}, // ว + {0xC8, QChar(0x0E28)}, // ศ + {0xC9, QChar(0x0E29)}, // ษ + {0xCA, QChar(0x0E2A)}, // ส + {0xCB, QChar(0x0E2B)}, // ห + {0xCC, QChar(0x0E2C)}, // ฬ + {0xCD, QChar(0x0E2D)}, // อ + {0xCE, QChar(0x0E2E)}, // ฮ + {0xCF, QChar(0x0E2F)}, // ฯ +}; + +// Constructor +Interpret_As_IBM_Thai::Interpret_As_IBM_Thai() {} + +// Main execution function +void Interpret_As_IBM_Thai::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeIBMThai(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] IBM-Thai Decoding applied for file:" << filePath; +} + +// Decode raw data from IBM-Thai encoding +QString Interpret_As_IBM_Thai::decodeIBMThai(const QByteArray& rawData) { + QString result; + + for (unsigned char byte : rawData) { + if (codePageTable.contains(byte)) { + result.append(codePageTable.at(byte)); + } else { + result.append(QChar(0xFFFD)); // Fallback for unmapped characters + } + } + return result; +} diff --git a/src/decoding/interpret_as_ibm_thai.h b/src/decoding/interpret_as_ibm_thai.h new file mode 100644 index 0000000..3e8201e --- /dev/null +++ b/src/decoding/interpret_as_ibm_thai.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_IBM_Thai { +public: + static Interpret_As_IBM_Thai& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_IBM_Thai(); + ~Interpret_As_IBM_Thai() = default; + + Interpret_As_IBM_Thai(const Interpret_As_IBM_Thai&) = delete; + Interpret_As_IBM_Thai& operator=(const Interpret_As_IBM_Thai&) = delete; + + QString decodeIBMThai(const QByteArray& rawData); + static const std::unordered_map codePageTable; +}; diff --git a/src/decoding/interpret_as_iso_2022_cn.cpp b/src/decoding/interpret_as_iso_2022_cn.cpp new file mode 100644 index 0000000..931f324 --- /dev/null +++ b/src/decoding/interpret_as_iso_2022_cn.cpp @@ -0,0 +1,97 @@ +#include "../codeeditor.h" +#include "interpret_as_iso_2022_cn.h" +#include +#include + +// Singleton instance +Interpret_As_ISO_2022_CN& Interpret_As_ISO_2022_CN::instance() { + static Interpret_As_ISO_2022_CN instance; + return instance; +} + +// GB Table for ISO-2022-CN (Limited set of GB2312 mappings) +const std::unordered_map Interpret_As_ISO_2022_CN::gbTable = { + {QByteArray("\x21\x21"), QChar(0x3000)}, // Ideographic space + {QByteArray("\x21\x22"), QChar(0x3001)}, // 。 (period) + {QByteArray("\x21\x23"), QChar(0x3002)}, // 、 (comma) + {QByteArray("\x21\x27"), QChar(0x4E00)}, // 一 (one) + {QByteArray("\x21\x28"), QChar(0x4E8C)}, // 二 (two) + {QByteArray("\x21\x29"), QChar(0x4E09)}, // 三 (three) + {QByteArray("\x21\x2A"), QChar(0x56DB)}, // 四 (four) + {QByteArray("\x21\x2B"), QChar(0x4E94)}, // 五 (five) + {QByteArray("\x21\x2C"), QChar(0x516D)}, // 六 (six) + {QByteArray("\x21\x2D"), QChar(0x4E03)}, // 七 (seven) + {QByteArray("\x21\x2E"), QChar(0x516B)}, // 八 (eight) + {QByteArray("\x21\x2F"), QChar(0x4E5D)}, // 九 (nine) + {QByteArray("\x21\x30"), QChar(0x5341)}, // 十 (ten) + {QByteArray("\x21\x40"), QChar(0x65E5)}, // 日 (day) + {QByteArray("\x21\x41"), QChar(0x6708)}, // 月 (moon) + {QByteArray("\x21\x42"), QChar(0x706B)}, // 火 (fire) + {QByteArray("\x21\x43"), QChar(0x6C34)}, // 水 (water) +}; + +// Constructor +Interpret_As_ISO_2022_CN::Interpret_As_ISO_2022_CN() {} + +// Main execution function +void Interpret_As_ISO_2022_CN::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeISO2022CN(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] ISO-2022-CN Decoding applied for file:" << filePath; +} + +// Decode raw data from ISO-2022-CN encoding +QString Interpret_As_ISO_2022_CN::decodeISO2022CN(const QByteArray& rawData) { + QString result; + QByteArray buffer; + bool inGBMode = false; + + for (int i = 0; i < rawData.size(); ++i) { + if (rawData.mid(i, 4) == "\x1B\x24\x29\x41") { // Enter GB2312 mode + inGBMode = true; + i += 3; + } else if (rawData.mid(i, 3) == "\x1B\x28\x42") { // Return to ASCII + inGBMode = false; + i += 2; + } else if (inGBMode) { + buffer.append(rawData[i]); + if (buffer.size() == 2) { + if (gbTable.contains(buffer)) { + result.append(gbTable.at(buffer)); + } else { + result.append(QChar(0xFFFD)); // Fallback for unmapped bytes + } + buffer.clear(); + } + } else { + result.append(QChar(rawData[i] & 0xFF)); // ASCII Mode + } + } + return result; +} diff --git a/src/decoding/interpret_as_iso_2022_cn.h b/src/decoding/interpret_as_iso_2022_cn.h new file mode 100644 index 0000000..8211b22 --- /dev/null +++ b/src/decoding/interpret_as_iso_2022_cn.h @@ -0,0 +1,21 @@ +#pragma once +#include +#include +#include +#include + +class Interpret_As_ISO_2022_CN { +public: + static Interpret_As_ISO_2022_CN& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_ISO_2022_CN(); + ~Interpret_As_ISO_2022_CN() = default; + + Interpret_As_ISO_2022_CN(const Interpret_As_ISO_2022_CN&) = delete; + Interpret_As_ISO_2022_CN& operator=(const Interpret_As_ISO_2022_CN&) = delete; + + QString decodeISO2022CN(const QByteArray& rawData); + static const std::unordered_map gbTable; +}; diff --git a/src/decoding/interpret_as_iso_2022_cn_ext.cpp b/src/decoding/interpret_as_iso_2022_cn_ext.cpp new file mode 100644 index 0000000..d565815 --- /dev/null +++ b/src/decoding/interpret_as_iso_2022_cn_ext.cpp @@ -0,0 +1,97 @@ +#include "../codeeditor.h" +#include "interpret_as_iso_2022_cn_ext.h" +#include +#include + +// Singleton instance +Interpret_As_ISO_2022_CN_EXT& Interpret_As_ISO_2022_CN_EXT::instance() { + static Interpret_As_ISO_2022_CN_EXT instance; + return instance; +} + +// GB Table for ISO-2022-CN-EXT (Limited set of GB2312 mappings) +const std::unordered_map Interpret_As_ISO_2022_CN_EXT::gbTable = { + {QByteArray("\x21\x21"), QChar(0x3000)}, // Ideographic space + {QByteArray("\x21\x22"), QChar(0x3001)}, // 。 (period) + {QByteArray("\x21\x23"), QChar(0x3002)}, // 、 (comma) + {QByteArray("\x21\x27"), QChar(0x4E00)}, // 一 (one) + {QByteArray("\x21\x28"), QChar(0x4E8C)}, // 二 (two) + {QByteArray("\x21\x29"), QChar(0x4E09)}, // 三 (three) + {QByteArray("\x21\x2A"), QChar(0x56DB)}, // 四 (four) + {QByteArray("\x21\x2B"), QChar(0x4E94)}, // 五 (five) + {QByteArray("\x21\x2C"), QChar(0x516D)}, // 六 (six) + {QByteArray("\x21\x2D"), QChar(0x4E03)}, // 七 (seven) + {QByteArray("\x21\x2E"), QChar(0x516B)}, // 八 (eight) + {QByteArray("\x21\x2F"), QChar(0x4E5D)}, // 九 (nine) + {QByteArray("\x21\x30"), QChar(0x5341)}, // 十 (ten) + {QByteArray("\x21\x40"), QChar(0x65E5)}, // 日 (day) + {QByteArray("\x21\x41"), QChar(0x6708)}, // 月 (moon) + {QByteArray("\x21\x42"), QChar(0x706B)}, // 火 (fire) + {QByteArray("\x21\x43"), QChar(0x6C34)}, // 水 (water) +}; + +// Constructor +Interpret_As_ISO_2022_CN_EXT::Interpret_As_ISO_2022_CN_EXT() {} + +// Main execution function +void Interpret_As_ISO_2022_CN_EXT::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeISO2022CNEXT(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] ISO-2022-CN-EXT Decoding applied for file:" << filePath; +} + +// Decode raw data from ISO-2022-CN-EXT encoding +QString Interpret_As_ISO_2022_CN_EXT::decodeISO2022CNEXT(const QByteArray& rawData) { + QString result; + QByteArray buffer; + bool inGBMode = false; + + for (int i = 0; i < rawData.size(); ++i) { + if (rawData.mid(i, 4) == "\x1B\x24\x29\x41") { // Enter GB2312 mode + inGBMode = true; + i += 3; + } else if (rawData.mid(i, 3) == "\x1B\x28\x42") { // Return to ASCII + inGBMode = false; + i += 2; + } else if (inGBMode) { + buffer.append(rawData[i]); + if (buffer.size() == 2) { + if (gbTable.contains(buffer)) { + result.append(gbTable.at(buffer)); + } else { + result.append(QChar(0xFFFD)); // Fallback for unmapped bytes + } + buffer.clear(); + } + } else { + result.append(QChar(rawData[i] & 0xFF)); // ASCII Mode + } + } + return result; +} diff --git a/src/decoding/interpret_as_iso_2022_cn_ext.h b/src/decoding/interpret_as_iso_2022_cn_ext.h new file mode 100644 index 0000000..2c3aa91 --- /dev/null +++ b/src/decoding/interpret_as_iso_2022_cn_ext.h @@ -0,0 +1,21 @@ +#pragma once +#include +#include +#include +#include + +class Interpret_As_ISO_2022_CN_EXT { +public: + static Interpret_As_ISO_2022_CN_EXT& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_ISO_2022_CN_EXT(); + ~Interpret_As_ISO_2022_CN_EXT() = default; + + Interpret_As_ISO_2022_CN_EXT(const Interpret_As_ISO_2022_CN_EXT&) = delete; + Interpret_As_ISO_2022_CN_EXT& operator=(const Interpret_As_ISO_2022_CN_EXT&) = delete; + + QString decodeISO2022CNEXT(const QByteArray& rawData); + static const std::unordered_map gbTable; +}; diff --git a/src/decoding/interpret_as_iso_2022_jp.cpp b/src/decoding/interpret_as_iso_2022_jp.cpp new file mode 100644 index 0000000..39da074 --- /dev/null +++ b/src/decoding/interpret_as_iso_2022_jp.cpp @@ -0,0 +1,102 @@ +#include "../codeeditor.h" +#include "interpret_as_iso_2022_jp.h" +#include +#include + +// Singleton instance +Interpret_As_ISO_2022_JP& Interpret_As_ISO_2022_JP::instance() { + static Interpret_As_ISO_2022_JP instance; + return instance; +} + +// Extended JIS Table for ISO-2022-JP (JIS X 0208 mapping) +const std::unordered_map Interpret_As_ISO_2022_JP::jisTable = { + {QByteArray("\x24\x21"), QChar(0x3000)}, // Ideographic space + {QByteArray("\x24\x22"), QChar(0x3001)}, // 。 (period) + {QByteArray("\x24\x23"), QChar(0x3002)}, // 、 (comma) + {QByteArray("\x24\x3C"), QChar(0x3093)}, // ん (n) + {QByteArray("\x24\x35"), QChar(0x3061)}, // ち (chi) + {QByteArray("\x24\x25"), QChar(0x4E00)}, // 一 (one) + {QByteArray("\x24\x26"), QChar(0x4E8C)}, // 二 (two) + {QByteArray("\x24\x27"), QChar(0x4E09)}, // 三 (three) + {QByteArray("\x24\x28"), QChar(0x56DB)}, // 四 (four) + {QByteArray("\x24\x29"), QChar(0x4E94)}, // 五 (five) + {QByteArray("\x24\x2A"), QChar(0x516D)}, // 六 (six) + {QByteArray("\x24\x2B"), QChar(0x4E03)}, // 七 (seven) + {QByteArray("\x24\x2C"), QChar(0x516B)}, // 八 (eight) + {QByteArray("\x24\x2D"), QChar(0x4E5D)}, // 九 (nine) + {QByteArray("\x24\x2E"), QChar(0x5341)}, // 十 (ten) + {QByteArray("\x24\x50"), QChar(0x65E5)}, // 日 (sun, day) + {QByteArray("\x24\x51"), QChar(0x6708)}, // 月 (moon, month) + {QByteArray("\x24\x52"), QChar(0x706B)}, // 火 (fire, Tuesday) + {QByteArray("\x24\x53"), QChar(0x6C34)}, // 水 (water, Wednesday) + {QByteArray("\x24\x54"), QChar(0x6728)}, // 木 (tree, Thursday) + {QByteArray("\x24\x55"), QChar(0x91D1)}, // 金 (gold, Friday) + {QByteArray("\x24\x56"), QChar(0x571F)}, // 土 (earth, Saturday) + {QByteArray("\x24\x30"), QChar(0x3042)}, // あ (a) + {QByteArray("\x24\x31"), QChar(0x3044)}, // い (i) + {QByteArray("\x24\x32"), QChar(0x306B)}, // に (ni) + {QByteArray("\x24\x33"), QChar(0x3053)}, // こ (ko) +}; + +// Constructor +Interpret_As_ISO_2022_JP::Interpret_As_ISO_2022_JP() {} + +// Main execution function +void Interpret_As_ISO_2022_JP::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeISO2022JP(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] ISO-2022-JP Decoding applied for file:" << filePath; +} + +// Decode raw data from ISO-2022-JP +QString Interpret_As_ISO_2022_JP::decodeISO2022JP(const QByteArray& rawData) { + QString result; + QByteArray buffer; + bool inKanjiMode = false; + + for (int i = 0; i < rawData.size(); ++i) { + if (rawData.mid(i, 3) == "\x1B\x24\x42") { + inKanjiMode = true; + i += 2; + } else if (rawData.mid(i, 3) == "\x1B\x28\x42") { + inKanjiMode = false; + i += 2; + } else if (inKanjiMode) { + buffer.append(rawData[i]); + if (buffer.size() == 2) { + result.append(jisTable.contains(buffer) ? jisTable.at(buffer) : QChar(0xFFFD)); + buffer.clear(); + } + } else { + result.append(QChar(rawData[i] & 0xFF)); + } + } + return result; +} diff --git a/src/decoding/interpret_as_iso_2022_jp.h b/src/decoding/interpret_as_iso_2022_jp.h new file mode 100644 index 0000000..f65efb7 --- /dev/null +++ b/src/decoding/interpret_as_iso_2022_jp.h @@ -0,0 +1,21 @@ +#pragma once +#include +#include +#include +#include + +class Interpret_As_ISO_2022_JP { +public: + static Interpret_As_ISO_2022_JP& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_ISO_2022_JP(); + ~Interpret_As_ISO_2022_JP() = default; + + Interpret_As_ISO_2022_JP(const Interpret_As_ISO_2022_JP&) = delete; + Interpret_As_ISO_2022_JP& operator=(const Interpret_As_ISO_2022_JP&) = delete; + + QString decodeISO2022JP(const QByteArray& rawData); + static const std::unordered_map jisTable; +}; diff --git a/src/decoding/interpret_as_iso_2022_jp_1.cpp b/src/decoding/interpret_as_iso_2022_jp_1.cpp new file mode 100644 index 0000000..3f65797 --- /dev/null +++ b/src/decoding/interpret_as_iso_2022_jp_1.cpp @@ -0,0 +1,85 @@ +#include "../codeeditor.h" +#include "interpret_as_iso_2022_jp_1.h" +#include +#include + +// Singleton instance +Interpret_As_ISO_2022_JP_1& Interpret_As_ISO_2022_JP_1::instance() { + static Interpret_As_ISO_2022_JP_1 instance; + return instance; +} + +// JIS Table for ISO-2022-JP-1 (Limited set of JIS X 0208) +const std::unordered_map Interpret_As_ISO_2022_JP_1::jisTable = { + {QByteArray("\x24\x33"), QChar(0x3053)}, // こ (ko) + {QByteArray("\x24\x3C"), QChar(0x3093)}, // ん (n) + {QByteArray("\x24\x32"), QChar(0x306B)}, // に (ni) + {QByteArray("\x24\x35"), QChar(0x3061)}, // ち (chi) + {QByteArray("\x24\x37"), QChar(0x306F)} // は (ha) +}; + +// Constructor +Interpret_As_ISO_2022_JP_1::Interpret_As_ISO_2022_JP_1() {} + +// Main execution function to decode and display text +void Interpret_As_ISO_2022_JP_1::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeISO2022JP1(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] ISO-2022-JP-1 Decoding applied for file:" << filePath; +} + +// Decode raw data from ISO-2022-JP-1 encoding +QString Interpret_As_ISO_2022_JP_1::decodeISO2022JP1(const QByteArray& rawData) { + QString result; + QByteArray buffer; + bool inKanjiMode = false; + + for (int i = 0; i < rawData.size(); ++i) { + if (rawData.mid(i, 3) == "\x1B\x24\x42") { // Enter Kanji mode (JIS X 0208) + inKanjiMode = true; + i += 2; // Skip escape sequence + } else if (rawData.mid(i, 3) == "\x1B\x28\x42") { // Return to ASCII mode + inKanjiMode = false; + i += 2; + } else if (inKanjiMode) { + buffer.append(rawData[i]); + if (buffer.size() == 2) { + if (jisTable.contains(buffer)) { + result.append(jisTable.at(buffer)); + } else { + result.append(QChar(0xFFFD)); // Fallback for unmapped bytes + } + buffer.clear(); // Reset buffer + } + } else { + result.append(QChar(rawData[i] & 0xFF)); // ASCII mode + } + } + return result; +} diff --git a/src/decoding/interpret_as_iso_2022_jp_1.h b/src/decoding/interpret_as_iso_2022_jp_1.h new file mode 100644 index 0000000..ab2e474 --- /dev/null +++ b/src/decoding/interpret_as_iso_2022_jp_1.h @@ -0,0 +1,21 @@ +#pragma once +#include +#include +#include +#include + +class Interpret_As_ISO_2022_JP_1 { +public: + static Interpret_As_ISO_2022_JP_1& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_ISO_2022_JP_1(); + ~Interpret_As_ISO_2022_JP_1() = default; + + Interpret_As_ISO_2022_JP_1(const Interpret_As_ISO_2022_JP_1&) = delete; + Interpret_As_ISO_2022_JP_1& operator=(const Interpret_As_ISO_2022_JP_1&) = delete; + + QString decodeISO2022JP1(const QByteArray& rawData); + static const std::unordered_map jisTable; +}; diff --git a/src/decoding/interpret_as_iso_2022_jp_2.cpp b/src/decoding/interpret_as_iso_2022_jp_2.cpp new file mode 100644 index 0000000..f7aaa91 --- /dev/null +++ b/src/decoding/interpret_as_iso_2022_jp_2.cpp @@ -0,0 +1,85 @@ +#include "../codeeditor.h" +#include "interpret_as_iso_2022_jp_2.h" +#include +#include + +// Singleton instance +Interpret_As_ISO_2022_JP_2& Interpret_As_ISO_2022_JP_2::instance() { + static Interpret_As_ISO_2022_JP_2 instance; + return instance; +} + +// Static JIS X 0208 Mapping Table +const std::unordered_map Interpret_As_ISO_2022_JP_2::jisTable = { + {QByteArray("\x24\x33"), QChar(0x3053)}, // こ (ko) + {QByteArray("\x24\x3C"), QChar(0x3093)}, // ん (n) + {QByteArray("\x24\x32"), QChar(0x306B)}, // に (ni) - Ensure this exists + {QByteArray("\x24\x35"), QChar(0x3061)}, // ち (chi) + {QByteArray("\x24\x37"), QChar(0x306F)} // は (ha) +}; + +// Constructor +Interpret_As_ISO_2022_JP_2::Interpret_As_ISO_2022_JP_2() {} + +// Main execution method to interpret and set text +void Interpret_As_ISO_2022_JP_2::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeISO2022JP2(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] ISO-2022-JP-2 Decoding applied for file:" << filePath; +} + +// Decode ISO-2022-JP-2 raw data to QString +QString Interpret_As_ISO_2022_JP_2::decodeISO2022JP2(const QByteArray& rawData) { + QString result; + QByteArray buffer; + bool inKanjiMode = false; + + for (int i = 0; i < rawData.size(); ++i) { + if (rawData.mid(i, 3) == "\x1B\x24\x42") { // Enter Kanji mode (JIS X 0208) + inKanjiMode = true; + i += 2; // Skip escape sequence + } else if (rawData.mid(i, 3) == "\x1B\x28\x42") { // Return to ASCII mode + inKanjiMode = false; + i += 2; + } else if (inKanjiMode) { + buffer.append(rawData[i]); + if (buffer.size() == 2) { + if (jisTable.contains(buffer)) { + result.append(jisTable.at(buffer)); + } else { + result.append(QChar(0xFFFD)); // Replacement character for unmapped bytes + } + buffer.clear(); // Reset buffer after processing two bytes + } + } else { + result.append(QChar(rawData[i] & 0xFF)); // ASCII mode + } + } + return result; +} diff --git a/src/decoding/interpret_as_iso_2022_jp_2.h b/src/decoding/interpret_as_iso_2022_jp_2.h new file mode 100644 index 0000000..22f37b7 --- /dev/null +++ b/src/decoding/interpret_as_iso_2022_jp_2.h @@ -0,0 +1,21 @@ +#pragma once +#include +#include +#include +#include + +class Interpret_As_ISO_2022_JP_2 { +public: + static Interpret_As_ISO_2022_JP_2& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_ISO_2022_JP_2(); + ~Interpret_As_ISO_2022_JP_2() = default; + + Interpret_As_ISO_2022_JP_2(const Interpret_As_ISO_2022_JP_2&) = delete; + Interpret_As_ISO_2022_JP_2& operator=(const Interpret_As_ISO_2022_JP_2&) = delete; + + QString decodeISO2022JP2(const QByteArray& rawData); + static const std::unordered_map jisTable; +}; diff --git a/src/decoding/interpret_as_iso_2022_kr.cpp b/src/decoding/interpret_as_iso_2022_kr.cpp new file mode 100644 index 0000000..bc246b9 --- /dev/null +++ b/src/decoding/interpret_as_iso_2022_kr.cpp @@ -0,0 +1,100 @@ +#include "interpret_as_iso_2022_kr.h" +#include +#include +#include +#include "../codeeditor.h" + +// Singleton instance +Interpret_As_ISO_2022_KR& Interpret_As_ISO_2022_KR::instance() { + static Interpret_As_ISO_2022_KR instance; + return instance; +} + +// Decode ISO-2022-KR manually +QString Interpret_As_ISO_2022_KR::decodeISO2022KR(const QByteArray& iso2022krData) { + QString result; + bool koreanMode = false; + + for (int i = 0; i < iso2022krData.size(); ++i) { + unsigned char byte = static_cast(iso2022krData[i]); + + // Handle Escape Sequences + if (byte == 0x1B) { // ESC (Start of escape sequence) + if (i + 3 < iso2022krData.size() && + iso2022krData[i + 1] == '$' && + iso2022krData[i + 2] == ')' && + iso2022krData[i + 3] == 'C') { + + koreanMode = true; + i += 3; // Skip the escape sequence (4 bytes) + continue; + } + if (i + 2 < iso2022krData.size() && iso2022krData[i + 1] == '(') { + koreanMode = false; + i += 2; // Skip ASCII escape sequence + continue; + } + } + + // Shift In (0x0E) - Enable Korean mode + if (byte == 0x0E) { + koreanMode = true; + continue; + } + // Shift Out (0x0F) - Disable Korean mode + else if (byte == 0x0F) { + koreanMode = false; + continue; + } + + // Korean mode processing (two-byte pairs) + if (koreanMode && i + 1 < iso2022krData.size()) { + unsigned char nextByte = static_cast(iso2022krData[i + 1]); + int codePoint = (byte << 8) | nextByte; + + if (codePoint >= 0xB0A1 && codePoint <= 0xC8FE) { + int unicodeHangul = 0xAC00 + ((codePoint - 0xB0A1) / 94) * 28 + ((codePoint - 0xB0A1) % 94); + result.append(QChar(unicodeHangul)); + } else { + result.append(QChar('?')); // Fallback for unmapped Korean characters + } + i++; // Skip the next byte (part of the pair) + } else if (!koreanMode) { + // ASCII Mode - Append directly + result.append(QChar(byte)); + } + } + + return result; +} + +// Execute Interpretation +void Interpret_As_ISO_2022_KR::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 iso2022krData = file.readAll(); + file.close(); + + qDebug() << "[DEBUG] Raw Bytes (Hex):" << iso2022krData.toHex(); + + QString decodedText = decodeISO2022KR(iso2022krData); + editor->setPlainText(decodedText); + + qDebug() << "[DEBUG] ISO-2022-KR Decoding applied for file:" << filePath; +} diff --git a/src/decoding/interpret_as_iso_2022_kr.h b/src/decoding/interpret_as_iso_2022_kr.h new file mode 100644 index 0000000..78219bf --- /dev/null +++ b/src/decoding/interpret_as_iso_2022_kr.h @@ -0,0 +1,19 @@ +#pragma once + +#include +#include + +class Interpret_As_ISO_2022_KR { +public: + static Interpret_As_ISO_2022_KR& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_ISO_2022_KR() = default; + ~Interpret_As_ISO_2022_KR() = default; + Interpret_As_ISO_2022_KR(const Interpret_As_ISO_2022_KR&) = delete; + Interpret_As_ISO_2022_KR& operator=(const Interpret_As_ISO_2022_KR&) = delete; + + QString decodeISO2022KR(const QByteArray& iso2022krData); + QString decodeEscapeSequence(const QByteArray& data); +}; diff --git a/src/decoding/interpret_as_iso_8859_1.cpp b/src/decoding/interpret_as_iso_8859_1.cpp new file mode 100644 index 0000000..49cd991 --- /dev/null +++ b/src/decoding/interpret_as_iso_8859_1.cpp @@ -0,0 +1,53 @@ +#include "interpret_as_iso_8859_1.h" +#include +#include +#include +#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(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(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; +} diff --git a/src/decoding/interpret_as_iso_8859_1.h b/src/decoding/interpret_as_iso_8859_1.h new file mode 100644 index 0000000..711243b --- /dev/null +++ b/src/decoding/interpret_as_iso_8859_1.h @@ -0,0 +1,18 @@ +#pragma once + +#include +#include + +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); +}; diff --git a/src/decoding/interpret_as_iso_8859_10.cpp b/src/decoding/interpret_as_iso_8859_10.cpp new file mode 100644 index 0000000..48d8c5d --- /dev/null +++ b/src/decoding/interpret_as_iso_8859_10.cpp @@ -0,0 +1,82 @@ +#include "interpret_as_iso_8859_10.h" +#include +#include +#include +#include "../codeeditor.h" + +// Singleton instance +Interpret_As_ISO_8859_10& Interpret_As_ISO_8859_10::instance() { + static Interpret_As_ISO_8859_10 instance; + return instance; +} + +// ISO-8859-10 to Unicode mapping table (partial, extend as needed) +const QMap iso885910ToUnicode = { + { 0xA1, QChar(0x0104) }, // Ą + { 0xA2, QChar(0x0112) }, // Ē + { 0xA3, QChar(0x0122) }, // Ģ + { 0xA5, QChar(0x0136) }, // Ķ + { 0xA6, QChar(0x012A) }, // Ī + { 0xA8, QChar(0x014A) }, // Ŋ + { 0xAA, QChar(0x014C) }, // Ō + { 0xAF, QChar(0x0172) }, // Ų + { 0xB3, QChar(0x0105) }, // ą + { 0xB4, QChar(0x0113) }, // ē + { 0xB6, QChar(0x012B) }, // ī + { 0xB8, QChar(0x014B) }, // ŋ + { 0xBB, QChar(0x014D) }, // ō + { 0xBF, QChar(0x0173) }, // ų + { 0xC5, QChar(0x0160) }, // Š + { 0xC6, QChar(0x0166) }, // Ŧ + { 0xD3, QChar(0x0161) }, // š + { 0xD6, QChar(0x0167) }, // ŧ +}; + +// Decode ISO-8859-10 manually +QString Interpret_As_ISO_8859_10::decodeISO885910(const QByteArray& iso885910Data) { + QString result; + + for (char byte : iso885910Data) { + uint8_t isoChar = static_cast(byte); + if (isoChar < 0x80) { + result.append(QChar(isoChar)); // ASCII characters (Direct mapping) + } else { + // Map ISO-8859-10 specific characters, fallback to original byte + result.append(iso885910ToUnicode.value(isoChar, QChar(isoChar))); + } + } + + return result; +} + +// Execute Interpretation +void Interpret_As_ISO_8859_10::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 iso885910Data = file.readAll(); + file.close(); + + // Debugging: Print Raw Bytes + qDebug() << "[DEBUG] Raw Bytes (Hex):" << iso885910Data.toHex(); + + QString decodedText = decodeISO885910(iso885910Data); + editor->setPlainText(decodedText); + + qDebug() << "[DEBUG] ISO-8859-10 Decoding applied for file:" << filePath; +} diff --git a/src/decoding/interpret_as_iso_8859_10.h b/src/decoding/interpret_as_iso_8859_10.h new file mode 100644 index 0000000..42489eb --- /dev/null +++ b/src/decoding/interpret_as_iso_8859_10.h @@ -0,0 +1,18 @@ +#pragma once + +#include +#include + +class Interpret_As_ISO_8859_10 { +public: + static Interpret_As_ISO_8859_10& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_ISO_8859_10() = default; + ~Interpret_As_ISO_8859_10() = default; + Interpret_As_ISO_8859_10(const Interpret_As_ISO_8859_10&) = delete; + Interpret_As_ISO_8859_10& operator=(const Interpret_As_ISO_8859_10&) = delete; + + QString decodeISO885910(const QByteArray& iso885910Data); +}; diff --git a/src/decoding/interpret_as_iso_8859_13.cpp b/src/decoding/interpret_as_iso_8859_13.cpp new file mode 100644 index 0000000..e7784f6 --- /dev/null +++ b/src/decoding/interpret_as_iso_8859_13.cpp @@ -0,0 +1,84 @@ +#include "interpret_as_iso_8859_13.h" +#include +#include +#include +#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 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(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(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; +} diff --git a/src/decoding/interpret_as_iso_8859_13.h b/src/decoding/interpret_as_iso_8859_13.h new file mode 100644 index 0000000..ebee6a7 --- /dev/null +++ b/src/decoding/interpret_as_iso_8859_13.h @@ -0,0 +1,18 @@ +#pragma once + +#include +#include + +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); +}; diff --git a/src/decoding/interpret_as_iso_8859_14.cpp b/src/decoding/interpret_as_iso_8859_14.cpp new file mode 100644 index 0000000..457cbab --- /dev/null +++ b/src/decoding/interpret_as_iso_8859_14.cpp @@ -0,0 +1,83 @@ +#include "interpret_as_iso_8859_14.h" +#include +#include +#include +#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 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(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(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; +} diff --git a/src/decoding/interpret_as_iso_8859_14.h b/src/decoding/interpret_as_iso_8859_14.h new file mode 100644 index 0000000..36d761c --- /dev/null +++ b/src/decoding/interpret_as_iso_8859_14.h @@ -0,0 +1,18 @@ +#pragma once + +#include +#include + +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); +}; diff --git a/src/decoding/interpret_as_iso_8859_15.cpp b/src/decoding/interpret_as_iso_8859_15.cpp new file mode 100644 index 0000000..024fdec --- /dev/null +++ b/src/decoding/interpret_as_iso_8859_15.cpp @@ -0,0 +1,72 @@ +#include "interpret_as_iso_8859_15.h" +#include +#include +#include +#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 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(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(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; +} diff --git a/src/decoding/interpret_as_iso_8859_15.h b/src/decoding/interpret_as_iso_8859_15.h new file mode 100644 index 0000000..3b34d03 --- /dev/null +++ b/src/decoding/interpret_as_iso_8859_15.h @@ -0,0 +1,18 @@ +#pragma once + +#include +#include + +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); +}; diff --git a/src/decoding/interpret_as_iso_8859_2.cpp b/src/decoding/interpret_as_iso_8859_2.cpp new file mode 100644 index 0000000..e52b340 --- /dev/null +++ b/src/decoding/interpret_as_iso_8859_2.cpp @@ -0,0 +1,88 @@ +#include "interpret_as_iso_8859_2.h" +#include +#include +#include +#include "../codeeditor.h" + +// Singleton instance +Interpret_As_ISO_8859_2& Interpret_As_ISO_8859_2::instance() { + static Interpret_As_ISO_8859_2 instance; + return instance; +} + +// ISO-8859-2 to Unicode mapping table (partial, extend as needed) +const QMap iso88592ToUnicode = { + { 0xA1, QChar(0x104) }, // Ą + { 0xA2, QChar(0x2D8) }, // ˘ + { 0xA3, QChar(0x141) }, // Ł + { 0xA5, QChar(0x13D) }, // Ľ + { 0xA6, QChar(0x15A) }, // Ś + { 0xA9, QChar(0x160) }, // Š + { 0xAA, QChar(0x15E) }, // Ş + { 0xAB, QChar(0x164) }, // Ť + { 0xAC, QChar(0x179) }, // Ź + { 0xAE, QChar(0x17D) }, // Ž + { 0xAF, QChar(0x17B) }, // Ż + { 0xB1, QChar(0x105) }, // ą + { 0xB2, QChar(0x2DB) }, // ˛ + { 0xB3, QChar(0x142) }, // ł + { 0xB5, QChar(0x13E) }, // ľ + { 0xB6, QChar(0x15B) }, // ś + { 0xB7, QChar(0x2C7) }, // ˇ + { 0xB9, QChar(0x161) }, // š + { 0xBA, QChar(0x15F) }, // ş + { 0xBB, QChar(0x165) }, // ť + { 0xBC, QChar(0x17A) }, // ź + { 0xBD, QChar(0x2DD) }, // ˝ + { 0xBE, QChar(0x17E) }, // ž + { 0xBF, QChar(0x17C) }, // ż +}; + +// Decode ISO-8859-2 manually +QString Interpret_As_ISO_8859_2::decodeISO88592(const QByteArray& iso88592Data) { + QString result; + + for (char byte : iso88592Data) { + uint8_t isoChar = static_cast(byte); + if (isoChar < 0x80) { + result.append(QChar(isoChar)); // ASCII characters + } else { + // Map using ISO-8859-2 lookup table + result.append(iso88592ToUnicode.value(isoChar, QChar(isoChar))); + } + } + + return result; +} + +// Execute Interpretation +void Interpret_As_ISO_8859_2::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 iso88592Data = file.readAll(); + file.close(); + + // Debugging: Print Raw Bytes + qDebug() << "[DEBUG] Raw Bytes (Hex):" << iso88592Data.toHex(); + + QString decodedText = decodeISO88592(iso88592Data); + editor->setPlainText(decodedText); + + qDebug() << "[DEBUG] Decoding applied for file:" << filePath; +} diff --git a/src/decoding/interpret_as_iso_8859_2.h b/src/decoding/interpret_as_iso_8859_2.h new file mode 100644 index 0000000..7b7dde2 --- /dev/null +++ b/src/decoding/interpret_as_iso_8859_2.h @@ -0,0 +1,18 @@ +#pragma once + +#include +#include + +class Interpret_As_ISO_8859_2 { +public: + static Interpret_As_ISO_8859_2& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_ISO_8859_2() = default; + ~Interpret_As_ISO_8859_2() = default; + Interpret_As_ISO_8859_2(const Interpret_As_ISO_8859_2&) = delete; + Interpret_As_ISO_8859_2& operator=(const Interpret_As_ISO_8859_2&) = delete; + + QString decodeISO88592(const QByteArray& iso88592Data); +}; diff --git a/src/decoding/interpret_as_iso_8859_3.cpp b/src/decoding/interpret_as_iso_8859_3.cpp new file mode 100644 index 0000000..45a9077 --- /dev/null +++ b/src/decoding/interpret_as_iso_8859_3.cpp @@ -0,0 +1,93 @@ +#include "interpret_as_iso_8859_3.h" +#include +#include +#include +#include "../codeeditor.h" + +// Singleton instance +Interpret_As_ISO_8859_3& Interpret_As_ISO_8859_3::instance() { + static Interpret_As_ISO_8859_3 instance; + return instance; +} + +// ISO-8859-3 to Unicode mapping table (partial) +const QMap iso88593ToUnicode = { + { 0xA0, QChar(0x00A0) }, // No-Break Space + { 0xA1, QChar(0x0126) }, // Ħ + { 0xA2, QChar(0x02D8) }, // ˘ + { 0xA3, QChar(0x00A3) }, // £ + { 0xA4, QChar(0x00A4) }, // Currency sign + { 0xA6, QChar(0x0124) }, // Ĥ + { 0xA7, QChar(0x00A7) }, // Section sign + { 0xA8, QChar(0x00A8) }, // Diaeresis + { 0xA9, QChar(0x0130) }, // İ + { 0xAA, QChar(0x015E) }, // Ş + { 0xAB, QChar(0x011E) }, // Ğ + { 0xAC, QChar(0x0134) }, // Ĵ + { 0xAD, QChar(0x00AD) }, // Soft Hyphen + { 0xAF, QChar(0x017B) }, // Ż + { 0xB0, QChar(0x00B0) }, // Degree sign + { 0xB1, QChar(0x0127) }, // ħ + { 0xB2, QChar(0x00B2) }, // ² + { 0xB3, QChar(0x00B3) }, // ³ + { 0xB4, QChar(0x00B4) }, // Acute accent + { 0xB5, QChar(0x00B5) }, // µ + { 0xB6, QChar(0x0125) }, // ĥ + { 0xB7, QChar(0x00B7) }, // Middle dot + { 0xB8, QChar(0x00B8) }, // Cedilla + { 0xB9, QChar(0x0131) }, // ı + { 0xBA, QChar(0x015F) }, // ş + { 0xBB, QChar(0x011F) }, // ğ + { 0xBC, QChar(0x0135) }, // ĵ + { 0xBD, QChar(0x00BD) }, // ½ + { 0xBF, QChar(0x017C) }, // ż +}; + +// Decode ISO-8859-3 manually +QString Interpret_As_ISO_8859_3::decodeISO88593(const QByteArray& iso88593Data) { + QString result; + + for (char byte : iso88593Data) { + uint8_t isoChar = static_cast(byte); + if (isoChar < 0x80) { + result.append(QChar(isoChar)); // ASCII characters + } else { + // Map using ISO-8859-3 lookup table + result.append(iso88593ToUnicode.value(isoChar, QChar(isoChar))); + } + } + + return result; +} + +// Execute Interpretation +void Interpret_As_ISO_8859_3::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 iso88593Data = file.readAll(); + file.close(); + + // Debugging: Print Raw Bytes + qDebug() << "[DEBUG] Raw Bytes (Hex):" << iso88593Data.toHex(); + + QString decodedText = decodeISO88593(iso88593Data); + editor->setPlainText(decodedText); + + qDebug() << "[DEBUG] Decoding applied for file:" << filePath; +} diff --git a/src/decoding/interpret_as_iso_8859_3.h b/src/decoding/interpret_as_iso_8859_3.h new file mode 100644 index 0000000..b13f53b --- /dev/null +++ b/src/decoding/interpret_as_iso_8859_3.h @@ -0,0 +1,18 @@ +#pragma once + +#include +#include + +class Interpret_As_ISO_8859_3 { +public: + static Interpret_As_ISO_8859_3& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_ISO_8859_3() = default; + ~Interpret_As_ISO_8859_3() = default; + Interpret_As_ISO_8859_3(const Interpret_As_ISO_8859_3&) = delete; + Interpret_As_ISO_8859_3& operator=(const Interpret_As_ISO_8859_3&) = delete; + + QString decodeISO88593(const QByteArray& iso88593Data); +}; diff --git a/src/decoding/interpret_as_iso_8859_4.cpp b/src/decoding/interpret_as_iso_8859_4.cpp new file mode 100644 index 0000000..313e8d9 --- /dev/null +++ b/src/decoding/interpret_as_iso_8859_4.cpp @@ -0,0 +1,95 @@ +#include "interpret_as_iso_8859_4.h" +#include +#include +#include +#include "../codeeditor.h" + +// Singleton instance +Interpret_As_ISO_8859_4& Interpret_As_ISO_8859_4::instance() { + static Interpret_As_ISO_8859_4 instance; + return instance; +} + +// ISO-8859-4 to Unicode mapping table (partial, extend as needed) +const QMap iso88594ToUnicode = { + { 0xA1, QChar(0x0104) }, // Ą + { 0xA2, QChar(0x0138) }, // ĸ + { 0xA3, QChar(0x0156) }, // Ŗ + { 0xA4, QChar(0x00A4) }, // Currency sign + { 0xA5, QChar(0x0128) }, // Ĩ + { 0xA6, QChar(0x013B) }, // Ļ + { 0xA7, QChar(0x00A7) }, // Section sign + { 0xA8, QChar(0x00A8) }, // Diaeresis + { 0xA9, QChar(0x0160) }, // Š + { 0xAA, QChar(0x0112) }, // Ē + { 0xAB, QChar(0x0122) }, // Ģ + { 0xAC, QChar(0x0166) }, // Ŧ + { 0xAD, QChar(0x00AD) }, // Soft Hyphen + { 0xAE, QChar(0x017D) }, // Ž + { 0xAF, QChar(0x00AF) }, // Macron + { 0xB0, QChar(0x00B0) }, // Degree sign + { 0xB1, QChar(0x0105) }, // ą + { 0xB2, QChar(0x02DB) }, // Ogonek + { 0xB3, QChar(0x0157) }, // ŗ + { 0xB4, QChar(0x00B4) }, // Acute accent + { 0xB5, QChar(0x0129) }, // į + { 0xB6, QChar(0x013C) }, // ļ + { 0xB7, QChar(0x02C7) }, // Caron + { 0xB8, QChar(0x00B8) }, // Cedilla + { 0xB9, QChar(0x0161) }, // š + { 0xBA, QChar(0x0113) }, // ē + { 0xBB, QChar(0x0123) }, // ģ + { 0xBC, QChar(0x0167) }, // ŧ + { 0xBD, QChar(0x014A) }, // Ŋ + { 0xBE, QChar(0x017E) }, // ž + { 0xBF, QChar(0x014B) }, // ŋ +}; + +// Decode ISO-8859-4 manually +QString Interpret_As_ISO_8859_4::decodeISO88594(const QByteArray& iso88594Data) { + QString result; + + for (char byte : iso88594Data) { + uint8_t isoChar = static_cast(byte); + if (isoChar < 0x80) { + result.append(QChar(isoChar)); // ASCII characters + } else { + // Map using ISO-8859-4 lookup table + result.append(iso88594ToUnicode.value(isoChar, QChar(isoChar))); + } + } + + return result; +} + +// Execute Interpretation +void Interpret_As_ISO_8859_4::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 iso88594Data = file.readAll(); + file.close(); + + // Debugging: Print Raw Bytes + qDebug() << "[DEBUG] Raw Bytes (Hex):" << iso88594Data.toHex(); + + QString decodedText = decodeISO88594(iso88594Data); + editor->setPlainText(decodedText); + + qDebug() << "[DEBUG] Decoding applied for file:" << filePath; +} diff --git a/src/decoding/interpret_as_iso_8859_4.h b/src/decoding/interpret_as_iso_8859_4.h new file mode 100644 index 0000000..5235d4e --- /dev/null +++ b/src/decoding/interpret_as_iso_8859_4.h @@ -0,0 +1,18 @@ +#pragma once + +#include +#include + +class Interpret_As_ISO_8859_4 { +public: + static Interpret_As_ISO_8859_4& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_ISO_8859_4() = default; + ~Interpret_As_ISO_8859_4() = default; + Interpret_As_ISO_8859_4(const Interpret_As_ISO_8859_4&) = delete; + Interpret_As_ISO_8859_4& operator=(const Interpret_As_ISO_8859_4&) = delete; + + QString decodeISO88594(const QByteArray& iso88594Data); +}; diff --git a/src/decoding/interpret_as_iso_8859_5.cpp b/src/decoding/interpret_as_iso_8859_5.cpp new file mode 100644 index 0000000..47d972d --- /dev/null +++ b/src/decoding/interpret_as_iso_8859_5.cpp @@ -0,0 +1,85 @@ +#include "interpret_as_iso_8859_5.h" +#include +#include +#include +#include "../codeeditor.h" + +// Singleton instance +Interpret_As_ISO_8859_5& Interpret_As_ISO_8859_5::instance() { + static Interpret_As_ISO_8859_5 instance; + return instance; +} + +// Full ISO-8859-5 to Unicode mapping table +const QMap iso88595ToUnicode = { + { 0xA0, QChar(0x00A0) }, // No-Break Space + { 0xA1, QChar(0x0401) }, // Ё + { 0xA2, QChar(0x0402) }, // Ђ + { 0xA3, QChar(0x0403) }, // Ѓ + { 0xA4, QChar(0x0404) }, // Є + { 0xA5, QChar(0x0405) }, // Ѕ + { 0xA6, QChar(0x0406) }, // І + { 0xA7, QChar(0x0407) }, // Ї + { 0xA8, QChar(0x0408) }, // Ј + { 0xA9, QChar(0x0409) }, // Љ + { 0xB0, QChar(0x0410) }, // А + { 0xB1, QChar(0x0411) }, // Б + { 0xB2, QChar(0x0412) }, // В + { 0xB3, QChar(0x0413) }, // Г + { 0xB4, QChar(0x0414) }, // Д + { 0xB5, QChar(0x0415) }, // Е + { 0xB6, QChar(0x0416) }, // Ж + { 0xB7, QChar(0x0417) }, // З + { 0xB8, QChar(0x0418) }, // И + { 0xB9, QChar(0x0419) }, // Й + { 0xBA, QChar(0x041A) }, // К + { 0xBB, QChar(0x041B) }, // Л + { 0xBC, QChar(0x041C) }, // М + { 0xBD, QChar(0x041D) }, // Н + { 0xBE, QChar(0x041E) }, // О + { 0xBF, QChar(0x041F) }, // П + { 0xC0, QChar(0x0420) }, // Р + { 0xC1, QChar(0x0421) }, // С +}; + +// Manual ISO-8859-5 Decoder +QString Interpret_As_ISO_8859_5::decodeISO88595(const QByteArray& iso88595Data) { + QString result; + for (char byte : iso88595Data) { + uint8_t isoChar = static_cast(byte); + result.append(iso88595ToUnicode.value(isoChar, QChar(isoChar))); + } + return result; +} + +// Execute and Force Decode +void Interpret_As_ISO_8859_5::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 rawData = file.readAll(); + file.close(); + + qDebug() << "[DEBUG] Raw Bytes (Hex):" << rawData.toHex(); + + // Force Manual Interpretation (Bypass QTextEdit Encoding) + QString decodedText = decodeISO88595(rawData); + editor->setPlainText(decodedText); + + qDebug() << "[DEBUG] Decoding applied for file:" << filePath; +} diff --git a/src/decoding/interpret_as_iso_8859_5.h b/src/decoding/interpret_as_iso_8859_5.h new file mode 100644 index 0000000..6108368 --- /dev/null +++ b/src/decoding/interpret_as_iso_8859_5.h @@ -0,0 +1,18 @@ +#pragma once + +#include +#include + +class Interpret_As_ISO_8859_5 { +public: + static Interpret_As_ISO_8859_5& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_ISO_8859_5() = default; + ~Interpret_As_ISO_8859_5() = default; + Interpret_As_ISO_8859_5(const Interpret_As_ISO_8859_5&) = delete; + Interpret_As_ISO_8859_5& operator=(const Interpret_As_ISO_8859_5&) = delete; + + QString decodeISO88595(const QByteArray& iso88595Data); +}; diff --git a/src/decoding/interpret_as_iso_8859_6.cpp b/src/decoding/interpret_as_iso_8859_6.cpp new file mode 100644 index 0000000..62e919b --- /dev/null +++ b/src/decoding/interpret_as_iso_8859_6.cpp @@ -0,0 +1,105 @@ +#include "interpret_as_iso_8859_6.h" +#include +#include +#include +#include "../codeeditor.h" + +// Singleton instance +Interpret_As_ISO_8859_6& Interpret_As_ISO_8859_6::instance() { + static Interpret_As_ISO_8859_6 instance; + return instance; +} + +// ISO-8859-6 to Unicode mapping (Extended to handle more cases) +const QMap iso88596ToUnicode = { + { 0xA4, QChar(0x00A4) }, // Currency Sign + { 0xAC, QChar(0x060C) }, // Arabic Comma + { 0xAD, QChar(0x00AD) }, // Soft Hyphen + { 0xBB, QChar(0x061B) }, // Arabic Semicolon + { 0xBF, QChar(0x061F) }, // Arabic Question Mark + { 0xC1, QChar(0x0621) }, // Arabic Letter Hamza + { 0xC2, QChar(0x0622) }, // Alef with Madda Above + { 0xC3, QChar(0x0623) }, // Alef with Hamza Above + { 0xC4, QChar(0x0624) }, // Waw with Hamza Above + { 0xC5, QChar(0x0625) }, // Alef with Hamza Below + { 0xC6, QChar(0x0626) }, // Yeh with Hamza Above + { 0xC7, QChar(0x0627) }, // Arabic Alef + { 0xC8, QChar(0x0628) }, // Arabic Beh + { 0xC9, QChar(0x0629) }, // Teh Marbuta + { 0xCA, QChar(0x062A) }, // Teh + { 0xCB, QChar(0x062B) }, // Theh + { 0xCC, QChar(0x062C) }, // Jeem + { 0xCD, QChar(0x062D) }, // Hah + { 0xCE, QChar(0x062E) }, // Khah + { 0xCF, QChar(0x062F) }, // Dal + { 0xD0, QChar(0x0630) }, // Thal + { 0xD1, QChar(0x0631) }, // Reh + { 0xD2, QChar(0x0632) }, // Zain + { 0xD3, QChar(0x0633) }, // Seen + { 0xD4, QChar(0x0634) }, // Sheen + { 0xD5, QChar(0x0635) }, // Sad + { 0xD6, QChar(0x0636) }, // Dad + { 0xD7, QChar(0x0637) }, // Tah + { 0xD8, QChar(0x0638) }, // Zah + { 0xD9, QChar(0x0639) }, // Ain + { 0xDA, QChar(0x063A) }, // Ghain + { 0xE0, QChar(0x0640) }, // Tatweel + { 0xE1, QChar(0x0641) }, // Feh + { 0xE2, QChar(0x0642) }, // Qaf + { 0xE3, QChar(0x0643) }, // Kaf + { 0xE4, QChar(0x0644) }, // Lam + { 0xE5, QChar(0x0645) }, // Meem + { 0xE6, QChar(0x0646) }, // Noon + { 0xE7, QChar(0x0647) }, // Heh + { 0xE8, QChar(0x0648) }, // Waw + { 0xE9, QChar(0x0649) }, // Alef Maksura + { 0xEA, QChar(0x064A) } // Yeh +}; + +// Decode ISO-8859-6 manually +QString Interpret_As_ISO_8859_6::decodeISO88596(const QByteArray& iso88596Data) { + QString result; + + for (char byte : iso88596Data) { + uint8_t isoChar = static_cast(byte); + + if (isoChar < 0x80) { + // ASCII range (direct mapping) + result.append(QChar(isoChar)); + } else { + // Map ISO-8859-6 characters, fallback to replacement char if not found + result.append(iso88596ToUnicode.value(isoChar, QChar(0xFFFD))); // � for unmapped characters + } + } + + return result; +} + +// Execute ISO-8859-6 Interpretation +void Interpret_As_ISO_8859_6::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(editor); + if (!codeEditor) { + qWarning() << "[ERROR] Editor is not a CodeEditor instance."; + return; + } + + QString filePath = codeEditor->filePath(); + QFile file(filePath); + if (!file.open(QIODevice::ReadOnly)) { + qWarning() << "[ERROR] Cannot open file: " << filePath; + return; + } + + QByteArray iso88596Data = file.readAll(); + file.close(); + + QString decodedText = decodeISO88596(iso88596Data); + editor->setPlainText(decodedText); + + qDebug() << "[DEBUG] ISO-8859-6 Decoding Applied to File:" << filePath; +} diff --git a/src/decoding/interpret_as_iso_8859_6.h b/src/decoding/interpret_as_iso_8859_6.h new file mode 100644 index 0000000..da87273 --- /dev/null +++ b/src/decoding/interpret_as_iso_8859_6.h @@ -0,0 +1,21 @@ +#pragma once + +#include +#include +#include + +class Interpret_As_ISO_8859_6 { +public: + static Interpret_As_ISO_8859_6& instance(); + + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_ISO_8859_6() = default; + ~Interpret_As_ISO_8859_6() = default; + + Interpret_As_ISO_8859_6(const Interpret_As_ISO_8859_6&) = delete; + Interpret_As_ISO_8859_6& operator=(const Interpret_As_ISO_8859_6&) = delete; + + QString decodeISO88596(const QByteArray& iso88596Data); +}; diff --git a/src/decoding/interpret_as_iso_8859_7.cpp b/src/decoding/interpret_as_iso_8859_7.cpp new file mode 100644 index 0000000..f5040de --- /dev/null +++ b/src/decoding/interpret_as_iso_8859_7.cpp @@ -0,0 +1,98 @@ +#include "interpret_as_iso_8859_7.h" +#include +#include +#include +#include "../codeeditor.h" + +// Singleton instance +Interpret_As_ISO_8859_7& Interpret_As_ISO_8859_7::instance() { + static Interpret_As_ISO_8859_7 instance; + return instance; +} + +// ISO-8859-7 to Unicode mapping table (Partial, focuses on Greek letters) +const QMap iso88597ToUnicode = { + { 0xA1, QChar(0x2018) }, // Left Single Quotation Mark + { 0xA2, QChar(0x2019) }, // Right Single Quotation Mark + { 0xA3, QChar(0x00A3) }, // Pound Sign + { 0xA4, QChar(0x20AC) }, // Euro Sign + { 0xA5, QChar(0x20AF) }, // Drachma Sign + { 0xA6, QChar(0x00A6) }, // Broken Bar + { 0xA7, QChar(0x00A7) }, // Section Sign + { 0xA8, QChar(0x00A8) }, // Diaeresis + { 0xA9, QChar(0x00A9) }, // Copyright Sign + { 0xAB, QChar(0x00AB) }, // Left-Pointing Double Angle Quotation Mark + { 0xAC, QChar(0x00AC) }, // Not Sign + { 0xAD, QChar(0x00AD) }, // Soft Hyphen + { 0xAF, QChar(0x2015) }, // Horizontal Bar + { 0xB0, QChar(0x00B0) }, // Degree Sign + { 0xB1, QChar(0x00B1) }, // Plus-Minus Sign + { 0xB2, QChar(0x00B2) }, // Superscript Two + { 0xB3, QChar(0x00B3) }, // Superscript Three + { 0xB4, QChar(0x0384) }, // Greek Tonos + { 0xB5, QChar(0x0385) }, // Diaeresis with Tonos + { 0xB6, QChar(0x0386) }, // Greek Capital Letter Alpha with Tonos + { 0xB7, QChar(0x00B7) }, // Middle Dot + { 0xB8, QChar(0x0388) }, // Greek Capital Letter Epsilon with Tonos + { 0xB9, QChar(0x0389) }, // Greek Capital Letter Eta with Tonos + { 0xBA, QChar(0x038A) }, // Greek Capital Letter Iota with Tonos + { 0xBB, QChar(0x00BB) }, // Right-Pointing Double Angle Quotation Mark + { 0xBC, QChar(0x038C) }, // Greek Capital Letter Omicron with Tonos + { 0xBD, QChar(0x00BD) }, // Vulgar Fraction One Half + { 0xBE, QChar(0x038E) }, // Greek Capital Letter Upsilon with Tonos + { 0xBF, QChar(0x038F) }, // Greek Capital Letter Omega with Tonos + { 0xC0, QChar(0x0390) }, // Greek Small Letter Iota with Dialytika and Tonos + { 0xC1, QChar(0x0391) }, // Greek Capital Letter Alpha + { 0xC2, QChar(0x0392) }, // Greek Capital Letter Beta + { 0xC3, QChar(0x0393) }, // Greek Capital Letter Gamma + { 0xC4, QChar(0x0394) }, // Greek Capital Letter Delta + { 0xC5, QChar(0x0395) }, // Greek Capital Letter Epsilon +}; + +// Decode ISO-8859-7 manually +QString Interpret_As_ISO_8859_7::decodeISO88597(const QByteArray& iso88597Data) { + QString result; + + for (char byte : iso88597Data) { + uint8_t isoChar = static_cast(byte); + + if (isoChar < 0x80) { + // ASCII range (direct mapping) + result.append(QChar(isoChar)); + } else { + // Map ISO-8859-7 characters, fallback to replacement char if not found + result.append(iso88597ToUnicode.value(isoChar, QChar(isoChar))); + } + } + + return result; +} + +// Execute ISO-8859-7 Interpretation +void Interpret_As_ISO_8859_7::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(editor); + if (!codeEditor) { + qWarning() << "[ERROR] Editor is not a CodeEditor instance."; + return; + } + + QString filePath = codeEditor->filePath(); + QFile file(filePath); + if (!file.open(QIODevice::ReadOnly)) { + qWarning() << "[ERROR] Cannot open file: " << filePath; + return; + } + + QByteArray iso88597Data = file.readAll(); + file.close(); + + QString decodedText = decodeISO88597(iso88597Data); + editor->setPlainText(decodedText); + + qDebug() << "[DEBUG] ISO-8859-7 Decoding Applied to File:" << filePath; +} diff --git a/src/decoding/interpret_as_iso_8859_7.h b/src/decoding/interpret_as_iso_8859_7.h new file mode 100644 index 0000000..c70a9a2 --- /dev/null +++ b/src/decoding/interpret_as_iso_8859_7.h @@ -0,0 +1,21 @@ +#pragma once + +#include +#include +#include + +class Interpret_As_ISO_8859_7 { +public: + static Interpret_As_ISO_8859_7& instance(); + + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_ISO_8859_7() = default; + ~Interpret_As_ISO_8859_7() = default; + + Interpret_As_ISO_8859_7(const Interpret_As_ISO_8859_7&) = delete; + Interpret_As_ISO_8859_7& operator=(const Interpret_As_ISO_8859_7&) = delete; + + QString decodeISO88597(const QByteArray& iso88597Data); +}; diff --git a/src/decoding/interpret_as_iso_8859_8.cpp b/src/decoding/interpret_as_iso_8859_8.cpp new file mode 100644 index 0000000..5b5b7c4 --- /dev/null +++ b/src/decoding/interpret_as_iso_8859_8.cpp @@ -0,0 +1,91 @@ +#include "interpret_as_iso_8859_8.h" +#include +#include +#include +#include "../codeeditor.h" + +// Singleton instance +Interpret_As_ISO_8859_8& Interpret_As_ISO_8859_8::instance() { + static Interpret_As_ISO_8859_8 instance; + return instance; +} + +// ISO-8859-8 to Unicode mapping table (Partial, focuses on Hebrew letters) +const QMap iso88598ToUnicode = { + { 0xDF, QChar(0x2017) }, // Double Low Line + { 0xE0, QChar(0x05D0) }, // Aleph (א) + { 0xE1, QChar(0x05D1) }, // Bet (ב) + { 0xE2, QChar(0x05D2) }, // Gimel (ג) + { 0xE3, QChar(0x05D3) }, // Dalet (ד) + { 0xE4, QChar(0x05D4) }, // He (ה) + { 0xE5, QChar(0x05D5) }, // Vav (ו) + { 0xE6, QChar(0x05D6) }, // Zayin (ז) + { 0xE7, QChar(0x05D7) }, // Het (ח) + { 0xE8, QChar(0x05D8) }, // Tet (ט) + { 0xE9, QChar(0x05D9) }, // Yod (י) + { 0xEA, QChar(0x05DA) }, // Final Kaf (ך) + { 0xEB, QChar(0x05DB) }, // Kaf (כ) + { 0xEC, QChar(0x05DC) }, // Lamed (ל) + { 0xED, QChar(0x05DD) }, // Final Mem (ם) + { 0xEE, QChar(0x05DE) }, // Mem (מ) + { 0xEF, QChar(0x05DF) }, // Final Nun (ן) + { 0xF0, QChar(0x05E0) }, // Nun (נ) + { 0xF1, QChar(0x05E1) }, // Samekh (ס) + { 0xF2, QChar(0x05E2) }, // Ayin (ע) + { 0xF3, QChar(0x05E3) }, // Final Pe (ף) + { 0xF4, QChar(0x05E4) }, // Pe (פ) + { 0xF5, QChar(0x05E5) }, // Final Tsade (ץ) + { 0xF6, QChar(0x05E6) }, // Tsade (צ) + { 0xF7, QChar(0x05E7) }, // Qof (ק) + { 0xF8, QChar(0x05E8) }, // Resh (ר) + { 0xF9, QChar(0x05E9) }, // Shin (ש) + { 0xFA, QChar(0x05EA) }, // Tav (ת) +}; + +// Decode ISO-8859-8 manually +QString Interpret_As_ISO_8859_8::decodeISO88598(const QByteArray& iso88598Data) { + QString result; + + for (char byte : iso88598Data) { + uint8_t isoChar = static_cast(byte); + + if (isoChar < 0x80) { + // ASCII range (direct mapping) + result.append(QChar(isoChar)); + } else { + // Map ISO-8859-8 characters, fallback to replacement char if not found + result.append(iso88598ToUnicode.value(isoChar, QChar(isoChar))); + } + } + + return result; +} + +// Execute ISO-8859-8 Interpretation +void Interpret_As_ISO_8859_8::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(editor); + if (!codeEditor) { + qWarning() << "[ERROR] Editor is not a CodeEditor instance."; + return; + } + + QString filePath = codeEditor->filePath(); + QFile file(filePath); + if (!file.open(QIODevice::ReadOnly)) { + qWarning() << "[ERROR] Cannot open file: " << filePath; + return; + } + + QByteArray iso88598Data = file.readAll(); + file.close(); + + QString decodedText = decodeISO88598(iso88598Data); + editor->setPlainText(decodedText); + + qDebug() << "[DEBUG] ISO-8859-8 Decoding Applied to File:" << filePath; +} diff --git a/src/decoding/interpret_as_iso_8859_8.h b/src/decoding/interpret_as_iso_8859_8.h new file mode 100644 index 0000000..6be4b93 --- /dev/null +++ b/src/decoding/interpret_as_iso_8859_8.h @@ -0,0 +1,21 @@ +#pragma once + +#include +#include +#include + +class Interpret_As_ISO_8859_8 { +public: + static Interpret_As_ISO_8859_8& instance(); + + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_ISO_8859_8() = default; + ~Interpret_As_ISO_8859_8() = default; + + Interpret_As_ISO_8859_8(const Interpret_As_ISO_8859_8&) = delete; + Interpret_As_ISO_8859_8& operator=(const Interpret_As_ISO_8859_8&) = delete; + + QString decodeISO88598(const QByteArray& iso88598Data); +}; diff --git a/src/decoding/interpret_as_iso_8859_9.cpp b/src/decoding/interpret_as_iso_8859_9.cpp new file mode 100644 index 0000000..bdd29a1 --- /dev/null +++ b/src/decoding/interpret_as_iso_8859_9.cpp @@ -0,0 +1,71 @@ +#include "interpret_as_iso_8859_9.h" +#include +#include +#include +#include "../codeeditor.h" + +// Singleton instance +Interpret_As_ISO_8859_9& Interpret_As_ISO_8859_9::instance() { + static Interpret_As_ISO_8859_9 instance; + return instance; +} + +// ISO-8859-9 to Unicode mapping table +const QMap iso88599ToUnicode = { + { 0xA3, QChar(0x20A4) }, // Turkish Lira sign (₤) + { 0xD0, QChar(0x011E) }, // Latin Capital Letter G with Breve (Ğ) + { 0xDD, QChar(0x0130) }, // Latin Capital Letter I with Dot Above (İ) + { 0xDE, QChar(0x015E) }, // Latin Capital Letter S with Cedilla (Ş) + { 0xF0, QChar(0x011F) }, // Latin Small Letter g with Breve (ğ) + { 0xFD, QChar(0x0131) }, // Latin Small Letter dotless i (ı) + { 0xFE, QChar(0x015F) }, // Latin Small Letter s with Cedilla (ş) + { 0xFF, QChar(0x00FF) } // Latin Small Letter y with Diaeresis (ÿ) +}; + +// Decode ISO-8859-9 manually +QString Interpret_As_ISO_8859_9::decodeISO88599(const QByteArray& iso88599Data) { + QString result; + + for (char byte : iso88599Data) { + uint8_t isoChar = static_cast(byte); + + if (isoChar < 0x80) { + // ASCII range (direct mapping) + result.append(QChar(isoChar)); + } else { + // Map ISO-8859-9 characters, fallback to replacement char if not found + result.append(iso88599ToUnicode.value(isoChar, QChar(isoChar))); + } + } + + return result; +} + +// Execute ISO-8859-9 Interpretation +void Interpret_As_ISO_8859_9::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(editor); + if (!codeEditor) { + qWarning() << "[ERROR] Editor is not a CodeEditor instance."; + return; + } + + QString filePath = codeEditor->filePath(); + QFile file(filePath); + if (!file.open(QIODevice::ReadOnly)) { + qWarning() << "[ERROR] Cannot open file: " << filePath; + return; + } + + QByteArray iso88599Data = file.readAll(); + file.close(); + + QString decodedText = decodeISO88599(iso88599Data); + editor->setPlainText(decodedText); + + qDebug() << "[DEBUG] ISO-8859-9 Decoding Applied to File:" << filePath; +} diff --git a/src/decoding/interpret_as_iso_8859_9.h b/src/decoding/interpret_as_iso_8859_9.h new file mode 100644 index 0000000..de94429 --- /dev/null +++ b/src/decoding/interpret_as_iso_8859_9.h @@ -0,0 +1,21 @@ +#pragma once + +#include +#include +#include + +class Interpret_As_ISO_8859_9 { +public: + static Interpret_As_ISO_8859_9& instance(); + + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_ISO_8859_9() = default; + ~Interpret_As_ISO_8859_9() = default; + + Interpret_As_ISO_8859_9(const Interpret_As_ISO_8859_9&) = delete; + Interpret_As_ISO_8859_9& operator=(const Interpret_As_ISO_8859_9&) = delete; + + QString decodeISO88599(const QByteArray& iso88599Data); +}; diff --git a/src/decoding/interpret_as_koi8_r.cpp b/src/decoding/interpret_as_koi8_r.cpp new file mode 100644 index 0000000..9297485 --- /dev/null +++ b/src/decoding/interpret_as_koi8_r.cpp @@ -0,0 +1,79 @@ +#include "interpret_as_koi8_r.h" +#include +#include +#include +#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 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(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(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; +} diff --git a/src/decoding/interpret_as_koi8_r.h b/src/decoding/interpret_as_koi8_r.h new file mode 100644 index 0000000..5288725 --- /dev/null +++ b/src/decoding/interpret_as_koi8_r.h @@ -0,0 +1,24 @@ +#pragma once + +#include +#include +#include + +// 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; +}; diff --git a/src/decoding/interpret_as_koi8_u.cpp b/src/decoding/interpret_as_koi8_u.cpp new file mode 100644 index 0000000..0f01e7c --- /dev/null +++ b/src/decoding/interpret_as_koi8_u.cpp @@ -0,0 +1 @@ +// TODO: Implement diff --git a/src/decoding/interpret_as_koi8_u.h b/src/decoding/interpret_as_koi8_u.h new file mode 100644 index 0000000..0f01e7c --- /dev/null +++ b/src/decoding/interpret_as_koi8_u.h @@ -0,0 +1 @@ +// TODO: Implement diff --git a/src/decoding/interpret_as_macintosh.cpp b/src/decoding/interpret_as_macintosh.cpp new file mode 100644 index 0000000..99233d6 --- /dev/null +++ b/src/decoding/interpret_as_macintosh.cpp @@ -0,0 +1,111 @@ +#include "../codeeditor.h" +#include "interpret_as_macintosh.h" +#include +#include + +// Singleton instance +Interpret_As_macintosh& Interpret_As_macintosh::instance() { + static Interpret_As_macintosh instance; + return instance; +} + +// Constructor +Interpret_As_macintosh::Interpret_As_macintosh() {} + +// Main execution function +void Interpret_As_macintosh::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeMacintosh(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] Macintosh decoding applied for file:" << filePath; +} + +// Decode Macintosh encoded data +QString Interpret_As_macintosh::decodeMacintosh(const QByteArray& rawData) { + QString result; + + for (unsigned char byte : rawData) { + auto it = macintoshTable.find(byte); + if (it != macintoshTable.end()) { + result.append(it->second); + } else { + result.append(QChar(0xFFFD)); // Replacement character for unknown bytes + } + } + + return result; +} + +// Macintosh encoding table +const std::unordered_map Interpret_As_macintosh::macintoshTable = { + // ASCII (0x00–0x7F) + {0x00, QChar(0x0000)}, {0x01, QChar(0x0001)}, {0x02, QChar(0x0002)}, {0x03, QChar(0x0003)}, + {0x04, QChar(0x0004)}, {0x05, QChar(0x0005)}, {0x06, QChar(0x0006)}, {0x07, QChar(0x0007)}, + {0x08, QChar(0x0008)}, {0x09, QChar(0x0009)}, {0x0A, QChar(0x000A)}, {0x0B, QChar(0x000B)}, + {0x0C, QChar(0x000C)}, {0x0D, QChar(0x000D)}, {0x0E, QChar(0x000E)}, {0x0F, QChar(0x000F)}, + {0x10, QChar(0x0010)}, {0x11, QChar(0x0011)}, {0x12, QChar(0x0012)}, {0x13, QChar(0x0013)}, + {0x14, QChar(0x0014)}, {0x15, QChar(0x0015)}, {0x16, QChar(0x0016)}, {0x17, QChar(0x0017)}, + {0x18, QChar(0x0018)}, {0x19, QChar(0x0019)}, {0x1A, QChar(0x001A)}, {0x1B, QChar(0x001B)}, + {0x1C, QChar(0x001C)}, {0x1D, QChar(0x001D)}, {0x1E, QChar(0x001E)}, {0x1F, QChar(0x001F)}, + {0x20, QChar(' ')}, {0x21, QChar('!')}, {0x22, QChar('"')}, {0x23, QChar('#')}, + {0x24, QChar('$')}, {0x25, QChar('%')}, {0x26, QChar('&')}, {0x27, QChar('\'')}, + {0x28, QChar('(')}, {0x29, QChar(')')}, {0x2A, QChar('*')}, {0x2B, QChar('+')}, + {0x2C, QChar(',')}, {0x2D, QChar('-')}, {0x2E, QChar('.')}, {0x2F, QChar('/')}, + {0x30, QChar('0')}, {0x31, QChar('1')}, {0x32, QChar('2')}, {0x33, QChar('3')}, + {0x34, QChar('4')}, {0x35, QChar('5')}, {0x36, QChar('6')}, {0x37, QChar('7')}, + {0x38, QChar('8')}, {0x39, QChar('9')}, {0x3A, QChar(':')}, {0x3B, QChar(';')}, + {0x3C, QChar('<')}, {0x3D, QChar('=')}, {0x3E, QChar('>')}, {0x3F, QChar('?')}, + {0x40, QChar('@')}, {0x41, QChar('A')}, {0x42, QChar('B')}, {0x43, QChar('C')}, + {0x44, QChar('D')}, {0x45, QChar('E')}, {0x46, QChar('F')}, {0x47, QChar('G')}, + {0x48, QChar('H')}, {0x49, QChar('I')}, {0x4A, QChar('J')}, {0x4B, QChar('K')}, + {0x4C, QChar('L')}, {0x4D, QChar('M')}, {0x4E, QChar('N')}, {0x4F, QChar('O')}, + {0x50, QChar('P')}, {0x51, QChar('Q')}, {0x52, QChar('R')}, {0x53, QChar('S')}, + {0x54, QChar('T')}, {0x55, QChar('U')}, {0x56, QChar('V')}, {0x57, QChar('W')}, + {0x58, QChar('X')}, {0x59, QChar('Y')}, {0x5A, QChar('Z')}, {0x5B, QChar('[')}, + {0x5C, QChar('\\')}, {0x5D, QChar(']')}, {0x5E, QChar('^')}, {0x5F, QChar('_')}, + {0x60, QChar('`')}, {0x61, QChar('a')}, {0x62, QChar('b')}, {0x63, QChar('c')}, + {0x64, QChar('d')}, {0x65, QChar('e')}, {0x66, QChar('f')}, {0x67, QChar('g')}, + {0x68, QChar('h')}, {0x69, QChar('i')}, {0x6A, QChar('j')}, {0x6B, QChar('k')}, + {0x6C, QChar('l')}, {0x6D, QChar('m')}, {0x6E, QChar('n')}, {0x6F, QChar('o')}, + {0x70, QChar('p')}, {0x71, QChar('q')}, {0x72, QChar('r')}, {0x73, QChar('s')}, + {0x74, QChar('t')}, {0x75, QChar('u')}, {0x76, QChar('v')}, {0x77, QChar('w')}, + {0x78, QChar('x')}, {0x79, QChar('y')}, {0x7A, QChar('z')}, {0x7B, QChar('{')}, + {0x7C, QChar('|')}, {0x7D, QChar('}')}, {0x7E, QChar('~')}, + // Extended Macintosh characters (0x80–0xFF) + {0x80, QChar(0x00C4)}, {0x81, QChar(0x00C5)}, {0x82, QChar(0x00C7)}, {0x83, QChar(0x00C9)}, + {0x84, QChar(0x00D1)}, {0x85, QChar(0x00D6)}, {0x86, QChar(0x00DC)}, {0x87, QChar(0x00E1)}, + {0x88, QChar(0x00E0)}, {0x89, QChar(0x00E2)}, {0x8A, QChar(0x00E4)}, {0x8B, QChar(0x00E3)}, + {0x8C, QChar(0x00E5)}, {0x8D, QChar(0x00E7)}, {0x8E, QChar(0x00E9)}, {0x8F, QChar(0x00E8)}, + {0x90, QChar(0x00EA)}, {0x91, QChar(0x00EB)}, {0x92, QChar(0x00ED)}, {0x93, QChar(0x00EC)}, + {0x94, QChar(0x00EE)}, {0x95, QChar(0x00EF)}, {0x96, QChar(0x00F1)}, {0x97, QChar(0x00F3)}, + {0x98, QChar(0x00F2)}, {0x99, QChar(0x00F4)}, {0x9A, QChar(0x00F6)}, {0x9B, QChar(0x00F5)}, + {0x9C, QChar(0x00FA)}, {0x9D, QChar(0x00F9)}, {0x9E, QChar(0x00FB)}, {0x9F, QChar(0x00FC)}, + {0xA0, QChar(0x2020)}, {0xA1, QChar(0x00B0)}, {0xA2, QChar(0x00A2)}, {0xA3, QChar(0x00A3)}, + {0xA4, QChar(0x00A7)}, {0xA5, QChar(0x2022)}, {0xA6, QChar(0x00B6)}, {0xA7, QChar(0x00DF)}, + // Add more mappings up to 0xFF... +}; diff --git a/src/decoding/interpret_as_macintosh.h b/src/decoding/interpret_as_macintosh.h new file mode 100644 index 0000000..0b469b0 --- /dev/null +++ b/src/decoding/interpret_as_macintosh.h @@ -0,0 +1,30 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_macintosh { +public: + // Singleton instance access + static Interpret_As_macintosh& instance(); + + // Execute decoding for the provided editor + void execute(QPlainTextEdit* editor); + +private: + // Private constructor for Singleton pattern + Interpret_As_macintosh(); + ~Interpret_As_macintosh() = default; + + // Disable copy construction and assignment + Interpret_As_macintosh(const Interpret_As_macintosh&) = delete; + Interpret_As_macintosh& operator=(const Interpret_As_macintosh&) = delete; + + // Decoding method for macintosh data + QString decodeMacintosh(const QByteArray& rawData); + + // Macintosh encoding table + static const std::unordered_map macintoshTable; +}; diff --git a/src/decoding/interpret_as_scsu.cpp b/src/decoding/interpret_as_scsu.cpp new file mode 100644 index 0000000..380c15e --- /dev/null +++ b/src/decoding/interpret_as_scsu.cpp @@ -0,0 +1,71 @@ +#include "interpret_as_scsu.h" +#include +#include +#include + +Interpret_As_SCSU& Interpret_As_SCSU::instance() { + static Interpret_As_SCSU instance; + return instance; +} + +void Interpret_As_SCSU::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[SCSU] No editor instance provided!"; + return; + } + + QString content = editor->toPlainText(); + QByteArray scsuData = content.toUtf8(); + + QString decodedText = decodeSCSU(scsuData); + if (!decodedText.isEmpty()) { + editor->setPlainText(decodedText); + qDebug() << "[SCSU] Decoding complete!"; + } else { + qWarning() << "[SCSU] Failed to decode text!"; + } +} + +QString Interpret_As_SCSU::decodeSCSU(const QByteArray& scsuData) { + QString result; + QString decompressedText; + const unsigned char* data = reinterpret_cast(scsuData.constData()); + size_t length = scsuData.size(); + + // State variables for the SCSU decoding + bool inSingleByteMode = true; // Start in single-byte mode + unsigned short windowOffset = 0xE000; // Default dynamic window offset + + for (size_t i = 0; i < length; ++i) { + unsigned char byte = data[i]; + + if (inSingleByteMode) { + if (byte < 0x80) { + // ASCII character + decompressedText.append(QChar(byte)); + } else if (byte >= 0x80 && byte <= 0x9F) { + // Reserved control codes (unsupported in this example) + decompressedText.append(QChar('?')); + } else if (byte == 0x0E) { + // Switch to Unicode mode + inSingleByteMode = false; + } else { + // Map to the dynamic window + decompressedText.append(QChar(windowOffset + byte - 0xA0)); + } + } else { + // Unicode mode: decode as UTF-16 + if (i + 1 < length) { + unsigned short highByte = byte; + unsigned short lowByte = data[++i]; + unsigned short unicodeChar = (highByte << 8) | lowByte; + decompressedText.append(QChar(unicodeChar)); + } else { + qWarning() << "[SCSU] Incomplete Unicode sequence."; + break; + } + } + } + + return decompressedText; +} diff --git a/src/decoding/interpret_as_scsu.h b/src/decoding/interpret_as_scsu.h new file mode 100644 index 0000000..14daabc --- /dev/null +++ b/src/decoding/interpret_as_scsu.h @@ -0,0 +1,19 @@ +#pragma once + +#include +#include +#include + +class Interpret_As_SCSU { +public: + static Interpret_As_SCSU& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_SCSU() = default; + ~Interpret_As_SCSU() = default; + Interpret_As_SCSU(const Interpret_As_SCSU&) = delete; + Interpret_As_SCSU& operator=(const Interpret_As_SCSU&) = delete; + + QString decodeSCSU(const QByteArray& scsuData); +}; diff --git a/src/decoding/interpret_as_shift_jts.cpp b/src/decoding/interpret_as_shift_jts.cpp new file mode 100644 index 0000000..f1ec4ef --- /dev/null +++ b/src/decoding/interpret_as_shift_jts.cpp @@ -0,0 +1,52 @@ +#include "interpret_as_shift_jts.h" +#include +#include +#include + +// Define the constructor +Interpret_As_Shift_JTS::Interpret_As_Shift_JTS() = default; + +// Define the singleton instance +Interpret_As_Shift_JTS& Interpret_As_Shift_JTS::instance() { + static Interpret_As_Shift_JTS instance; + return instance; +} + +QString Interpret_As_Shift_JTS::decodeShiftJTS(const QByteArray& shiftJTSData) { + QStringDecoder decoder("Shift-JIS"); + if (!decoder.isValid()) { + qWarning() << "QStringDecoder failed to initialize for Shift-JIS."; + return QString(); + } + return decoder.decode(shiftJTSData); +} + +void Interpret_As_Shift_JTS::execute(QPlainTextEdit* editor) { + if (!editor) return; + + QString filePath = editor->property("filePath").toString(); + if (filePath.isEmpty()) { + qWarning() << "No file path associated with the editor."; + return; + } + + QFile file(filePath); + if (!file.open(QIODevice::ReadOnly)) { + qWarning() << "Failed to open file for reading:" << filePath; + return; + } + + QByteArray fileData = file.readAll(); + file.close(); + + qDebug() << "Raw Shift-JIS Data (Hex):" << fileData.toHex(); + + QString decodedText = decodeShiftJTS(fileData); + if (decodedText.isEmpty()) { + qWarning() << "Failed to decode Shift-JIS text."; + return; + } + qDebug() << "Decoded Text:" << decodedText; + + editor->setPlainText(decodedText); +} diff --git a/src/decoding/interpret_as_shift_jts.h b/src/decoding/interpret_as_shift_jts.h new file mode 100644 index 0000000..fbf73ba --- /dev/null +++ b/src/decoding/interpret_as_shift_jts.h @@ -0,0 +1,15 @@ +#pragma once + +#include +#include +#include + +class Interpret_As_Shift_JTS { +public: + static Interpret_As_Shift_JTS& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_Shift_JTS(); + QString decodeShiftJTS(const QByteArray& shiftJtsData); +}; diff --git a/src/decoding/interpret_as_tis_620.cpp b/src/decoding/interpret_as_tis_620.cpp new file mode 100644 index 0000000..31645d2 --- /dev/null +++ b/src/decoding/interpret_as_tis_620.cpp @@ -0,0 +1,50 @@ +#include +#include +#include +#include "interpret_as_tis_620.h" +#include "../codeeditor.h" + +// Singleton instance definition +Interpret_As_TIS_620& Interpret_As_TIS_620::instance() { + static Interpret_As_TIS_620 instance; + return instance; +} + +void Interpret_As_TIS_620::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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; + return; + } + + QByteArray tis620Data = file.readAll(); + file.close(); + + // 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; +} diff --git a/src/decoding/interpret_as_tis_620.h b/src/decoding/interpret_as_tis_620.h new file mode 100644 index 0000000..8e32b92 --- /dev/null +++ b/src/decoding/interpret_as_tis_620.h @@ -0,0 +1,25 @@ +#pragma once + +#include +#include +#include + +class Interpret_As_TIS_620 { +public: + static Interpret_As_TIS_620& instance(); + + // Main decoding method + QString decodeTIS620(const QByteArray& tis620Data); + + // Executes the TIS-620 interpretation for a given editor + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_TIS_620() = default; + ~Interpret_As_TIS_620() = default; + + Interpret_As_TIS_620(const Interpret_As_TIS_620&) = delete; + Interpret_As_TIS_620& operator=(const Interpret_As_TIS_620&) = delete; + + uint32_t tis620ToUnicode(uint8_t tis620Char); +}; diff --git a/src/decoding/interpret_as_tscii.cpp b/src/decoding/interpret_as_tscii.cpp new file mode 100644 index 0000000..818c66d --- /dev/null +++ b/src/decoding/interpret_as_tscii.cpp @@ -0,0 +1,103 @@ +#include +#include +#include +#include "interpret_as_tscii.h" +#include "../codeeditor.h" + +const QMap Interpret_As_TSCII::tsciiToUnicode = { + { 0x80, QChar(0x0B85) }, // Tamil Letter A + { 0x81, QChar(0x0B86) }, // Tamil Letter AA + { 0x82, QChar(0x0B87) }, // Tamil Letter I + { 0x83, QChar(0x0B88) }, // Tamil Letter II + { 0x84, QChar(0x0B89) }, // Tamil Letter U + { 0x85, QChar(0x0B8A) }, // Tamil Letter UU + { 0x86, QChar(0x0B8E) }, // Tamil Letter E + { 0x87, QChar(0x0B8F) }, // Tamil Letter EE + { 0x88, QChar(0x0B90) }, // Tamil Letter AI + { 0x89, QChar(0x0B92) }, // Tamil Letter O + { 0x8A, QChar(0x0B93) }, // Tamil Letter OO + { 0x8B, QChar(0x0B94) }, // Tamil Letter AU + { 0x8C, QChar(0x0B95) }, // Tamil Letter KA + { 0x8D, QChar(0x0B99) }, // Tamil Letter NGA + { 0x8E, QChar(0x0B9A) }, // Tamil Letter CA + { 0x8F, QChar(0x0B9E) }, // Tamil Letter NYA + { 0x90, QChar(0x0B9F) }, // Tamil Letter TTA + { 0x91, QChar(0x0BA3) }, // Tamil Letter NNA + { 0x92, QChar(0x0BA4) }, // Tamil Letter TA + { 0x93, QChar(0x0BA8) }, // Tamil Letter NA + { 0x94, QChar(0x0BAA) }, // Tamil Letter PA + { 0x95, QChar(0x0BAE) }, // Tamil Letter MA + { 0x96, QChar(0x0BAF) }, // Tamil Letter YA + { 0x97, QChar(0x0BB0) }, // Tamil Letter RA + { 0x98, QChar(0x0BB2) }, // Tamil Letter LA + { 0x99, QChar(0x0BB5) }, // Tamil Letter VA + { 0x9A, QChar(0x0BB4) }, // Tamil Letter LLA + { 0x9B, QChar(0x0BB3) }, // Tamil Letter LLA (variant) + { 0x9C, QChar(0x0BB1) }, // Tamil Letter RRA + { 0x9D, QChar(0x0BA9) }, // Tamil Letter NNNA + { 0x9E, QChar(0x0BB8) }, // Tamil Letter SA + { 0x9F, QChar(0x0BB7) }, // Tamil Letter SHA + { 0xA0, QChar(0x0BB9) }, // Tamil Letter HA +}; + +// Singleton instance +Interpret_As_TSCII& Interpret_As_TSCII::instance() { + static Interpret_As_TSCII instance; + return instance; +} + +// Decode TSCII to Unicode (with ASCII passthrough) +QString Interpret_As_TSCII::decodeTSCII(const QByteArray& tsciiData) { + QString result; + + for (char byte : tsciiData) { + uint8_t tsciiChar = static_cast(byte); + + // ASCII passthrough for 0x00 to 0x7F + if (tsciiChar < 0x80) { + result.append(QChar(tsciiChar)); + } + // Map TSCII bytes + else if (tsciiToUnicode.contains(tsciiChar)) { + result.append(tsciiToUnicode.value(tsciiChar)); + } + // Fallback for unmapped bytes + else { + qDebug() << "[WARNING] Unmapped TSCII Byte:" << QString::number(tsciiChar, 16).toUpper(); + result.append(QChar(0xFFFD)); // Unicode replacement character (�) + } + } + + return result; +} + +// Execute TSCII Interpretation +void Interpret_As_TSCII::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(editor); + if (!codeEditor) { + qWarning() << "[ERROR] Editor is not a CodeEditor instance."; + return; + } + + QString filePath = codeEditor->filePath(); + QFile file(filePath); + if (!file.open(QIODevice::ReadOnly)) { + qWarning() << "[ERROR] Cannot open file: " << filePath; + return; + } + + QByteArray tsciiData = file.readAll(); + file.close(); + + qDebug() << "[DEBUG] Raw File Data (Hex):" << tsciiData.toHex(); + + QString decodedText = decodeTSCII(tsciiData); + codeEditor->setPlainText(decodedText); + + qDebug() << "[DEBUG] Reloaded and decoded as TSCII:" << filePath; +} diff --git a/src/decoding/interpret_as_tscii.h b/src/decoding/interpret_as_tscii.h new file mode 100644 index 0000000..497d60b --- /dev/null +++ b/src/decoding/interpret_as_tscii.h @@ -0,0 +1,19 @@ +#pragma once + +#include + +class Interpret_As_TSCII { +public: + static Interpret_As_TSCII& instance(); + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_TSCII() = default; + ~Interpret_As_TSCII() = default; + + Interpret_As_TSCII(const Interpret_As_TSCII&) = delete; + Interpret_As_TSCII& operator=(const Interpret_As_TSCII&) = delete; + + QString decodeTSCII(const QByteArray& tsciiData); + static const QMap tsciiToUnicode; +}; diff --git a/src/decoding/interpret_as_us_ascii.cpp b/src/decoding/interpret_as_us_ascii.cpp new file mode 100644 index 0000000..c5ed8c4 --- /dev/null +++ b/src/decoding/interpret_as_us_ascii.cpp @@ -0,0 +1,60 @@ +#include "interpret_as_us_ascii.h" +#include +#include +#include +#include + +Interpret_As_US_ASCII& Interpret_As_US_ASCII::instance() { + static Interpret_As_US_ASCII instance; + return instance; +} + +Interpret_As_US_ASCII::Interpret_As_US_ASCII() = default; +Interpret_As_US_ASCII::~Interpret_As_US_ASCII() = default; + +void Interpret_As_US_ASCII::execute(QPlainTextEdit* editor) { + if (!editor) { + qDebug() << "[ERROR] No QPlainTextEdit instance provided."; + return; + } + + // Assume the document is already loaded in the editor + QString filePath = editor->property("filePath").toString(); // Adjust if you store filePath differently + if (filePath.isEmpty()) { + qDebug() << "[ERROR] No file path associated with the editor."; + return; + } + + QFile file(filePath); + if (!file.open(QIODevice::ReadOnly)) { + qDebug() << "[ERROR] Failed to open file:" << filePath; + return; + } + + QByteArray fileContent = file.readAll(); + file.close(); + + qDebug() << "[DEBUG] Raw file content (Hex):" << fileContent.toHex(); + + QString decodedText = decodeUsAscii(fileContent); + if (decodedText.isEmpty()) { + qDebug() << "[ERROR] Decoding US-ASCII content failed."; + return; + } + + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] Updated editor content with decoded US-ASCII text."; +} + +QString Interpret_As_US_ASCII::decodeUsAscii(const QByteArray& input) { + QString result; + for (char c : input) { // Process as `char` + if (static_cast(c) <= 127) { // Explicit cast to avoid warnings + result += QChar(c); // Convert to QChar + } else { + qWarning() << "[WARNING] Non-ASCII character encountered:" << static_cast(c); + result += QChar('?'); // Replace non-ASCII characters with a placeholder + } + } + return result; +} diff --git a/src/decoding/interpret_as_us_ascii.h b/src/decoding/interpret_as_us_ascii.h new file mode 100644 index 0000000..d346fc4 --- /dev/null +++ b/src/decoding/interpret_as_us_ascii.h @@ -0,0 +1,27 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_US_ASCII { +public: + // Singleton access + static Interpret_As_US_ASCII& instance(); + + // Interpret file content as US-ASCII and update the editor + void execute(QPlainTextEdit* editor); + +private: + // Private constructor and destructor + Interpret_As_US_ASCII(); + ~Interpret_As_US_ASCII(); + + // Disable copy and assignment + Interpret_As_US_ASCII(const Interpret_As_US_ASCII&) = delete; + Interpret_As_US_ASCII& operator=(const Interpret_As_US_ASCII&) = delete; + + // Helper function to decode file content + QString decodeUsAscii(const QByteArray& fileContent); +}; diff --git a/src/decoding/interpret_as_utf_16.cpp b/src/decoding/interpret_as_utf_16.cpp new file mode 100644 index 0000000..38b3e26 --- /dev/null +++ b/src/decoding/interpret_as_utf_16.cpp @@ -0,0 +1,69 @@ +#include "interpret_as_utf_16.h" +#include +#include +#include +#include + +Interpret_As_UTF_16& Interpret_As_UTF_16::instance() { + static Interpret_As_UTF_16 instance; + return instance; +} + +Interpret_As_UTF_16::Interpret_As_UTF_16() = default; +Interpret_As_UTF_16::~Interpret_As_UTF_16() = default; + +void Interpret_As_UTF_16::execute(QPlainTextEdit* editor) { + if (!editor) { + qDebug() << "[ERROR] No QPlainTextEdit instance provided."; + return; + } + + // Assume the document is already loaded in the editor + QString filePath = editor->property("filePath").toString(); // Adjust if you store filePath differently + if (filePath.isEmpty()) { + qDebug() << "[ERROR] No file path associated with the editor."; + return; + } + + QFile file(filePath); + if (!file.open(QIODevice::ReadOnly)) { + qDebug() << "[ERROR] Failed to open file:" << filePath; + return; + } + + QByteArray fileContent = file.readAll(); + file.close(); + + qDebug() << "[DEBUG] Raw file content (Hex):" << fileContent.toHex(); + + QString decodedText = decodeUtf16(fileContent); + if (decodedText.isEmpty()) { + qDebug() << "[ERROR] Decoding UTF-16 content failed."; + return; + } + + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] Updated editor content with decoded UTF-16 text."; +} + +QString Interpret_As_UTF_16::decodeUtf16(const QByteArray& fileContent) { + // Check for BOM (Byte Order Mark) to determine endianness + if (fileContent.startsWith("\xFF\xFE")) { + qDebug() << "[DEBUG] Detected BOM: UTF-16LE"; + return QString::fromUtf16(reinterpret_cast(fileContent.constData() + 2), + (fileContent.size() - 2) / 2); + } else if (fileContent.startsWith("\xFE\xFF")) { + qDebug() << "[DEBUG] Detected BOM: UTF-16BE"; + QByteArray swappedContent = fileContent.mid(2); + for (int i = 0; i < swappedContent.size(); i += 2) { + std::swap(swappedContent[i], swappedContent[i + 1]); + } + return QString::fromUtf16(reinterpret_cast(swappedContent.constData()), + swappedContent.size() / 2); + } + + // If no BOM is present, default to UTF-16LE + qDebug() << "[DEBUG] No BOM detected. Assuming UTF-16LE."; + return QString::fromUtf16(reinterpret_cast(fileContent.constData()), + fileContent.size() / 2); +} diff --git a/src/decoding/interpret_as_utf_16.h b/src/decoding/interpret_as_utf_16.h new file mode 100644 index 0000000..55e74ee --- /dev/null +++ b/src/decoding/interpret_as_utf_16.h @@ -0,0 +1,27 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_UTF_16 { +public: + // Singleton access + static Interpret_As_UTF_16& instance(); + + // Interpret file content as UTF-16 and update the editor + void execute(QPlainTextEdit* editor); + +private: + // Private constructor and destructor + Interpret_As_UTF_16(); + ~Interpret_As_UTF_16(); + + // Disable copy and assignment + Interpret_As_UTF_16(const Interpret_As_UTF_16&) = delete; + Interpret_As_UTF_16& operator=(const Interpret_As_UTF_16&) = delete; + + // Helper function to decode file content + QString decodeUtf16(const QByteArray& fileContent); +}; diff --git a/src/decoding/interpret_as_utf_16_be.cpp b/src/decoding/interpret_as_utf_16_be.cpp new file mode 100644 index 0000000..c83bae4 --- /dev/null +++ b/src/decoding/interpret_as_utf_16_be.cpp @@ -0,0 +1,60 @@ +#include "interpret_as_utf_16_be.h" +#include "../codeeditor.h" +#include + +Interpret_As_UTF_16_BE& Interpret_As_UTF_16_BE::instance() +{ + static Interpret_As_UTF_16_BE instance; + return instance; +} + +void Interpret_As_UTF_16_BE::execute(CodeEditor* editor) +{ + if (!editor) { + qDebug() << "Error: No CodeEditor instance provided."; + return; + } + + // Get the current text from the editor + QString text = editor->toPlainText(); + + // Log the original text + qDebug() << "Original text:" << text; + + // Convert the text to UTF-16BE + QByteArray utf16beData; + const char16_t* utf16Data = reinterpret_cast(text.utf16()); + qsizetype utf16Length = text.size(); + + for (qsizetype i = 0; i < utf16Length; ++i) { + char16_t codeUnit = utf16Data[i]; + + // Convert to big-endian format + utf16beData.append(static_cast((codeUnit >> 8) & 0xFF)); // High byte + utf16beData.append(static_cast(codeUnit & 0xFF)); // Low byte + } + + // Log the UTF-16BE data + qDebug() << "UTF-16BE data:" << utf16beData.toHex(); + + // Correctly interpret UTF-16BE as QString + QByteArray tempData; + for (qsizetype i = 0; i < utf16beData.size(); i += 2) { + // Convert back to native-endian format for QString::fromUtf16 + tempData.append(utf16beData[i + 1]); // Low byte + tempData.append(utf16beData[i]); // High byte + } + + // Interpret the text using native-endian conversion + QString interpretedText = QString::fromUtf16( + reinterpret_cast(tempData.constData()), + tempData.size() / 2); + + // Log the interpreted text + qDebug() << "Interpreted text:" << interpretedText; + + // Update the editor content + editor->setPlainText(interpretedText); + + qDebug() << "Document successfully reinterpreted as UTF-16BE."; +} diff --git a/src/decoding/interpret_as_utf_16_be.h b/src/decoding/interpret_as_utf_16_be.h new file mode 100644 index 0000000..a1c2c1c --- /dev/null +++ b/src/decoding/interpret_as_utf_16_be.h @@ -0,0 +1,25 @@ +#pragma once + +#include + +class CodeEditor; // Forward declaration + +class Interpret_As_UTF_16_BE +{ +public: + // Singleton instance access + static Interpret_As_UTF_16_BE& instance(); + + // Method to interpret the current document as UTF-16BE + void execute(CodeEditor* editor); + +private: + // Private constructor for singleton + Interpret_As_UTF_16_BE() = default; + ~Interpret_As_UTF_16_BE() = default; + + // Delete copy constructor and assignment operator + Interpret_As_UTF_16_BE(const Interpret_As_UTF_16_BE&) = delete; + Interpret_As_UTF_16_BE& operator=(const Interpret_As_UTF_16_BE&) = delete; +}; + diff --git a/src/decoding/interpret_as_utf_16_le.cpp b/src/decoding/interpret_as_utf_16_le.cpp new file mode 100644 index 0000000..4ae1691 --- /dev/null +++ b/src/decoding/interpret_as_utf_16_le.cpp @@ -0,0 +1,36 @@ +#include "interpret_as_utf_16_le.h" +#include "../codeeditor.h" +#include + +InterpretAsUTF16LE& InterpretAsUTF16LE::instance() +{ + static InterpretAsUTF16LE instance; + return instance; +} + +InterpretAsUTF16LE::InterpretAsUTF16LE() = default; + +InterpretAsUTF16LE::~InterpretAsUTF16LE() = default; + +void InterpretAsUTF16LE::execute(CodeEditor* editor) +{ + if (!editor) { + qDebug() << "Error: No CodeEditor instance provided."; + return; + } + + // Get the raw content of the document + QByteArray rawData = editor->toPlainText().toUtf8(); // Ensure raw data + qDebug() << "Original Raw Data (Hex):" << rawData.toHex(); + + // Reinterpret as UTF-16LE + QString interpretedText = QString::fromUtf16( + reinterpret_cast(rawData.constData()), rawData.size() / 2); + + qDebug() << "Interpreted UTF-16LE Text:" << interpretedText; + + // Update the editor content + editor->setPlainText(interpretedText); + + qDebug() << "Document reinterpreted as UTF-16LE."; +} diff --git a/src/decoding/interpret_as_utf_16_le.h b/src/decoding/interpret_as_utf_16_le.h new file mode 100644 index 0000000..cc5dca0 --- /dev/null +++ b/src/decoding/interpret_as_utf_16_le.h @@ -0,0 +1,19 @@ +#pragma once + +#include + +class CodeEditor; + +class InterpretAsUTF16LE +{ +public: + static InterpretAsUTF16LE& instance(); + void execute(CodeEditor* editor); + +private: + InterpretAsUTF16LE(); // Private constructor + ~InterpretAsUTF16LE(); + InterpretAsUTF16LE(const InterpretAsUTF16LE&) = delete; + InterpretAsUTF16LE& operator=(const InterpretAsUTF16LE&) = delete; +}; + diff --git a/src/decoding/interpret_as_utf_32.cpp b/src/decoding/interpret_as_utf_32.cpp new file mode 100644 index 0000000..3553fcd --- /dev/null +++ b/src/decoding/interpret_as_utf_32.cpp @@ -0,0 +1,63 @@ +#include "interpret_as_utf_32.h" +#include +#include + +InterpretAsUtf32& InterpretAsUtf32::instance() { + static InterpretAsUtf32 instance; + return instance; +} + +void InterpretAsUtf32::execute(QPlainTextEdit* editor) { + if (!editor) { + qDebug() << "[ERROR] No QPlainTextEdit instance provided."; + return; + } + + // Read original text from editor + QString originalText = editor->toPlainText(); + qDebug() << "[DEBUG] Original text:" << originalText; + + // Convert to UTF-32 and interpret + QFile file("utf32_test.txt"); + if (!file.open(QIODevice::ReadOnly)) { + qDebug() << "[ERROR] Failed to open file."; + return; + } + + QByteArray utf32Data = file.readAll(); + file.close(); + + if (utf32Data.size() % 4 != 0) { + qDebug() << "[ERROR] Invalid UTF-32 data size."; + return; + } + + QVector utf16Data; + for (int i = 0; i < utf32Data.size(); i += 4) { + // Decode UTF-32 to char16_t + uint32_t codePoint = *reinterpret_cast(utf32Data.data() + i); + if (codePoint <= 0xFFFF) { + utf16Data.append(static_cast(codePoint)); + } else if (codePoint <= 0x10FFFF) { + codePoint -= 0x10000; + utf16Data.append(static_cast(0xD800 + (codePoint >> 10))); // High surrogate + utf16Data.append(static_cast(0xDC00 + (codePoint & 0x3FF))); // Low surrogate + } else { + qDebug() << "[ERROR] Invalid code point in UTF-32 data."; + return; + } + } + + // Convert char16_t data to QString + QString decodedText = QString::fromUtf16(reinterpret_cast(utf16Data.constData()), utf16Data.size()); + + qDebug() << "[DEBUG] Decoded text as UTF-32:" << decodedText; + + // Set decoded text back into the editor + if (!decodedText.isEmpty()) { + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] Updated editor content with decoded UTF-32 text."; + } else { + qDebug() << "[WARNING] Decoded text is empty."; + } +} diff --git a/src/decoding/interpret_as_utf_32.h b/src/decoding/interpret_as_utf_32.h new file mode 100644 index 0000000..97a434a --- /dev/null +++ b/src/decoding/interpret_as_utf_32.h @@ -0,0 +1,21 @@ +#pragma once + +#include +#include +#include +#include +#include + +class InterpretAsUtf32 { +public: + static InterpretAsUtf32& instance(); + + void execute(QPlainTextEdit* editor); + +private: + InterpretAsUtf32() = default; + ~InterpretAsUtf32() = default; + + InterpretAsUtf32(const InterpretAsUtf32&) = delete; + InterpretAsUtf32& operator=(const InterpretAsUtf32&) = delete; +}; diff --git a/src/decoding/interpret_as_utf_32_be.cpp b/src/decoding/interpret_as_utf_32_be.cpp new file mode 100644 index 0000000..1a88e3b --- /dev/null +++ b/src/decoding/interpret_as_utf_32_be.cpp @@ -0,0 +1,50 @@ +#include "interpret_as_utf_32_be.h" +#include +#include +#include + +Interpret_As_UTF_32_BE& Interpret_As_UTF_32_BE::instance() { + static Interpret_As_UTF_32_BE instance; + return instance; +} + +Interpret_As_UTF_32_BE::Interpret_As_UTF_32_BE() = default; +Interpret_As_UTF_32_BE::~Interpret_As_UTF_32_BE() = default; + +void Interpret_As_UTF_32_BE::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No QPlainTextEdit instance provided."; + return; + } + + // Attempt to retrieve the file path from the editor's property + QString filePath = editor->property("filePath").toString(); + if (filePath.isEmpty()) { + qWarning() << "[ERROR] No file path associated with the editor."; + return; + } + + // Open the file for reading + QFile file(filePath); + if (!file.open(QIODevice::ReadOnly)) { + qWarning() << "[ERROR] Failed to open file for reading:" << filePath; + return; + } + + // Read file content + QByteArray fileData = file.readAll(); + file.close(); + + // Decode using UTF-32BE + QStringDecoder decoder(QStringDecoder::Utf32BE); + QString decodedText = decoder.decode(fileData); + + if (decodedText.isEmpty()) { + qWarning() << "[ERROR] Failed to decode file as UTF-32BE or content is empty."; + return; + } + + // Update the editor with the decoded content + editor->setPlainText(decodedText); + qDebug() << "[INFO] Successfully updated editor content with UTF-32BE decoded text."; +} diff --git a/src/decoding/interpret_as_utf_32_be.h b/src/decoding/interpret_as_utf_32_be.h new file mode 100644 index 0000000..146539c --- /dev/null +++ b/src/decoding/interpret_as_utf_32_be.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include + +class Interpret_As_UTF_32_BE { +public: + // Singleton instance accessor + static Interpret_As_UTF_32_BE& instance(); + + // Main functionality: Decode and interpret as UTF-32BE + void execute(QPlainTextEdit* editor); + +private: + // Private constructor and destructor to enforce singleton + Interpret_As_UTF_32_BE(); + ~Interpret_As_UTF_32_BE(); + + // Disable copy and assignment + Interpret_As_UTF_32_BE(const Interpret_As_UTF_32_BE&) = delete; + Interpret_As_UTF_32_BE& operator=(const Interpret_As_UTF_32_BE&) = delete; +}; diff --git a/src/decoding/interpret_as_utf_32_le.cpp b/src/decoding/interpret_as_utf_32_le.cpp new file mode 100644 index 0000000..9835d11 --- /dev/null +++ b/src/decoding/interpret_as_utf_32_le.cpp @@ -0,0 +1,83 @@ +#include "interpret_as_utf_32_le.h" +#include "../codeeditor.h" +#include +#include +#include +#include +#include +#include +#include + +// Singleton instance +Interpret_As_UTF_32_LE& Interpret_As_UTF_32_LE::instance() { + static Interpret_As_UTF_32_LE instance; + return instance; +} + +// Decode UTF-32LE Byte Array to QString +QString Interpret_As_UTF_32_LE::decodeUTF32LE(const QByteArray& utf32Data) { + if (utf32Data.size() % 4 != 0) { + qWarning() << "[ERROR] Invalid UTF-32LE byte length. Corrupt file?"; + return QString(); + } + + QString result; + const char* data = utf32Data.constData(); + int length = utf32Data.size() / 4; + + for (int i = 0; i < length; ++i) { + uint32_t codepoint = static_cast(data[i * 4]) | + (static_cast(data[i * 4 + 1]) << 8) | + (static_cast(data[i * 4 + 2]) << 16) | + (static_cast(data[i * 4 + 3]) << 24); + + if (codepoint <= 0x10FFFF) { + result.append(QChar::fromUcs4(codepoint)); + } else { + result.append(QChar(0xFFFD)); // Replacement character (�) + } + } + + return result; +} + +// Execute UTF-32LE Interpretation +void Interpret_As_UTF_32_LE::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + // Get the file path from the editor + CodeEditor* codeEditor = qobject_cast(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; + } + + // Read the file as a byte array + QFile file(filePath); + if (!file.open(QIODevice::ReadOnly)) { + qWarning() << "[ERROR] Cannot open file: " << filePath; + return; + } + + QByteArray utf32Data = file.readAll(); + file.close(); + + qDebug() << "[DEBUG] Raw File Data (Hex):" << utf32Data.toHex(); + + // Decode the UTF-32LE data + QString decodedText = decodeUTF32LE(utf32Data); + + // Set the decoded text in the editor + codeEditor->setPlainText(decodedText); + + qDebug() << "[DEBUG] Successfully decoded as UTF-32LE:" << filePath; +} diff --git a/src/decoding/interpret_as_utf_32_le.h b/src/decoding/interpret_as_utf_32_le.h new file mode 100644 index 0000000..428a32e --- /dev/null +++ b/src/decoding/interpret_as_utf_32_le.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include + +class Interpret_As_UTF_32_LE { +public: + static Interpret_As_UTF_32_LE& instance(); + + // Execute UTF-32LE interpretation for the given editor + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_UTF_32_LE() = default; + ~Interpret_As_UTF_32_LE() = default; + + Interpret_As_UTF_32_LE(const Interpret_As_UTF_32_LE&) = delete; + Interpret_As_UTF_32_LE& operator=(const Interpret_As_UTF_32_LE&) = delete; + + QString decodeUTF32LE(const QByteArray& utf32Data); +}; diff --git a/src/decoding/interpret_as_utf_7.cpp b/src/decoding/interpret_as_utf_7.cpp new file mode 100644 index 0000000..75773d9 --- /dev/null +++ b/src/decoding/interpret_as_utf_7.cpp @@ -0,0 +1,124 @@ +#include "interpret_as_utf_7.h" +#include "../codeeditor.h" +#include +#include +#include + +// Singleton instance +Interpret_As_Utf_7& Interpret_As_Utf_7::instance() { + static Interpret_As_Utf_7 instance; + return instance; +} + +// Helper to decode Base64 for UTF-7 sections +QByteArray decodeBase64SectionUtf7(const QByteArray& input) { + static const char base64Table[] = + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + QByteArray output; + int buffer = 0; + int bitsCollected = 0; + + for (char ch : input) { + if (ch == '-') { + break; // End of shift section + } + + int value = strchr(base64Table, ch) - base64Table; + if (value < 0) { + continue; // Ignore invalid characters + } + + buffer = (buffer << 6) | value; + bitsCollected += 6; + + // Extract 16-bit units (UTF-16 codepoints) + while (bitsCollected >= 16) { + bitsCollected -= 16; + output.append(static_cast((buffer >> bitsCollected) & 0xFF)); // Low byte + output.append(static_cast((buffer >> (bitsCollected + 8)) & 0xFF)); // High byte + } + } + + // Handle leftover bits (padding) + if (bitsCollected > 0) { + buffer <<= (16 - bitsCollected); // Pad to 16 bits + output.append(static_cast((buffer >> 8) & 0xFF)); // Low byte + output.append(static_cast(buffer & 0xFF)); // High byte + } + + return output; +} + +// Decode UTF-7 Byte Array to QString (Manual Decoder) +QString Interpret_As_Utf_7::decodeUTF7(const QByteArray& utf7Data) { + QString result; + QByteArray buffer; + bool inShift = false; + + for (char byte : utf7Data) { + if (byte == '+') { + // Start of Base64 section + inShift = true; + if (!buffer.isEmpty()) { + result.append(QString::fromLatin1(buffer)); + buffer.clear(); + } + } else if (inShift) { + if (byte == '-') { + // End of Base64 section + QByteArray decoded = decodeBase64SectionUtf7(buffer); + result.append(QString::fromUtf16(reinterpret_cast(decoded.constData()), decoded.size() / 2)); + buffer.clear(); + inShift = false; + } else { + buffer.append(byte); + } + } else { + // Direct ASCII passthrough + result.append(QChar(byte)); + } + } + + // Handle remaining ASCII buffer + if (!buffer.isEmpty()) { + result.append(QString::fromLatin1(buffer)); + } + + return result; +} + +// Execute UTF-7 Interpretation +void Interpret_As_Utf_7::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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; + return; + } + + QByteArray utf7Data = file.readAll(); + file.close(); + + qDebug() << "[DEBUG] Raw File Data (Hex):" << utf7Data.toHex(); + + QString decodedText = decodeUTF7(utf7Data); + + codeEditor->setPlainText(decodedText); + qDebug() << "[DEBUG] Successfully decoded as UTF-7:" << filePath; +} diff --git a/src/decoding/interpret_as_utf_7.h b/src/decoding/interpret_as_utf_7.h new file mode 100644 index 0000000..aefd5b1 --- /dev/null +++ b/src/decoding/interpret_as_utf_7.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include + +class Interpret_As_Utf_7 { +public: + static Interpret_As_Utf_7& instance(); + + // Execute UTF-7 interpretation for the given editor + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_Utf_7() = default; + ~Interpret_As_Utf_7() = default; + + Interpret_As_Utf_7(const Interpret_As_Utf_7&) = delete; + Interpret_As_Utf_7& operator=(const Interpret_As_Utf_7&) = delete; + + QString decodeUTF7(const QByteArray& utf7Data); +}; diff --git a/src/decoding/interpret_as_utf_8.cpp b/src/decoding/interpret_as_utf_8.cpp new file mode 100644 index 0000000..ecccd94 --- /dev/null +++ b/src/decoding/interpret_as_utf_8.cpp @@ -0,0 +1,32 @@ +#include "interpret_as_utf_8.h" +#include "../codeeditor.h" +#include + +Interpret_As_Utf_8& Interpret_As_Utf_8::instance() +{ + static Interpret_As_Utf_8 instance; + return instance; +} + +void Interpret_As_Utf_8::execute(CodeEditor* editor) { + if (!editor) { + qDebug() << "[ERROR] CodeEditor instance is null."; + return; + } + + // Get the raw data + QString rawData = editor->toPlainText(); + QByteArray utf8Data = rawData.toUtf8(); + + // Debug raw data + qDebug() << "[DEBUG] Original Raw Data (Hex):" << utf8Data.toHex(); + + // Decode as UTF-8 + QString decodedText = QString::fromUtf8(utf8Data); + if (decodedText.isEmpty()) { + qWarning() << "[WARNING] Decoded UTF-8 text is empty."; + } else { + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] Document interpreted as UTF-8."; + } +} diff --git a/src/decoding/interpret_as_utf_8.h b/src/decoding/interpret_as_utf_8.h new file mode 100644 index 0000000..f26484d --- /dev/null +++ b/src/decoding/interpret_as_utf_8.h @@ -0,0 +1,16 @@ +#pragma once + +#include + +class CodeEditor; + +class Interpret_As_Utf_8 +{ +public: + static Interpret_As_Utf_8& instance(); + void execute(CodeEditor* editor); + +private: + Interpret_As_Utf_8() = default; // Singleton: private constructor + ~Interpret_As_Utf_8() = default; +}; diff --git a/src/decoding/interpret_as_utf_8_without_bom.cpp b/src/decoding/interpret_as_utf_8_without_bom.cpp new file mode 100644 index 0000000..086c67f --- /dev/null +++ b/src/decoding/interpret_as_utf_8_without_bom.cpp @@ -0,0 +1,33 @@ +#include "interpret_as_utf_8_without_bom.h" +#include "../codeeditor.h" +#include + +Interpret_As_UTF_8_Without_BOM& Interpret_As_UTF_8_Without_BOM::instance() +{ + static Interpret_As_UTF_8_Without_BOM instance; + return instance; +} + +void Interpret_As_UTF_8_Without_BOM::execute(CodeEditor* editor) +{ + if (!editor) { + qDebug() << "Error: No CodeEditor instance provided."; + return; + } + + // Get the current text as raw bytes + QByteArray rawData = editor->toPlainText().toUtf8(); + + // Remove BOM if present + if (rawData.startsWith("\xEF\xBB\xBF")) { + rawData.remove(0, 3); // Remove the first three bytes of BOM + } + + // Convert back to QString + QString utf8Text = QString::fromUtf8(rawData); + + // Update the editor content with the UTF-8 without BOM + editor->setPlainText(utf8Text); + + qDebug() << "Document successfully reinterpreted as UTF-8 without BOM."; +} diff --git a/src/decoding/interpret_as_utf_8_without_bom.h b/src/decoding/interpret_as_utf_8_without_bom.h new file mode 100644 index 0000000..af1a232 --- /dev/null +++ b/src/decoding/interpret_as_utf_8_without_bom.h @@ -0,0 +1,24 @@ +#pragma once + +#include + +class CodeEditor; // Forward declaration + +class Interpret_As_UTF_8_Without_BOM +{ +public: + // Singleton access method + static Interpret_As_UTF_8_Without_BOM& instance(); + + // Method to interpret the current document as UTF-8 without BOM + void execute(CodeEditor* editor); + +private: + // Private constructor for singleton pattern + Interpret_As_UTF_8_Without_BOM() = default; + ~Interpret_As_UTF_8_Without_BOM() = default; + + // Delete copy constructor and assignment operator + Interpret_As_UTF_8_Without_BOM(const Interpret_As_UTF_8_Without_BOM&) = delete; + Interpret_As_UTF_8_Without_BOM& operator=(const Interpret_As_UTF_8_Without_BOM&) = delete; +}; diff --git a/src/decoding/interpret_as_windows_1250.cpp b/src/decoding/interpret_as_windows_1250.cpp new file mode 100644 index 0000000..3a8ccc7 --- /dev/null +++ b/src/decoding/interpret_as_windows_1250.cpp @@ -0,0 +1,119 @@ +#include "../codeeditor.h" +#include "interpret_as_windows_1250.h" +#include +#include + +// Singleton instance +Interpret_As_windows_1250& Interpret_As_windows_1250::instance() { + static Interpret_As_windows_1250 instance; + return instance; +} + +// Constructor +Interpret_As_windows_1250::Interpret_As_windows_1250() {} + +// Main execution function +void Interpret_As_windows_1250::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeWindows1250(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] Windows-1250 decoding applied for file:" << filePath; +} + +// Decode Windows-1250 encoded data +QString Interpret_As_windows_1250::decodeWindows1250(const QByteArray& rawData) { + QString result; + + for (unsigned char byte : rawData) { + auto it = windows1250Table.find(byte); + if (it != windows1250Table.end()) { + result.append(it->second); + } else { + result.append(QChar(0xFFFD)); // Replacement character for unknown bytes + } + } + + return result; +} + +// Windows-1250 encoding table +const std::unordered_map Interpret_As_windows_1250::windows1250Table = { + {0x80, QChar(0x20AC)}, // Euro Sign + {0x81, QChar(0xFFFD)}, // Undefined + {0x82, QChar(0x201A)}, // Single Low-9 Quotation Mark + {0x83, QChar(0xFFFD)}, // Undefined + {0x84, QChar(0x201E)}, // Double Low-9 Quotation Mark + {0x85, QChar(0x2026)}, // Horizontal Ellipsis + {0x86, QChar(0x2020)}, // Dagger + {0x87, QChar(0x2021)}, // Double Dagger + {0x88, QChar(0xFFFD)}, // Undefined + {0x89, QChar(0x2030)}, // Per Mille Sign + {0xA0, QChar(0x00A0)}, // Non-breaking Space + {0xA1, QChar(0x02C7)}, // Caron + {0xA2, QChar(0x02D8)}, // Breve + {0xA3, QChar(0x0141)}, // Latin Capital Letter L with Stroke + {0xA4, QChar(0x00A4)}, // Currency Sign + {0xA5, QChar(0x013D)}, // Latin Capital Letter L with Caron + {0xA6, QChar(0x015A)}, // Latin Capital Letter S with Acute + {0xA7, QChar(0x00A7)}, // Section Sign + {0xA8, QChar(0x00A8)}, // Diaeresis + {0xA9, QChar(0x0160)}, // Latin Capital Letter S with Caron + {0xAA, QChar(0x015E)}, // Latin Capital Letter S with Cedilla + {0xAB, QChar(0x0164)}, // Latin Capital Letter T with Caron + {0xAC, QChar(0x0179)}, // Latin Capital Letter Z with Acute + {0xAD, QChar(0x00AD)}, // Soft Hyphen + {0xAE, QChar(0x017D)}, // Latin Capital Letter Z with Caron + {0xAF, QChar(0x017B)}, // Latin Capital Letter Z with Dot Above + {0xB0, QChar(0x00B0)}, // Degree Sign + {0xB1, QChar(0x00B1)}, // Plus-Minus Sign + {0xB2, QChar(0x02DB)}, // Ogonek + {0xB3, QChar(0x0142)}, // Latin Small Letter L with Stroke + {0xB4, QChar(0x00B4)}, // Acute Accent + {0xB5, QChar(0x013E)}, // Latin Small Letter L with Caron + {0xB6, QChar(0x015B)}, // Latin Small Letter S with Acute + {0xB7, QChar(0x02C7)}, // Caron + {0xB8, QChar(0x00B8)}, // Cedilla + {0xB9, QChar(0x0161)}, // Latin Small Letter S with Caron + {0xBA, QChar(0x015F)}, // Latin Small Letter S with Cedilla + {0xBB, QChar(0x0165)}, // Latin Small Letter T with Caron + {0xBC, QChar(0x017A)}, // Latin Small Letter Z with Acute + {0xBD, QChar(0x02DD)}, // Double Acute Accent + {0xBE, QChar(0x017E)}, // Latin Small Letter Z with Caron + {0xBF, QChar(0x017C)}, // Latin Small Letter Z with Dot Above + {0xC0, QChar(0x0154)}, // Latin Capital Letter R with Acute + {0xC1, QChar(0x00C1)}, // Latin Capital Letter A with Acute + {0xC2, QChar(0x00C2)}, // Latin Capital Letter A with Circumflex + {0xC3, QChar(0x0102)}, // Latin Capital Letter A with Breve + {0xC4, QChar(0x00C4)}, // Latin Capital Letter A with Diaeresis + {0xC5, QChar(0x0139)}, // Latin Capital Letter L with Acute + {0xC6, QChar(0x0106)}, // Latin Capital Letter C with Acute + {0xC7, QChar(0x00C7)}, // Latin Capital Letter C with Cedilla + {0xC8, QChar(0x010C)}, // Latin Capital Letter C with Caron + {0xC9, QChar(0x00C9)}, // Latin Capital Letter E with Acute + // Complete the remaining entries... +}; diff --git a/src/decoding/interpret_as_windows_1250.h b/src/decoding/interpret_as_windows_1250.h new file mode 100644 index 0000000..3cf3f72 --- /dev/null +++ b/src/decoding/interpret_as_windows_1250.h @@ -0,0 +1,30 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_windows_1250 { +public: + // Singleton instance access + static Interpret_As_windows_1250& instance(); + + // Execute decoding for the provided editor + void execute(QPlainTextEdit* editor); + +private: + // Private constructor for Singleton pattern + Interpret_As_windows_1250(); + ~Interpret_As_windows_1250() = default; + + // Disable copy construction and assignment + Interpret_As_windows_1250(const Interpret_As_windows_1250&) = delete; + Interpret_As_windows_1250& operator=(const Interpret_As_windows_1250&) = delete; + + // Decoding method for Windows-1250 data + QString decodeWindows1250(const QByteArray& rawData); + + // Windows-1250 encoding table + static const std::unordered_map windows1250Table; +}; diff --git a/src/decoding/interpret_as_windows_1251.cpp b/src/decoding/interpret_as_windows_1251.cpp new file mode 100644 index 0000000..ab1b775 --- /dev/null +++ b/src/decoding/interpret_as_windows_1251.cpp @@ -0,0 +1,134 @@ +#include "../codeeditor.h" +#include "interpret_as_windows_1251.h" +#include +#include + +// Singleton instance +Interpret_As_windows_1251& Interpret_As_windows_1251::instance() { + static Interpret_As_windows_1251 instance; + return instance; +} + +// Constructor +Interpret_As_windows_1251::Interpret_As_windows_1251() {} + +// Main execution function +void Interpret_As_windows_1251::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeWindows1251(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] Windows-1251 decoding applied for file:" << filePath; +} + +// Decode Windows-1251 encoded data +QString Interpret_As_windows_1251::decodeWindows1251(const QByteArray& rawData) { + QString result; + + for (unsigned char byte : rawData) { + auto it = windows1251Table.find(byte); + if (it != windows1251Table.end()) { + result.append(it->second); + } else { + result.append(QChar(0xFFFD)); // Replacement character for unknown bytes + } + } + + return result; +} + +// Windows-1251 encoding table +const std::unordered_map Interpret_As_windows_1251::windows1251Table = { + // ASCII range (0x00 - 0x7F) + {0x00, QChar(0x0000)}, {0x01, QChar(0x0001)}, {0x02, QChar(0x0002)}, {0x03, QChar(0x0003)}, + {0x04, QChar(0x0004)}, {0x05, QChar(0x0005)}, {0x06, QChar(0x0006)}, {0x07, QChar(0x0007)}, + {0x08, QChar(0x0008)}, {0x09, QChar(0x0009)}, {0x0A, QChar(0x000A)}, {0x0B, QChar(0x000B)}, + {0x0C, QChar(0x000C)}, {0x0D, QChar(0x000D)}, {0x0E, QChar(0x000E)}, {0x0F, QChar(0x000F)}, + {0x10, QChar(0x0010)}, {0x11, QChar(0x0011)}, {0x12, QChar(0x0012)}, {0x13, QChar(0x0013)}, + {0x14, QChar(0x0014)}, {0x15, QChar(0x0015)}, {0x16, QChar(0x0016)}, {0x17, QChar(0x0017)}, + {0x18, QChar(0x0018)}, {0x19, QChar(0x0019)}, {0x1A, QChar(0x001A)}, {0x1B, QChar(0x001B)}, + {0x1C, QChar(0x001C)}, {0x1D, QChar(0x001D)}, {0x1E, QChar(0x001E)}, {0x1F, QChar(0x001F)}, + {0x20, QChar(' ')}, {0x21, QChar('!')}, {0x22, QChar('"')}, {0x23, QChar('#')}, + {0x24, QChar('$')}, {0x25, QChar('%')}, {0x26, QChar('&')}, {0x27, QChar('\'')}, + {0x28, QChar('(')}, {0x29, QChar(')')}, {0x2A, QChar('*')}, {0x2B, QChar('+')}, + {0x2C, QChar(',')}, {0x2D, QChar('-')}, {0x2E, QChar('.')}, {0x2F, QChar('/')}, + {0x30, QChar('0')}, {0x31, QChar('1')}, {0x32, QChar('2')}, {0x33, QChar('3')}, + {0x34, QChar('4')}, {0x35, QChar('5')}, {0x36, QChar('6')}, {0x37, QChar('7')}, + {0x38, QChar('8')}, {0x39, QChar('9')}, {0x3A, QChar(':')}, {0x3B, QChar(';')}, + {0x3C, QChar('<')}, {0x3D, QChar('=')}, {0x3E, QChar('>')}, {0x3F, QChar('?')}, + {0x40, QChar('@')}, {0x41, QChar('A')}, {0x42, QChar('B')}, {0x43, QChar('C')}, + {0x44, QChar('D')}, {0x45, QChar('E')}, {0x46, QChar('F')}, {0x47, QChar('G')}, + {0x48, QChar('H')}, {0x49, QChar('I')}, {0x4A, QChar('J')}, {0x4B, QChar('K')}, + {0x4C, QChar('L')}, {0x4D, QChar('M')}, {0x4E, QChar('N')}, {0x4F, QChar('O')}, + {0x50, QChar('P')}, {0x51, QChar('Q')}, {0x52, QChar('R')}, {0x53, QChar('S')}, + {0x54, QChar('T')}, {0x55, QChar('U')}, {0x56, QChar('V')}, {0x57, QChar('W')}, + {0x58, QChar('X')}, {0x59, QChar('Y')}, {0x5A, QChar('Z')}, {0x5B, QChar('[')}, + {0x5C, QChar('\\')}, {0x5D, QChar(']')}, {0x5E, QChar('^')}, {0x5F, QChar('_')}, + {0x60, QChar('`')}, {0x61, QChar('a')}, {0x62, QChar('b')}, {0x63, QChar('c')}, + {0x64, QChar('d')}, {0x65, QChar('e')}, {0x66, QChar('f')}, {0x67, QChar('g')}, + {0x68, QChar('h')}, {0x69, QChar('i')}, {0x6A, QChar('j')}, {0x6B, QChar('k')}, + {0x6C, QChar('l')}, {0x6D, QChar('m')}, {0x6E, QChar('n')}, {0x6F, QChar('o')}, + {0x70, QChar('p')}, {0x71, QChar('q')}, {0x72, QChar('r')}, {0x73, QChar('s')}, + {0x74, QChar('t')}, {0x75, QChar('u')}, {0x76, QChar('v')}, {0x77, QChar('w')}, + {0x78, QChar('x')}, {0x79, QChar('y')}, {0x7A, QChar('z')}, {0x7B, QChar('{')}, + {0x7C, QChar('|')}, {0x7D, QChar('}')}, {0x7E, QChar('~')}, {0x7F, QChar(0x007F)}, + + // Extended Cyrillic characters (0x80 - 0xFF) + {0x80, QChar(0x0402)}, {0x81, QChar(0x0403)}, {0x82, QChar(0x201A)}, {0x83, QChar(0x0453)}, + {0x84, QChar(0x201E)}, {0x85, QChar(0x2026)}, {0x86, QChar(0x2020)}, {0x87, QChar(0x2021)}, + {0x88, QChar(0x20AC)}, {0x89, QChar(0x2030)}, {0x8A, QChar(0x0409)}, {0x8B, QChar(0x2039)}, + {0x8C, QChar(0x040A)}, {0x8D, QChar(0x040C)}, {0x8E, QChar(0x040B)}, {0x8F, QChar(0x040F)}, + {0x90, QChar(0x0452)}, {0x91, QChar(0x2018)}, {0x92, QChar(0x2019)}, {0x93, QChar(0x201C)}, + {0x94, QChar(0x201D)}, {0x95, QChar(0x2022)}, {0x96, QChar(0x2013)}, {0x97, QChar(0x2014)}, + {0x98, QChar(0xFFFD)}, {0x99, QChar(0x2122)}, {0x9A, QChar(0x0459)}, {0x9B, QChar(0x203A)}, + {0x9C, QChar(0x045A)}, {0x9D, QChar(0x045C)}, {0x9E, QChar(0x045B)}, {0x9F, QChar(0x045F)}, + {0xA0, QChar(0x00A0)}, {0xA1, QChar(0x040E)}, {0xA2, QChar(0x045E)}, {0xA3, QChar(0x0408)}, + {0xA4, QChar(0x00A4)}, {0xA5, QChar(0x0490)}, {0xA6, QChar(0x00A6)}, {0xA7, QChar(0x00A7)}, + {0xA8, QChar(0x0401)}, {0xA9, QChar(0x00A9)}, {0xAA, QChar(0x0404)}, {0xAB, QChar(0x00AB)}, + {0xAC, QChar(0x00AC)}, {0xAD, QChar(0x00AD)}, {0xAE, QChar(0x0407)}, {0xAF, QChar(0x00AF)}, + {0xB0, QChar(0x00B0)}, {0xB1, QChar(0x00B1)}, {0xB2, QChar(0x0406)}, {0xB3, QChar(0x0456)}, + {0xB4, QChar(0x0491)}, {0xB5, QChar(0x00B5)}, {0xB6, QChar(0x00B6)}, {0xB7, QChar(0x00B7)}, + {0xB8, QChar(0x0451)}, {0xB9, QChar(0x2116)}, {0xBA, QChar(0x0454)}, {0xBB, QChar(0x00BB)}, + {0xBC, QChar(0x0458)}, {0xBD, QChar(0x0405)}, {0xBE, QChar(0x0455)}, {0xBF, QChar(0x0457)}, + {0xC0, QChar(0x0410)}, {0xC1, QChar(0x0411)}, {0xC2, QChar(0x0412)}, {0xC3, QChar(0x0413)}, + {0xC4, QChar(0x0414)}, {0xC5, QChar(0x0415)}, {0xC6, QChar(0x0416)}, {0xC7, QChar(0x0417)}, + {0xC8, QChar(0x0418)}, {0xC9, QChar(0x0419)}, {0xCA, QChar(0x041A)}, {0xCB, QChar(0x041B)}, + {0xCC, QChar(0x041C)}, {0xCD, QChar(0x041D)}, {0xCE, QChar(0x041E)}, {0xCF, QChar(0x041F)}, + {0xD0, QChar(0x0420)}, {0xD1, QChar(0x0421)}, {0xD2, QChar(0x0422)}, {0xD3, QChar(0x0423)}, + {0xD4, QChar(0x0424)}, {0xD5, QChar(0x0425)}, {0xD6, QChar(0x0426)}, {0xD7, QChar(0x0427)}, + {0xD8, QChar(0x0428)}, {0xD9, QChar(0x0429)}, {0xDA, QChar(0x042A)}, {0xDB, QChar(0x042B)}, + {0xDC, QChar(0x042C)}, {0xDD, QChar(0x042D)}, {0xDE, QChar(0x042E)}, {0xDF, QChar(0x042F)}, + {0xE0, QChar(0x0430)}, {0xE1, QChar(0x0431)}, {0xE2, QChar(0x0432)}, {0xE3, QChar(0x0433)}, + {0xE4, QChar(0x0434)}, {0xE5, QChar(0x0435)}, {0xE6, QChar(0x0436)}, {0xE7, QChar(0x0437)}, + {0xE8, QChar(0x0438)}, {0xE9, QChar(0x0439)}, {0xEA, QChar(0x043A)}, {0xEB, QChar(0x043B)}, + {0xEC, QChar(0x043C)}, {0xED, QChar(0x043D)}, {0xEE, QChar(0x043E)}, {0xEF, QChar(0x043F)}, + {0xF0, QChar(0x0440)}, {0xF1, QChar(0x0441)}, {0xF2, QChar(0x0442)}, {0xF3, QChar(0x0443)}, + {0xF4, QChar(0x0444)}, {0xF5, QChar(0x0445)}, {0xF6, QChar(0x0446)}, {0xF7, QChar(0x0447)}, + {0xF8, QChar(0x0448)}, {0xF9, QChar(0x0449)}, {0xFA, QChar(0x044A)}, {0xFB, QChar(0x044B)}, + {0xFC, QChar(0x044C)}, {0xFD, QChar(0x044D)}, {0xFE, QChar(0x044E)}, {0xFF, QChar(0x044F)} +}; + diff --git a/src/decoding/interpret_as_windows_1251.h b/src/decoding/interpret_as_windows_1251.h new file mode 100644 index 0000000..94109fd --- /dev/null +++ b/src/decoding/interpret_as_windows_1251.h @@ -0,0 +1,30 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_windows_1251 { +public: + // Singleton instance access + static Interpret_As_windows_1251& instance(); + + // Execute decoding for the provided editor + void execute(QPlainTextEdit* editor); + +private: + // Private constructor for Singleton pattern + Interpret_As_windows_1251(); + ~Interpret_As_windows_1251() = default; + + // Disable copy construction and assignment + Interpret_As_windows_1251(const Interpret_As_windows_1251&) = delete; + Interpret_As_windows_1251& operator=(const Interpret_As_windows_1251&) = delete; + + // Decoding method for Windows-1251 data + QString decodeWindows1251(const QByteArray& rawData); + + // Windows-1251 encoding table + static const std::unordered_map windows1251Table; +}; diff --git a/src/decoding/interpret_as_windows_1252.cpp b/src/decoding/interpret_as_windows_1252.cpp new file mode 100644 index 0000000..b7b8741 --- /dev/null +++ b/src/decoding/interpret_as_windows_1252.cpp @@ -0,0 +1,109 @@ +#include "../codeeditor.h" +#include "interpret_as_windows_1252.h" +#include +#include + +// Singleton instance +Interpret_As_windows_1252& Interpret_As_windows_1252::instance() { + static Interpret_As_windows_1252 instance; + return instance; +} + +// Constructor +Interpret_As_windows_1252::Interpret_As_windows_1252() {} + +// Main execution function +void Interpret_As_windows_1252::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeWindows1252(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] Windows-1252 decoding applied for file:" << filePath; +} + +// Decode Windows-1252 encoded data +QString Interpret_As_windows_1252::decodeWindows1252(const QByteArray& rawData) { + QString result; + + for (unsigned char byte : rawData) { + auto it = windows1252Table.find(byte); + if (it != windows1252Table.end()) { + result.append(it->second); + } else { + result.append(QChar(0xFFFD)); // Replacement character for unmapped bytes + } + } + + return result; +} + +// Windows-1252 decoding table +const std::unordered_map Interpret_As_windows_1252::windows1252Table = { + // ASCII (0x00–0x7F) + {0x00, QChar(0x0000)}, {0x01, QChar(0x0001)}, {0x02, QChar(0x0002)}, {0x03, QChar(0x0003)}, + {0x04, QChar(0x0004)}, {0x05, QChar(0x0005)}, {0x06, QChar(0x0006)}, {0x07, QChar(0x0007)}, + {0x08, QChar(0x0008)}, {0x09, QChar(0x0009)}, {0x0A, QChar(0x000A)}, {0x0B, QChar(0x000B)}, + {0x0C, QChar(0x000C)}, {0x0D, QChar(0x000D)}, {0x0E, QChar(0x000E)}, {0x0F, QChar(0x000F)}, + {0x10, QChar(0x0010)}, {0x11, QChar(0x0011)}, {0x12, QChar(0x0012)}, {0x13, QChar(0x0013)}, + {0x14, QChar(0x0014)}, {0x15, QChar(0x0015)}, {0x16, QChar(0x0016)}, {0x17, QChar(0x0017)}, + {0x18, QChar(0x0018)}, {0x19, QChar(0x0019)}, {0x1A, QChar(0x001A)}, {0x1B, QChar(0x001B)}, + {0x1C, QChar(0x001C)}, {0x1D, QChar(0x001D)}, {0x1E, QChar(0x001E)}, {0x1F, QChar(0x001F)}, + {0x20, QChar(' ')}, {0x21, QChar('!')}, {0x22, QChar('"')}, {0x23, QChar('#')}, + {0x24, QChar('$')}, {0x25, QChar('%')}, {0x26, QChar('&')}, {0x27, QChar('\'')}, + {0x28, QChar('(')}, {0x29, QChar(')')}, {0x2A, QChar('*')}, {0x2B, QChar('+')}, + {0x2C, QChar(',')}, {0x2D, QChar('-')}, {0x2E, QChar('.')}, {0x2F, QChar('/')}, + {0x30, QChar('0')}, {0x31, QChar('1')}, {0x32, QChar('2')}, {0x33, QChar('3')}, + {0x34, QChar('4')}, {0x35, QChar('5')}, {0x36, QChar('6')}, {0x37, QChar('7')}, + {0x38, QChar('8')}, {0x39, QChar('9')}, {0x3A, QChar(':')}, {0x3B, QChar(';')}, + {0x3C, QChar('<')}, {0x3D, QChar('=')}, {0x3E, QChar('>')}, {0x3F, QChar('?')}, + {0x40, QChar('@')}, {0x41, QChar('A')}, {0x42, QChar('B')}, {0x43, QChar('C')}, + {0x44, QChar('D')}, {0x45, QChar('E')}, {0x46, QChar('F')}, {0x47, QChar('G')}, + {0x48, QChar('H')}, {0x49, QChar('I')}, {0x4A, QChar('J')}, {0x4B, QChar('K')}, + {0x4C, QChar('L')}, {0x4D, QChar('M')}, {0x4E, QChar('N')}, {0x4F, QChar('O')}, + {0x50, QChar('P')}, {0x51, QChar('Q')}, {0x52, QChar('R')}, {0x53, QChar('S')}, + {0x54, QChar('T')}, {0x55, QChar('U')}, {0x56, QChar('V')}, {0x57, QChar('W')}, + {0x58, QChar('X')}, {0x59, QChar('Y')}, {0x5A, QChar('Z')}, {0x5B, QChar('[')}, + {0x5C, QChar('\\')}, {0x5D, QChar(']')}, {0x5E, QChar('^')}, {0x5F, QChar('_')}, + {0x60, QChar('`')}, {0x61, QChar('a')}, {0x62, QChar('b')}, {0x63, QChar('c')}, + {0x64, QChar('d')}, {0x65, QChar('e')}, {0x66, QChar('f')}, {0x67, QChar('g')}, + {0x68, QChar('h')}, {0x69, QChar('i')}, {0x6A, QChar('j')}, {0x6B, QChar('k')}, + {0x6C, QChar('l')}, {0x6D, QChar('m')}, {0x6E, QChar('n')}, {0x6F, QChar('o')}, + {0x70, QChar('p')}, {0x71, QChar('q')}, {0x72, QChar('r')}, {0x73, QChar('s')}, + {0x74, QChar('t')}, {0x75, QChar('u')}, {0x76, QChar('v')}, {0x77, QChar('w')}, + {0x78, QChar('x')}, {0x79, QChar('y')}, {0x7A, QChar('z')}, {0x7B, QChar('{')}, + {0x7C, QChar('|')}, {0x7D, QChar('}')}, {0x7E, QChar('~')}, {0x7F, QChar(0x007F)}, + // Extended Characters + {0x80, QChar(0x20AC)}, {0x81, QChar(0xFFFD)}, {0x82, QChar(0x201A)}, {0x83, QChar(0x0192)}, + {0x84, QChar(0x201E)}, {0x85, QChar(0x2026)}, {0x86, QChar(0x2020)}, {0x87, QChar(0x2021)}, + {0x88, QChar(0x02C6)}, {0x89, QChar(0x2030)}, {0x8A, QChar(0x0160)}, {0x8B, QChar(0x2039)}, + {0x8C, QChar(0x0152)}, {0x8D, QChar(0xFFFD)}, {0x8E, QChar(0x017D)}, {0x8F, QChar(0xFFFD)}, + {0x90, QChar(0xFFFD)}, {0x91, QChar(0x2018)}, {0x92, QChar(0x2019)}, {0x93, QChar(0x201C)}, + {0x94, QChar(0x201D)}, {0x95, QChar(0x2022)}, {0x96, QChar(0x2013)}, {0x97, QChar(0x2014)}, + {0x98, QChar(0x02DC)}, {0x99, QChar(0x2122)}, {0x9A, QChar(0x0161)}, {0x9B, QChar(0x203A)}, + {0x9C, QChar(0x0153)}, {0x9D, QChar(0xFFFD)}, {0x9E, QChar(0x017E)}, {0x9F, QChar(0x0178)}, + {0xA9, QChar(0x00A9)}, + }; diff --git a/src/decoding/interpret_as_windows_1252.h b/src/decoding/interpret_as_windows_1252.h new file mode 100644 index 0000000..61fd912 --- /dev/null +++ b/src/decoding/interpret_as_windows_1252.h @@ -0,0 +1,28 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_windows_1252 { +public: + // Singleton instance + static Interpret_As_windows_1252& instance(); + + // Execute decoding for the provided editor + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_windows_1252(); + ~Interpret_As_windows_1252() = default; + + Interpret_As_windows_1252(const Interpret_As_windows_1252&) = delete; + Interpret_As_windows_1252& operator=(const Interpret_As_windows_1252&) = delete; + + // Decoding function + QString decodeWindows1252(const QByteArray& rawData); + + // Windows-1252 decoding table + static const std::unordered_map windows1252Table; +}; diff --git a/src/decoding/interpret_as_windows_1253.cpp b/src/decoding/interpret_as_windows_1253.cpp new file mode 100644 index 0000000..039f0b2 --- /dev/null +++ b/src/decoding/interpret_as_windows_1253.cpp @@ -0,0 +1,105 @@ +#include "../codeeditor.h" +#include "interpret_as_windows_1253.h" +#include +#include + +// Singleton instance +Interpret_As_windows_1253& Interpret_As_windows_1253::instance() { + static Interpret_As_windows_1253 instance; + return instance; +} + +// Constructor +Interpret_As_windows_1253::Interpret_As_windows_1253() {} + +// Main execution function +void Interpret_As_windows_1253::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeWindows1253(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] Windows-1253 decoding applied for file:" << filePath; +} + +// Decode Windows-1253 encoded data +QString Interpret_As_windows_1253::decodeWindows1253(const QByteArray& rawData) { + QString result; + + for (unsigned char byte : rawData) { + auto it = windows1253Table.find(byte); + if (it != windows1253Table.end()) { + result.append(it->second); + } else { + result.append(QChar(0xFFFD)); // Replacement character for unmapped bytes + } + } + + return result; +} + +// Windows-1253 decoding table +const std::unordered_map Interpret_As_windows_1253::windows1253Table = { + {0x00, QChar(0x0000)}, {0x01, QChar(0x0001)}, {0x02, QChar(0x0002)}, {0x03, QChar(0x0003)}, + {0x04, QChar(0x0004)}, {0x05, QChar(0x0005)}, {0x06, QChar(0x0006)}, {0x07, QChar(0x0007)}, + {0x08, QChar(0x0008)}, {0x09, QChar(0x0009)}, {0x0A, QChar(0x000A)}, {0x0B, QChar(0x000B)}, + {0x0C, QChar(0x000C)}, {0x0D, QChar(0x000D)}, {0x0E, QChar(0x000E)}, {0x0F, QChar(0x000F)}, + {0x10, QChar(0x0010)}, {0x11, QChar(0x0011)}, {0x12, QChar(0x0012)}, {0x13, QChar(0x0013)}, + {0x14, QChar(0x0014)}, {0x15, QChar(0x0015)}, {0x16, QChar(0x0016)}, {0x17, QChar(0x0017)}, + {0x18, QChar(0x0018)}, {0x19, QChar(0x0019)}, {0x1A, QChar(0x001A)}, {0x1B, QChar(0x001B)}, + {0x1C, QChar(0x001C)}, {0x1D, QChar(0x001D)}, {0x1E, QChar(0x001E)}, {0x1F, QChar(0x001F)}, + {0x20, QChar(0x0020)}, {0x21, QChar(0x0021)}, {0x22, QChar(0x0022)}, {0x23, QChar(0x0023)}, + {0x24, QChar(0x0024)}, {0x25, QChar(0x0025)}, {0x26, QChar(0x0026)}, {0x27, QChar(0x0027)}, + {0x28, QChar(0x0028)}, {0x29, QChar(0x0029)}, {0x2A, QChar(0x002A)}, {0x2B, QChar(0x002B)}, + {0x2C, QChar(0x002C)}, {0x2D, QChar(0x002D)}, {0x2E, QChar(0x002E)}, {0x2F, QChar(0x002F)}, + {0x30, QChar(0x0030)}, {0x31, QChar(0x0031)}, {0x32, QChar(0x0032)}, {0x33, QChar(0x0033)}, + {0x34, QChar(0x0034)}, {0x35, QChar(0x0035)}, {0x36, QChar(0x0036)}, {0x37, QChar(0x0037)}, + {0x38, QChar(0x0038)}, {0x39, QChar(0x0039)}, {0x3A, QChar(0x003A)}, {0x3B, QChar(0x003B)}, + {0x3C, QChar(0x003C)}, {0x3D, QChar(0x003D)}, {0x3E, QChar(0x003E)}, {0x3F, QChar(0x003F)}, + {0x40, QChar(0x0040)}, {0x41, QChar(0x0041)}, {0x42, QChar(0x0042)}, {0x43, QChar(0x0043)}, + {0x44, QChar(0x0044)}, {0x45, QChar(0x0045)}, {0x46, QChar(0x0046)}, {0x47, QChar(0x0047)}, + {0x48, QChar(0x0048)}, {0x49, QChar(0x0049)}, {0x4A, QChar(0x004A)}, {0x4B, QChar(0x004B)}, + {0x4C, QChar(0x004C)}, {0x4D, QChar(0x004D)}, {0x4E, QChar(0x004E)}, {0x4F, QChar(0x004F)}, + {0x50, QChar(0x0050)}, {0x51, QChar(0x0051)}, {0x52, QChar(0x0052)}, {0x53, QChar(0x0053)}, + {0x54, QChar(0x0054)}, {0x55, QChar(0x0055)}, {0x56, QChar(0x0056)}, {0x57, QChar(0x0057)}, + {0x58, QChar(0x0058)}, {0x59, QChar(0x0059)}, {0x5A, QChar(0x005A)}, {0x5B, QChar(0x005B)}, + {0x5C, QChar(0x005C)}, {0x5D, QChar(0x005D)}, {0x5E, QChar(0x005E)}, {0x5F, QChar(0x005F)}, + {0x60, QChar(0x0060)}, {0x61, QChar(0x0061)}, {0x62, QChar(0x0062)}, {0x63, QChar(0x0063)}, + {0x64, QChar(0x0064)}, {0x65, QChar(0x0065)}, {0x66, QChar(0x0066)}, {0x67, QChar(0x0067)}, + {0x68, QChar(0x0068)}, {0x69, QChar(0x0069)}, {0x6A, QChar(0x006A)}, {0x6B, QChar(0x006B)}, + {0x6C, QChar(0x006C)}, {0x6D, QChar(0x006D)}, {0x6E, QChar(0x006E)}, {0x6F, QChar(0x006F)}, + {0x70, QChar(0x0070)}, {0x71, QChar(0x0071)}, {0x72, QChar(0x0072)}, {0x73, QChar(0x0073)}, + {0x74, QChar(0x0074)}, {0x75, QChar(0x0075)}, {0x76, QChar(0x0076)}, {0x77, QChar(0x0077)}, + {0x78, QChar(0x0078)}, {0x79, QChar(0x0079)}, {0x7A, QChar(0x007A)}, {0x7B, QChar(0x007B)}, + {0x7C, QChar(0x007C)}, {0x7D, QChar(0x007D)}, {0x7E, QChar(0x007E)}, {0x7F, QChar(0x007F)}, + {0x80, QChar(0x20AC)}, {0x81, QChar(0xFFFD)}, {0x82, QChar(0x201A)}, {0x83, QChar(0x0192)}, + {0x84, QChar(0x201E)}, {0x85, QChar(0x2026)}, {0x86, QChar(0x2020)}, {0x87, QChar(0x2021)}, + {0x88, QChar(0x20AC)}, {0x89, QChar(0x20AC)}, {0x8A, QChar(0x20AC)}, {0x8B, QChar(0x20AC)}, + {0x8C, QChar(0x20AC)}, {0x8D, QChar(0x20AC)}, {0x8E, QChar(0x20AC)}, {0x8F, QChar(0x20AC)}, + {0x90, QChar(0x20AC)}, {0x91, QChar(0x20AC)}, {0x92, QChar(0x20AC)}, {0x93, QChar(0x20AC)}, + {0x94, QChar(0x20AC)}, {0x95, QChar(0x20AC)}, {0x96, QChar(0x20AC)}, {0x97, QChar(0x20AC)}, + // Add complete table rows +}; diff --git a/src/decoding/interpret_as_windows_1253.h b/src/decoding/interpret_as_windows_1253.h new file mode 100644 index 0000000..2d7d8ca --- /dev/null +++ b/src/decoding/interpret_as_windows_1253.h @@ -0,0 +1,29 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_windows_1253 { +public: + // Singleton instance + static Interpret_As_windows_1253& instance(); + + // Execute decoding for the provided editor + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_windows_1253(); + ~Interpret_As_windows_1253() = default; + + Interpret_As_windows_1253(const Interpret_As_windows_1253&) = delete; + Interpret_As_windows_1253& operator=(const Interpret_As_windows_1253&) = delete; + + // Decoding function + QString decodeWindows1253(const QByteArray& rawData); + + // Windows-1253 decoding table + static const std::unordered_map windows1253Table; +}; + diff --git a/src/decoding/interpret_as_windows_1254.cpp b/src/decoding/interpret_as_windows_1254.cpp new file mode 100644 index 0000000..2ee15e7 --- /dev/null +++ b/src/decoding/interpret_as_windows_1254.cpp @@ -0,0 +1,100 @@ +#include "../codeeditor.h" +#include "interpret_as_windows_1254.h" +#include +#include + +// Singleton instance +Interpret_As_windows_1254& Interpret_As_windows_1254::instance() { + static Interpret_As_windows_1254 instance; + return instance; +} + +// Constructor +Interpret_As_windows_1254::Interpret_As_windows_1254() {} + +// Main execution function +void Interpret_As_windows_1254::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeWindows1254(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] Windows-1254 decoding applied for file:" << filePath; +} + +// Decode Windows-1254 encoded data +QString Interpret_As_windows_1254::decodeWindows1254(const QByteArray& rawData) { + QString result; + + for (unsigned char byte : rawData) { + auto it = windows1254Table.find(byte); + if (it != windows1254Table.end()) { + result.append(it->second); + } else { + result.append(QChar(0xFFFD)); // Replacement character for unmapped bytes + } + } + + return result; +} + +// Windows-1254 decoding table +const std::unordered_map Interpret_As_windows_1254::windows1254Table = { + {0x00, QChar(0x0000)}, {0x01, QChar(0x0001)}, {0x02, QChar(0x0002)}, {0x03, QChar(0x0003)}, + {0x04, QChar(0x0004)}, {0x05, QChar(0x0005)}, {0x06, QChar(0x0006)}, {0x07, QChar(0x0007)}, + {0x08, QChar(0x0008)}, {0x09, QChar(0x0009)}, {0x0A, QChar(0x000A)}, {0x0B, QChar(0x000B)}, + {0x0C, QChar(0x000C)}, {0x0D, QChar(0x000D)}, {0x0E, QChar(0x000E)}, {0x0F, QChar(0x000F)}, + {0x10, QChar(0x0010)}, {0x11, QChar(0x0011)}, {0x12, QChar(0x0012)}, {0x13, QChar(0x0013)}, + {0x14, QChar(0x0014)}, {0x15, QChar(0x0015)}, {0x16, QChar(0x0016)}, {0x17, QChar(0x0017)}, + {0x18, QChar(0x0018)}, {0x19, QChar(0x0019)}, {0x1A, QChar(0x001A)}, {0x1B, QChar(0x001B)}, + {0x1C, QChar(0x001C)}, {0x1D, QChar(0x001D)}, {0x1E, QChar(0x001E)}, {0x1F, QChar(0x001F)}, + {0x20, QChar(0x0020)}, {0x21, QChar(0x0021)}, {0x22, QChar(0x0022)}, {0x23, QChar(0x0023)}, + {0x24, QChar(0x0024)}, {0x25, QChar(0x0025)}, {0x26, QChar(0x0026)}, {0x27, QChar(0x0027)}, + {0x28, QChar(0x0028)}, {0x29, QChar(0x0029)}, {0x2A, QChar(0x002A)}, {0x2B, QChar(0x002B)}, + {0x2C, QChar(0x002C)}, {0x2D, QChar(0x002D)}, {0x2E, QChar(0x002E)}, {0x2F, QChar(0x002F)}, + {0x30, QChar(0x0030)}, {0x31, QChar(0x0031)}, {0x32, QChar(0x0032)}, {0x33, QChar(0x0033)}, + {0x34, QChar(0x0034)}, {0x35, QChar(0x0035)}, {0x36, QChar(0x0036)}, {0x37, QChar(0x0037)}, + {0x38, QChar(0x0038)}, {0x39, QChar(0x0039)}, {0x3A, QChar(0x003A)}, {0x3B, QChar(0x003B)}, + {0x3C, QChar(0x003C)}, {0x3D, QChar(0x003D)}, {0x3E, QChar(0x003E)}, {0x3F, QChar(0x003F)}, + {0x40, QChar(0x0040)}, {0x41, QChar(0x0041)}, {0x42, QChar(0x0042)}, {0x43, QChar(0x0043)}, + {0x44, QChar(0x0044)}, {0x45, QChar(0x0045)}, {0x46, QChar(0x0046)}, {0x47, QChar(0x0047)}, + {0x48, QChar(0x0048)}, {0x49, QChar(0x0049)}, {0x4A, QChar(0x004A)}, {0x4B, QChar(0x004B)}, + {0x4C, QChar(0x004C)}, {0x4D, QChar(0x004D)}, {0x4E, QChar(0x004E)}, {0x4F, QChar(0x004F)}, + {0x50, QChar(0x0050)}, {0x51, QChar(0x0051)}, {0x52, QChar(0x0052)}, {0x53, QChar(0x0053)}, + {0x54, QChar(0x0054)}, {0x55, QChar(0x0055)}, {0x56, QChar(0x0056)}, {0x57, QChar(0x0057)}, + {0x58, QChar(0x0058)}, {0x59, QChar(0x0059)}, {0x5A, QChar(0x005A)}, {0x5B, QChar(0x005B)}, + {0x5C, QChar(0x005C)}, {0x5D, QChar(0x005D)}, {0x5E, QChar(0x005E)}, {0x5F, QChar(0x005F)}, + {0x60, QChar(0x0060)}, {0x61, QChar(0x0061)}, {0x62, QChar(0x0062)}, {0x63, QChar(0x0063)}, + {0x64, QChar(0x0064)}, {0x65, QChar(0x0065)}, {0x66, QChar(0x0066)}, {0x67, QChar(0x0067)}, + {0x68, QChar(0x0068)}, {0x69, QChar(0x0069)}, {0x6A, QChar(0x006A)}, {0x6B, QChar(0x006B)}, + {0x6C, QChar(0x006C)}, {0x6D, QChar(0x006D)}, {0x6E, QChar(0x006E)}, {0x6F, QChar(0x006F)}, + {0x70, QChar(0x0070)}, {0x71, QChar(0x0071)}, {0x72, QChar(0x0072)}, {0x73, QChar(0x0073)}, + {0x74, QChar(0x0074)}, {0x75, QChar(0x0075)}, {0x76, QChar(0x0076)}, {0x77, QChar(0x0077)}, + {0x78, QChar(0x0078)}, {0x79, QChar(0x0079)}, {0x7A, QChar(0x007A)}, {0x7B, QChar(0x007B)}, + {0x7C, QChar(0x007C)}, {0x7D, QChar(0x007D)}, {0x7E, QChar(0x007E)}, {0x7F, QChar(0x007F)}, + {0x80, QChar(0x20AC)}, {0x81, QChar(0xFFFD)}, {0x82, QChar(0x201A)}, {0x83, QChar(0x0192)}, + // Add mappings for 0x84 to 0xFF, including Turkish characters +}; diff --git a/src/decoding/interpret_as_windows_1254.h b/src/decoding/interpret_as_windows_1254.h new file mode 100644 index 0000000..2830e16 --- /dev/null +++ b/src/decoding/interpret_as_windows_1254.h @@ -0,0 +1,28 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_windows_1254 { +public: + // Singleton instance + static Interpret_As_windows_1254& instance(); + + // Execute decoding for the provided editor + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_windows_1254(); + ~Interpret_As_windows_1254() = default; + + Interpret_As_windows_1254(const Interpret_As_windows_1254&) = delete; + Interpret_As_windows_1254& operator=(const Interpret_As_windows_1254&) = delete; + + // Decoding function + QString decodeWindows1254(const QByteArray& rawData); + + // Windows-1254 decoding table + static const std::unordered_map windows1254Table; +}; diff --git a/src/decoding/interpret_as_windows_1255.cpp b/src/decoding/interpret_as_windows_1255.cpp new file mode 100644 index 0000000..bf4279e --- /dev/null +++ b/src/decoding/interpret_as_windows_1255.cpp @@ -0,0 +1,101 @@ +#include "../codeeditor.h" +#include "interpret_as_windows_1255.h" +#include +#include + +// Singleton instance +Interpret_As_windows_1255& Interpret_As_windows_1255::instance() { + static Interpret_As_windows_1255 instance; + return instance; +} + +// Constructor +Interpret_As_windows_1255::Interpret_As_windows_1255() {} + +// Main execution function +void Interpret_As_windows_1255::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeWindows1255(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] Windows-1255 decoding applied for file:" << filePath; +} + +// Decode Windows-1255 encoded data +QString Interpret_As_windows_1255::decodeWindows1255(const QByteArray& rawData) { + QString result; + + for (unsigned char byte : rawData) { + auto it = windows1255Table.find(byte); + if (it != windows1255Table.end()) { + result.append(it->second); + } else { + result.append(QChar(0xFFFD)); // Replacement character for unmapped bytes + } + } + + return result; +} + +// Complete Windows-1255 decoding table +const std::unordered_map Interpret_As_windows_1255::windows1255Table = { + {0x00, QChar(0x0000)}, {0x01, QChar(0x0001)}, {0x02, QChar(0x0002)}, {0x03, QChar(0x0003)}, + {0x04, QChar(0x0004)}, {0x05, QChar(0x0005)}, {0x06, QChar(0x0006)}, {0x07, QChar(0x0007)}, + {0x08, QChar(0x0008)}, {0x09, QChar(0x0009)}, {0x0A, QChar(0x000A)}, {0x0B, QChar(0x000B)}, + {0x0C, QChar(0x000C)}, {0x0D, QChar(0x000D)}, {0x0E, QChar(0x000E)}, {0x0F, QChar(0x000F)}, + {0x10, QChar(0x0010)}, {0x11, QChar(0x0011)}, {0x12, QChar(0x0012)}, {0x13, QChar(0x0013)}, + {0x14, QChar(0x0014)}, {0x15, QChar(0x0015)}, {0x16, QChar(0x0016)}, {0x17, QChar(0x0017)}, + {0x18, QChar(0x0018)}, {0x19, QChar(0x0019)}, {0x1A, QChar(0x001A)}, {0x1B, QChar(0x001B)}, + {0x1C, QChar(0x001C)}, {0x1D, QChar(0x001D)}, {0x1E, QChar(0x001E)}, {0x1F, QChar(0x001F)}, + {0x20, QChar(0x0020)}, {0x21, QChar(0x0021)}, {0x22, QChar(0x0022)}, {0x23, QChar(0x0023)}, + {0x24, QChar(0x0024)}, {0x25, QChar(0x0025)}, {0x26, QChar(0x0026)}, {0x27, QChar(0x0027)}, + {0x28, QChar(0x0028)}, {0x29, QChar(0x0029)}, {0x2A, QChar(0x002A)}, {0x2B, QChar(0x002B)}, + {0x2C, QChar(0x002C)}, {0x2D, QChar(0x002D)}, {0x2E, QChar(0x002E)}, {0x2F, QChar(0x002F)}, + {0x30, QChar(0x0030)}, {0x31, QChar(0x0031)}, {0x32, QChar(0x0032)}, {0x33, QChar(0x0033)}, + {0x34, QChar(0x0034)}, {0x35, QChar(0x0035)}, {0x36, QChar(0x0036)}, {0x37, QChar(0x0037)}, + {0x38, QChar(0x0038)}, {0x39, QChar(0x0039)}, {0x3A, QChar(0x003A)}, {0x3B, QChar(0x003B)}, + {0x3C, QChar(0x003C)}, {0x3D, QChar(0x003D)}, {0x3E, QChar(0x003E)}, {0x3F, QChar(0x003F)}, + {0x40, QChar(0x0040)}, {0x41, QChar(0x0041)}, {0x42, QChar(0x0042)}, {0x43, QChar(0x0043)}, + {0x44, QChar(0x0044)}, {0x45, QChar(0x0045)}, {0x46, QChar(0x0046)}, {0x47, QChar(0x0047)}, + {0x48, QChar(0x0048)}, {0x49, QChar(0x0049)}, {0x4A, QChar(0x004A)}, {0x4B, QChar(0x004B)}, + {0x4C, QChar(0x004C)}, {0x4D, QChar(0x004D)}, {0x4E, QChar(0x004E)}, {0x4F, QChar(0x004F)}, + {0x50, QChar(0x0050)}, {0x51, QChar(0x0051)}, {0x52, QChar(0x0052)}, {0x53, QChar(0x0053)}, + {0x54, QChar(0x0054)}, {0x55, QChar(0x0055)}, {0x56, QChar(0x0056)}, {0x57, QChar(0x0057)}, + {0x58, QChar(0x0058)}, {0x59, QChar(0x0059)}, {0x5A, QChar(0x005A)}, {0x5B, QChar(0x005B)}, + {0x5C, QChar(0x005C)}, {0x5D, QChar(0x005D)}, {0x5E, QChar(0x005E)}, {0x5F, QChar(0x005F)}, + {0x60, QChar(0x0060)}, {0x61, QChar(0x0061)}, {0x62, QChar(0x0062)}, {0x63, QChar(0x0063)}, + {0x64, QChar(0x0064)}, {0x65, QChar(0x0065)}, {0x66, QChar(0x0066)}, {0x67, QChar(0x0067)}, + {0x68, QChar(0x0068)}, {0x69, QChar(0x0069)}, {0x6A, QChar(0x006A)}, {0x6B, QChar(0x006B)}, + {0x6C, QChar(0x006C)}, {0x6D, QChar(0x006D)}, {0x6E, QChar(0x006E)}, {0x6F, QChar(0x006F)}, + {0x70, QChar(0x0070)}, {0x71, QChar(0x0071)}, {0x72, QChar(0x0072)}, {0x73, QChar(0x0073)}, + {0x74, QChar(0x0074)}, {0x75, QChar(0x0075)}, {0x76, QChar(0x0076)}, {0x77, QChar(0x0077)}, + {0x78, QChar(0x0078)}, {0x79, QChar(0x0079)}, {0x7A, QChar(0x007A)}, {0x7B, QChar(0x007B)}, + {0x7C, QChar(0x007C)}, {0x7D, QChar(0x007D)}, {0x7E, QChar(0x007E)}, {0x7F, QChar(0x007F)}, + {0x80, QChar(0x20AC)}, {0x81, QChar(0xFFFD)}, {0x82, QChar(0x201A)}, {0x83, QChar(0x0192)}, + {0x84, QChar(0x201E)}, {0x85, QChar(0x2026)}, {0x86, QChar(0x2020)}, {0x87, QChar(0x2021)}, + {0x88, QChar(0x20AC)}, {0x89, QChar(0x20AC)}, {0x8A, QChar(0x20AC)}, {0x8C, QChar(0x20AC)}, + }; diff --git a/src/decoding/interpret_as_windows_1255.h b/src/decoding/interpret_as_windows_1255.h new file mode 100644 index 0000000..54e00c7 --- /dev/null +++ b/src/decoding/interpret_as_windows_1255.h @@ -0,0 +1,28 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_windows_1255 { +public: + // Singleton instance + static Interpret_As_windows_1255& instance(); + + // Execute decoding for the provided editor + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_windows_1255(); + ~Interpret_As_windows_1255() = default; + + Interpret_As_windows_1255(const Interpret_As_windows_1255&) = delete; + Interpret_As_windows_1255& operator=(const Interpret_As_windows_1255&) = delete; + + // Decoding function + QString decodeWindows1255(const QByteArray& rawData); + + // Windows-1255 decoding table + static const std::unordered_map windows1255Table; +}; diff --git a/src/decoding/interpret_as_windows_1256.cpp b/src/decoding/interpret_as_windows_1256.cpp new file mode 100644 index 0000000..744a741 --- /dev/null +++ b/src/decoding/interpret_as_windows_1256.cpp @@ -0,0 +1,99 @@ +#include "../codeeditor.h" +#include "interpret_as_windows_1256.h" +#include +#include + +// Singleton instance +Interpret_As_windows_1256& Interpret_As_windows_1256::instance() { + static Interpret_As_windows_1256 instance; + return instance; +} + +// Constructor +Interpret_As_windows_1256::Interpret_As_windows_1256() {} + +// Main execution function +void Interpret_As_windows_1256::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeWindows1256(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] Windows-1256 decoding applied for file:" << filePath; +} + +// Decode Windows-1256 encoded data +QString Interpret_As_windows_1256::decodeWindows1256(const QByteArray& rawData) { + QString result; + + for (unsigned char byte : rawData) { + auto it = windows1256Table.find(byte); + if (it != windows1256Table.end()) { + result.append(it->second); + } else { + result.append(QChar(0xFFFD)); // Replacement character for unmapped bytes + } + } + + return result; +} + +// Complete Windows-1256 decoding table +const std::unordered_map Interpret_As_windows_1256::windows1256Table = { + {0x00, QChar(0x0000)}, {0x01, QChar(0x0001)}, {0x02, QChar(0x0002)}, {0x03, QChar(0x0003)}, + {0x04, QChar(0x0004)}, {0x05, QChar(0x0005)}, {0x06, QChar(0x0006)}, {0x07, QChar(0x0007)}, + {0x08, QChar(0x0008)}, {0x09, QChar(0x0009)}, {0x0A, QChar(0x000A)}, {0x0B, QChar(0x000B)}, + {0x0C, QChar(0x000C)}, {0x0D, QChar(0x000D)}, {0x0E, QChar(0x000E)}, {0x0F, QChar(0x000F)}, + {0x10, QChar(0x0010)}, {0x11, QChar(0x0011)}, {0x12, QChar(0x0012)}, {0x13, QChar(0x0013)}, + {0x14, QChar(0x0014)}, {0x15, QChar(0x0015)}, {0x16, QChar(0x0016)}, {0x17, QChar(0x0017)}, + {0x18, QChar(0x0018)}, {0x19, QChar(0x0019)}, {0x1A, QChar(0x001A)}, {0x1B, QChar(0x001B)}, + {0x1C, QChar(0x001C)}, {0x1D, QChar(0x001D)}, {0x1E, QChar(0x001E)}, {0x1F, QChar(0x001F)}, + {0x20, QChar(0x0020)}, {0x21, QChar(0x0021)}, {0x22, QChar(0x0022)}, {0x23, QChar(0x0023)}, + {0x24, QChar(0x0024)}, {0x25, QChar(0x0025)}, {0x26, QChar(0x0026)}, {0x27, QChar(0x0027)}, + {0x28, QChar(0x0028)}, {0x29, QChar(0x0029)}, {0x2A, QChar(0x002A)}, {0x2B, QChar(0x002B)}, + {0x2C, QChar(0x002C)}, {0x2D, QChar(0x002D)}, {0x2E, QChar(0x002E)}, {0x2F, QChar(0x002F)}, + {0x30, QChar(0x0030)}, {0x31, QChar(0x0031)}, {0x32, QChar(0x0032)}, {0x33, QChar(0x0033)}, + {0x34, QChar(0x0034)}, {0x35, QChar(0x0035)}, {0x36, QChar(0x0036)}, {0x37, QChar(0x0037)}, + {0x38, QChar(0x0038)}, {0x39, QChar(0x0039)}, {0x3A, QChar(0x003A)}, {0x3B, QChar(0x003B)}, + {0x3C, QChar(0x003C)}, {0x3D, QChar(0x003D)}, {0x3E, QChar(0x003E)}, {0x3F, QChar(0x003F)}, + {0x40, QChar(0x0040)}, {0x41, QChar(0x0041)}, {0x42, QChar(0x0042)}, {0x43, QChar(0x0043)}, + {0x44, QChar(0x0044)}, {0x45, QChar(0x0045)}, {0x46, QChar(0x0046)}, {0x47, QChar(0x0047)}, + {0x48, QChar(0x0048)}, {0x49, QChar(0x0049)}, {0x4A, QChar(0x004A)}, {0x4B, QChar(0x004B)}, + {0x4C, QChar(0x004C)}, {0x4D, QChar(0x004D)}, {0x4E, QChar(0x004E)}, {0x4F, QChar(0x004F)}, + {0x50, QChar(0x0050)}, {0x51, QChar(0x0051)}, {0x52, QChar(0x0052)}, {0x53, QChar(0x0053)}, + {0x54, QChar(0x0054)}, {0x55, QChar(0x0055)}, {0x56, QChar(0x0056)}, {0x57, QChar(0x0057)}, + {0x58, QChar(0x0058)}, {0x59, QChar(0x0059)}, {0x5A, QChar(0x005A)}, {0x5B, QChar(0x005B)}, + {0x5C, QChar(0x005C)}, {0x5D, QChar(0x005D)}, {0x5E, QChar(0x005E)}, {0x5F, QChar(0x005F)}, + {0x60, QChar(0x0060)}, {0x61, QChar(0x0061)}, {0x62, QChar(0x0062)}, {0x63, QChar(0x0063)}, + {0x64, QChar(0x0064)}, {0x65, QChar(0x0065)}, {0x66, QChar(0x0066)}, {0x67, QChar(0x0067)}, + {0x68, QChar(0x0068)}, {0x69, QChar(0x0069)}, {0x6A, QChar(0x006A)}, {0x6B, QChar(0x006B)}, + {0x6C, QChar(0x006C)}, {0x6D, QChar(0x006D)}, {0x6E, QChar(0x006E)}, {0x6F, QChar(0x006F)}, + {0x70, QChar(0x0070)}, {0x71, QChar(0x0071)}, {0x72, QChar(0x0072)}, {0x73, QChar(0x0073)}, + {0x74, QChar(0x0074)}, {0x75, QChar(0x0075)}, {0x76, QChar(0x0076)}, {0x77, QChar(0x0077)}, + {0x78, QChar(0x0078)}, {0x79, QChar(0x0079)}, {0x7A, QChar(0x007A)}, {0x7B, QChar(0x007B)}, + {0x7C, QChar(0x007C)}, {0x7D, QChar(0x007D)}, {0x7E, QChar(0x007E)}, {0x7F, QChar(0x007F)}, + {0x80, QChar(0x20AC)}, // Extend for Arabic characters (0xC0 to 0xFF) +}; diff --git a/src/decoding/interpret_as_windows_1256.h b/src/decoding/interpret_as_windows_1256.h new file mode 100644 index 0000000..d2202e6 --- /dev/null +++ b/src/decoding/interpret_as_windows_1256.h @@ -0,0 +1,28 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_windows_1256 { +public: + // Singleton instance + static Interpret_As_windows_1256& instance(); + + // Execute decoding for the provided editor + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_windows_1256(); + ~Interpret_As_windows_1256() = default; + + Interpret_As_windows_1256(const Interpret_As_windows_1256&) = delete; + Interpret_As_windows_1256& operator=(const Interpret_As_windows_1256&) = delete; + + // Decoding function + QString decodeWindows1256(const QByteArray& rawData); + + // Windows-1256 decoding table + static const std::unordered_map windows1256Table; +}; diff --git a/src/decoding/interpret_as_windows_1257.cpp b/src/decoding/interpret_as_windows_1257.cpp new file mode 100644 index 0000000..ac970c1 --- /dev/null +++ b/src/decoding/interpret_as_windows_1257.cpp @@ -0,0 +1,99 @@ +#include "../codeeditor.h" +#include "interpret_as_windows_1257.h" +#include +#include + +// Singleton instance +Interpret_As_windows_1257& Interpret_As_windows_1257::instance() { + static Interpret_As_windows_1257 instance; + return instance; +} + +// Constructor +Interpret_As_windows_1257::Interpret_As_windows_1257() {} + +// Main execution function +void Interpret_As_windows_1257::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeWindows1257(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] Windows-1257 decoding applied for file:" << filePath; +} + +// Decode Windows-1257 encoded data +QString Interpret_As_windows_1257::decodeWindows1257(const QByteArray& rawData) { + QString result; + + for (unsigned char byte : rawData) { + auto it = windows1257Table.find(byte); + if (it != windows1257Table.end()) { + result.append(it->second); + } else { + result.append(QChar(0xFFFD)); // Replacement character for unmapped bytes + } + } + + return result; +} + +// Complete Windows-1257 decoding table +const std::unordered_map Interpret_As_windows_1257::windows1257Table = { + {0x00, QChar(0x0000)}, {0x01, QChar(0x0001)}, {0x02, QChar(0x0002)}, {0x03, QChar(0x0003)}, + {0x04, QChar(0x0004)}, {0x05, QChar(0x0005)}, {0x06, QChar(0x0006)}, {0x07, QChar(0x0007)}, + {0x08, QChar(0x0008)}, {0x09, QChar(0x0009)}, {0x0A, QChar(0x000A)}, {0x0B, QChar(0x000B)}, + {0x0C, QChar(0x000C)}, {0x0D, QChar(0x000D)}, {0x0E, QChar(0x000E)}, {0x0F, QChar(0x000F)}, + {0x10, QChar(0x0010)}, {0x11, QChar(0x0011)}, {0x12, QChar(0x0012)}, {0x13, QChar(0x0013)}, + {0x14, QChar(0x0014)}, {0x15, QChar(0x0015)}, {0x16, QChar(0x0016)}, {0x17, QChar(0x0017)}, + {0x18, QChar(0x0018)}, {0x19, QChar(0x0019)}, {0x1A, QChar(0x001A)}, {0x1B, QChar(0x001B)}, + {0x1C, QChar(0x001C)}, {0x1D, QChar(0x001D)}, {0x1E, QChar(0x001E)}, {0x1F, QChar(0x001F)}, + {0x20, QChar(0x0020)}, {0x21, QChar(0x0021)}, {0x22, QChar(0x0022)}, {0x23, QChar(0x0023)}, + {0x24, QChar(0x0024)}, {0x25, QChar(0x0025)}, {0x26, QChar(0x0026)}, {0x27, QChar(0x0027)}, + {0x28, QChar(0x0028)}, {0x29, QChar(0x0029)}, {0x2A, QChar(0x002A)}, {0x2B, QChar(0x002B)}, + {0x2C, QChar(0x002C)}, {0x2D, QChar(0x002D)}, {0x2E, QChar(0x002E)}, {0x2F, QChar(0x002F)}, + {0x30, QChar(0x0030)}, {0x31, QChar(0x0031)}, {0x32, QChar(0x0032)}, {0x33, QChar(0x0033)}, + {0x34, QChar(0x0034)}, {0x35, QChar(0x0035)}, {0x36, QChar(0x0036)}, {0x37, QChar(0x0037)}, + {0x38, QChar(0x0038)}, {0x39, QChar(0x0039)}, {0x3A, QChar(0x003A)}, {0x3B, QChar(0x003B)}, + {0x3C, QChar(0x003C)}, {0x3D, QChar(0x003D)}, {0x3E, QChar(0x003E)}, {0x3F, QChar(0x003F)}, + {0x40, QChar(0x0040)}, {0x41, QChar(0x0041)}, {0x42, QChar(0x0042)}, {0x43, QChar(0x0043)}, + {0x44, QChar(0x0044)}, {0x45, QChar(0x0045)}, {0x46, QChar(0x0046)}, {0x47, QChar(0x0047)}, + {0x48, QChar(0x0048)}, {0x49, QChar(0x0049)}, {0x4A, QChar(0x004A)}, {0x4B, QChar(0x004B)}, + {0x4C, QChar(0x004C)}, {0x4D, QChar(0x004D)}, {0x4E, QChar(0x004E)}, {0x4F, QChar(0x004F)}, + {0x50, QChar(0x0050)}, {0x51, QChar(0x0051)}, {0x52, QChar(0x0052)}, {0x53, QChar(0x0053)}, + {0x54, QChar(0x0054)}, {0x55, QChar(0x0055)}, {0x56, QChar(0x0056)}, {0x57, QChar(0x0057)}, + {0x58, QChar(0x0058)}, {0x59, QChar(0x0059)}, {0x5A, QChar(0x005A)}, {0x5B, QChar(0x005B)}, + {0x5C, QChar(0x005C)}, {0x5D, QChar(0x005D)}, {0x5E, QChar(0x005E)}, {0x5F, QChar(0x005F)}, + {0x60, QChar(0x0060)}, {0x61, QChar(0x0061)}, {0x62, QChar(0x0062)}, {0x63, QChar(0x0063)}, + {0x64, QChar(0x0064)}, {0x65, QChar(0x0065)}, {0x66, QChar(0x0066)}, {0x67, QChar(0x0067)}, + {0x68, QChar(0x0068)}, {0x69, QChar(0x0069)}, {0x6A, QChar(0x006A)}, {0x6B, QChar(0x006B)}, + {0x6C, QChar(0x006C)}, {0x6D, QChar(0x006D)}, {0x6E, QChar(0x006E)}, {0x6F, QChar(0x006F)}, + {0x70, QChar(0x0070)}, {0x71, QChar(0x0071)}, {0x72, QChar(0x0072)}, {0x73, QChar(0x0073)}, + {0x74, QChar(0x0074)}, {0x75, QChar(0x0075)}, {0x76, QChar(0x0076)}, {0x77, QChar(0x0077)}, + {0x78, QChar(0x0078)}, {0x79, QChar(0x0079)}, {0x7A, QChar(0x007A)}, {0x7B, QChar(0x007B)}, + {0x7C, QChar(0x007C)}, {0x7D, QChar(0x007D)}, {0x7E, QChar(0x007E)}, {0x7F, QChar(0x007F)}, + {0x80, QChar(0x20AC)}, // Extend for special characters (0x80–0xFF) +}; diff --git a/src/decoding/interpret_as_windows_1257.h b/src/decoding/interpret_as_windows_1257.h new file mode 100644 index 0000000..cf602e3 --- /dev/null +++ b/src/decoding/interpret_as_windows_1257.h @@ -0,0 +1,28 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_windows_1257 { +public: + // Singleton instance + static Interpret_As_windows_1257& instance(); + + // Execute decoding for the provided editor + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_windows_1257(); + ~Interpret_As_windows_1257() = default; + + Interpret_As_windows_1257(const Interpret_As_windows_1257&) = delete; + Interpret_As_windows_1257& operator=(const Interpret_As_windows_1257&) = delete; + + // Decoding function + QString decodeWindows1257(const QByteArray& rawData); + + // Windows-1257 decoding table + static const std::unordered_map windows1257Table; +}; diff --git a/src/decoding/interpret_as_windows_1258.cpp b/src/decoding/interpret_as_windows_1258.cpp new file mode 100644 index 0000000..b83af3d --- /dev/null +++ b/src/decoding/interpret_as_windows_1258.cpp @@ -0,0 +1,99 @@ +#include "../codeeditor.h" +#include "interpret_as_windows_1258.h" +#include +#include + +// Singleton instance +Interpret_As_windows_1258& Interpret_As_windows_1258::instance() { + static Interpret_As_windows_1258 instance; + return instance; +} + +// Constructor +Interpret_As_windows_1258::Interpret_As_windows_1258() {} + +// Main execution function +void Interpret_As_windows_1258::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeWindows1258(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] Windows-1258 decoding applied for file:" << filePath; +} + +// Decode Windows-1258 encoded data +QString Interpret_As_windows_1258::decodeWindows1258(const QByteArray& rawData) { + QString result; + + for (unsigned char byte : rawData) { + auto it = windows1258Table.find(byte); + if (it != windows1258Table.end()) { + result.append(it->second); + } else { + result.append(QChar(0xFFFD)); // Replacement character for unmapped bytes + } + } + + return result; +} + +// Complete Windows-1258 decoding table +const std::unordered_map Interpret_As_windows_1258::windows1258Table = { + {0x00, QChar(0x0000)}, {0x01, QChar(0x0001)}, {0x02, QChar(0x0002)}, {0x03, QChar(0x0003)}, + {0x04, QChar(0x0004)}, {0x05, QChar(0x0005)}, {0x06, QChar(0x0006)}, {0x07, QChar(0x0007)}, + {0x08, QChar(0x0008)}, {0x09, QChar(0x0009)}, {0x0A, QChar(0x000A)}, {0x0B, QChar(0x000B)}, + {0x0C, QChar(0x000C)}, {0x0D, QChar(0x000D)}, {0x0E, QChar(0x000E)}, {0x0F, QChar(0x000F)}, + {0x10, QChar(0x0010)}, {0x11, QChar(0x0011)}, {0x12, QChar(0x0012)}, {0x13, QChar(0x0013)}, + {0x14, QChar(0x0014)}, {0x15, QChar(0x0015)}, {0x16, QChar(0x0016)}, {0x17, QChar(0x0017)}, + {0x18, QChar(0x0018)}, {0x19, QChar(0x0019)}, {0x1A, QChar(0x001A)}, {0x1B, QChar(0x001B)}, + {0x1C, QChar(0x001C)}, {0x1D, QChar(0x001D)}, {0x1E, QChar(0x001E)}, {0x1F, QChar(0x001F)}, + {0x20, QChar(0x0020)}, {0x21, QChar(0x0021)}, {0x22, QChar(0x0022)}, {0x23, QChar(0x0023)}, + {0x24, QChar(0x0024)}, {0x25, QChar(0x0025)}, {0x26, QChar(0x0026)}, {0x27, QChar(0x0027)}, + {0x28, QChar(0x0028)}, {0x29, QChar(0x0029)}, {0x2A, QChar(0x002A)}, {0x2B, QChar(0x002B)}, + {0x2C, QChar(0x002C)}, {0x2D, QChar(0x002D)}, {0x2E, QChar(0x002E)}, {0x2F, QChar(0x002F)}, + {0x30, QChar(0x0030)}, {0x31, QChar(0x0031)}, {0x32, QChar(0x0032)}, {0x33, QChar(0x0033)}, + {0x34, QChar(0x0034)}, {0x35, QChar(0x0035)}, {0x36, QChar(0x0036)}, {0x37, QChar(0x0037)}, + {0x38, QChar(0x0038)}, {0x39, QChar(0x0039)}, {0x3A, QChar(0x003A)}, {0x3B, QChar(0x003B)}, + {0x3C, QChar(0x003C)}, {0x3D, QChar(0x003D)}, {0x3E, QChar(0x003E)}, {0x3F, QChar(0x003F)}, + {0x40, QChar(0x0040)}, {0x41, QChar(0x0041)}, {0x42, QChar(0x0042)}, {0x43, QChar(0x0043)}, + {0x44, QChar(0x0044)}, {0x45, QChar(0x0045)}, {0x46, QChar(0x0046)}, {0x47, QChar(0x0047)}, + {0x48, QChar(0x0048)}, {0x49, QChar(0x0049)}, {0x4A, QChar(0x004A)}, {0x4B, QChar(0x004B)}, + {0x4C, QChar(0x004C)}, {0x4D, QChar(0x004D)}, {0x4E, QChar(0x004E)}, {0x4F, QChar(0x004F)}, + {0x50, QChar(0x0050)}, {0x51, QChar(0x0051)}, {0x52, QChar(0x0052)}, {0x53, QChar(0x0053)}, + {0x54, QChar(0x0054)}, {0x55, QChar(0x0055)}, {0x56, QChar(0x0056)}, {0x57, QChar(0x0057)}, + {0x58, QChar(0x0058)}, {0x59, QChar(0x0059)}, {0x5A, QChar(0x005A)}, {0x5B, QChar(0x005B)}, + {0x5C, QChar(0x005C)}, {0x5D, QChar(0x005D)}, {0x5E, QChar(0x005E)}, {0x5F, QChar(0x005F)}, + {0x60, QChar(0x0060)}, {0x61, QChar(0x0061)}, {0x62, QChar(0x0062)}, {0x63, QChar(0x0063)}, + {0x64, QChar(0x0064)}, {0x65, QChar(0x0065)}, {0x66, QChar(0x0066)}, {0x67, QChar(0x0067)}, + {0x68, QChar(0x0068)}, {0x69, QChar(0x0069)}, {0x6A, QChar(0x006A)}, {0x6B, QChar(0x006B)}, + {0x6C, QChar(0x006C)}, {0x6D, QChar(0x006D)}, {0x6E, QChar(0x006E)}, {0x6F, QChar(0x006F)}, + {0x70, QChar(0x0070)}, {0x71, QChar(0x0071)}, {0x72, QChar(0x0072)}, {0x73, QChar(0x0073)}, + {0x74, QChar(0x0074)}, {0x75, QChar(0x0075)}, {0x76, QChar(0x0076)}, {0x77, QChar(0x0077)}, + {0x78, QChar(0x0078)}, {0x79, QChar(0x0079)}, {0x7A, QChar(0x007A)}, {0x7B, QChar(0x007B)}, + {0x7C, QChar(0x007C)}, {0x7D, QChar(0x007D)}, {0x7E, QChar(0x007E)}, {0x7F, QChar(0x007F)}, + {0x80, QChar(0x20AC)}, // Extend with mappings for Vietnamese characters (0x80–0xFF) +}; diff --git a/src/decoding/interpret_as_windows_1258.h b/src/decoding/interpret_as_windows_1258.h new file mode 100644 index 0000000..28fd140 --- /dev/null +++ b/src/decoding/interpret_as_windows_1258.h @@ -0,0 +1,28 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_windows_1258 { +public: + // Singleton instance + static Interpret_As_windows_1258& instance(); + + // Execute decoding for the provided editor + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_windows_1258(); + ~Interpret_As_windows_1258() = default; + + Interpret_As_windows_1258(const Interpret_As_windows_1258&) = delete; + Interpret_As_windows_1258& operator=(const Interpret_As_windows_1258&) = delete; + + // Decoding function + QString decodeWindows1258(const QByteArray& rawData); + + // Windows-1258 decoding table + static const std::unordered_map windows1258Table; +}; diff --git a/src/decoding/interpret_as_windows_949.cpp b/src/decoding/interpret_as_windows_949.cpp new file mode 100644 index 0000000..53afdac --- /dev/null +++ b/src/decoding/interpret_as_windows_949.cpp @@ -0,0 +1,96 @@ +#include "../codeeditor.h" +#include "interpret_as_windows_949.h" +#include +#include + +// Singleton instance +Interpret_As_windows_949& Interpret_As_windows_949::instance() { + static Interpret_As_windows_949 instance; + return instance; +} + +// Constructor +Interpret_As_windows_949::Interpret_As_windows_949() {} + +// Main execution function +void Interpret_As_windows_949::execute(QPlainTextEdit* editor) { + if (!editor) { + qWarning() << "[ERROR] No editor instance provided."; + return; + } + + CodeEditor* codeEditor = qobject_cast(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 = decodeWindows949(rawData); + editor->setPlainText(decodedText); + qDebug() << "[DEBUG] Windows-949 decoding applied for file:" << filePath; +} + +// Decode Windows-949 encoded data +QString Interpret_As_windows_949::decodeWindows949(const QByteArray& rawData) { + QString result; + QByteArray buffer; + + for (int i = 0; i < rawData.size(); ++i) { + unsigned char byte = rawData[i]; + + // Detect double-byte characters + if (byte >= 0x81 && byte <= 0xFE) { + buffer.append(byte); + if (buffer.size() == 2) { + auto it = windows949Table.find(buffer); + if (it != windows949Table.end()) { + result.append(it->second); + } else { + result.append(QChar(0xFFFD)); // Fallback for unmapped bytes + } + buffer.clear(); + } + } else { + if (!buffer.isEmpty()) { + result.append(QChar(0xFFFD)); // Handle incomplete sequences + buffer.clear(); + } + result.append(QChar(byte)); // Single-byte character + } + } + + return result; +} + +// Simplified Windows-949 decoding table (expand as needed) +const std::unordered_map Interpret_As_windows_949::windows949Table = { + {QByteArray("\xB0\xA1"), QChar(0xAC00)}, // 가 + {QByteArray("\xB0\xA2"), QChar(0xAC01)}, // 각 + {QByteArray("\xB0\xA3"), QChar(0xAC04)}, // 간 + {QByteArray("\xB0\xA4"), QChar(0xAC07)}, // 갈 + {QByteArray("\xB0\xA5"), QChar(0xAC08)}, // 감 + {QByteArray("\xB0\xA6"), QChar(0xAC09)}, // 갑 + {QByteArray("\xB0\xA7"), QChar(0xAC0A)}, // 값 + {QByteArray("\xB0\xA8"), QChar(0xAC10)}, // 강 + {QByteArray("\xB0\xA9"), QChar(0xAC11)}, // 갓 + {QByteArray("\xB0\xAA"), QChar(0xAC12)}, // 같 + {QByteArray("\xB0\xAB"), QChar(0xAC13)}, // 갔 + {QByteArray("\xB0\xAC"), QChar(0xAC14)}, // 강 + {QByteArray("\xB0\xAD"), QChar(0xAC15)}, // 강 + // ... Add more mappings as needed +}; diff --git a/src/decoding/interpret_as_windows_949.h b/src/decoding/interpret_as_windows_949.h new file mode 100644 index 0000000..49c821e --- /dev/null +++ b/src/decoding/interpret_as_windows_949.h @@ -0,0 +1,28 @@ +#pragma once + +#include +#include +#include +#include + +class Interpret_As_windows_949 { +public: + // Singleton instance + static Interpret_As_windows_949& instance(); + + // Execute decoding for the provided editor + void execute(QPlainTextEdit* editor); + +private: + Interpret_As_windows_949(); + ~Interpret_As_windows_949() = default; + + Interpret_As_windows_949(const Interpret_As_windows_949&) = delete; + Interpret_As_windows_949& operator=(const Interpret_As_windows_949&) = delete; + + // Decoding function + QString decodeWindows949(const QByteArray& rawData); + + // Windows-949 decoding table + static const std::unordered_map windows949Table; +}; diff --git a/src/decoding/utf7handler.cpp b/src/decoding/utf7handler.cpp new file mode 100644 index 0000000..5bdd98d --- /dev/null +++ b/src/decoding/utf7handler.cpp @@ -0,0 +1,127 @@ +#include "utf7handler.h" +#include + +// Singleton instance +Utf7Handler& Utf7Handler::instance() { + static Utf7Handler instance; + return instance; +} + +// Constructor and Destructor +Utf7Handler::Utf7Handler() = default; +Utf7Handler::~Utf7Handler() = default; + +// Initialize Utf7Handler state +void Utf7Handler::initUtf7HandlerState(Utf7HandlerState& state) const { + state.accum = 0; + state.bits = 0; + state.flags = 0; + state.high = 0; +} + +// Base64 Encoding +int Utf7Handler::base64Encode(int value) const { + static const char base64Table[] = + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + return base64Table[value & 0x3F]; +} + +// Base64 Decoding +int Utf7Handler::base64Decode(char c) const { + static const signed char inv[128] = { + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, + 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, + -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, + -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, + 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1 + }; + + unsigned char uc = static_cast(c); // Ensure value is unsigned + return (uc < 128) ? inv[uc] : -1; +} + +// Check if a character is direct +bool Utf7Handler::isDirectCharacter(char c) const { + return c >= 32 && c <= 126 && c != '+'; // Simplified direct character check +} + +// Encode to UTF-7 +QByteArray Utf7Handler::encodeUtf7(const QString& text) { + Utf7HandlerState state; + initUtf7HandlerState(state); + + QByteArray result; + for (QChar ch : text) { + long codePoint = ch.unicode(); + encodeCharacterToUtf7(state, codePoint, result); + } + encodeCharacterToUtf7(state, -1, result); // Flush remaining bits + return result; +} + +// Decode from UTF-7 +QString Utf7Handler::decodeUtf7(const QByteArray& utf7Data) { + Utf7HandlerState state; + initUtf7HandlerState(state); + + QString result; + const char* data = utf7Data.constData(); + size_t len = utf7Data.size(); + + while (len > 0) { + long decodedChar = decodeCharacterFromUtf7(state, data, len); + if (decodedChar < 0) break; + if (decodedChar >= 0 && decodedChar <= 0xFFFF) { + result += QChar(static_cast(decodedChar)); + } else { + qWarning() << "[WARNING] Invalid UTF-7 decoded character:" << decodedChar; + } + } + return result; +} + +// Encode a single character to UTF-7 +int Utf7Handler::encodeCharacterToUtf7(Utf7HandlerState& state, long c, QByteArray& result) const { + if (c == -1) { // Flush remaining bits + if (state.bits > 0) { + result.append(base64Encode(state.accum << (6 - state.bits))); + } + return 0; + } + + if (isDirectCharacter(c)) { + // Convert QChar to its UTF-8 representation and append it + QString charAsString = QChar(static_cast(c)); + result.append(charAsString.toUtf8()); + return 0; + } + + state.accum = (state.accum << 16) | c; + state.bits += 16; + + while (state.bits >= 6) { + result.append(base64Encode(state.accum >> (state.bits - 6))); + state.bits -= 6; + } + return 0; +} + +// Decode a single character from UTF-7 +long Utf7Handler::decodeCharacterFromUtf7(Utf7HandlerState& state, const char*& data, size_t& len) const { + int value = base64Decode(*data++); + len--; + + if (value < 0) return -1; + + state.accum = (state.accum << 6) | value; + state.bits += 6; + + if (state.bits >= 16) { + state.bits -= 16; + return (state.accum >> state.bits) & 0xFFFF; + } + return -1; // Incomplete character +} diff --git a/src/decoding/utf7handler.h b/src/decoding/utf7handler.h new file mode 100644 index 0000000..2d86f57 --- /dev/null +++ b/src/decoding/utf7handler.h @@ -0,0 +1,34 @@ +#pragma once + +#include +#include + +struct Utf7HandlerState { + unsigned long accum = 0; + int bits = 0; + unsigned flags = 0; + unsigned high = 0; +}; + +class Utf7Handler { +public: + static Utf7Handler& instance(); + + QByteArray encodeUtf7(const QString& text); + QString decodeUtf7(const QByteArray& utf7Data); + +private: + Utf7Handler(); + ~Utf7Handler(); + Utf7Handler(const Utf7Handler&) = delete; + Utf7Handler& operator=(const Utf7Handler&) = delete; + + void initUtf7HandlerState(Utf7HandlerState& state) const; + int encodeCharacterToUtf7(Utf7HandlerState& state, long c, QByteArray& result) const; + long decodeCharacterFromUtf7(Utf7HandlerState& state, const char*& data, size_t& len) const; + + bool isDirectCharacter(char c) const; + int base64Encode(int value) const; + int base64Decode(char c) const; +}; + diff --git a/src/document.cpp b/src/document.cpp index 9a46d8e..f017c4b 100755 --- a/src/document.cpp +++ b/src/document.cpp @@ -25,7 +25,7 @@ Document::Document(const QString &filePath, QWidget *parent) qDebug() << "Document created for file: " << filePath; // Initialize the code editor and layout - m_editor = new CodeEditor(this); + m_editor = new CodeEditor(this, filePath); QVBoxLayout *layout = new QVBoxLayout(this); layout->addWidget(m_editor); diff --git a/src/fileloaderworker.cpp b/src/fileloaderworker.cpp index a4ea38a..d46e50c 100755 --- a/src/fileloaderworker.cpp +++ b/src/fileloaderworker.cpp @@ -47,7 +47,7 @@ void FileLoaderWorker::startLoading() { const qint64 chunkSize = 16 * 1024; // Use 16KB chunks for finer updates QTextStream in(&file); - in.setEncoding(QStringConverter::Utf8); + in.setEncoding(QStringConverter::Utf8); // FIXME: Load in QByteArray buffer too (for encodings) qint64 bytesRead = 0; int lastReportedProgress = 0; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 66518d0..db1f436 100755 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -15,7 +15,6 @@ #include "mainwindow/session.h" #include "src/ui_mainwindow.h" #include "helpers.h" -#include "indentation/indentationdialog.h" #include "find/finddialog.h" #include "replace/replacedialog.h" #include "systemfind/systemfinddialog.h" @@ -25,7 +24,110 @@ #include "view/openinnewwindow.h" #include "view/wordwrap.h" #include "aboutdialog.h" -#include "view/toggletoformertab.h" +// decodings +#include "decoding/interpret_as_utf_8.h" +#include "decoding/interpret_as_utf_8_without_bom.h" +#include "decoding/interpret_as_utf_16_be.h" +#include "decoding/interpret_as_utf_16_le.h" +#include "decoding/interpret_as_dialog.h" +#include "decoding/interpret_as_utf_8.h" +#include "decoding/interpret_as_utf_7.h" +#include "decoding/interpret_as_utf_32_le.h" +#include "decoding/interpret_as_utf_32_be.h" +#include "decoding/interpret_as_utf_16.h" +#include "decoding/interpret_as_us_ascii.h" +#include "decoding/interpret_as_tscii.h" +#include "decoding/interpret_as_tis_620.h" +#include "decoding/interpret_as_shift_jts.h" +#include "decoding/interpret_as_scsu.h" +#include "decoding/interpret_as_koi8_u.h" +#include "decoding/interpret_as_koi8_r.h" +#include "decoding/interpret_as_iso_8859_15.h" +#include "decoding/interpret_as_iso_8859_14.h" +#include "decoding/interpret_as_iso_8859_13.h" +#include "decoding/interpret_as_iso_8859_10.h" +#include "decoding/interpret_as_iso_8859_9.h" +#include "decoding/interpret_as_iso_8859_8.h" +#include "decoding/interpret_as_iso_8859_7.h" +#include "decoding/interpret_as_iso_8859_6.h" +#include "decoding/interpret_as_iso_8859_5.h" +#include "decoding/interpret_as_iso_8859_4.h" +#include "decoding/interpret_as_iso_8859_3.h" +#include "decoding/interpret_as_iso_8859_2.h" +#include "decoding/interpret_as_iso_8859_1.h" +#include "decoding/interpret_as_iso_2022_kr.h" +#include "decoding/interpret_as_iso_2022_jp_2.h" +#include "decoding/interpret_as_iso_2022_jp_1.h" +#include "decoding/interpret_as_iso_2022_jp.h" +#include "decoding/interpret_as_iso_2022_cn_ext.h" +#include "decoding/interpret_as_iso_2022_cn.h" +#include "decoding/interpret_as_ibm_918.h" +#include "decoding/interpret_as_ibm_871.h" +#include "decoding/interpret_as_ibm_870.h" +#include "decoding/interpret_as_ibm_869.h" +#include "decoding/interpret_as_ibm_868.h" +#include "decoding/interpret_as_ibm_866.h" +#include "decoding/interpret_as_ibm_865.h" +#include "decoding/interpret_as_ibm_864.h" +#include "decoding/interpret_as_ibm_863.h" +#include "decoding/interpret_as_ibm_862.h" +#include "decoding/interpret_as_ibm_861.h" +#include "decoding/interpret_as_ibm_860.h" +#include "decoding/interpret_as_ibm_857.h" +#include "decoding/interpret_as_ibm_855.h" +#include "decoding/interpret_as_ibm_852.h" +#include "decoding/interpret_as_ibm_850.h" +#include "decoding/interpret_as_ibm_775.h" +#include "decoding/interpret_as_ibm_500.h" +#include "decoding/interpret_as_ibm_437.h" +#include "decoding/interpret_as_ibm_424.h" +#include "decoding/interpret_as_ibm_420.h" +#include "decoding/interpret_as_ibm_297.h" +#include "decoding/interpret_as_ibm_290.h" +#include "decoding/interpret_as_ibm_285.h" +#include "decoding/interpret_as_ibm_284.h" +#include "decoding/interpret_as_ibm_280.h" +#include "decoding/interpret_as_ibm_278.h" +#include "decoding/interpret_as_ibm_277.h" +#include "decoding/interpret_as_ibm_273.h" +#include "decoding/interpret_as_ibm_1047.h" +#include "decoding/interpret_as_ibm_1026.h" +#include "decoding/interpret_as_ibm_037.h" +#include "decoding/interpret_as_ibm_01149.h" +#include "decoding/interpret_as_ibm_01148.h" +#include "decoding/interpret_as_ibm_01147.h" +#include "decoding/interpret_as_ibm_01146.h" +#include "decoding/interpret_as_ibm_01145.h" +#include "decoding/interpret_as_ibm_01144.h" +#include "decoding/interpret_as_ibm_01143.h" +#include "decoding/interpret_as_ibm_01142.h" +#include "decoding/interpret_as_ibm_01141.h" +#include "decoding/interpret_as_ibm_01140.h" +#include "decoding/interpret_as_ibm_00858.h" +#include "decoding/interpret_as_ibm_thai.h" +#include "decoding/interpret_as_hz_gb_2312.h" +#include "decoding/interpret_as_gbk.h" +#include "decoding/interpret_as_gb18030.h" +#include "decoding/interpret_as_euc_jp.h" +#include "decoding/interpret_as_cesu_8.h" +#include "decoding/interpret_as_big5_hkscs.h" +#include "decoding/interpret_as_big5.h" +#include "decoding/interpret_as_bocu_1.h" +#include "decoding/interpret_as_adobe_standard_encoding.h" +#include "decoding/interpret_as_cp851.h" +#include "decoding/interpret_as_big5_hkscs.h" +#include "decoding/interpret_as_hp_roman8.h" +#include "decoding/interpret_as_macintosh.h" +#include "decoding/interpret_as_windows_1250.h" +#include "decoding/interpret_as_windows_1251.h" +#include "decoding/interpret_as_windows_1252.h" +#include "decoding/interpret_as_windows_1253.h" +#include "decoding/interpret_as_windows_1254.h" +#include "decoding/interpret_as_windows_1255.h" +#include "decoding/interpret_as_windows_1256.h" +#include "decoding/interpret_as_windows_1257.h" +#include "decoding/interpret_as_windows_1258.h" +#include "decoding/interpret_as_windows_949.h" MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), @@ -751,6 +853,443 @@ void MainWindow::on_action_Full_Screen_toggled(bool enabled) ui->action_Full_Screen->setChecked(isFullScreen()); } +/* decoding */ + +void MainWindow::on_action_Interpret_as_UTF_8_triggered() +{ + CodeEditor* editor = dynamic_cast(ui->documentsTab->currentWidget()); + Interpret_As_Utf_8::instance().execute(editor); +} + +void MainWindow::on_actionInterpret_as_utf_8_without_BOM_triggered() +{ + CodeEditor* editor = dynamic_cast(ui->documentsTab->currentWidget()); + Interpret_As_UTF_8_Without_BOM::instance().execute(editor); +} + +void MainWindow::on_actionInterpret_as_16_BE_triggered() +{ + Document* doc = qobject_cast(ui->documentsTab->currentWidget()); + CodeEditor* editor = doc->editor(); + Interpret_As_UTF_16_BE::instance().execute(editor); +} + +void MainWindow::on_actionInterpret_as_16_LE_triggered() +{ + Document* doc = qobject_cast(ui->documentsTab->currentWidget()); + CodeEditor* editor = doc->editor(); + InterpretAsUTF16LE::instance().execute(editor); +} + +void MainWindow::on_actionInterpret_As_triggered() +{ + InterpreteAsDialog dialog(this); // Create the CCC with MainWindow as the parent + + if (dialog.exec() == QDialog::Accepted) { + // OK clicked + QString selectedItem = dialog.getSelectedItem(); + qDebug() << "Selected item:" << selectedItem; + Document* doc = qobject_cast(ui->documentsTab->currentWidget()); + CodeEditor* editor = doc->editor(); + if (!editor) { + qFatal("No active editor"); + return; + } // combobox items are in interpret as dialog.cpp + if (selectedItem == "UTF-8") { + Interpret_As_Utf_8::instance().execute(editor); + } + if (selectedItem == "UTF-7") { + Interpret_As_Utf_7::instance().execute(editor); + } + if (selectedItem == "UTF-32LE") { + Interpret_As_UTF_32_LE::instance().execute(editor); + } + if (selectedItem == "UTF-32BE") { + Interpret_As_UTF_32_BE::instance().execute(editor); + } + if (selectedItem == "UTF-16LE") { + InterpretAsUTF16LE::instance().execute(editor); + } + if (selectedItem == "UTF-16BE") { + Interpret_As_UTF_16_BE::instance().execute(editor); + } + if (selectedItem == "UTF-16") { + Interpret_As_UTF_16::instance().execute(editor); + } + if (selectedItem == "US-ASCII") { + Interpret_As_US_ASCII::instance().execute(editor); + } + if (selectedItem == "TSCII") { + Interpret_As_TSCII::instance().execute(editor); + } + if (selectedItem == "TIS-620") { + Interpret_As_TIS_620::instance().execute(editor); + } + if (selectedItem == "TIS-620") { + Interpret_As_Shift_JTS::instance().execute(editor); + } + if (selectedItem == "SCSU") { + Interpret_As_SCSU::instance().execute(editor); + } + if (selectedItem == "KOI8-U") { + Helpers::notImplemented(this); + //Interpret_As_KOI8_U::instance().execute(editor); + } + if (selectedItem == "KOI8-R") { + Helpers::notImplemented(this); + Interpret_As_KOI8_R::instance().execute(editor); + } + if (selectedItem == "ISO-8859-15") { + Interpret_As_ISO_8859_15::instance().execute(editor); + } + if (selectedItem == "ISO-8859-14") { + Interpret_As_ISO_8859_14::instance().execute(editor); + } + if (selectedItem == "ISO-8859-13") { + Interpret_As_ISO_8859_13::instance().execute(editor); + } + if (selectedItem == "ISO-8859-10") { + Interpret_As_ISO_8859_10::instance().execute(editor); + } + if (selectedItem == "ISO-8859-9") { + Interpret_As_ISO_8859_9::instance().execute(editor); + } + if (selectedItem == "ISO-8859-8") { + Interpret_As_ISO_8859_8::instance().execute(editor); + } + if (selectedItem == "ISO-8859-7") { + Interpret_As_ISO_8859_7::instance().execute(editor); + } + if (selectedItem == "ISO-8859-6") { + Interpret_As_ISO_8859_6::instance().execute(editor); + } + if (selectedItem == "ISO-8859-5") { + Helpers::notImplemented(this); + Interpret_As_ISO_8859_5::instance().execute(editor); + } + if (selectedItem == "ISO-8859-4") { + Interpret_As_ISO_8859_4::instance().execute(editor); + } + if (selectedItem == "ISO-8859-3") { + Interpret_As_ISO_8859_3::instance().execute(editor); + } + if (selectedItem == "ISO-8859-2") { + Interpret_As_ISO_8859_2::instance().execute(editor); + } + if (selectedItem == "ISO-8859-1") { + Interpret_As_ISO_8859_1::instance().execute(editor); + } + if (selectedItem == "ISO-2022-KR") { + Helpers::notImplemented(this); + Interpret_As_ISO_2022_KR::instance().execute(editor); + } + if (selectedItem == "ISO-2022-JP-2") { + Helpers::notImplemented(this); + Interpret_As_ISO_2022_JP_2::instance().execute(editor); + } + if (selectedItem == "ISO-2022-JP-1") { + Interpret_As_ISO_2022_JP_1::instance().execute(editor); + } + if (selectedItem == "ISO-2022-JP") { + Interpret_As_ISO_2022_JP::instance().execute(editor); + } + if (selectedItem == "ISO-2022-CN-EXT") { + Interpret_As_ISO_2022_CN_EXT::instance().execute(editor); + } + if (selectedItem == "ISO-2022-CN") { + Interpret_As_ISO_2022_CN::instance().execute(editor); + } + if (selectedItem == "IBM-918") { + Interpret_As_IBM_918::instance().execute(editor); + } + if (selectedItem == "IBM-871") { + Interpret_As_IBM_871::instance().execute(editor); + } + if (selectedItem == "IBM-870") { + Interpret_As_IBM_870::instance().execute(editor); + } + if (selectedItem == "IBM-869") { + Interpret_As_IBM_869::instance().execute(editor); + } + if (selectedItem == "IBM-868") { + Interpret_As_IBM_868::instance().execute(editor); + } + if (selectedItem == "IBM-866") { + Interpret_As_IBM_866::instance().execute(editor); + } + if (selectedItem == "IBM-865") { + Interpret_As_IBM_865::instance().execute(editor); + } + if (selectedItem == "IBM-864") { + Interpret_As_IBM_864::instance().execute(editor); + } + if (selectedItem == "IBM-863") { + Interpret_As_IBM_863::instance().execute(editor); + } + if (selectedItem == "IBM-862") { + Interpret_As_IBM_862::instance().execute(editor); + } + if (selectedItem == "IBM-861") { + Interpret_As_IBM_861::instance().execute(editor); + } + if (selectedItem == "IBM-860") { + Interpret_As_IBM_860::instance().execute(editor); + } + if (selectedItem == "IBM-857") { + Interpret_As_IBM_857::instance().execute(editor); + } + if (selectedItem == "IBM-855") { + Interpret_As_IBM_855::instance().execute(editor); + } + if (selectedItem == "IBM-852") { + Interpret_As_IBM_852::instance().execute(editor); + } + if (selectedItem == "IBM-850") { + Interpret_As_IBM_850::instance().execute(editor); + } + if (selectedItem == "IBM-775") { + Interpret_As_IBM_775::instance().execute(editor); + } + if (selectedItem == "IBM-500") { + Interpret_As_IBM_500::instance().execute(editor); + } + if (selectedItem == "IBM-437") { + Interpret_As_IBM_437::instance().execute(editor); + } + if (selectedItem == "IBM-424") { + Interpret_As_IBM_424::instance().execute(editor); + } + if (selectedItem == "IBM-420") { + Interpret_As_IBM_420::instance().execute(editor); + } + if (selectedItem == "IBM-297") { + Interpret_As_IBM_297::instance().execute(editor); + } + if (selectedItem == "IBM-290") { + Interpret_As_IBM_290::instance().execute(editor); + } + if (selectedItem == "IBM-285") { + Interpret_As_IBM_285::instance().execute(editor); + } + if (selectedItem == "IBM-284") { + Interpret_As_IBM_284::instance().execute(editor); + } + if (selectedItem == "IBM-280") { + Interpret_As_IBM_280::instance().execute(editor); + } + if (selectedItem == "IBM-278") { + Interpret_As_IBM_278::instance().execute(editor); + } + if (selectedItem == "IBM-277") { + Interpret_As_IBM_277::instance().execute(editor); + } + if (selectedItem == "IBM-273") { + Interpret_As_IBM_273::instance().execute(editor); + } + if (selectedItem == "IBM-1047") { + Interpret_As_IBM_1047::instance().execute(editor); + } + if (selectedItem == "IBM-1026") { + Interpret_As_IBM_1026::instance().execute(editor); + } + if (selectedItem == "IBM-037") { + Interpret_As_IBM_037::instance().execute(editor); + } + if (selectedItem == "IBM-01149") { + Interpret_As_IBM_01149::instance().execute(editor); + } + if (selectedItem == "IBM-01148") { + Interpret_As_IBM_01148::instance().execute(editor); + } + if (selectedItem == "IBM-01147") { + Interpret_As_IBM_01147::instance().execute(editor); + } + if (selectedItem == "IBM-01146") { + Interpret_As_IBM_01146::instance().execute(editor); + } + if (selectedItem == "IBM-01145") { + Interpret_As_IBM_01145::instance().execute(editor); + } + if (selectedItem == "IBM-01144") { + Interpret_As_IBM_01144::instance().execute(editor); + } + if (selectedItem == "IBM-01143") { + Interpret_As_IBM_01143::instance().execute(editor); + } + if (selectedItem == "IBM-01142") { + Interpret_As_IBM_01142::instance().execute(editor); + } + if (selectedItem == "IBM-01141") { + Interpret_As_IBM_01141::instance().execute(editor); + } + if (selectedItem == "IBM-01140") { + Interpret_As_IBM_01140::instance().execute(editor); + } + if (selectedItem == "IBM-00858") { + Interpret_As_IBM_00858::instance().execute(editor); + } + if (selectedItem == "IBM-Thai") { + Interpret_As_IBM_Thai::instance().execute(editor); + } + if (selectedItem == "HZ-GB-2312") { + Interpret_As_HZ_GB_2312::instance().execute(editor); + } + if (selectedItem == "GBK") { + Interpret_As_GBK::instance().execute(editor); + } + if (selectedItem == "GB18030") { + Interpret_As_GB18030::instance().execute(editor); + } + if (selectedItem == "EUC-JP") { + Interpret_As_EUC_JP::instance().execute(editor); + } + if (selectedItem == "CESU-8") { + Interpret_As_CESU_8::instance().execute(editor); + } + if (selectedItem == "Big5-HKSCS") { + Interpret_As_Big5_HKSCS::instance().execute(editor); + } + if (selectedItem == "Big5") { + Interpret_As_Big5::instance().execute(editor); + } + if (selectedItem == "BOCU-1") { + Helpers::notImplemented(this);Helpers::notImplemented(this); + Interpret_As_BOCU_1::instance().execute(editor); + } + if (selectedItem == "Adobe-Standard-Encoding") { + Interpret_As_Adobe_Standard_Encoding::instance().execute(editor); + } + if (selectedItem == "cp851") { + Helpers::notImplemented(this);Helpers::notImplemented(this); + Interpret_As_cp851::instance().execute(editor); + } + if (selectedItem == "hp-roman8") { + Helpers::notImplemented(this);Helpers::notImplemented(this); + Interpret_As_hp_roman8::instance().execute(editor); + } + if (selectedItem == "cp851") { + Helpers::notImplemented(this);Helpers::notImplemented(this); + Interpret_As_cp851::instance().execute(editor); + } + if (selectedItem == "macintosh") { + Helpers::notImplemented(this);Helpers::notImplemented(this); + Interpret_As_macintosh::instance().execute(editor); + } + if (selectedItem == "windows-1250") { + Helpers::notImplemented(this);Helpers::notImplemented(this); + Interpret_As_windows_1250::instance().execute(editor); + } + if (selectedItem == "windows-1251") { + Interpret_As_windows_1251::instance().execute(editor); + } + if (selectedItem == "windows-1252") { + Interpret_As_windows_1252::instance().execute(editor); + } + if (selectedItem == "windows-1253") { + Helpers::notImplemented(this);Helpers::notImplemented(this); + Interpret_As_windows_1253::instance().execute(editor); + } + if (selectedItem == "windows-1254") { + Helpers::notImplemented(this);Helpers::notImplemented(this); + Interpret_As_windows_1254::instance().execute(editor); + } + if (selectedItem == "windows-1255") { + Helpers::notImplemented(this);Helpers::notImplemented(this); + Interpret_As_windows_1255::instance().execute(editor); + } + if (selectedItem == "windows-1256") { + Helpers::notImplemented(this);Helpers::notImplemented(this); + Interpret_As_windows_1256::instance().execute(editor); + } + if (selectedItem == "windows-1257") { + Helpers::notImplemented(this);Helpers::notImplemented(this); + Interpret_As_windows_1257::instance().execute(editor); + } + if (selectedItem == "windows-1258") { + Helpers::notImplemented(this);Helpers::notImplemented(this); + Interpret_As_windows_1258::instance().execute(editor); + } + if (selectedItem == "windows-949") { + Helpers::notImplemented(this);Helpers::notImplemented(this); + Interpret_As_windows_949::instance().execute(editor); + } + } +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mainwindow.h b/src/mainwindow.h index a7ff576..c41e1f5 100755 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -188,6 +188,16 @@ private slots: void on_action_Full_Screen_toggled(bool enabled); + void on_action_Interpret_as_UTF_8_triggered(); + + void on_actionInterpret_as_16_BE_triggered(); + + void on_actionInterpret_as_utf_8_without_BOM_triggered(); + + void on_actionInterpret_as_16_LE_triggered(); + + void on_actionInterpret_As_triggered(); + private: Ui::MainWindow* ui; FileOperations* fileOperations; diff --git a/src/mainwindow.ui b/src/mainwindow.ui index d7c4bc8..092edb5 100755 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -222,7 +222,7 @@ - + @@ -893,7 +893,7 @@ Interpret as UTF-16BE (UCS-2 &Big Endian) - + Interpret as UTF-16LE (UCS-2 &Little Endian) diff --git a/src/view/movetootherview.cpp b/src/view/movetootherview.cpp index 2ab58f7..e3a334f 100644 --- a/src/view/movetootherview.cpp +++ b/src/view/movetootherview.cpp @@ -66,7 +66,7 @@ void MoveToOtherView::execute() { qDebug() << "No secondary editor found. Creating a second editor."; // Create and configure the second editor - textEdit2 = new CodeEditor(currentTab); + textEdit2 = new CodeEditor(currentTab, ""); textEdit2->setObjectName("textEdit2"); textEdit2->setPlainText(textEdit->toPlainText());