Changeset - 571af19990ed
[Not reviewed]
Hasan Yavuz Ă–ZDERYA - 10 years ago 2015-10-10 16:03:20
hy@ozderya.net
implemented escaping of LF, CR, TAB characters with \n, \r, \t respectively
3 files changed with 30 insertions and 3 deletions:
0 comments (0 inline, 0 general)
commandedit.cpp
Show inline comments
 
@@ -72,6 +72,9 @@ CommandEdit::~CommandEdit()
 
    delete hexValidator;
 
}
 

	
 
QString unEscape(QString str);
 
QString escape(QString str);
 

	
 
void CommandEdit::setMode(bool ascii)
 
{
 
    ascii_mode = ascii;
 
@@ -87,12 +90,13 @@ void CommandEdit::setMode(bool ascii)
 
            hexText.replace(hexText.size()-1, 1, "3F"); // 0x3F = '?'
 
            qWarning() << "Broken byte in hex command is replaced. Check your command!";
 
        }
 
        setText(QByteArray::fromHex(hexText.toLatin1()));
 

	
 
        setText(escape(QByteArray::fromHex(hexText.toLatin1())));
 
    }
 
    else
 
    {
 
        setValidator(hexValidator);
 
        setText(text().toLatin1().toHex());
 
        setText(unEscape(text()).toLatin1().toHex());
 
    }
 
}
 

	
 
@@ -115,3 +119,24 @@ void CommandEdit::keyPressEvent(QKeyEven
 

	
 
    QLineEdit::keyPressEvent(event);
 
}
 

	
 
QString CommandEdit::unEscapedText()
 
{
 
    return unEscape(text());
 
}
 

	
 
QString unEscape(QString str)
 
{
 
    str.replace("\\n", "\n");
 
    str.replace("\\r", "\r");
 
    str.replace("\\t", "\t");
 
    return str;
 
}
 

	
 
QString escape(QString str)
 
{
 
    str.replace("\n", "\\n");
 
    str.replace("\r", "\\r");
 
    str.replace("\t", "\\t");
 
    return str;
 
}
commandedit.h
Show inline comments
 
@@ -22,6 +22,7 @@
 

	
 
#include <QLineEdit>
 
#include <QValidator>
 
#include <QString>
 

	
 
class CommandEdit : public QLineEdit
 
{
 
@@ -31,6 +32,7 @@ public:
 
    explicit CommandEdit(QWidget *parent = 0);
 
    ~CommandEdit();
 
    void setMode(bool ascii); // true = ascii, false = hex
 
    QString unEscapedText(); // return unescaped text(), used in ascii_mode only
 

	
 
private:
 
    bool ascii_mode;
commandwidget.cpp
Show inline comments
 
@@ -60,7 +60,7 @@ void CommandWidget::onSendClicked()
 
    if (isASCIIMode())
 
    {
 
        qDebug() << "Sending:" << command;
 
        emit sendCommand(command.toLatin1());
 
        emit sendCommand(ui->leCommand->unEscapedText().toLatin1());
 
    }
 
    else // hex mode
 
    {
0 comments (0 inline, 0 general)