aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs/utils/textutils.cpp
diff options
context:
space:
mode:
authorDavid Schulz <[email protected]>2023-05-12 10:59:04 +0200
committerDavid Schulz <[email protected]>2023-05-16 08:24:28 +0000
commitb4734ff7279284eec4f0ced0e4de07cb348c481e (patch)
tree803cbf99748e3022f383c51ced2fe7d2df803871 /src/libs/utils/textutils.cpp
parente2df60abc2acf465c2941719ab6e56573d07a762 (diff)
Utils: add tests for Position::fromFileName
Change-Id: I321b91567e47e08883c7b991cd24d02bb8a9b9c6 Reviewed-by: Jarek Kobus <[email protected]>
Diffstat (limited to 'src/libs/utils/textutils.cpp')
-rw-r--r--src/libs/utils/textutils.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/libs/utils/textutils.cpp b/src/libs/utils/textutils.cpp
index 8cf7a41ed60..9cb7c1e011f 100644
--- a/src/libs/utils/textutils.cpp
+++ b/src/libs/utils/textutils.cpp
@@ -32,7 +32,6 @@ Position Position::fromFileName(QStringView fileName, int &postfixPos)
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
@@ -44,6 +43,8 @@ Position Position::fromFileName(QStringView fileName, int &postfixPos)
if (vsMatch.lastCapturedIndex() > 1) // index 1 includes closing )
pos.line = vsMatch.captured(2).toInt();
}
+ if (pos.line > 0 && pos.column < 0)
+ pos.column = 0; // if we got a valid line make sure to return a valid TextPosition
return pos;
}
@@ -264,4 +265,10 @@ void applyReplacements(QTextDocument *doc, const Replacements &replacements)
editCursor.endEditBlock();
}
+QDebug &operator<<(QDebug &stream, const Position &pos)
+{
+ stream << "line: " << pos.line << ", column: " << pos.column;
+ return stream;
+}
+
} // namespace Utils::Text