Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SDK
libkomparediff2
Commits
67894519
Commit
67894519
authored
Oct 30, 2022
by
Volker Krause
Browse files
Port unified hunk header parsing to QRegularExpression
parent
818b5c8b
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/parserbase.cpp
View file @
67894519
...
...
@@ -92,7 +92,7 @@ ParserBase::ParserBase(const KompareModelList* list, const QStringList& diff) :
m_unifiedDiffHeader1
.
setPattern
(
QRegularExpression
::
anchoredPattern
(
QStringLiteral
(
"--- ([^
\\
t]+)(?:
\\
t([^
\\
t]+)(?:
\\
t?)(.*))?
\\
n"
)));
m_unifiedDiffHeader2
.
setPattern
(
QRegularExpression
::
anchoredPattern
(
QStringLiteral
(
"
\\
+
\\
+
\\
+ ([^
\\
t]+)(?:
\\
t([^
\\
t]+)(?:
\\
t?)(.*))?
\\
n"
)));
m_unifiedHunkHeader
.
setPattern
(
QStringLiteral
(
"@@ -([0-9]+)(|,([0-9]+))
\\
+([0-9]+)(|,([0-9]+)) @@(?: ?)(.*)
\\
n"
));
m_unifiedHunkHeader
.
setPattern
(
QRegularExpression
::
anchoredPattern
(
QStringLiteral
(
"@@ -([0-9]+)(|,([0-9]+))
\\
+([0-9]+)(|,([0-9]+)) @@(?: ?)(.*)
\\
n"
))
)
;
m_unifiedHunkBodyAdded
.
setPattern
(
QStringLiteral
(
"
\\
+(.*)"
));
m_unifiedHunkBodyRemoved
.
setPattern
(
QStringLiteral
(
"-(.*)"
));
m_unifiedHunkBodyContext
.
setPattern
(
QStringLiteral
(
" (.*)"
));
...
...
@@ -345,17 +345,16 @@ bool ParserBase::parseUnifiedHunkHeader()
{
// qCDebug(LIBKOMPAREDIFF2) << "ParserBase::parseUnifiedHunkHeader()";
if
(
m_diffIterator
!=
m_diffLines
.
end
()
&&
m_unifiedHunkHeader
.
exactMatch
(
*
m_diffIterator
))
{
++
m_diffIterator
;
return
true
;
}
else
if
(
m_diffIterator
!=
m_diffLines
.
end
())
{
// qCDebug(LIBKOMPAREDIFF2) << "This is not a unified hunk header : " << (*m_diffIterator);
return
false
;
m_unifiedHunkHeaderMatch
=
m_unifiedHunkHeader
.
match
(
*
m_diffIterator
);
if
(
m_unifiedHunkHeaderMatch
.
hasMatch
())
{
++
m_diffIterator
;
return
true
;
}
}
// qCDebug(LIBKOMPAREDIFF2) << "This is not a unified hunk header : " << (*m_diffIterator);
return
false
;
}
bool
ParserBase
::
parseContextHunkBody
()
...
...
@@ -605,11 +604,11 @@ bool ParserBase::parseUnifiedHunkBody()
bool
wasNum
;
// Fetching the stuff we need from the hunkheader regexp that was parsed in parseUnifiedHunkHeader();
linenoA
=
m_unifiedHunkHeader
.
cap
(
1
).
toInt
();
linenoA
=
m_unifiedHunkHeader
Match
.
captured
(
1
).
toInt
();
int
lineCountA
=
1
,
lineCountB
=
1
;
// an omitted line count in the header implies a line count of 1
if
(
!
m_unifiedHunkHeader
.
cap
(
3
).
isEmpty
())
if
(
!
m_unifiedHunkHeader
Match
.
captured
(
3
).
isEmpty
())
{
lineCountA
=
m_unifiedHunkHeader
.
cap
(
3
).
toInt
(
&
wasNum
);
lineCountA
=
m_unifiedHunkHeader
Match
.
captured
(
3
).
toInt
(
&
wasNum
);
if
(
!
wasNum
)
return
false
;
...
...
@@ -618,16 +617,16 @@ bool ParserBase::parseUnifiedHunkBody()
if
(
lineCountA
==
0
)
++
linenoA
;
}
linenoB
=
m_unifiedHunkHeader
.
cap
(
4
).
toInt
();
if
(
!
m_unifiedHunkHeader
.
cap
(
6
).
isEmpty
())
{
lineCountB
=
m_unifiedHunkHeader
.
cap
(
6
).
toInt
(
&
wasNum
);
linenoB
=
m_unifiedHunkHeader
Match
.
captured
(
4
).
toInt
();
if
(
!
m_unifiedHunkHeader
Match
.
captured
(
6
).
isEmpty
())
{
lineCountB
=
m_unifiedHunkHeader
Match
.
captured
(
6
).
toInt
(
&
wasNum
);
if
(
!
wasNum
)
return
false
;
if
(
lineCountB
==
0
)
// see above
++
linenoB
;
}
QString
function
=
m_unifiedHunkHeader
.
cap
(
7
);
QString
function
=
m_unifiedHunkHeader
Match
.
captured
(
7
);
DiffHunk
*
hunk
=
new
DiffHunk
(
linenoA
,
linenoB
,
function
);
m_currentModel
->
addHunk
(
hunk
);
...
...
src/parserbase.h
View file @
67894519
...
...
@@ -110,7 +110,8 @@ protected:
QRegularExpression
m_unifiedDiffHeader1
;
QRegularExpression
m_unifiedDiffHeader2
;
QRegExp
m_unifiedHunkHeader
;
QRegularExpression
m_unifiedHunkHeader
;
QRegularExpressionMatch
m_unifiedHunkHeaderMatch
;
QRegExp
m_unifiedHunkBodyAdded
;
QRegExp
m_unifiedHunkBodyRemoved
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment