MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / sanitiseTitleForPath

Function sanitiseTitleForPath

app/src/Sessions/DatabaseManager.cpp:53–83  ·  view source on GitHub ↗

* @brief Scrubs a project title for use as a folder/file name component. */

Source from the content-addressed store, hash-verified

51 * @brief Scrubs a project title for use as a folder/file name component.
52 */
53static QString sanitiseTitleForPath(const QString& title)
54{
55 QString safe = title;
56 safe.remove(QChar('/'));
57 safe.remove(QChar('\\'));
58 safe.remove(QChar(':'));
59 safe.remove(QChar('*'));
60 safe.remove(QChar('?'));
61 safe.remove(QChar('"'));
62 safe.remove(QChar('<'));
63 safe.remove(QChar('>'));
64 safe.remove(QChar('|'));
65 safe.remove(QChar('\0'));
66 safe.remove(QStringLiteral(".."));
67 safe = safe.simplified();
68
69 int keep = 0;
70 for (int i = safe.size(); i > 0; --i) {
71 const QChar c = safe.at(i - 1);
72 if (c != QChar('.') && c != QChar(' ')) {
73 keep = i;
74 break;
75 }
76 }
77 safe.truncate(keep);
78
79 if (safe.isEmpty())
80 safe = QStringLiteral("Untitled");
81
82 return safe;
83}
84
85//--------------------------------------------------------------------------------------------------
86// Constructor & singleton

Callers 3

canonicalDbPathMethod · 0.85
exportSessionToCsvMethod · 0.85
requestPdfOutputPathMethod · 0.85

Calls 3

isEmptyMethod · 0.80
removeMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected