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
ad33f9f5
Commit
ad33f9f5
authored
Oct 30, 2022
by
Volker Krause
Browse files
Port normal hunk header parsing to QRegularExpression
parent
c783fe10
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/parserbase.cpp
View file @
ad33f9f5
...
...
@@ -82,9 +82,9 @@ ParserBase::ParserBase(const KompareModelList* list, const QStringList& diff) :
// This regexp sucks... i'll see what happens
m_normalDiffHeader
.
setPattern
(
QRegularExpression
::
anchoredPattern
(
QStringLiteral
(
"diff (?:(?:-|--)[a-zA-Z0-9=
\\\"
]+ )*(?:|-- +)(.*) +(.*)
\\
n"
)));
m_normalHunkHeaderAdded
.
setPattern
(
QStringLiteral
(
"([0-9]+)a([0-9]+)(|,[0-9]+)(.*)
\\
n"
));
m_normalHunkHeaderRemoved
.
setPattern
(
QStringLiteral
(
"([0-9]+)(|,[0-9]+)d([0-9]+)(.*)
\\
n"
));
m_normalHunkHeaderChanged
.
setPattern
(
QStringLiteral
(
"([0-9]+)(|,[0-9]+)c([0-9]+)(|,[0-9]+)(.*)
\\
n"
));
m_normalHunkHeaderAdded
.
setPattern
(
QRegularExpression
::
anchoredPattern
(
QStringLiteral
(
"([0-9]+)a([0-9]+)(|,[0-9]+)(.*)
\\
n"
))
)
;
m_normalHunkHeaderRemoved
.
setPattern
(
QRegularExpression
::
anchoredPattern
(
QStringLiteral
(
"([0-9]+)(|,[0-9]+)d([0-9]+)(.*)
\\
n"
))
)
;
m_normalHunkHeaderChanged
.
setPattern
(
QRegularExpression
::
anchoredPattern
(
QStringLiteral
(
"([0-9]+)(|,[0-9]+)c([0-9]+)(|,[0-9]+)(.*)
\\
n"
))
)
;
m_normalHunkBodyRemoved
.
setPattern
(
QStringLiteral
(
"< (.*)"
));
m_normalHunkBodyAdded
.
setPattern
(
QStringLiteral
(
"> (.*)"
));
...
...
@@ -314,15 +314,15 @@ bool ParserBase::parseNormalHunkHeader()
if
(
m_diffIterator
!=
m_diffLines
.
end
())
{
// qCDebug(LIBKOMPAREDIFF2) << "Header = " << *m_diffIterator;
if
(
m_normalHunkHeaderAdded
.
exactMatch
(
*
m_diffIterator
))
if
(
m_normalHunkHeaderAdded
Match
=
m_normalHunkHeaderAdded
.
match
(
*
m_diffIterator
);
m_normalHunkHeaderAddedMatch
.
hasMatch
(
))
{
m_normalDiffType
=
Difference
::
Insert
;
}
else
if
(
m_normalHunkHeaderRemoved
.
exactMatch
(
*
m_diffIterator
))
else
if
(
m_normalHunkHeaderRemoved
Match
=
m_normalHunkHeaderRemoved
.
match
(
*
m_diffIterator
);
m_normalHunkHeaderRemovedMatch
.
hasMatch
(
))
{
m_normalDiffType
=
Difference
::
Delete
;
}
else
if
(
m_normalHunkHeaderChanged
.
exactMatch
(
*
m_diffIterator
))
else
if
(
m_normalHunkHeaderChanged
Match
=
m_normalHunkHeaderChanged
.
match
(
*
m_diffIterator
);
m_normalHunkHeaderChangedMatch
.
hasMatch
(
))
{
m_normalDiffType
=
Difference
::
Change
;
}
...
...
@@ -523,18 +523,18 @@ bool ParserBase::parseNormalHunkBody()
if
(
m_normalDiffType
==
Difference
::
Insert
)
{
linenoA
=
m_normalHunkHeaderAdded
.
cap
(
1
).
toInt
();
linenoB
=
m_normalHunkHeaderAdded
.
cap
(
2
).
toInt
();
linenoA
=
m_normalHunkHeaderAdded
Match
.
captured
(
1
).
toInt
();
linenoB
=
m_normalHunkHeaderAdded
Match
.
captured
(
2
).
toInt
();
}
else
if
(
m_normalDiffType
==
Difference
::
Delete
)
{
linenoA
=
m_normalHunkHeaderRemoved
.
cap
(
1
).
toInt
();
linenoB
=
m_normalHunkHeaderRemoved
.
cap
(
3
).
toInt
();
linenoA
=
m_normalHunkHeaderRemoved
Match
.
captured
(
1
).
toInt
();
linenoB
=
m_normalHunkHeaderRemoved
Match
.
captured
(
3
).
toInt
();
}
else
if
(
m_normalDiffType
==
Difference
::
Change
)
{
linenoA
=
m_normalHunkHeaderChanged
.
cap
(
1
).
toInt
();
linenoB
=
m_normalHunkHeaderChanged
.
cap
(
3
).
toInt
();
linenoA
=
m_normalHunkHeaderChanged
Match
.
captured
(
1
).
toInt
();
linenoB
=
m_normalHunkHeaderChanged
Match
.
captured
(
3
).
toInt
();
}
DiffHunk
*
hunk
=
new
DiffHunk
(
linenoA
,
linenoB
);
...
...
src/parserbase.h
View file @
ad33f9f5
...
...
@@ -90,9 +90,12 @@ protected:
// Regexps for normal parsing
QRegularExpression
m_normalDiffHeader
;
QRegExp
m_normalHunkHeaderAdded
;
QRegExp
m_normalHunkHeaderRemoved
;
QRegExp
m_normalHunkHeaderChanged
;
QRegularExpression
m_normalHunkHeaderAdded
;
QRegularExpression
m_normalHunkHeaderRemoved
;
QRegularExpression
m_normalHunkHeaderChanged
;
QRegularExpressionMatch
m_normalHunkHeaderAddedMatch
;
QRegularExpressionMatch
m_normalHunkHeaderRemovedMatch
;
QRegularExpressionMatch
m_normalHunkHeaderChangedMatch
;
QRegExp
m_normalHunkBodyRemoved
;
QRegExp
m_normalHunkBodyAdded
;
...
...
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