refactor: CoreProcess make wrapIpv6, Simplify wrapIpV6 method

This commit is contained in:
sithlord48 2025-10-10 20:29:02 -04:00 committed by Chris Rizzitello
parent de6be901b9
commit ac7bd1ceca
2 changed files with 12 additions and 7 deletions

View file

@ -66,23 +66,27 @@ QString CoreProcess::makeQuotedArgs(const QString &app, const QStringList &args)
/** /**
* @brief If IPv6, ensures the IP is surround in square brackets. * @brief If IPv6, ensures the IP is surround in square brackets.
*/ */
QString wrapIpv6(const QString &address) QString CoreProcess::wrapIpv6(const QString &address)
{ {
if (!address.contains(':') || address.isEmpty()) { static const auto colon = QStringLiteral(":");
static const auto openBracket = QStringLiteral("[");
static const auto closeBracket = QStringLiteral("]");
if (!address.contains(colon) || address.isEmpty()) {
return address; return address;
} }
QString wrapped = address; QString wrapped = address;
if (address[0] != '[') { if (!address.startsWith(openBracket)) {
wrapped.insert(0, '['); wrapped.prepend(openBracket);
} }
if (address[address.size() - 1] != ']') { if (!address.endsWith(closeBracket)) {
wrapped.push_back(']'); wrapped.append(closeBracket);
} }
return address; return wrapped;
} }
// //

View file

@ -125,6 +125,7 @@ private:
static QString makeQuotedArgs(const QString &app, const QStringList &args); static QString makeQuotedArgs(const QString &app, const QStringList &args);
static QString processModeToString(const Settings::ProcessMode mode); static QString processModeToString(const Settings::ProcessMode mode);
static QString processStateToString(const CoreProcess::ProcessState state); static QString processStateToString(const CoreProcess::ProcessState state);
static QString wrapIpv6(const QString &address);
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
void checkOSXNotification(const QString &line); void checkOSXNotification(const QString &line);