mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-03 16:25:54 +08:00
Improved beautify name function (fixed during T171)
This commit is contained in:
@@ -148,21 +148,31 @@ namespace BlackMisc
|
|||||||
|
|
||||||
QString CUser::beautifyRealName(const QString &realName)
|
QString CUser::beautifyRealName(const QString &realName)
|
||||||
{
|
{
|
||||||
QString newRealName(realName.simplified().trimmed().toLower());
|
QString newRealName(realName.simplified().trimmed());
|
||||||
if (newRealName.isEmpty()) { return ""; }
|
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();
|
QString::Iterator i = newRealName.begin();
|
||||||
bool upperNextChar = true;
|
bool upperNextChar = true;
|
||||||
while (i != newRealName.end())
|
while (i != newRealName.end())
|
||||||
{
|
{
|
||||||
if (i->isSpace())
|
if (i->isSpace() || *i == '-')
|
||||||
{
|
{
|
||||||
upperNextChar = true;
|
upperNextChar = true;
|
||||||
}
|
}
|
||||||
else if (upperNextChar)
|
else if (upperNextChar)
|
||||||
{
|
{
|
||||||
QChar u(i->toUpper());
|
const QChar u(i->toUpper());
|
||||||
*i = u;
|
*i = u;
|
||||||
upperNextChar = false;
|
upperNextChar = false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user