From 00abc6bc1b460da78b0221a0166d1f2f71a6df32 Mon Sep 17 00:00:00 2001 From: Albert S Date: Sat, 6 Aug 2022 08:57:37 +0200 Subject: [PATCH] gui, shared: Fix and simplify word extraction regexes They did not work for chars like '-', causing errors. We can actually just extract non-space chars for these cases. --- gui/mainwindow.cpp | 2 +- shared/looqsquery.cpp | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index e7a73b1..c93e9a1 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -669,7 +669,7 @@ void MainWindow::makePreviews(int page) processedPdfPreviews = 0; QVector wordsToHighlight; - QRegularExpression extractor(R"#("([^"]*)"|((\p{L}|\p{N})+))#"); + QRegularExpression extractor(R"#("([^"]*)"|([^\s]+))#"); for(const Token &token : this->contentSearchQuery.getTokens()) { if(token.type == FILTER_CONTENT_CONTAINS) diff --git a/shared/looqsquery.cpp b/shared/looqsquery.cpp index c606b54..29fc187 100644 --- a/shared/looqsquery.cpp +++ b/shared/looqsquery.cpp @@ -180,9 +180,8 @@ LooqsQuery LooqsQuery::build(QString expression, TokenType loneWordsTokenType, b QStringList loneWords; LooqsQuery result; - QRegularExpression rx( - "((?(\\.|\\w)+):(?\\((?[^\\)]+)\\)|([\\p{L}\\p{N},])+)|(?AND|OR)" - "|(?!)|(?\\(|\\))|(?[\"\\p{L}\\p{N}]+))"); + QRegularExpression rx("((?(\\.|\\w)+):(?\\((?[^\\)]+)\\)|([^\\s])+)|(?AND|OR)" + "|(?!)|(?\\(|\\))|(?[^\\s]+))"); QRegularExpressionMatchIterator i = rx.globalMatch(expression); auto previousWasBool = [&result] { return !result.tokens.empty() && ((result.tokens.last().type & BOOL) == BOOL); }; auto previousWas = [&result](TokenType t) { return !result.tokens.empty() && (result.tokens.last().type == t); };