Skip to content

Commit

Permalink
feat(MessageLogger): make messages HTMLescaped (#70)
Browse files Browse the repository at this point in the history
Compiler messages like `vector<int>` should be HTMLescaped.
  • Loading branch information
ouuan authored and coder3101 committed Jan 8, 2020
1 parent 0488da9 commit 78bdfb3
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/MessageLogger.cpp
Expand Up @@ -26,57 +26,63 @@ void MessageLogger::setContainer(QTextBrowser *value)

void MessageLogger::info(std::string head, std::string body)
{
auto qHead = QString::fromStdString(head).toHtmlEscaped();
auto qBody = QString::fromStdString(body).toHtmlEscaped();
std::string ans = "<b>[";
int long long timestamp = QDateTime::currentSecsSinceEpoch();
auto val = QDateTime::fromSecsSinceEpoch(timestamp).time();
ans += val.toString().toStdString();
ans += "] [";
ans += head;
ans += qHead.toStdString();
ans += "] </b>";
ans += "[";
ans += body;
ans += qBody.toStdString();
ans += "]";
box->append(QString::fromStdString(ans));
}

void MessageLogger::warn(std::string head, std::string body, bool multiline)
{
auto qHead = QString::fromStdString(head).toHtmlEscaped();
auto qBody = QString::fromStdString(body).toHtmlEscaped();
std::string ans = "<b>[";
auto timestamp = QDateTime::currentSecsSinceEpoch();
auto val = QDateTime::fromSecsSinceEpoch(timestamp).time();
ans += val.toString().toStdString();
ans += "] [";
ans += head;
ans += qHead.toStdString();
ans += "] </b>";
ans += "<font color=green>[";
if (multiline)
{
ans += "<br>";
ans += QString::fromStdString(body).replace("\n", "<br>").toStdString();
ans += qBody.replace("\n", "<br>").toStdString();
}
else
ans += body;
ans += qBody.toStdString();
ans += "]</font>";

box->append(QString::fromStdString(ans));
}
void MessageLogger::error(std::string head, std::string body, bool multiline)
{
auto qHead = QString::fromStdString(head).toHtmlEscaped();
auto qBody = QString::fromStdString(body).toHtmlEscaped();
std::string ans = "<b>[";
auto timestamp = QDateTime::currentSecsSinceEpoch();
auto val = QDateTime::fromSecsSinceEpoch(timestamp).time();
ans += val.toString().toStdString();
ans += "] [";
ans += head;
ans += qHead.toStdString();
ans += "] </b>";
ans += "<font color=red>[";
if (multiline)
{
ans += "<br>";
ans += QString::fromStdString(body).replace("\n", "<br>").toStdString();
ans += qBody.replace("\n", "<br>").toStdString();
}
else
ans += body;
ans += qBody.toStdString();
ans += "]</font>";

box->append(QString::fromStdString(ans));
Expand Down

0 comments on commit 78bdfb3

Please sign in to comment.