Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/epasveer/seer
Browse files Browse the repository at this point in the history
  • Loading branch information
epasveer committed Sep 7, 2024
2 parents fec95f5 + 3303a17 commit e35c03c
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 73 deletions.
86 changes: 19 additions & 67 deletions src/SeerGdbLogWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,84 +15,36 @@ void SeerGdbLogWidget::processText (const QString& text) {
QString str;

// Remove leading "~"
// ~"For help, type "help".
// "
if (text.front() == '~') {
str = text.mid(1);

// Remove leading """
if (str.front() == '"') {
str = str.mid(1);
}

// Remove trailing """
if (str.back() == '"') {
str.chop(1);
}

// Remove trailing "\n"
if (str.back() == '\n') {
str.chop(1);
}

// Remove leading "&"
// &"p name
// "
} else if (text.front() == '&') {

str = text.mid(1);

// Remove leading """
if (str.front() == '"') {
str = str.mid(1);
}

// Remove trailing """
if (str.back() == '"') {
str.chop(1);
}

// Remove trailing "\n"
if (str.back() == '\n') {
str.chop(1);
}


// Remove leading "@"
// @"memcheck monitor commands:
// "
} else if (text.front() == '@') {

str = text.mid(1);
switch (text.front().unicode()) {
case QChar('~').unicode():
case QChar('&').unicode():
case QChar('@').unicode():

// Remove leading """
if (str.front() == '"') {
str = str.mid(1);
}
str = text.mid(1);

// Remove trailing """
if (str.back() == '"') {
str.chop(1);
}
// Remove leading """
if (str.front() == '"') {
str = str.mid(1);
}

// Remove trailing "\n"
if (str.back() == '\n') {
str.chop(1);
}
// Remove trailing """
if (str.back() == '"') {
str.chop(1);
}

break;

// Use string as it is.
}else{
str = text;
default:
str = text;
}

// Filter out \n and \t.
// Should probably do something better and expand them.
str.replace("\\t", "");
str.replace("\\n", "");
// https://github.com/epasveer/seer/issues/238
str = Seer::unescape(str);

// Write the string to the log.
textEdit->append(str);
textEdit->insertPlainText(str);

// If there is breakpoint message (via a manual command), ask
// for the breakpoint list to be refreshed.
Expand Down
2 changes: 2 additions & 0 deletions src/SeerLogWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@ void SeerLogWidget::setLogEnabled (bool flag) {

void SeerLogWidget::moveToEnd () {

/* XXX
// Move to the end and then to the beginning of that line.
QTextCursor cursor = textEdit->textCursor();
textEdit->moveCursor(QTextCursor::End, QTextCursor::MoveAnchor);
textEdit->moveCursor(QTextCursor::StartOfBlock, QTextCursor::MoveAnchor);
*/

textEdit->verticalScrollBar()->setValue(textEdit->verticalScrollBar()->maximum());
}
Expand Down
6 changes: 1 addition & 5 deletions src/SeerTildeLogWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ void SeerTildeLogWidget::processText (const QString& text) {

str = Seer::filterEscapes(str);

if (str.back() == '\n') { // Remove trailing "\n"
str.chop(1);
}

textEdit->append(str);
textEdit->insertPlainText(str);
}

91 changes: 91 additions & 0 deletions src/SeerUtl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -920,5 +920,96 @@ namespace Seer {
// All good.
return true;
}

QString unescape (const QString& str) {

QString result;
bool quoted = false;

// Maybe reserve `str.length()` bytes in result, so that it will not allocate during `push_back()`
result.reserve(str.length());

// Loop through each character in 'str'. Look for a '\'.
for (int i=0; i<str.length(); i++) {

// Found a '\'.
if (str[i] == QChar('\\')) {
// Can we look at the following character?
if (i+1 >= str.length()) {
// Nope, just add it.
result.push_back(str[i]);
break;
}

// If the following character is another '\', skip the first one.
// This removes one level of '\'.
if (str[i+1] == QChar('\\')) {
continue;
}

// Treat the following character as an escaped character.
// Unescape it. (Is that even a word?)
switch(str[i+1].unicode()) {
// We don't want to unescape things that are in double quotes.
// So keep track of that. (Not the more fool proof implementation).
case QChar('\"').unicode():
result.push_back(QChar('\"'));
if (quoted) {
quoted = false;
}else{
quoted = true;
}
break;
case QChar('n').unicode():
if (quoted == false) {
result.push_back(QChar('\n'));
}else{
result.push_back(QChar('\\'));
result.push_back(str[i+1]);
}
break;
case QChar('\'').unicode():
if (quoted == false) {
result.push_back(QChar('\''));
}else{
result.push_back(QChar('\\'));
result.push_back(str[i+1]);
}
break;
case QChar('\\').unicode():
if (quoted == false) {
result.push_back(QChar('\\'));
}else{
result.push_back(QChar('\\'));
result.push_back(str[i+1]);
}
break;
case QChar('t').unicode():
if (quoted == false) {
result.push_back(QChar('\t'));
}else{
result.push_back(QChar('\\'));
result.push_back(str[i+1]);
}
break;
// and so on for \a, \b, \e, \f, \r, \t, \v
// maybe handle octal, hexadecimal ASCII and Unicode forms, but probably in the more distant future
// ...
default:
// unknown escape sequence — do not escape it — I think it is reasonable default
result.push_back(QChar('\\'));
result.push_back(str[i+1]);
break;
}
i++;

// Normal character. Just add it.
}else{
result.push_back(str[i]);
}
}

return result;
}
}

1 change: 1 addition & 0 deletions src/SeerUtl.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ namespace Seer {
bool matchesWildcard (const QStringList& regexpatterns, const QString& string);
QString elideText (const QString& str, Qt::TextElideMode mode, int length);
QStringList split (const QString& str);
QString unescape (const QString& str);

int createID ();

Expand Down
2 changes: 1 addition & 1 deletion tests/hellostruct/hellostruct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ int main (int argc, char** argv) {
Person me;
Location where;

me.name = "Pasveer, Ernie";
me.name = "Pasveer,\tErnie";
me.age = 60;
me.salary = 0.25;
me.location.city = "Houston";
Expand Down

0 comments on commit e35c03c

Please sign in to comment.