Copy as C string added.

This commit is contained in:
Eelke Klein 2017-02-05 08:23:06 +01:00
parent 4a2c6cc396
commit df866d7b67
9 changed files with 89 additions and 32 deletions

View file

@ -3,6 +3,7 @@
#include <QApplication>
#include <QTextStream>
#include <QClipboard>
#include <sstream>
// Supported range from microseconds to seconds
// min:sec to hours::min::sec
@ -81,3 +82,33 @@ void copySelectionToClipboard(const QTableView *view)
QApplication::clipboard()->setText(clipboard_string);
}
}
QString ConvertToMultiLineCString(const QString &in)
{
// We need to atleast escape " and \
// also any multi byte utf8 char
QString out;
out.append('"');
QByteArray ba = in.toUtf8();
for (auto c : ba) {
if (c == '\\') {
out.append("\\\\");
}
else if (c == '"') {
out.append("\\\"");
}
else if (uchar(c) > 127) {
out.append(QString("\\x%1").arg(uchar(c), 2, 16, QChar('0')));
}
else if (c == '\n') {
// at end of line we add a space and a new line in the string then we put in the end quote go to the next line and put the open quote
out.append(" \\n\"\n\"");
}
else {
out.append(c);
}
}
out.append('"');
return out;
}