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