From 500be2f7d14837b9b797973f47ef0524548433fe Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Wed, 11 Oct 2017 03:44:31 +0200 Subject: [PATCH] Improved beautify name function (fixed during T171) --- src/blackmisc/network/user.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/blackmisc/network/user.cpp b/src/blackmisc/network/user.cpp index a54889484..f7bc9b52a 100644 --- a/src/blackmisc/network/user.cpp +++ b/src/blackmisc/network/user.cpp @@ -148,21 +148,31 @@ namespace BlackMisc QString CUser::beautifyRealName(const QString &realName) { - QString newRealName(realName.simplified().trimmed().toLower()); - if (newRealName.isEmpty()) { return ""; } + QString newRealName(realName.simplified().trimmed()); + if (newRealName.isEmpty()) { return newRealName; } - // simple title case + int uc = 0; + int lc = 0; + for (const QChar ch : realName) + { + if (uc > 1 && lc > 1) { return newRealName; } // mixed case name, no need to beautify + if (ch.isLower()) { lc++; continue; } + if (ch.isUpper()) { uc++; continue;} + } + + // simple title case beautifying + newRealName = newRealName.toLower(); QString::Iterator i = newRealName.begin(); bool upperNextChar = true; while (i != newRealName.end()) { - if (i->isSpace()) + if (i->isSpace() || *i == '-') { upperNextChar = true; } else if (upperNextChar) { - QChar u(i->toUpper()); + const QChar u(i->toUpper()); *i = u; upperNextChar = false; }