-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
17bfa1c
commit 5e830c5
Showing
18 changed files
with
522 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#include "interpretcurrentdocumentasutf16be.h" | ||
#include "../codeeditor.h" | ||
#include <QDebug> | ||
|
||
InterpretCurrentDocumentAsUTF16BE& InterpretCurrentDocumentAsUTF16BE::instance() | ||
{ | ||
static InterpretCurrentDocumentAsUTF16BE instance; | ||
return instance; | ||
} | ||
|
||
void InterpretCurrentDocumentAsUTF16BE::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<const char16_t*>(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<char>((codeUnit >> 8) & 0xFF)); // High byte | ||
utf16beData.append(static_cast<char>(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<const char16_t*>(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."; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#pragma once | ||
|
||
#include <QString> | ||
|
||
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; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include "interpretcurrentdocumentasutf16le.h" | ||
#include "../codeeditor.h" | ||
#include <QDebug> | ||
|
||
InterpretCurrentDocumentAsUTF16LE& InterpretCurrentDocumentAsUTF16LE::instance() | ||
{ | ||
static InterpretCurrentDocumentAsUTF16LE instance; | ||
return instance; | ||
} | ||
|
||
InterpretCurrentDocumentAsUTF16LE::InterpretCurrentDocumentAsUTF16LE() = default; | ||
|
||
InterpretCurrentDocumentAsUTF16LE::~InterpretCurrentDocumentAsUTF16LE() = default; | ||
|
||
void InterpretCurrentDocumentAsUTF16LE::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<const char16_t*>(rawData.constData()), rawData.size() / 2); | ||
|
||
qDebug() << "Interpreted UTF-16LE Text:" << interpretedText; | ||
|
||
// Update the editor content | ||
editor->setPlainText(interpretedText); | ||
|
||
qDebug() << "Document reinterpreted as UTF-16LE."; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#pragma once | ||
|
||
#include <QString> | ||
|
||
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; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include "interpretcurrentdocumentasutf8.h" | ||
#include "../codeeditor.h" | ||
#include <QDebug> | ||
|
||
// 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."; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#pragma once | ||
|
||
#include <QString> | ||
|
||
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 | ||
}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include "interpretcurrentdocumentasutf8withoutbom.h" | ||
#include "../codeeditor.h" | ||
#include <QDebug> | ||
|
||
InterpretCurrentDocumentAsUTF8WithoutBOM& InterpretCurrentDocumentAsUTF8WithoutBOM::instance() | ||
{ | ||
static InterpretCurrentDocumentAsUTF8WithoutBOM instance; | ||
return instance; | ||
} | ||
|
||
void InterpretCurrentDocumentAsUTF8WithoutBOM::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."; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#pragma once | ||
|
||
#include <QString> | ||
|
||
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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include "interpreteasdialog.h" | ||
#include <QComboBox> | ||
#include <QVBoxLayout> | ||
#include <QDialogButtonBox> | ||
|
||
InterpreteAsDialog::InterpreteAsDialog(QWidget* parent) | ||
: QDialog(parent) | ||
{ | ||
setWindowTitle("Interpret As"); | ||
|
||
// Create and populate the combobox | ||
comboBox = new QComboBox(this); | ||
comboBox->addItems({ | ||
"UTF-8", | ||
"UTF-7" | ||
}); | ||
|
||
// 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(); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#pragma once | ||
|
||
#include <QDialog> | ||
#include <QString> | ||
|
||
class QComboBox; | ||
|
||
class InterpreteAsDialog : public QDialog | ||
{ | ||
public: | ||
explicit InterpreteAsDialog(QWidget* parent = nullptr); | ||
QString getSelectedItem() const; | ||
|
||
private: | ||
QComboBox* comboBox; // Pointer to the combobox | ||
}; |
Oops, something went wrong.