Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 32 additions & 8 deletions lib/errorlogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,20 +227,44 @@ void ErrorMessage::setmsg(const std::string &msg)
// lines, none of the error messages should end into it.
assert(!endsWith(msg,'\n'));

std::string msg2;

const bool allprint = std::all_of(msg.cbegin(), msg.cend(), [](char c){
return std::isprint(c) || c == '\n';
});
if (!allprint) {
// encode any unprintable characters
auto I = msg.begin();
const auto E = msg.end();
while (I != E) {
if (std::isprint(*I) || *I == '\n') {
msg2 += *I;
}
else {
msg2 += '\\';
msg2 += std::to_string(static_cast<int>(*I)); // TODO: pad to three digits
}
++I;
}
}
else {
msg2 = msg;
}

// The summary and verbose message are separated by a newline
// If there is no newline then both the summary and verbose messages
// are the given message
const std::string::size_type pos = msg.find('\n');
const std::string::size_type pos = msg2.find('\n');
const std::string symbolName = mSymbolNames.empty() ? std::string() : mSymbolNames.substr(0, mSymbolNames.find('\n'));
if (pos == std::string::npos) {
mShortMessage = replaceStr(msg, "$symbol", symbolName);
mVerboseMessage = replaceStr(msg, "$symbol", symbolName);
} else if (startsWith(msg,"$symbol:")) {
mSymbolNames += msg.substr(8, pos-7);
setmsg(msg.substr(pos + 1));
mShortMessage = replaceStr(msg2, "$symbol", symbolName);
mVerboseMessage = replaceStr(msg2, "$symbol", symbolName);
} else if (startsWith(msg2,"$symbol:")) {
mSymbolNames += msg2.substr(8, pos-7);
setmsg(msg2.substr(pos + 1));
} else {
mShortMessage = replaceStr(msg.substr(0, pos), "$symbol", symbolName);
mVerboseMessage = replaceStr(msg.substr(pos + 1), "$symbol", symbolName);
mShortMessage = replaceStr(msg2.substr(0, pos), "$symbol", symbolName);
mVerboseMessage = replaceStr(msg2.substr(pos + 1), "$symbol", symbolName);
}
}

Expand Down