From 27c9ee40abe5b5988522343809f7cff2b7a13194 Mon Sep 17 00:00:00 2001 From: Remisa Yousefvand Date: Thu, 19 Dec 2024 12:58:57 +0330 Subject: [PATCH] V0.0.74 --- CHANGELOG.md | 5 + CMakeLists.txt | 44 ++-- CMakeLists.txt.user | 241 ------------------ ...teasdialog.cpp => interpret_as_dialog.cpp} | 11 +- ...rpreteasdialog.h => interpret_as_dialog.h} | 0 ...reteasdialog.ui => interpret_as_dialog.ui} | 0 src/encoding/interpret_as_us_ascii.cpp | 60 +++++ src/encoding/interpret_as_us_ascii.h | 27 ++ src/encoding/interpret_as_utf_16.cpp | 69 +++++ src/encoding/interpret_as_utf_16.h | 27 ++ ...utf16be.cpp => interpret_as_utf_16_be.cpp} | 8 +- src/encoding/interpret_as_utf_16_be.h | 25 ++ ...utf16le.cpp => interpret_as_utf_16_le.cpp} | 12 +- src/encoding/interpret_as_utf_16_le.h | 19 ++ src/encoding/interpret_as_utf_32.cpp | 63 +++++ src/encoding/interpret_as_utf_32.h | 21 ++ src/encoding/interpret_as_utf_32_be.cpp | 50 ++++ src/encoding/interpret_as_utf_32_be.h | 22 ++ src/encoding/interpret_as_utf_32_le.cpp | 86 +++++++ ...ntasutf32le.h => interpret_as_utf_32_le.h} | 0 ...preteasutf7.cpp => interpret_as_utf_7.cpp} | 2 +- ...nterpreteasutf7.h => interpret_as_utf_7.h} | 0 src/encoding/interpret_as_utf_8.cpp | 32 +++ ...nterpreteasutf8.h => interpret_as_utf_8.h} | 0 ...cpp => interpret_as_utf_8_without_bom.cpp} | 8 +- src/encoding/interpret_as_utf_8_without_bom.h | 24 ++ .../interpretcurrentdocumentasutf16be.h | 25 -- .../interpretcurrentdocumentasutf16le.h | 19 -- .../interpretcurrentdocumentasutf32le.cpp | 66 ----- .../interpretcurrentdocumentasutf8.cpp | 30 --- src/encoding/interpretcurrentdocumentasutf8.h | 23 -- ...interpretcurrentdocumentasutf8withoutbom.h | 24 -- src/encoding/interprete_as_tscii.cpp | 59 +++++ src/encoding/interprete_as_tscii.h | 18 ++ src/encoding/interpreteasutf8.cpp | 33 --- src/mainwindow.cpp | 89 ++++++- 36 files changed, 735 insertions(+), 507 deletions(-) delete mode 100644 CMakeLists.txt.user rename src/encoding/{interpreteasdialog.cpp => interpret_as_dialog.cpp} (83%) rename src/encoding/{interpreteasdialog.h => interpret_as_dialog.h} (100%) rename src/encoding/{interpreteasdialog.ui => interpret_as_dialog.ui} (100%) create mode 100644 src/encoding/interpret_as_us_ascii.cpp create mode 100644 src/encoding/interpret_as_us_ascii.h create mode 100644 src/encoding/interpret_as_utf_16.cpp create mode 100644 src/encoding/interpret_as_utf_16.h rename src/encoding/{interpretcurrentdocumentasutf16be.cpp => interpret_as_utf_16_be.cpp} (87%) create mode 100644 src/encoding/interpret_as_utf_16_be.h rename src/encoding/{interpretcurrentdocumentasutf16le.cpp => interpret_as_utf_16_le.cpp} (63%) create mode 100644 src/encoding/interpret_as_utf_16_le.h create mode 100644 src/encoding/interpret_as_utf_32.cpp create mode 100644 src/encoding/interpret_as_utf_32.h create mode 100644 src/encoding/interpret_as_utf_32_be.cpp create mode 100644 src/encoding/interpret_as_utf_32_be.h create mode 100644 src/encoding/interpret_as_utf_32_le.cpp rename src/encoding/{interpretcurrentdocumentasutf32le.h => interpret_as_utf_32_le.h} (100%) rename src/encoding/{interpreteasutf7.cpp => interpret_as_utf_7.cpp} (99%) rename src/encoding/{interpreteasutf7.h => interpret_as_utf_7.h} (100%) create mode 100644 src/encoding/interpret_as_utf_8.cpp rename src/encoding/{interpreteasutf8.h => interpret_as_utf_8.h} (100%) rename src/encoding/{interpretcurrentdocumentasutf8withoutbom.cpp => interpret_as_utf_8_without_bom.cpp} (70%) create mode 100644 src/encoding/interpret_as_utf_8_without_bom.h delete mode 100644 src/encoding/interpretcurrentdocumentasutf16be.h delete mode 100644 src/encoding/interpretcurrentdocumentasutf16le.h delete mode 100644 src/encoding/interpretcurrentdocumentasutf32le.cpp delete mode 100644 src/encoding/interpretcurrentdocumentasutf8.cpp delete mode 100644 src/encoding/interpretcurrentdocumentasutf8.h delete mode 100644 src/encoding/interpretcurrentdocumentasutf8withoutbom.h create mode 100644 src/encoding/interprete_as_tscii.cpp create mode 100644 src/encoding/interprete_as_tscii.h delete mode 100644 src/encoding/interpreteasutf8.cpp diff --git a/CHANGELOG.md b/CHANGELOG.md index 010e468..f95112e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ ============ +## 0.0.74 + +- Implemented: +- Encoding Menu -> Interpret as ... UTF-7, 32LE, 32BE, UTF32, UTF-16, US-ASCII, TSCII + ## 0.0.73 - Implemented: diff --git a/CMakeLists.txt b/CMakeLists.txt index 277d035..e80d443 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,7 +38,7 @@ set(PROJECT_UI src/systemreplace/systemreplacedialog.ui src/systemsearchresultdialog.ui src/aboutdialog.ui - src/encoding/interpreteasdialog.ui + src/encoding/interpret_as_dialog.ui ) set(CMAKE_AUTOUIC_SEARCH_PATHS src) @@ -118,24 +118,34 @@ set(PROJECT_SOURCES src/view/wordwrap.h src/view/toggletoformertab.cpp src/view/toggletoformertab.h - src/encoding/interpretcurrentdocumentasutf8.cpp - src/encoding/interpretcurrentdocumentasutf8.h - src/encoding/interpretcurrentdocumentasutf8withoutbom.cpp - src/encoding/interpretcurrentdocumentasutf8withoutbom.h - src/encoding/interpretcurrentdocumentasutf16be.cpp - src/encoding/interpretcurrentdocumentasutf16be.h - src/encoding/interpretcurrentdocumentasutf16le.cpp - src/encoding/interpretcurrentdocumentasutf16le.h - src/encoding/interpreteasdialog.cpp - src/encoding/interpreteasdialog.h - src/encoding/interpreteasutf8.cpp - src/encoding/interpreteasutf8.h - src/encoding/interpreteasutf7.cpp - src/encoding/interpreteasutf7.h + src/encoding/interpret_as_utf_8.cpp + src/encoding/interpret_as_utf_8.h + src/encoding/interpret_as_utf_8_without_bom.cpp + src/encoding/interpret_as_utf_8_without_bom.h + src/encoding/interpret_as_utf_16_be.cpp + src/encoding/interpret_as_utf_16_be.h + src/encoding/interpret_as_utf_16_le.cpp + src/encoding/interpret_as_utf_16_le.h + src/encoding/interpret_as_dialog.cpp + src/encoding/interpret_as_dialog.h + src/encoding/interpret_as_utf_8.cpp + src/encoding/interpret_as_utf_8.h + src/encoding/interpret_as_utf_7.cpp + src/encoding/interpret_as_utf_7.h src/encoding/utf7handler.cpp src/encoding/utf7handler.h - src/encoding/interpretcurrentdocumentasutf32le.cpp - src/encoding/interpretcurrentdocumentasutf32le.h + src/encoding/interpret_as_utf_32_le.cpp + src/encoding/interpret_as_utf_32_le.h + src/encoding/interpret_as_utf_32_be.cpp + src/encoding/interpret_as_utf_32_be.h + src/encoding/interpret_as_utf_32.cpp + src/encoding/interpret_as_utf_32.h + src/encoding/interpret_as_utf_16.cpp + src/encoding/interpret_as_utf_16.h + src/encoding/interpret_as_us_ascii.cpp + src/encoding/interpret_as_us_ascii.h + src/encoding/interprete_as_tscii.cpp + src/encoding/interprete_as_tscii.h ${PROJECT_UI} ) diff --git a/CMakeLists.txt.user b/CMakeLists.txt.user deleted file mode 100644 index 7639071..0000000 --- a/CMakeLists.txt.user +++ /dev/null @@ -1,241 +0,0 @@ - - - - - - EnvironmentId - {8d9160d8-ad41-44aa-87e4-cafeb5abba83} - - - ProjectExplorer.Project.ActiveTarget - 0 - - - ProjectExplorer.Project.EditorSettings - - true - false - true - - Cpp - - CppGlobal - - - - QmlJS - - QmlJSGlobal - - - 2 - UTF-8 - false - 4 - false - 0 - 80 - true - true - 1 - 0 - false - true - false - 2 - true - true - 0 - 8 - true - false - 1 - true - true - true - *.md, *.MD, Makefile - false - true - true - - - - ProjectExplorer.Project.PluginSettings - - - true - false - true - true - true - true - - false - - - 0 - true - - true - true - Builtin.DefaultTidyAndClazy - 6 - true - - - - true - - - - - ProjectExplorer.Project.Target.0 - - Desktop - Desktop Qt 6.8.1 - Desktop Qt 6.8.1 - qt.qt6.681.linux_gcc_64_kit - 0 - 0 - 0 - - Debug - 2 - false - - -DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} --DCMAKE_BUILD_TYPE:STRING=Debug --DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} --DCMAKE_GENERATOR:STRING=Ninja --DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake --DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} --DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} --DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} - /data/Code/Qt/Notepad-- - 0 - /data/Code/Qt/Notepad--/build/Desktop_Qt_6_8_1-Debug - - - - - all - - false - - true - Build - CMakeProjectManager.MakeStep - - 1 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - - - clean - - false - - true - Build - CMakeProjectManager.MakeStep - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - false - - Debug - CMakeProjectManager.CMakeBuildConfiguration - - 1 - - - 0 - Deploy - Deploy - ProjectExplorer.BuildSteps.Deploy - - 1 - - false - ProjectExplorer.DefaultDeployConfiguration - - - - - - - - - false - - true - ApplicationManagerPlugin.Deploy.CMakePackageStep - - - install-package --acknowledge - true - Install Application Manager package - ApplicationManagerPlugin.Deploy.InstallPackageStep - - - - - - - - 2 - Deploy - Deploy - ProjectExplorer.BuildSteps.Deploy - - 1 - - false - ApplicationManagerPlugin.Deploy.Configuration - - 2 - - true - true - 0 - true - - 2 - - false - -e cpu-cycles --call-graph dwarf,4096 -F 250 - Notepad-- - CMakeProjectManager.CMakeRunConfiguration. - Notepad-- - false - true - true - true - /data/Code/Qt/Notepad--/build/Desktop_Qt_6_8_1-Debug - - 1 - - - - ProjectExplorer.Project.TargetCount - 1 - - - ProjectExplorer.Project.Updater.FileVersion - 22 - - - Version - 22 - - diff --git a/src/encoding/interpreteasdialog.cpp b/src/encoding/interpret_as_dialog.cpp similarity index 83% rename from src/encoding/interpreteasdialog.cpp rename to src/encoding/interpret_as_dialog.cpp index da79227..853ac79 100644 --- a/src/encoding/interpreteasdialog.cpp +++ b/src/encoding/interpret_as_dialog.cpp @@ -1,4 +1,4 @@ -#include "interpreteasdialog.h" +#include "interpret_as_dialog.h" #include #include #include @@ -13,7 +13,14 @@ InterpreteAsDialog::InterpreteAsDialog(QWidget* parent) comboBox->addItems({ "UTF-8", "UTF-7", - "UTF-32LE" + "UTF-32LE", + "UTF-32BE", + "UTF-32", + "UTF-16LE", + "UTF16BE", + "UTF-16", + "US-ASCII", + "TSCII" }); // Create OK and Cancel buttons using QDialogButtonBox diff --git a/src/encoding/interpreteasdialog.h b/src/encoding/interpret_as_dialog.h similarity index 100% rename from src/encoding/interpreteasdialog.h rename to src/encoding/interpret_as_dialog.h diff --git a/src/encoding/interpreteasdialog.ui b/src/encoding/interpret_as_dialog.ui similarity index 100% rename from src/encoding/interpreteasdialog.ui rename to src/encoding/interpret_as_dialog.ui diff --git a/src/encoding/interpret_as_us_ascii.cpp b/src/encoding/interpret_as_us_ascii.cpp new file mode 100644 index 0000000..c5ed8c4 --- /dev/null +++ b/src/encoding/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/encoding/interpret_as_us_ascii.h b/src/encoding/interpret_as_us_ascii.h new file mode 100644 index 0000000..d346fc4 --- /dev/null +++ b/src/encoding/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/encoding/interpret_as_utf_16.cpp b/src/encoding/interpret_as_utf_16.cpp new file mode 100644 index 0000000..38b3e26 --- /dev/null +++ b/src/encoding/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/encoding/interpret_as_utf_16.h b/src/encoding/interpret_as_utf_16.h new file mode 100644 index 0000000..55e74ee --- /dev/null +++ b/src/encoding/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/encoding/interpretcurrentdocumentasutf16be.cpp b/src/encoding/interpret_as_utf_16_be.cpp similarity index 87% rename from src/encoding/interpretcurrentdocumentasutf16be.cpp rename to src/encoding/interpret_as_utf_16_be.cpp index bfe2fd9..5632695 100644 --- a/src/encoding/interpretcurrentdocumentasutf16be.cpp +++ b/src/encoding/interpret_as_utf_16_be.cpp @@ -1,14 +1,14 @@ -#include "interpretcurrentdocumentasutf16be.h" +#include "interpret_as_utf_16_be.h" #include "../codeeditor.h" #include -InterpretCurrentDocumentAsUTF16BE& InterpretCurrentDocumentAsUTF16BE::instance() +InterpretAsUTF16BE& InterpretAsUTF16BE::instance() { - static InterpretCurrentDocumentAsUTF16BE instance; + static InterpretAsUTF16BE instance; return instance; } -void InterpretCurrentDocumentAsUTF16BE::execute(CodeEditor* editor) +void InterpretAsUTF16BE::execute(CodeEditor* editor) { if (!editor) { qDebug() << "Error: No CodeEditor instance provided."; diff --git a/src/encoding/interpret_as_utf_16_be.h b/src/encoding/interpret_as_utf_16_be.h new file mode 100644 index 0000000..74e4ac4 --- /dev/null +++ b/src/encoding/interpret_as_utf_16_be.h @@ -0,0 +1,25 @@ +#pragma once + +#include + +class CodeEditor; // Forward declaration + +class InterpretAsUTF16BE +{ +public: + // Singleton instance access + static InterpretAsUTF16BE& instance(); + + // Method to interpret the current document as UTF-16BE + void execute(CodeEditor* editor); + +private: + // Private constructor for singleton + InterpretAsUTF16BE() = default; + ~InterpretAsUTF16BE() = default; + + // Delete copy constructor and assignment operator + InterpretAsUTF16BE(const InterpretAsUTF16BE&) = delete; + InterpretAsUTF16BE& operator=(const InterpretAsUTF16BE&) = delete; +}; + diff --git a/src/encoding/interpretcurrentdocumentasutf16le.cpp b/src/encoding/interpret_as_utf_16_le.cpp similarity index 63% rename from src/encoding/interpretcurrentdocumentasutf16le.cpp rename to src/encoding/interpret_as_utf_16_le.cpp index f64dc49..4ae1691 100644 --- a/src/encoding/interpretcurrentdocumentasutf16le.cpp +++ b/src/encoding/interpret_as_utf_16_le.cpp @@ -1,18 +1,18 @@ -#include "interpretcurrentdocumentasutf16le.h" +#include "interpret_as_utf_16_le.h" #include "../codeeditor.h" #include -InterpretCurrentDocumentAsUTF16LE& InterpretCurrentDocumentAsUTF16LE::instance() +InterpretAsUTF16LE& InterpretAsUTF16LE::instance() { - static InterpretCurrentDocumentAsUTF16LE instance; + static InterpretAsUTF16LE instance; return instance; } -InterpretCurrentDocumentAsUTF16LE::InterpretCurrentDocumentAsUTF16LE() = default; +InterpretAsUTF16LE::InterpretAsUTF16LE() = default; -InterpretCurrentDocumentAsUTF16LE::~InterpretCurrentDocumentAsUTF16LE() = default; +InterpretAsUTF16LE::~InterpretAsUTF16LE() = default; -void InterpretCurrentDocumentAsUTF16LE::execute(CodeEditor* editor) +void InterpretAsUTF16LE::execute(CodeEditor* editor) { if (!editor) { qDebug() << "Error: No CodeEditor instance provided."; diff --git a/src/encoding/interpret_as_utf_16_le.h b/src/encoding/interpret_as_utf_16_le.h new file mode 100644 index 0000000..cc5dca0 --- /dev/null +++ b/src/encoding/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/encoding/interpret_as_utf_32.cpp b/src/encoding/interpret_as_utf_32.cpp new file mode 100644 index 0000000..3553fcd --- /dev/null +++ b/src/encoding/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/encoding/interpret_as_utf_32.h b/src/encoding/interpret_as_utf_32.h new file mode 100644 index 0000000..97a434a --- /dev/null +++ b/src/encoding/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/encoding/interpret_as_utf_32_be.cpp b/src/encoding/interpret_as_utf_32_be.cpp new file mode 100644 index 0000000..ca5a3de --- /dev/null +++ b/src/encoding/interpret_as_utf_32_be.cpp @@ -0,0 +1,50 @@ +#include "interpret_as_utf_32_be.h" +#include +#include +#include + +InterpreteAsUTF32BE& InterpreteAsUTF32BE::instance() { + static InterpreteAsUTF32BE instance; + return instance; +} + +InterpreteAsUTF32BE::InterpreteAsUTF32BE() = default; +InterpreteAsUTF32BE::~InterpreteAsUTF32BE() = default; + +void InterpreteAsUTF32BE::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/encoding/interpret_as_utf_32_be.h b/src/encoding/interpret_as_utf_32_be.h new file mode 100644 index 0000000..716a663 --- /dev/null +++ b/src/encoding/interpret_as_utf_32_be.h @@ -0,0 +1,22 @@ +#pragma once + +#include +#include + +class InterpreteAsUTF32BE { +public: + // Singleton instance accessor + static InterpreteAsUTF32BE& instance(); + + // Main functionality: Decode and interpret as UTF-32BE + void execute(QPlainTextEdit* editor); + +private: + // Private constructor and destructor to enforce singleton + InterpreteAsUTF32BE(); + ~InterpreteAsUTF32BE(); + + // Disable copy and assignment + InterpreteAsUTF32BE(const InterpreteAsUTF32BE&) = delete; + InterpreteAsUTF32BE& operator=(const InterpreteAsUTF32BE&) = delete; +}; diff --git a/src/encoding/interpret_as_utf_32_le.cpp b/src/encoding/interpret_as_utf_32_le.cpp new file mode 100644 index 0000000..136cd9e --- /dev/null +++ b/src/encoding/interpret_as_utf_32_le.cpp @@ -0,0 +1,86 @@ +#include "interpret_as_utf_32_le.h" +#include +#include +#include +#include +#include +#include +#include + +InterpreteAsUTF32LE& InterpreteAsUTF32LE::instance() +{ + static InterpreteAsUTF32LE instance; + return instance; +} + +InterpreteAsUTF32LE::InterpreteAsUTF32LE() = default; + +InterpreteAsUTF32LE::~InterpreteAsUTF32LE() = default; + +QString InterpreteAsUTF32LE::fromUTF32LE(const QByteArray& data) +{ + if (data.size() % 4 != 0) { + qWarning() << "[WARNING] Invalid UTF-32LE data size:" << data.size(); + return QString(); + } + + QString result; + const char32_t* utf32Data = reinterpret_cast(data.constData()); + int length = data.size() / 4; + + for (int i = 0; i < length; ++i) { + char32_t codePoint = utf32Data[i]; + result.append(QChar::fromUcs4(codePoint)); + } + + return result; +} + +void InterpreteAsUTF32LE::execute(QPlainTextEdit* editor) +{ + if (!editor) { + qDebug() << "[ERROR] QPlainTextEdit instance is null."; + return; + } + + QString filePath = editor->property("currentFilePath").toString(); + if (filePath.isEmpty()) { + qDebug() << "[ERROR] No file path associated with the editor."; + return; + } + + QFile file(filePath); + if (!file.open(QIODevice::ReadOnly)) { + qDebug() << "[ERROR] Unable to open file:" << filePath; + return; + } + + QByteArray fileContent = file.readAll(); + file.close(); + + qDebug() << "[DEBUG] Raw File Content (Hex):" << fileContent.toHex(); + + if (fileContent.startsWith("\xFF\xFE\x00\x00")) { + qDebug() << "[DEBUG] BOM detected: UTF-32LE"; + fileContent.remove(0, 4); + } + + if (fileContent.size() % 4 != 0) { + qDebug() << "[ERROR] File size is not a multiple of 4. Invalid UTF-32LE encoding."; + return; + } + + QString decodedText = QString::fromUtf16(reinterpret_cast(fileContent.constData()), + fileContent.size() / 2); + + if (decodedText.isEmpty()) { + qDebug() << "[WARNING] Decoded text is empty. Possible decoding issue."; + return; + } + + qDebug() << "[DEBUG] Decoded Text:" << decodedText; + + editor->setPlainText(decodedText); + editor->setFont(QFont("Noto Sans", 12)); // Ensure font supports Unicode + qDebug() << "[DEBUG] Document interpreted as UTF-32LE."; +} diff --git a/src/encoding/interpretcurrentdocumentasutf32le.h b/src/encoding/interpret_as_utf_32_le.h similarity index 100% rename from src/encoding/interpretcurrentdocumentasutf32le.h rename to src/encoding/interpret_as_utf_32_le.h diff --git a/src/encoding/interpreteasutf7.cpp b/src/encoding/interpret_as_utf_7.cpp similarity index 99% rename from src/encoding/interpreteasutf7.cpp rename to src/encoding/interpret_as_utf_7.cpp index 1ef4918..c8b16de 100644 --- a/src/encoding/interpreteasutf7.cpp +++ b/src/encoding/interpret_as_utf_7.cpp @@ -1,4 +1,4 @@ -#include "interpreteasutf7.h" +#include "interpret_as_utf_7.h" #include // Singleton instance diff --git a/src/encoding/interpreteasutf7.h b/src/encoding/interpret_as_utf_7.h similarity index 100% rename from src/encoding/interpreteasutf7.h rename to src/encoding/interpret_as_utf_7.h diff --git a/src/encoding/interpret_as_utf_8.cpp b/src/encoding/interpret_as_utf_8.cpp new file mode 100644 index 0000000..f71ca68 --- /dev/null +++ b/src/encoding/interpret_as_utf_8.cpp @@ -0,0 +1,32 @@ +#include "interpret_as_utf_8.h" +#include "../codeeditor.h" +#include + +InterpreteAsUtf8& InterpreteAsUtf8::instance() +{ + static InterpreteAsUtf8 instance; + return instance; +} + +void InterpreteAsUtf8::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/encoding/interpreteasutf8.h b/src/encoding/interpret_as_utf_8.h similarity index 100% rename from src/encoding/interpreteasutf8.h rename to src/encoding/interpret_as_utf_8.h diff --git a/src/encoding/interpretcurrentdocumentasutf8withoutbom.cpp b/src/encoding/interpret_as_utf_8_without_bom.cpp similarity index 70% rename from src/encoding/interpretcurrentdocumentasutf8withoutbom.cpp rename to src/encoding/interpret_as_utf_8_without_bom.cpp index 89422e6..6b094aa 100644 --- a/src/encoding/interpretcurrentdocumentasutf8withoutbom.cpp +++ b/src/encoding/interpret_as_utf_8_without_bom.cpp @@ -1,14 +1,14 @@ -#include "interpretcurrentdocumentasutf8withoutbom.h" +#include "interpret_as_utf_8_without_bom.h" #include "../codeeditor.h" #include -InterpretCurrentDocumentAsUTF8WithoutBOM& InterpretCurrentDocumentAsUTF8WithoutBOM::instance() +InterpretAsUTF8WithoutBOM& InterpretAsUTF8WithoutBOM::instance() { - static InterpretCurrentDocumentAsUTF8WithoutBOM instance; + static InterpretAsUTF8WithoutBOM instance; return instance; } -void InterpretCurrentDocumentAsUTF8WithoutBOM::execute(CodeEditor* editor) +void InterpretAsUTF8WithoutBOM::execute(CodeEditor* editor) { if (!editor) { qDebug() << "Error: No CodeEditor instance provided."; diff --git a/src/encoding/interpret_as_utf_8_without_bom.h b/src/encoding/interpret_as_utf_8_without_bom.h new file mode 100644 index 0000000..710d530 --- /dev/null +++ b/src/encoding/interpret_as_utf_8_without_bom.h @@ -0,0 +1,24 @@ +#pragma once + +#include + +class CodeEditor; // Forward declaration + +class InterpretAsUTF8WithoutBOM +{ +public: + // Singleton access method + static InterpretAsUTF8WithoutBOM& instance(); + + // Method to interpret the current document as UTF-8 without BOM + void execute(CodeEditor* editor); + +private: + // Private constructor for singleton pattern + InterpretAsUTF8WithoutBOM() = default; + ~InterpretAsUTF8WithoutBOM() = default; + + // Delete copy constructor and assignment operator + InterpretAsUTF8WithoutBOM(const InterpretAsUTF8WithoutBOM&) = delete; + InterpretAsUTF8WithoutBOM& operator=(const InterpretAsUTF8WithoutBOM&) = delete; +}; diff --git a/src/encoding/interpretcurrentdocumentasutf16be.h b/src/encoding/interpretcurrentdocumentasutf16be.h deleted file mode 100644 index cfe8710..0000000 --- a/src/encoding/interpretcurrentdocumentasutf16be.h +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#include - -class CodeEditor; // Forward declaration - -class InterpretCurrentDocumentAsUTF16BE -{ -public: - // Singleton instance access - static InterpretCurrentDocumentAsUTF16BE& instance(); - - // Method to interpret the current document as UTF-16BE - void execute(CodeEditor* editor); - -private: - // Private constructor for singleton - InterpretCurrentDocumentAsUTF16BE() = default; - ~InterpretCurrentDocumentAsUTF16BE() = default; - - // Delete copy constructor and assignment operator - InterpretCurrentDocumentAsUTF16BE(const InterpretCurrentDocumentAsUTF16BE&) = delete; - InterpretCurrentDocumentAsUTF16BE& operator=(const InterpretCurrentDocumentAsUTF16BE&) = delete; -}; - diff --git a/src/encoding/interpretcurrentdocumentasutf16le.h b/src/encoding/interpretcurrentdocumentasutf16le.h deleted file mode 100644 index fb08c1f..0000000 --- a/src/encoding/interpretcurrentdocumentasutf16le.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -#include - -class CodeEditor; - -class InterpretCurrentDocumentAsUTF16LE -{ -public: - static InterpretCurrentDocumentAsUTF16LE& instance(); - void execute(CodeEditor* editor); - -private: - InterpretCurrentDocumentAsUTF16LE(); // Private constructor - ~InterpretCurrentDocumentAsUTF16LE(); - InterpretCurrentDocumentAsUTF16LE(const InterpretCurrentDocumentAsUTF16LE&) = delete; - InterpretCurrentDocumentAsUTF16LE& operator=(const InterpretCurrentDocumentAsUTF16LE&) = delete; -}; - diff --git a/src/encoding/interpretcurrentdocumentasutf32le.cpp b/src/encoding/interpretcurrentdocumentasutf32le.cpp deleted file mode 100644 index 53b347e..0000000 --- a/src/encoding/interpretcurrentdocumentasutf32le.cpp +++ /dev/null @@ -1,66 +0,0 @@ -#include "interpretcurrentdocumentasutf32le.h" -#include -#include -#include -#include -#include -#include -#include - -InterpreteAsUTF32LE& InterpreteAsUTF32LE::instance() -{ - static InterpreteAsUTF32LE instance; - return instance; -} - -InterpreteAsUTF32LE::InterpreteAsUTF32LE() = default; - -InterpreteAsUTF32LE::~InterpreteAsUTF32LE() = default; - -QString InterpreteAsUTF32LE::fromUTF32LE(const QByteArray& data) -{ - if (data.size() % 4 != 0) { - qWarning() << "[WARNING] Invalid UTF-32LE data size:" << data.size(); - return QString(); - } - - QString result; - const char32_t* utf32Data = reinterpret_cast(data.constData()); - int length = data.size() / 4; - - for (int i = 0; i < length; ++i) { - char32_t codePoint = utf32Data[i]; - result.append(QChar::fromUcs4(codePoint)); - } - - return result; -} - -void InterpreteAsUTF32LE::execute(QPlainTextEdit* editor) -{ - if (!editor) { - qDebug() << "[ERROR] No QPlainTextEdit instance provided."; - return; // Exit early if the editor is null - } - - // Step 1: Retrieve the original text from the editor - QString originalText = editor->toPlainText(); - qDebug() << "[DEBUG] Original text from editor:" << originalText; - - // Step 2: Convert the text to UTF-32LE encoded data - QByteArray utf32leData = originalText.toUtf8(); // Assume the editor holds UTF-8 by default - - // Step 3: Decode the UTF-32LE data using QStringDecoder - QStringDecoder decoder(QStringDecoder::Utf32LE); - QString decodedText = decoder.decode(utf32leData); - - qDebug() << "[DEBUG] Decoded text as UTF-32LE:" << decodedText; - - // Step 4: Set the decoded text back into the editor - if (!decodedText.isEmpty()) { - editor->setPlainText(decodedText); - qDebug() << "[DEBUG] Updated editor content with decoded UTF-32LE text."; - } else { - qWarning() << "[WARNING] Decoding failed or resulted in empty content."; - } -} diff --git a/src/encoding/interpretcurrentdocumentasutf8.cpp b/src/encoding/interpretcurrentdocumentasutf8.cpp deleted file mode 100644 index 64c13ae..0000000 --- a/src/encoding/interpretcurrentdocumentasutf8.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include "interpretcurrentdocumentasutf8.h" -#include "../codeeditor.h" -#include - -// Singleton instance -InterpretCurrentDocumentAsUTF8& InterpretCurrentDocumentAsUTF8::instance() -{ - static InterpretCurrentDocumentAsUTF8 instance; - return instance; -} - -// Execute the reinterpretation of the current document as UTF-8 -void InterpretCurrentDocumentAsUTF8::execute(CodeEditor* editor) -{ - if (!editor) { - qDebug() << "Error: No CodeEditor instance provided."; - return; - } - - // Retrieve the raw text from the CodeEditor - QByteArray rawData = editor->toPlainText().toUtf8(); - - // Reinterpret the content as UTF-8 - QString utf8Text = QString::fromUtf8(rawData); - - // Update the editor content with the reinterpreted UTF-8 text - editor->setPlainText(utf8Text); - - qDebug() << "Document successfully reinterpreted as UTF-8."; -} diff --git a/src/encoding/interpretcurrentdocumentasutf8.h b/src/encoding/interpretcurrentdocumentasutf8.h deleted file mode 100644 index a7be3b7..0000000 --- a/src/encoding/interpretcurrentdocumentasutf8.h +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -#include - -class CodeEditor; // Forward declaration - -class InterpretCurrentDocumentAsUTF8 -{ -public: - // Singleton access - static InterpretCurrentDocumentAsUTF8& instance(); - - // Method to reinterpret the content of a CodeEditor as UTF-8 - void execute(CodeEditor* editor); - -private: - InterpretCurrentDocumentAsUTF8() = default; // Private constructor for singleton - ~InterpretCurrentDocumentAsUTF8() = default; // Destructor - InterpretCurrentDocumentAsUTF8(const InterpretCurrentDocumentAsUTF8&) = delete; // No copy - InterpretCurrentDocumentAsUTF8& operator=(const InterpretCurrentDocumentAsUTF8&) = delete; // No assignment -}; - - diff --git a/src/encoding/interpretcurrentdocumentasutf8withoutbom.h b/src/encoding/interpretcurrentdocumentasutf8withoutbom.h deleted file mode 100644 index 81706b5..0000000 --- a/src/encoding/interpretcurrentdocumentasutf8withoutbom.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include - -class CodeEditor; // Forward declaration - -class InterpretCurrentDocumentAsUTF8WithoutBOM -{ -public: - // Singleton access method - static InterpretCurrentDocumentAsUTF8WithoutBOM& instance(); - - // Method to interpret the current document as UTF-8 without BOM - void execute(CodeEditor* editor); - -private: - // Private constructor for singleton pattern - InterpretCurrentDocumentAsUTF8WithoutBOM() = default; - ~InterpretCurrentDocumentAsUTF8WithoutBOM() = default; - - // Delete copy constructor and assignment operator - InterpretCurrentDocumentAsUTF8WithoutBOM(const InterpretCurrentDocumentAsUTF8WithoutBOM&) = delete; - InterpretCurrentDocumentAsUTF8WithoutBOM& operator=(const InterpretCurrentDocumentAsUTF8WithoutBOM&) = delete; -}; diff --git a/src/encoding/interprete_as_tscii.cpp b/src/encoding/interprete_as_tscii.cpp new file mode 100644 index 0000000..df77496 --- /dev/null +++ b/src/encoding/interprete_as_tscii.cpp @@ -0,0 +1,59 @@ +#include "interprete_as_tscii.h" +#include +#include +#include + +// Constructor +Interprete_As_TSCII::Interprete_As_TSCII() = default; + +// Destructor definition +Interprete_As_TSCII::~Interprete_As_TSCII() = default; + +// Singleton instance +Interprete_As_TSCII& Interprete_As_TSCII::instance() { + static Interprete_As_TSCII instance; + return instance; +} + +// Helper: TSCII to Unicode mapping +static QMap createTSCIIMap() { + QMap map; + map[0xA1] = QChar(0x0B85); // Example: TSCII 0xA1 -> Unicode 'அ' + map[0xA2] = QChar(0x0B86); // Example: TSCII 0xA2 -> Unicode 'ஆ' + // Add remaining mappings as needed + return map; +} + +static const QMap& getTSCIIMap() { + static QMap tsciiMap = createTSCIIMap(); + return tsciiMap; +} + +// Helper: Decode TSCII to QString +QString decodeTSCII(const QByteArray& data) { + QString result; + const auto& map = getTSCIIMap(); + for (unsigned char c : data) { + if (map.contains(c)) { + result += map.value(c); + } else { + result += QChar(0xFFFD); // Unicode replacement character + } + } + return result; +} + +// Execute TSCII interpretation +void Interprete_As_TSCII::execute(QPlainTextEdit* editor) { + if (!editor) { + qDebug() << "[ERROR] No editor provided."; + return; + } + + QString originalText = editor->toPlainText(); + QByteArray tsciiData = originalText.toLocal8Bit(); + QString decodedText = decodeTSCII(tsciiData); + + qDebug() << "[DEBUG] Decoded TSCII text:" << decodedText; + editor->setPlainText(decodedText); +} diff --git a/src/encoding/interprete_as_tscii.h b/src/encoding/interprete_as_tscii.h new file mode 100644 index 0000000..75cad5a --- /dev/null +++ b/src/encoding/interprete_as_tscii.h @@ -0,0 +1,18 @@ +#pragma once + +#include +#include + +class Interprete_As_TSCII { +public: + static Interprete_As_TSCII& instance(); + + void execute(QPlainTextEdit* editor); + + ~Interprete_As_TSCII(); // Ensure destructor is declared here + +private: + Interprete_As_TSCII(); // Private constructor for singleton + Interprete_As_TSCII(const Interprete_As_TSCII&) = delete; + Interprete_As_TSCII& operator=(const Interprete_As_TSCII&) = delete; +}; diff --git a/src/encoding/interpreteasutf8.cpp b/src/encoding/interpreteasutf8.cpp deleted file mode 100644 index 3c58740..0000000 --- a/src/encoding/interpreteasutf8.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include "interpreteasutf8.h" -#include "../codeeditor.h" -#include - -InterpreteAsUtf8& InterpreteAsUtf8::instance() -{ - static InterpreteAsUtf8 instance; - return instance; -} - -void InterpreteAsUtf8::execute(CodeEditor* editor) -{ - if (!editor) { - qDebug() << "Error: No CodeEditor instance provided."; - return; - } - - // Retrieve the current document content as raw bytes - QByteArray rawData = editor->toPlainText().toUtf8(); - qDebug() << "Original Raw Data (Hex):" << rawData.toHex(); - - // Interpret the raw data as UTF-8 - QString interpretedText = QString::fromUtf8(rawData); - - if (interpretedText.isEmpty() && !rawData.isEmpty()) { - qDebug() << "Error: Failed to interpret document as UTF-8."; - return; - } - - // Set the interpreted text back into the editor - editor->setPlainText(interpretedText); - qDebug() << "Document interpreted as UTF-8."; -} diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 10f335b..969b656 100755 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -24,14 +24,18 @@ #include "view/openinnewwindow.h" #include "view/wordwrap.h" #include "aboutdialog.h" -#include "encoding/interpretcurrentdocumentasutf8.h" -#include "encoding/interpretcurrentdocumentasutf8withoutbom.h" -#include "encoding/interpretcurrentdocumentasutf16be.h" -#include "encoding/interpretcurrentdocumentasutf16le.h" -#include "encoding/interpreteasdialog.h" -#include "encoding/interpreteasutf8.h" -#include "encoding/interpreteasutf7.h" -#include "encoding/interpretcurrentdocumentasutf32le.h" +#include "encoding/interpret_as_utf_8.h" +#include "encoding/interpret_as_utf_8_without_bom.h" +#include "encoding/interpret_as_utf_16_be.h" +#include "encoding/interpret_as_utf_16_le.h" +#include "encoding/interpret_as_dialog.h" +#include "encoding/interpret_as_utf_8.h" +#include "encoding/interpret_as_utf_7.h" +#include "encoding/interpret_as_utf_32_le.h" +#include "encoding/interpret_as_utf_32_be.h" +#include "encoding/interpret_as_utf_16.h" +#include "encoding/interpret_as_us_ascii.h" +#include "encoding/interprete_as_tscii.h" MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), @@ -762,27 +766,27 @@ void MainWindow::on_action_Full_Screen_toggled(bool enabled) void MainWindow::on_action_Interpret_as_UTF_8_triggered() { CodeEditor* editor = dynamic_cast(ui->documentsTab->currentWidget()); - InterpretCurrentDocumentAsUTF8::instance().execute(editor); + InterpreteAsUtf8::instance().execute(editor); } void MainWindow::on_actionInterpret_as_utf_8_without_BOM_triggered() { CodeEditor* editor = dynamic_cast(ui->documentsTab->currentWidget()); - InterpretCurrentDocumentAsUTF8WithoutBOM::instance().execute(editor); + InterpretAsUTF8WithoutBOM::instance().execute(editor); } void MainWindow::on_actionInterpret_as_16_BE_triggered() { Document* doc = qobject_cast(ui->documentsTab->currentWidget()); CodeEditor* editor = doc->editor(); - InterpretCurrentDocumentAsUTF16BE::instance().execute(editor); + InterpretAsUTF16BE::instance().execute(editor); } void MainWindow::on_actionInterpret_as_16_LE_triggered() { Document* doc = qobject_cast(ui->documentsTab->currentWidget()); CodeEditor* editor = doc->editor(); - InterpretCurrentDocumentAsUTF16LE::instance().execute(editor); + InterpretAsUTF16LE::instance().execute(editor); } void MainWindow::on_actionInterpret_As_triggered() @@ -807,8 +811,28 @@ void MainWindow::on_actionInterpret_As_triggered() InterpreteAsUtf7::instance().execute(editor); } if (selectedItem == "UTF-32LE") { + Helpers::notImplemented(this); InterpreteAsUTF32LE::instance().execute(editor); } + if (selectedItem == "UTF-32BE") { + InterpreteAsUTF32BE::instance().execute(editor); + } + if (selectedItem == "UTF-16LE") { + InterpretAsUTF16LE::instance().execute(editor); + } + if (selectedItem == "UTF-16BE") { + InterpretAsUTF16BE::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") { + Helpers::notImplemented(this); + Interprete_As_TSCII::instance().execute(editor); + } } } @@ -880,6 +904,47 @@ void MainWindow::on_actionInterpret_As_triggered() + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +