add fallback display for non-printable characters
This commit is contained in:
parent
bb594e768c
commit
767eaa0a47
@ -91,7 +91,27 @@ void MainWindow::openDatabase(QString file, bool readOnly)
|
|||||||
static const QString getDisplayName(const QByteArray &qba) {
|
static const QString getDisplayName(const QByteArray &qba) {
|
||||||
// FIXME the formatting isn't so great when control characters, etc. are used
|
// FIXME the formatting isn't so great when control characters, etc. are used
|
||||||
// A C-style escape display, or the unicode-replacement-character would be preferable
|
// A C-style escape display, or the unicode-replacement-character would be preferable
|
||||||
return QString::fromUtf8(qba);
|
QString ret(QString::fromUtf8(qba));
|
||||||
|
|
||||||
|
bool allPrintable = true;
|
||||||
|
for (auto i = ret.begin(), e = ret.end(); i != e; ++i) {
|
||||||
|
if (! i->isPrint()) {
|
||||||
|
allPrintable = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (allPrintable) {
|
||||||
|
return ret; // fine
|
||||||
|
}
|
||||||
|
|
||||||
|
// Some of the characters weren't printable.
|
||||||
|
// Build up a replacement string
|
||||||
|
QString replacement;
|
||||||
|
for (auto i = ret.begin(), e = ret.end(); i != e; ++i) {
|
||||||
|
replacement += i->isPrint() ? *i : QStringLiteral("\\u{%1}").arg(i->unicode());
|
||||||
|
}
|
||||||
|
return replacement;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::refreshBucketTree(QTreeWidgetItem* itm)
|
void MainWindow::refreshBucketTree(QTreeWidgetItem* itm)
|
||||||
|
Loading…
Reference in New Issue
Block a user