MCPcopy Create free account
hub / github.com/KDE/kdevelop / extractCursor

Method extractCursor

kdevplatform/util/texteditorhelpers.cpp:41–70  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39}
40
41KTextEditor::Cursor KTextEditorHelpers::extractCursor(const QString& input, int* pathLength)
42{
43 // ":ll:cc", ":ll"
44 static const QRegularExpression pattern(QStringLiteral(":(\\d+)(?::(\\d+))?$"));
45 // "#Lll", "#nll", "#ll" as e.g. seen with repo web links
46 static const QRegularExpression pattern2(QStringLiteral("#(?:n|L|)(\\d+)$"));
47
48 auto match = pattern.match(input);
49
50 if (!match.hasMatch()) {
51 match = pattern2.match(input);
52 }
53
54 if (!match.hasMatch()) {
55 if (pathLength)
56 *pathLength = input.length();
57 return KTextEditor::Cursor::invalid();
58 }
59
60 const auto line = match.capturedView(1).toInt() - 1;
61 // captured(2) for pattern2 will yield null QString, toInt() thus 0, so no need for if-else
62 // don't use an invalid column when the line is valid
63 const auto column = qMax(0, match.capturedView(2).toInt() - 1);
64
65 if (pathLength)
66 *pathLength = match.capturedStart(0);
67 return {
68 line, column
69 };
70}
71
72}

Callers

nothing calls this directly

Calls 5

hasMatchMethod · 0.80
toIntMethod · 0.80
invalidFunction · 0.50
matchMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected