forked from qt-creator/qt-creator
Use regular expression for EditorManager::splitLineAndColumnNumber
Makes it actually easier to understand. Change-Id: I33c442f501ecdf66077f8785bf8418a6d699f2ee Reviewed-by: David Schulz <david.schulz@theqtcompany.com>
This commit is contained in:
@@ -79,6 +79,8 @@
|
|||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
|
#include <QRegularExpression>
|
||||||
|
#include <QRegularExpressionMatch>
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QTextCodec>
|
#include <QTextCodec>
|
||||||
@@ -165,30 +167,6 @@ void EditorManagerPlaceHolder::currentModeChanged(IMode *mode)
|
|||||||
static EditorManager *m_instance = 0;
|
static EditorManager *m_instance = 0;
|
||||||
static EditorManagerPrivate *d;
|
static EditorManagerPrivate *d;
|
||||||
|
|
||||||
static int extractNumericSuffix(QString *fileName, QString *postfix = 0)
|
|
||||||
{
|
|
||||||
int i = fileName->length() - 1;
|
|
||||||
for (; i >= 0; --i) {
|
|
||||||
if (!fileName->at(i).isNumber())
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (i == -1)
|
|
||||||
return -1;
|
|
||||||
const QChar c = fileName->at(i);
|
|
||||||
if (c == QLatin1Char(':') || c == QLatin1Char('+')) {
|
|
||||||
bool ok;
|
|
||||||
const QString suffix = fileName->mid(i + 1);
|
|
||||||
const int result = suffix.toInt(&ok);
|
|
||||||
if (suffix.isEmpty() || ok) {
|
|
||||||
if (postfix)
|
|
||||||
*postfix = fileName->mid(i);
|
|
||||||
fileName->truncate(i);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static QString autoSaveName(const QString &fileName)
|
static QString autoSaveName(const QString &fileName)
|
||||||
{
|
{
|
||||||
return fileName + QLatin1String(".autosave");
|
return fileName + QLatin1String(".autosave");
|
||||||
@@ -2565,20 +2543,20 @@ IEditor *EditorManager::openEditorAt(const QString &fileName, int line, int colu
|
|||||||
|
|
||||||
EditorManager::FilePathInfo EditorManager::splitLineAndColumnNumber(const QString &fullFilePath)
|
EditorManager::FilePathInfo EditorManager::splitLineAndColumnNumber(const QString &fullFilePath)
|
||||||
{
|
{
|
||||||
|
static const auto regexp = QRegularExpression(QLatin1String("[:+](\\d+)?([:+](\\d+)?)?$"));
|
||||||
|
const QRegularExpressionMatch match = regexp.match(fullFilePath);
|
||||||
QString postfix;
|
QString postfix;
|
||||||
QString filePath = fullFilePath;
|
QString filePath = fullFilePath;
|
||||||
int line = -1;
|
int line = -1;
|
||||||
int column = -1;
|
int column = -1;
|
||||||
const int last = extractNumericSuffix(&filePath, &postfix);
|
if (match.hasMatch()) {
|
||||||
if (last != -1) {
|
postfix = match.captured(0);
|
||||||
QString previousPostfix;
|
filePath = fullFilePath.left(match.capturedStart(0));
|
||||||
const int secondLast = extractNumericSuffix(&filePath, &previousPostfix);
|
line = 0; // for the case that there's only a : at the end
|
||||||
if (secondLast != -1) {
|
if (match.lastCapturedIndex() > 0) {
|
||||||
line = secondLast;
|
line = match.captured(1).toInt();
|
||||||
column = last - 1; //column is 0 based, despite line being 1 based
|
if (match.lastCapturedIndex() > 2) // index 2 includes the + or : for the column number
|
||||||
postfix.prepend(previousPostfix);
|
column = match.captured(3).toInt() - 1; //column is 0 based, despite line being 1 based
|
||||||
} else {
|
|
||||||
line = last;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {filePath, postfix, line, column};
|
return {filePath, postfix, line, column};
|
||||||
|
|||||||
Reference in New Issue
Block a user