diff --git a/src/libs/utils/CMakeLists.txt b/src/libs/utils/CMakeLists.txt index f05398094a4..5fa076027fd 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 50a24ada62c..00000000000 --- 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 - -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 922c981d79e..4cd982b8e7e 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 e4c7032eeb7..1a4b4f9f9af 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 55e8a736d05..5c9846a24d6 100644 --- a/src/libs/utils/textutils.cpp +++ b/src/libs/utils/textutils.cpp @@ -3,8 +3,9 @@ #include "textutils.h" -#include +#include #include +#include 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 573dc7aa1d7..e278cf919f5 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 f1940a053da..d3c826ef26f 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",