summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Schulz <david.schulz@qt.io>2023-05-09 14:24:24 +0200
committerDavid Schulz <david.schulz@qt.io>2023-05-11 10:45:49 +0000
commit5a0f2e6d15123559d0d489b8b466888af28136ef (patch)
treefa91090401dedbcef1f6ae4f08398dc29eda2d71
parent7d87233c9c70eed9bf10d36ff1d4da115c071db7 (diff)
downloadqt-creator-5a0f2e6d15123559d0d489b8b466888af28136ef.tar.gz
Utils: move extractFromFileName from LineColumn to Text::Position
Change-Id: Ibb2465e66c280d4201377921f69741a050d94bc1 Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
-rw-r--r--src/libs/utils/CMakeLists.txt2
-rw-r--r--src/libs/utils/linecolumn.cpp43
-rw-r--r--src/libs/utils/linecolumn.h5
-rw-r--r--src/libs/utils/link.cpp8
-rw-r--r--src/libs/utils/textutils.cpp36
-rw-r--r--src/libs/utils/textutils.h2
-rw-r--r--src/libs/utils/utils.qbs1
7 files changed, 42 insertions, 55 deletions
diff --git a/src/libs/utils/CMakeLists.txt b/src/libs/utils/CMakeLists.txt
index f05398094a..5fa076027f 100644
--- a/src/libs/utils/CMakeLists.txt
+++ b/src/libs/utils/CMakeLists.txt
@@ -89,7 +89,7 @@ add_qtc_library(Utils
launcherpackets.cpp launcherpackets.h
launchersocket.cpp launchersocket.h
layoutbuilder.cpp layoutbuilder.h
- linecolumn.cpp linecolumn.h
+ linecolumn.h
link.cpp link.h
listmodel.h
listutils.h
diff --git a/src/libs/utils/linecolumn.cpp b/src/libs/utils/linecolumn.cpp
deleted file mode 100644
index 50a24ada62..0000000000
--- a/src/libs/utils/linecolumn.cpp
+++ /dev/null
@@ -1,43 +0,0 @@
-// Copyright (C) 2021 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
-
-#include "linecolumn.h"
-
-#include <QRegularExpression>
-
-namespace Utils {
-
-/*!
- Returns the line and column of a \a fileName and sets the \a postfixPos if
- it can find a positional postfix.
-
- The following patterns are supported: \c {filepath.txt:19},
- \c{filepath.txt:19:12}, \c {filepath.txt+19},
- \c {filepath.txt+19+12}, and \c {filepath.txt(19)}.
-*/
-
-LineColumn LineColumn::extractFromFileName(QStringView fileName, int &postfixPos)
-{
- static const auto regexp = QRegularExpression("[:+](\\d+)?([:+](\\d+)?)?$");
- // (10) MSVC-style
- static const auto vsRegexp = QRegularExpression("[(]((\\d+)[)]?)?$");
- const QRegularExpressionMatch match = regexp.match(fileName);
- LineColumn lineColumn;
- if (match.hasMatch()) {
- postfixPos = match.capturedStart(0);
- lineColumn.line = 0; // for the case that there's only a : at the end
- if (match.lastCapturedIndex() > 0) {
- lineColumn.line = match.captured(1).toInt();
- if (match.lastCapturedIndex() > 2) // index 2 includes the + or : for the column number
- lineColumn.column = match.captured(3).toInt() - 1; //column is 0 based, despite line being 1 based
- }
- } else {
- const QRegularExpressionMatch vsMatch = vsRegexp.match(fileName);
- postfixPos = vsMatch.capturedStart(0);
- if (vsMatch.lastCapturedIndex() > 1) // index 1 includes closing )
- lineColumn.line = vsMatch.captured(2).toInt();
- }
- return lineColumn;
-}
-
-} // namespace Utils
diff --git a/src/libs/utils/linecolumn.h b/src/libs/utils/linecolumn.h
index 922c981d79..4cd982b8e7 100644
--- a/src/libs/utils/linecolumn.h
+++ b/src/libs/utils/linecolumn.h
@@ -14,9 +14,6 @@ namespace Utils {
class QTCREATOR_UTILS_EXPORT LineColumn
{
public:
- constexpr LineColumn() = default;
- constexpr LineColumn(int line, int column) : line(line), column(column) {}
-
bool isValid() const
{
return line > 0 && column >= 0;
@@ -32,8 +29,6 @@ public:
return !(first == second);
}
- static LineColumn extractFromFileName(QStringView fileName, int &postfixPos);
-
public:
int line = 0;
int column = -1;
diff --git a/src/libs/utils/link.cpp b/src/libs/utils/link.cpp
index e4c7032eeb..1a4b4f9f9a 100644
--- a/src/libs/utils/link.cpp
+++ b/src/libs/utils/link.cpp
@@ -3,7 +3,7 @@
#include "link.h"
-#include "linecolumn.h"
+#include "textutils.h"
namespace Utils {
@@ -24,10 +24,10 @@ Link Link::fromString(const QString &filePathWithNumbers, bool canContainLineNum
link.targetFilePath = FilePath::fromUserInput(filePathWithNumbers);
} else {
int postfixPos = -1;
- const LineColumn lineColumn = LineColumn::extractFromFileName(filePathWithNumbers, postfixPos);
+ const Text::Position pos = Text::Position::fromFileName(filePathWithNumbers, postfixPos);
link.targetFilePath = FilePath::fromUserInput(filePathWithNumbers.left(postfixPos));
- link.targetLine = lineColumn.line;
- link.targetColumn = lineColumn.column;
+ link.targetLine = pos.line;
+ link.targetColumn = pos.column;
}
return link;
}
diff --git a/src/libs/utils/textutils.cpp b/src/libs/utils/textutils.cpp
index 55e8a736d0..5c9846a24d 100644
--- a/src/libs/utils/textutils.cpp
+++ b/src/libs/utils/textutils.cpp
@@ -3,8 +3,9 @@
#include "textutils.h"
-#include <QTextDocument>
+#include <QRegularExpression>
#include <QTextBlock>
+#include <QTextDocument>
namespace Utils::Text {
@@ -13,6 +14,39 @@ bool Position::operator==(const Position &other) const
return line == other.line && column == other.column;
}
+/*!
+ Returns the text position of a \a fileName and sets the \a postfixPos if
+ it can find a positional postfix.
+
+ The following patterns are supported: \c {filepath.txt:19},
+ \c{filepath.txt:19:12}, \c {filepath.txt+19},
+ \c {filepath.txt+19+12}, and \c {filepath.txt(19)}.
+*/
+
+Position Position::fromFileName(QStringView fileName, int &postfixPos)
+{
+ static const auto regexp = QRegularExpression("[:+](\\d+)?([:+](\\d+)?)?$");
+ // (10) MSVC-style
+ static const auto vsRegexp = QRegularExpression("[(]((\\d+)[)]?)?$");
+ const QRegularExpressionMatch match = regexp.match(fileName);
+ Position pos;
+ if (match.hasMatch()) {
+ postfixPos = match.capturedStart(0);
+ pos.line = 0; // for the case that there's only a : at the end
+ if (match.lastCapturedIndex() > 0) {
+ pos.line = match.captured(1).toInt();
+ if (match.lastCapturedIndex() > 2) // index 2 includes the + or : for the column number
+ pos.column = match.captured(3).toInt() - 1; //column is 0 based, despite line being 1 based
+ }
+ } else {
+ const QRegularExpressionMatch vsMatch = vsRegexp.match(fileName);
+ postfixPos = vsMatch.capturedStart(0);
+ if (vsMatch.lastCapturedIndex() > 1) // index 1 includes closing )
+ pos.line = vsMatch.captured(2).toInt();
+ }
+ return pos;
+}
+
int Range::length(const QString &text) const
{
if (begin.line == end.line)
diff --git a/src/libs/utils/textutils.h b/src/libs/utils/textutils.h
index 573dc7aa1d..e278cf919f 100644
--- a/src/libs/utils/textutils.h
+++ b/src/libs/utils/textutils.h
@@ -28,6 +28,8 @@ public:
bool operator==(const Position &other) const;
bool operator!=(const Position &other) const { return !(operator==(other)); }
+
+ static Position fromFileName(QStringView fileName, int &postfixPos);
};
class QTCREATOR_UTILS_EXPORT Range
diff --git a/src/libs/utils/utils.qbs b/src/libs/utils/utils.qbs
index f1940a053d..d3c826ef26 100644
--- a/src/libs/utils/utils.qbs
+++ b/src/libs/utils/utils.qbs
@@ -185,7 +185,6 @@ Project {
"launchersocket.h",
"layoutbuilder.cpp",
"layoutbuilder.h",
- "linecolumn.cpp",
"linecolumn.h",
"link.cpp",
"link.h",