forked from qt-creator/qt-creator
CppEditor: Remove all leading/trailing "_" for a variable's base name
Change-Id: Iea1aa4ca3f34d11d2e55ce56572c3b19af5743e3 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
This commit is contained in:
@@ -300,17 +300,24 @@ bool nameIncludesOperatorName(const Name *name)
|
|||||||
QString memberBaseName(const QString &name)
|
QString memberBaseName(const QString &name)
|
||||||
{
|
{
|
||||||
QString baseName = name;
|
QString baseName = name;
|
||||||
if (baseName.startsWith(QLatin1Char('_'))) {
|
|
||||||
|
// Remove leading and trailing "_"
|
||||||
|
while (baseName.startsWith(QLatin1Char('_')))
|
||||||
baseName.remove(0, 1);
|
baseName.remove(0, 1);
|
||||||
} else if (baseName.endsWith(QLatin1Char('_'))) {
|
while (baseName.endsWith(QLatin1Char('_')))
|
||||||
baseName.chop(1);
|
baseName.chop(1);
|
||||||
} else if (baseName.startsWith(QLatin1String("m_"))) {
|
if (baseName != name)
|
||||||
|
return baseName;
|
||||||
|
|
||||||
|
// If no leading/trailing "_": remove "m_" and "m" prefix
|
||||||
|
if (baseName.startsWith(QLatin1String("m_"))) {
|
||||||
baseName.remove(0, 2);
|
baseName.remove(0, 2);
|
||||||
} else if (baseName.startsWith(QLatin1Char('m')) && baseName.length() > 1
|
} else if (baseName.startsWith(QLatin1Char('m')) && baseName.length() > 1
|
||||||
&& baseName.at(1).isUpper()) {
|
&& baseName.at(1).isUpper()) {
|
||||||
baseName.remove(0, 1);
|
baseName.remove(0, 1);
|
||||||
baseName[0] = baseName.at(0).toLower();
|
baseName[0] = baseName.at(0).toLower();
|
||||||
}
|
}
|
||||||
|
|
||||||
return baseName;
|
return baseName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user