refactor: Settings::cleanComputerName do not store empty QString for nothing

This commit is contained in:
sithlord48
2026-02-23 21:00:15 -05:00
committed by Nick Bolton
parent b4dbce385c
commit 37728cc7a3

View File

@ -137,12 +137,11 @@ QString Settings::cleanComputerName(const QString &name)
static const auto space = QStringLiteral(" "); static const auto space = QStringLiteral(" ");
static const auto underscore = QStringLiteral("_"); static const auto underscore = QStringLiteral("_");
static const auto period = QStringLiteral("."); static const auto period = QStringLiteral(".");
static const auto nothing = QStringLiteral("");
static const auto nameRegex = QRegularExpression(QStringLiteral("[^\\w\\-\\.]")); static const auto nameRegex = QRegularExpression(QStringLiteral("[^\\w\\-\\.]"));
QString cleanName = name.simplified(); QString cleanName = name.simplified();
cleanName.replace(space, underscore); cleanName.replace(space, underscore);
cleanName.replace(nameRegex, nothing); cleanName.replace(nameRegex, {});
while (cleanName.startsWith(hyphen) || cleanName.startsWith(underscore) || cleanName.startsWith(period)) while (cleanName.startsWith(hyphen) || cleanName.startsWith(underscore) || cleanName.startsWith(period))
cleanName.removeFirst(); cleanName.removeFirst();
while (cleanName.endsWith(hyphen) || cleanName.endsWith(underscore) || cleanName.endsWith(period)) while (cleanName.endsWith(hyphen) || cleanName.endsWith(underscore) || cleanName.endsWith(period))