Utils: Use QStringView for LineColumn::extractFromFileName

Change-Id: I006773a2cd42be1009cece45bb2174d6c1ea143f
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
hjk
2022-08-11 17:15:34 +02:00
parent 4c9860d582
commit 144cefcf43
2 changed files with 3 additions and 11 deletions

View File

@@ -38,17 +38,15 @@ namespace Utils {
\c {filepath.txt+19+12}, and \c {filepath.txt(19)}. \c {filepath.txt+19+12}, and \c {filepath.txt(19)}.
*/ */
LineColumn LineColumn::extractFromFileName(const QString &fileName, int &postfixPos) LineColumn LineColumn::extractFromFileName(QStringView fileName, int &postfixPos)
{ {
static const auto regexp = QRegularExpression("[:+](\\d+)?([:+](\\d+)?)?$"); static const auto regexp = QRegularExpression("[:+](\\d+)?([:+](\\d+)?)?$");
// (10) MSVC-style // (10) MSVC-style
static const auto vsRegexp = QRegularExpression("[(]((\\d+)[)]?)?$"); static const auto vsRegexp = QRegularExpression("[(]((\\d+)[)]?)?$");
const QRegularExpressionMatch match = regexp.match(fileName); const QRegularExpressionMatch match = regexp.match(fileName);
QString filePath = fileName;
LineColumn lineColumn; LineColumn lineColumn;
if (match.hasMatch()) { if (match.hasMatch()) {
postfixPos = match.capturedStart(0); postfixPos = match.capturedStart(0);
filePath = fileName.left(match.capturedStart(0));
lineColumn.line = 0; // for the case that there's only a : at the end lineColumn.line = 0; // for the case that there's only a : at the end
if (match.lastCapturedIndex() > 0) { if (match.lastCapturedIndex() > 0) {
lineColumn.line = match.captured(1).toInt(); lineColumn.line = match.captured(1).toInt();
@@ -58,7 +56,6 @@ LineColumn LineColumn::extractFromFileName(const QString &fileName, int &postfix
} else { } else {
const QRegularExpressionMatch vsMatch = vsRegexp.match(fileName); const QRegularExpressionMatch vsMatch = vsRegexp.match(fileName);
postfixPos = vsMatch.capturedStart(0); postfixPos = vsMatch.capturedStart(0);
filePath = fileName.left(vsMatch.capturedStart(0));
if (vsMatch.lastCapturedIndex() > 1) // index 1 includes closing ) if (vsMatch.lastCapturedIndex() > 1) // index 1 includes closing )
lineColumn.line = vsMatch.captured(2).toInt(); lineColumn.line = vsMatch.captured(2).toInt();
} }

View File

@@ -37,12 +37,7 @@ class QTCREATOR_UTILS_EXPORT LineColumn
{ {
public: public:
constexpr LineColumn() = default; constexpr LineColumn() = default;
constexpr constexpr LineColumn(int line, int column) : line(line), column(column) {}
LineColumn(int line, int column)
: line(line),
column(column)
{}
bool isValid() const bool isValid() const
{ {
@@ -59,7 +54,7 @@ public:
return !(first == second); return !(first == second);
} }
static LineColumn extractFromFileName(const QString &fileName, int &postfixPos); static LineColumn extractFromFileName(QStringView fileName, int &postfixPos);
public: public:
int line = -1; int line = -1;