Skip to content

Commit

Permalink
v0.0.94
Browse files Browse the repository at this point in the history
  • Loading branch information
yousefvand committed Jan 11, 2025
1 parent 33a0c60 commit bb9f7f7
Show file tree
Hide file tree
Showing 23 changed files with 1,169 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

============

## 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:
Expand Down
18 changes: 18 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,24 @@ set(PROJECT_SOURCES
src/encoding/interpret_as_ibm_278.h
src/encoding/interpret_as_ibm_277.cpp
src/encoding/interpret_as_ibm_277.h
src/encoding/interpret_as_ibm_273.cpp
src/encoding/interpret_as_ibm_273.h
src/encoding/interpret_as_ibm_1047.cpp
src/encoding/interpret_as_ibm_1047.h
src/encoding/interpret_as_ibm_1026.cpp
src/encoding/interpret_as_ibm_1026.h
src/encoding/interpret_as_ibm_037.cpp
src/encoding/interpret_as_ibm_037.h
src/encoding/interpret_as_ibm_01149.cpp
src/encoding/interpret_as_ibm_01149.h
src/encoding/interpret_as_ibm_01148.cpp
src/encoding/interpret_as_ibm_01148.h
src/encoding/interpret_as_ibm_01147.cpp
src/encoding/interpret_as_ibm_01147.h
src/encoding/interpret_as_ibm_01146.cpp
src/encoding/interpret_as_ibm_01146.h
src/encoding/interpret_as_ibm_01145.cpp
src/encoding/interpret_as_ibm_01145.h
${PROJECT_UI}
)

Expand Down
14 changes: 7 additions & 7 deletions CMakeLists.txt.user
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 15.0.0, 2025-01-10T14:27:51. -->
<!-- Written by QtCreator 15.0.0, 2025-01-11T14:36:00. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
Expand Down Expand Up @@ -103,14 +103,14 @@
<value type="int" key="CMake.Configure.BaseEnvironment">2</value>
<value type="bool" key="CMake.Configure.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="CMake.Configure.UserEnvironmentChanges"/>
<value type="QString" key="CMake.Initial.Parameters">-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx}
<value type="QString" key="CMake.Initial.Parameters">-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX}
-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake
-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx}
-DCMAKE_BUILD_TYPE:STRING=Debug
-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C}
-DCMAKE_GENERATOR:STRING=Ninja
-DCMAKE_BUILD_TYPE:STRING=Debug
-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG}
-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX}
-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{BuildConfig:BuildDirectory:NativeFilePath}/.qtc/package-manager/auto-setup.cmake
-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable}</value>
-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable}
-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG}</value>
<value type="QString" key="CMake.Source.Directory">/data/Code/Qt/Notepad--</value>
<value type="int" key="EnableQmlDebugging">0</value>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/data/Code/Qt/Notepad--/build/Desktop_Qt_6_8_1-Debug</value>
Expand Down
11 changes: 10 additions & 1 deletion src/encoding/interpret_as_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,16 @@ InterpreteAsDialog::InterpreteAsDialog(QWidget* parent)
"IBM-285",
"IBM-284",
"IBM-278",
"IBM-277"
"IBM-277",
"IBM-273",
"IBM-1047",
"IBM-1026",
"IBM-037",
"IBM-01149",
"IBM-01148",
"IBM-01147",
"IBM-01146",
"IBM-01145"
});

// Create OK and Cancel buttons using QDialogButtonBox
Expand Down
99 changes: 99 additions & 0 deletions src/encoding/interpret_as_ibm_01145.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#include "../codeeditor.h"
#include "interpret_as_ibm_01145.h"
#include <QFile>
#include <QDebug>

// 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<unsigned char, QChar> 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<CodeEditor*>(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;
}
22 changes: 22 additions & 0 deletions src/encoding/interpret_as_ibm_01145.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

#include <QPlainTextEdit>
#include <QString>
#include <QByteArray>
#include <unordered_map>

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<unsigned char, QChar> ebcdicTable;
};
99 changes: 99 additions & 0 deletions src/encoding/interpret_as_ibm_01146.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#include "../codeeditor.h"
#include "interpret_as_ibm_01146.h"
#include <QFile>
#include <QDebug>

// 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<unsigned char, QChar> 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<CodeEditor*>(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;
}
22 changes: 22 additions & 0 deletions src/encoding/interpret_as_ibm_01146.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

#include <QPlainTextEdit>
#include <QString>
#include <QByteArray>
#include <unordered_map>

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<unsigned char, QChar> ebcdicTable;
};
Loading

0 comments on commit bb9f7f7

Please sign in to comment.