debugger: more robust version string parsing

Fix for QTCREATORBUG-1490

Reviewed-By: Friedemann Kleint
This commit is contained in:
hjk
2010-05-27 15:41:52 +02:00
parent aa93d6f422
commit 5afeaa720d
6 changed files with 152 additions and 54 deletions

View File

@@ -32,6 +32,7 @@
#include <utils/qtcassert.h>
#include <QtCore/QByteArray>
#include <QtCore/QRegExp>
#include <QtCore/QTextStream>
#include <ctype.h>
@@ -400,5 +401,50 @@ QByteArray GdbResponse::toString() const
return result;
}
//////////////////////////////////////////////////////////////////////////////////
//
// GdbResponse
//
//////////////////////////////////////////////////////////////////////////////////
void extractGdbVersion(const QString &msg,
int *gdbVersion, int *gdbBuildVersion, bool *isMacGdb)
{
const QChar dot(QLatin1Char('.'));
QString cleaned;
QString build;
bool inClean = true;
foreach (QChar c, msg) {
if (inClean && !cleaned.isEmpty() && c != dot && (c.isPunct() || c.isSpace()))
inClean = false;
if (inClean) {
if (c.isDigit())
cleaned.append(c);
else if (!cleaned.isEmpty() && !cleaned.endsWith(dot))
cleaned.append(dot);
} else {
if (c.isDigit())
build.append(c);
else if (!build.isEmpty() && !build.endsWith(dot))
build.append(dot);
}
}
*isMacGdb = msg.contains(QLatin1String("Apple version"));
*gdbVersion = 10000 * cleaned.section(dot, 0, 0).toInt()
+ 100 * cleaned.section(dot, 1, 1).toInt()
+ 1 * cleaned.section(dot, 2, 2).toInt();
if (cleaned.count(dot) >= 3)
*gdbBuildVersion = cleaned.section(dot, 3, 3).toInt();
else
*gdbBuildVersion = build.section(dot, 0, 0).toInt();
if (*isMacGdb)
*gdbBuildVersion = build.section(dot, 1, 1).toInt();
}
} // namespace Internal
} // namespace Debugger