change eol to lf, set 4 space tab
This commit is contained in:
parent
7b94e714a3
commit
a6772a32f6
90
data.cpp
90
data.cpp
@ -6,83 +6,83 @@
|
||||
|
||||
Data::Data(QString &in, bool cap)
|
||||
{
|
||||
this->txt = in;
|
||||
this->cap = cap;
|
||||
this->txt = in;
|
||||
this->cap = cap;
|
||||
}
|
||||
|
||||
|
||||
Data::Data(int len, bool cap)
|
||||
{
|
||||
QByteArray rand;
|
||||
QTime cur = QTime::currentTime();
|
||||
qsrand(cur.second() * 1000 + cur.msec());
|
||||
while (len--) rand.append(qrand() % 256);
|
||||
this->txt = QString(rand.toHex());
|
||||
this->cap = cap;
|
||||
QByteArray rand;
|
||||
QTime cur = QTime::currentTime();
|
||||
qsrand(cur.second() * 1000 + cur.msec());
|
||||
while (len--) rand.append(qrand() % 256);
|
||||
this->txt = QString(rand.toHex());
|
||||
this->cap = cap;
|
||||
}
|
||||
|
||||
|
||||
void Data::to_hex()
|
||||
{
|
||||
this->txt = QString(this->txt.toLocal8Bit().toHex());
|
||||
this->txt = QString(this->txt.toLocal8Bit().toHex());
|
||||
}
|
||||
|
||||
|
||||
void Data::clean()
|
||||
{
|
||||
this->txt = this->txt.toLower().replace(QRegExp("(0x)|[^0-9a-fA-F\n]"), "");
|
||||
this->txt = this->txt.toLower().replace(QRegExp("(0x)|[^0-9a-fA-F\n]"), "");
|
||||
}
|
||||
|
||||
|
||||
QString Data::get_ascii()
|
||||
{
|
||||
return QString(QByteArray::fromHex(this->txt.toLocal8Bit()));
|
||||
return QString(QByteArray::fromHex(this->txt.toLocal8Bit()));
|
||||
}
|
||||
|
||||
|
||||
QString Data::get(int unit, enum format fmt)
|
||||
{
|
||||
QStringList work;
|
||||
QStringList work;
|
||||
|
||||
if (this->cap) this->txt = this->txt.toUpper();
|
||||
if (this->cap) this->txt = this->txt.toUpper();
|
||||
|
||||
if (0 > unit) {
|
||||
work = this->txt.split('\n');
|
||||
} else {
|
||||
this->txt.replace("\n", "");
|
||||
|
||||
if (unit) {
|
||||
unit *= 2;
|
||||
for (int i = 0; i < this->txt.size(); i += unit) {
|
||||
work << this->txt.mid(i, unit);
|
||||
}
|
||||
if (0 > unit) {
|
||||
work = this->txt.split('\n');
|
||||
} else {
|
||||
work << this->txt;
|
||||
this->txt.replace("\n", "");
|
||||
|
||||
if (unit) {
|
||||
unit *= 2;
|
||||
for (int i = 0; i < this->txt.size(); i += unit) {
|
||||
work << this->txt.mid(i, unit);
|
||||
}
|
||||
} else {
|
||||
work << this->txt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QString st;
|
||||
QString st;
|
||||
|
||||
switch (fmt) {
|
||||
case Data::seq:
|
||||
return work.join('\n');
|
||||
case Data::space:
|
||||
st = "\\1 ";
|
||||
break;
|
||||
case Data::prefix:
|
||||
st = "0x\\1, ";
|
||||
break;
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
switch (fmt) {
|
||||
case Data::seq:
|
||||
return work.join('\n');
|
||||
case Data::space:
|
||||
st = "\\1 ";
|
||||
break;
|
||||
case Data::prefix:
|
||||
st = "0x\\1, ";
|
||||
break;
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
|
||||
QStringList::iterator pick;
|
||||
for (pick = work.begin(); pick != work.end(); pick++) {
|
||||
if ((*pick).size() & 1) (*pick) += "0";
|
||||
(*pick).replace(QRegExp("([0-9a-fA-F]{2})"), st);
|
||||
(*pick).replace(QRegExp(" +$"), "");
|
||||
}
|
||||
QStringList::iterator pick;
|
||||
for (pick = work.begin(); pick != work.end(); pick++) {
|
||||
if ((*pick).size() & 1) (*pick) += "0";
|
||||
(*pick).replace(QRegExp("([0-9a-fA-F]{2})"), st);
|
||||
(*pick).replace(QRegExp(" +$"), "");
|
||||
}
|
||||
|
||||
return work.join('\n');
|
||||
return work.join('\n');
|
||||
}
|
||||
|
||||
|
22
data.h
22
data.h
@ -5,19 +5,19 @@
|
||||
|
||||
class Data
|
||||
{
|
||||
public:
|
||||
enum format { seq, space, prefix };
|
||||
bool cap;
|
||||
public:
|
||||
enum format { seq, space, prefix };
|
||||
bool cap;
|
||||
|
||||
Data(QString &in, bool cap);
|
||||
Data(int len, bool cap);
|
||||
void clean();
|
||||
void to_hex();
|
||||
QString get_ascii();
|
||||
QString get(int unit, enum format fmt);
|
||||
Data(QString &in, bool cap);
|
||||
Data(int len, bool cap);
|
||||
void clean();
|
||||
void to_hex();
|
||||
QString get_ascii();
|
||||
QString get(int unit, enum format fmt);
|
||||
|
||||
private:
|
||||
QString txt;
|
||||
private:
|
||||
QString txt;
|
||||
};
|
||||
|
||||
#endif // DATA_H
|
||||
|
8
main.cpp
8
main.cpp
@ -5,9 +5,9 @@
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
MainWindow w;
|
||||
w.show();
|
||||
QApplication a(argc, argv);
|
||||
MainWindow w;
|
||||
w.show();
|
||||
|
||||
return a.exec();
|
||||
return a.exec();
|
||||
}
|
||||
|
@ -8,117 +8,117 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
ui(new Ui::MainWindow)
|
||||
{
|
||||
this->bpl = 16;
|
||||
this->fmt = Data::prefix;
|
||||
this->bpl = 16;
|
||||
this->fmt = Data::prefix;
|
||||
|
||||
ui->setupUi(this);
|
||||
setWindowIcon(QIcon("hex.ico"));
|
||||
ui->setupUi(this);
|
||||
setWindowIcon(QIcon("hex.ico"));
|
||||
}
|
||||
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
delete ui;
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::unify_rand(QPlainTextEdit *to)
|
||||
{
|
||||
int len = ui->ln_rand_byte->text().toInt();
|
||||
if (len > maxlen) return;
|
||||
int len = ui->ln_rand_byte->text().toInt();
|
||||
if (len > maxlen) return;
|
||||
|
||||
Data d(len, ui->cb_cap->isChecked());
|
||||
to->setPlainText(d.get(this->bpl, this->fmt));
|
||||
Data d(len, ui->cb_cap->isChecked());
|
||||
to->setPlainText(d.get(this->bpl, this->fmt));
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::unify_trns(QPlainTextEdit *from, QPlainTextEdit *to)
|
||||
{
|
||||
QString get = from->toPlainText();
|
||||
Data d(get, ui->cb_cap->isChecked());
|
||||
if (ui->rb_trans_hex->isChecked()) {
|
||||
d.to_hex();
|
||||
to->setPlainText(d.get(this->bpl, this->fmt));
|
||||
} else {
|
||||
to->setPlainText(d.get_ascii());
|
||||
}
|
||||
QString get = from->toPlainText();
|
||||
Data d(get, ui->cb_cap->isChecked());
|
||||
if (ui->rb_trans_hex->isChecked()) {
|
||||
d.to_hex();
|
||||
to->setPlainText(d.get(this->bpl, this->fmt));
|
||||
} else {
|
||||
to->setPlainText(d.get_ascii());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void MainWindow::unify_fmt(QPlainTextEdit *from, QPlainTextEdit *to)
|
||||
{
|
||||
QString get = from->toPlainText();
|
||||
Data d(get, ui->cb_cap->isChecked());
|
||||
d.clean();
|
||||
to->setPlainText(d.get(this->bpl, this->fmt));
|
||||
QString get = from->toPlainText();
|
||||
Data d(get, ui->cb_cap->isChecked());
|
||||
d.clean();
|
||||
to->setPlainText(d.get(this->bpl, this->fmt));
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_rb_bl_set_clicked()
|
||||
{
|
||||
this->bpl = ui->ln_bl_byte->text().toInt();
|
||||
ui->ln_bl_byte->setEnabled(true);
|
||||
this->bpl = ui->ln_bl_byte->text().toInt();
|
||||
ui->ln_bl_byte->setEnabled(true);
|
||||
}
|
||||
|
||||
void MainWindow::on_rb_bl_none_clicked()
|
||||
{
|
||||
this->bpl = 0;
|
||||
ui->ln_bl_byte->setDisabled(true);
|
||||
this->bpl = 0;
|
||||
ui->ln_bl_byte->setDisabled(true);
|
||||
}
|
||||
|
||||
void MainWindow::on_rb_bl_keep_clicked()
|
||||
{
|
||||
this->bpl = -1;
|
||||
ui->ln_bl_byte->setDisabled(true);
|
||||
this->bpl = -1;
|
||||
ui->ln_bl_byte->setDisabled(true);
|
||||
}
|
||||
|
||||
void MainWindow::on_rb_fmt_prfx_clicked()
|
||||
{
|
||||
this->fmt = Data::prefix;
|
||||
this->fmt = Data::prefix;
|
||||
}
|
||||
|
||||
void MainWindow::on_rb_fmt_space_clicked()
|
||||
{
|
||||
this->fmt = Data::space;
|
||||
this->fmt = Data::space;
|
||||
}
|
||||
|
||||
void MainWindow::on_rb_fmt_seq_clicked()
|
||||
{
|
||||
this->fmt = Data::seq;
|
||||
this->fmt = Data::seq;
|
||||
}
|
||||
|
||||
void MainWindow::on_btn_fmt_left_clicked()
|
||||
{
|
||||
unify_fmt(ui->txt_right, ui->txt_left);
|
||||
unify_fmt(ui->txt_right, ui->txt_left);
|
||||
}
|
||||
|
||||
void MainWindow::on_btn_fmt_right_clicked()
|
||||
{
|
||||
unify_fmt(ui->txt_left, ui->txt_right);
|
||||
unify_fmt(ui->txt_left, ui->txt_right);
|
||||
}
|
||||
|
||||
void MainWindow::on_btn_trans_left_clicked()
|
||||
{
|
||||
unify_trns(ui->txt_right, ui->txt_left);
|
||||
unify_trns(ui->txt_right, ui->txt_left);
|
||||
}
|
||||
|
||||
void MainWindow::on_btn_trans_right_clicked()
|
||||
{
|
||||
unify_trns(ui->txt_left, ui->txt_right);
|
||||
unify_trns(ui->txt_left, ui->txt_right);
|
||||
}
|
||||
|
||||
void MainWindow::on_btn_rand_left_clicked()
|
||||
{
|
||||
unify_rand(ui->txt_left);
|
||||
unify_rand(ui->txt_left);
|
||||
}
|
||||
|
||||
void MainWindow::on_btn_rand_right_clicked()
|
||||
{
|
||||
unify_rand(ui->txt_right);
|
||||
unify_rand(ui->txt_right);
|
||||
}
|
||||
|
||||
void MainWindow::on_ln_bl_byte_editingFinished()
|
||||
{
|
||||
this->bpl = ui->ln_bl_byte->text().toInt();
|
||||
this->bpl = ui->ln_bl_byte->text().toInt();
|
||||
}
|
||||
|
64
mainwindow.h
64
mainwindow.h
@ -6,52 +6,40 @@
|
||||
#include "data.h"
|
||||
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
class MainWindow;
|
||||
}
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MainWindow(QWidget *parent = 0);
|
||||
~MainWindow();
|
||||
public:
|
||||
explicit MainWindow(QWidget *parent = 0);
|
||||
~MainWindow();
|
||||
|
||||
private slots:
|
||||
void on_rb_bl_set_clicked();
|
||||
private slots:
|
||||
void on_rb_bl_set_clicked();
|
||||
void on_rb_bl_none_clicked();
|
||||
void on_rb_bl_keep_clicked();
|
||||
void on_rb_fmt_prfx_clicked();
|
||||
void on_rb_fmt_space_clicked();
|
||||
void on_rb_fmt_seq_clicked();
|
||||
void on_btn_fmt_left_clicked();
|
||||
void on_btn_fmt_right_clicked();
|
||||
void on_btn_trans_left_clicked();
|
||||
void on_btn_trans_right_clicked();
|
||||
void on_btn_rand_left_clicked();
|
||||
void on_btn_rand_right_clicked();
|
||||
void on_ln_bl_byte_editingFinished();
|
||||
|
||||
void on_rb_bl_none_clicked();
|
||||
|
||||
void on_rb_bl_keep_clicked();
|
||||
|
||||
void on_rb_fmt_prfx_clicked();
|
||||
|
||||
void on_rb_fmt_space_clicked();
|
||||
|
||||
void on_rb_fmt_seq_clicked();
|
||||
|
||||
void on_btn_fmt_left_clicked();
|
||||
|
||||
void on_btn_fmt_right_clicked();
|
||||
|
||||
void on_btn_trans_left_clicked();
|
||||
|
||||
void on_btn_trans_right_clicked();
|
||||
|
||||
void on_btn_rand_left_clicked();
|
||||
|
||||
void on_btn_rand_right_clicked();
|
||||
|
||||
void on_ln_bl_byte_editingFinished();
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
int bpl;
|
||||
bool cap;
|
||||
Data::format fmt;
|
||||
void unify_rand(QPlainTextEdit *to);
|
||||
void unify_trns(QPlainTextEdit *from, QPlainTextEdit *to);
|
||||
void unify_fmt(QPlainTextEdit *from, QPlainTextEdit *to);
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
int bpl;
|
||||
bool cap;
|
||||
Data::format fmt;
|
||||
void unify_rand(QPlainTextEdit *to);
|
||||
void unify_trns(QPlainTextEdit *from, QPlainTextEdit *to);
|
||||
void unify_fmt(QPlainTextEdit *from, QPlainTextEdit *to);
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user