Skip to content

Commit

Permalink
Fix matching with parentheses (#303)
Browse files Browse the repository at this point in the history
  • Loading branch information
variar committed May 10, 2021
1 parent a77bf32 commit fadb25f
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/ui/src/highlighterset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ Highlighter::Highlighter( const QString& pattern, bool ignoreCase, bool onlyMatc
, foreColor_( foreColor )
, backColor_( backColor )
{
LOG_DEBUG << "New Highlighter, fore: " << foreColor_.name()
<< " back: " << backColor_.name();
LOG_DEBUG << "New Highlighter, fore: " << foreColor_.name() << " back: " << backColor_.name();
}

QString Highlighter::pattern() const
Expand Down Expand Up @@ -129,17 +128,16 @@ bool Highlighter::matchLine( const QString& line, std::vector<HighlightedMatch>&
{
matches.clear();

auto pattern = regexp_.pattern();
if ( !useRegex_ ) {
pattern = QRegularExpression::escape( pattern );
}
auto regexp = QRegularExpression( pattern, regexp_.patternOptions() );
const auto pattern
= useRegex_ ? regexp_.pattern() : QRegularExpression::escape( regexp_.pattern() );

const auto matchingRegex = QRegularExpression( pattern, regexp_.patternOptions() );

QRegularExpressionMatchIterator matchIterator = regexp.globalMatch( line );
QRegularExpressionMatchIterator matchIterator = matchingRegex.globalMatch( line );

while ( matchIterator.hasNext() ) {
QRegularExpressionMatch match = matchIterator.next();
if ( regexp_.captureCount() > 0 ) {
if ( matchingRegex.captureCount() > 0 ) {
for ( int i = 1; i <= match.lastCapturedIndex(); ++i ) {
matches.emplace_back( match.capturedStart( i ), match.capturedLength( i ),
foreColor_, backColor_ );
Expand Down Expand Up @@ -322,7 +320,7 @@ void HighlighterSetCollection::setHighlighterSets( const QList<HighlighterSet>&
HighlighterSet HighlighterSetCollection::currentSet() const
{
auto set = std::find_if( highlighters_.begin(), highlighters_.end(),
[this]( const auto& s ) { return s.id() == currentSet_; } );
[ this ]( const auto& s ) { return s.id() == currentSet_; } );

if ( set != highlighters_.end() ) {
return *set;
Expand All @@ -345,7 +343,7 @@ void HighlighterSetCollection::setCurrentSet( const QString& current )
bool HighlighterSetCollection::hasSet( const QString& setId ) const
{
return std::any_of( highlighters_.begin(), highlighters_.end(),
[setId]( const auto& s ) { return s.id() == setId; } );
[ setId ]( const auto& s ) { return s.id() == setId; } );
}

void HighlighterSetCollection::saveToStorage( QSettings& settings ) const
Expand Down

0 comments on commit fadb25f

Please sign in to comment.