Adapt generated header guards to the filename

Use _HPP for example for .hpp files, for example. Based on simply
putting the chosen extension in uppercase.
This commit is contained in:
Thorbjørn Lindeijer
2009-03-05 17:12:31 +01:00
parent 1f3908e0a5
commit cb2cce5139
5 changed files with 25 additions and 23 deletions

View File

@@ -36,10 +36,26 @@
namespace Core {
namespace Utils {
static QString toAlphaNum(const QString &s)
{
QString rc;
const int len = s.size();
const QChar underscore = QLatin1Char('_');
for (int i = 0; i < len; i++) {
const QChar c = s.at(i);
if (c == underscore || c.isLetterOrNumber())
rc += c;
}
return rc;
}
QWORKBENCH_UTILS_EXPORT QString headerGuard(const QString &file)
{
QString rc = QFileInfo(file).baseName().toUpper();
rc += QLatin1String("_H");
const QFileInfo fi(file);
QString rc = toAlphaNum(fi.completeBaseName()).toUpper();
rc += QLatin1Char('_');
rc += toAlphaNum(fi.suffix()).toUpper();
return rc;
}