From 7b94e714a3abd58467435b8f568574b609931f8b Mon Sep 17 00:00:00 2001 From: xw_y_am Date: Wed, 30 May 2018 22:44:36 +0800 Subject: [PATCH] add cap mode --- data.cpp | 12 ++++--- data.h | 5 +-- mainwindow.cpp | 6 ++-- mainwindow.h | 1 + mainwindow.ui | 89 +++++++++++++++++++++++++++++++++----------------- 5 files changed, 74 insertions(+), 39 deletions(-) diff --git a/data.cpp b/data.cpp index e4b6f40..9c04d90 100644 --- a/data.cpp +++ b/data.cpp @@ -4,19 +4,21 @@ #include -Data::Data(QString &in) +Data::Data(QString &in, bool cap) { this->txt = in; + this->cap = cap; } -Data::Data(int len) +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; } @@ -28,7 +30,7 @@ void Data::to_hex() void Data::clean() { - this->txt = this->txt.toLower().replace(QRegExp("(0x)|[^0-9a-f\n]"), ""); + this->txt = this->txt.toLower().replace(QRegExp("(0x)|[^0-9a-fA-F\n]"), ""); } @@ -42,6 +44,8 @@ QString Data::get(int unit, enum format fmt) { QStringList work; + if (this->cap) this->txt = this->txt.toUpper(); + if (0 > unit) { work = this->txt.split('\n'); } else { @@ -75,7 +79,7 @@ QString Data::get(int unit, enum format fmt) QStringList::iterator pick; for (pick = work.begin(); pick != work.end(); pick++) { if ((*pick).size() & 1) (*pick) += "0"; - (*pick).replace(QRegExp("([0-9a-z]{2})"), st); + (*pick).replace(QRegExp("([0-9a-fA-F]{2})"), st); (*pick).replace(QRegExp(" +$"), ""); } diff --git a/data.h b/data.h index e7d3ecf..52950f9 100644 --- a/data.h +++ b/data.h @@ -7,9 +7,10 @@ class Data { public: enum format { seq, space, prefix }; + bool cap; - Data(QString &in); - Data(int len); + Data(QString &in, bool cap); + Data(int len, bool cap); void clean(); void to_hex(); QString get_ascii(); diff --git a/mainwindow.cpp b/mainwindow.cpp index fb885a6..4478b3b 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -27,7 +27,7 @@ void MainWindow::unify_rand(QPlainTextEdit *to) int len = ui->ln_rand_byte->text().toInt(); if (len > maxlen) return; - Data d(len); + Data d(len, ui->cb_cap->isChecked()); to->setPlainText(d.get(this->bpl, this->fmt)); } @@ -35,7 +35,7 @@ void MainWindow::unify_rand(QPlainTextEdit *to) void MainWindow::unify_trns(QPlainTextEdit *from, QPlainTextEdit *to) { QString get = from->toPlainText(); - Data d(get); + Data d(get, ui->cb_cap->isChecked()); if (ui->rb_trans_hex->isChecked()) { d.to_hex(); to->setPlainText(d.get(this->bpl, this->fmt)); @@ -49,7 +49,7 @@ void MainWindow::unify_trns(QPlainTextEdit *from, QPlainTextEdit *to) void MainWindow::unify_fmt(QPlainTextEdit *from, QPlainTextEdit *to) { QString get = from->toPlainText(); - Data d(get); + Data d(get, ui->cb_cap->isChecked()); d.clean(); to->setPlainText(d.get(this->bpl, this->fmt)); } diff --git a/mainwindow.h b/mainwindow.h index e222925..9ec3b96 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -47,6 +47,7 @@ class MainWindow : public QMainWindow private: Ui::MainWindow *ui; int bpl; + bool cap; Data::format fmt; void unify_rand(QPlainTextEdit *to); void unify_trns(QPlainTextEdit *from, QPlainTextEdit *to); diff --git a/mainwindow.ui b/mainwindow.ui index 6b54cb8..fbf88c8 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -53,7 +53,7 @@ 370 - 500 + 570 120 111 @@ -135,38 +135,12 @@ 370 160 120 - 161 + 131 - 输出格式 + 格式选项 - - - - 10 - 100 - 75 - 23 - - - - ←整理 - - - - - - 40 - 130 - 75 - 23 - - - - 整理→ - - @@ -203,12 +177,28 @@ + + + + 10 + 110 + 71 + 16 + + + + 输出大写 + + + true + + 370 - 340 + 410 120 141 @@ -385,6 +375,45 @@ + + + + 370 + 310 + 120 + 80 + + + + 格式整理 + + + + + 40 + 50 + 75 + 23 + + + + 整理→ + + + + + + 10 + 20 + 75 + 23 + + + + ←整理 + + +