Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fixed hexadecimal escape sequence parsing
- affects user command strings read from menu.xml
  • Loading branch information
holsthei committed Feb 22, 2013
1 parent b449f84 commit 6236e7f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
7 changes: 5 additions & 2 deletions terminal.cpp
Expand Up @@ -142,21 +142,24 @@ void Terminal::putString(QString str, bool unEscape)
str.replace("\\b", "\b");
str.replace("\\t", "\t");

//hex
while(str.indexOf("\\x") != -1) {
int i = str.indexOf("\\x")+2;
QString num;
while(num.length() < 2 && str.length()>i && str.at(i).isNumber() ) {
while(num.length() < 2 && str.length()>i && Util::charIsHexDigit(str.at(i))) {
num.append(str.at(i));
i++;
}
str.remove(i-2-num.length(), num.length()+2);
bool ok;
str.insert(i-2-num.length(), QChar(num.toInt(&ok,16)));
}
//octal
while(str.indexOf("\\0") != -1) {
int i = str.indexOf("\\0")+2;
QString num;
while(num.length() < 3 && str.length()>i && str.at(i).isNumber() ) {
while(num.length() < 3 && str.length()>i &&
(str.at(i).toAscii() >= 48 && str.at(i).toAscii() <= 55)) { //accept only 0-7
num.append(str.at(i));
i++;
}
Expand Down
13 changes: 13 additions & 0 deletions util.cpp
Expand Up @@ -392,3 +392,16 @@ void Util::selectionFinished()
emit clipboardOrSelectionChanged();
}

//static
bool Util::charIsHexDigit(QChar ch)
{
if (ch.isDigit()) // 0-9
return true;
else if (ch.toAscii() >= 65 && ch.toAscii() <= 70) // A-F
return true;
else if (ch.toAscii() >= 97 && ch.toAscii() <= 102) // a-f
return true;

return false;
}

2 changes: 2 additions & 0 deletions util.h
Expand Up @@ -67,6 +67,8 @@ class Util : public QObject

Q_PROPERTY(bool allowGestures READ allowGestures WRITE setAllowGestures NOTIFY allowGesturesChanged)

static bool charIsHexDigit(QChar ch);

public slots:
void onMainWinFocusChanged(bool in);

Expand Down

0 comments on commit 6236e7f

Please sign in to comment.