1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

refactor: edit generateFilterWordsOnly

This commit is contained in:
TriKriSta 2018-07-08 16:25:29 +03:00
parent 4b2942d51d
commit 42f5ac67e7
4 changed files with 20 additions and 8 deletions

View File

@ -450,7 +450,7 @@ void Text::selectText(QTextCursor& cursor, const std::pair<int, int>& point)
cursor.endEditBlock(); cursor.endEditBlock();
QTextCharFormat format; QTextCharFormat format;
format.setBackground(QBrush(QColor("#ff7626"))); format.setBackground(QBrush(colorHighlight));
cursor.mergeCharFormat(format); cursor.mergeCharFormat(format);
regenerate(); regenerate();

View File

@ -97,6 +97,7 @@ private:
QFont defFont; QFont defFont;
QString defStyleSheet; QString defStyleSheet;
QColor color; QColor color;
const QColor colorHighlight{"#ff7626"};
}; };
#endif // TEXT_H #endif // TEXT_H

View File

@ -2,7 +2,7 @@
#define SEARCHSETTINGSFORM_H #define SEARCHSETTINGSFORM_H
#include <QWidget> #include <QWidget>
#include "../searchtypes.h" #include "src/widget/searchtypes.h"
namespace Ui { namespace Ui {
class SearchSettingsForm; class SearchSettingsForm;

View File

@ -2,6 +2,7 @@
#define SEARCHTYPES_H #define SEARCHTYPES_H
#include <QDate> #include <QDate>
#include <QRegularExpression>
enum class FilterSearch { enum class FilterSearch {
None, None,
@ -39,24 +40,34 @@ struct ParameterSearch {
class SearchExtraFunctions { class SearchExtraFunctions {
public: public:
/**
* @brief generateFilterWordsOnly generate string for filter "Whole words only" for correct search phrase
* containing symbols "\[]/^$.|?*+(){}"
* @param phrase for search
* @return new phrase for search
*/
static QString generateFilterWordsOnly(const QString &phrase) { static QString generateFilterWordsOnly(const QString &phrase) {
QString filter = phrase; QString filter = QRegularExpression::escape(phrase);
if (filter.contains("\\")) { QString symbols = {"\\[]/^$.|?*+(){}"};
filter.replace("\\", "\\\\");
if (filter.front() != '\\') { if (filter != phrase) {
if (filter.left(1) != QLatin1String("\\")) {
filter = "\\b" + filter; filter = "\\b" + filter;
} else {
filter = "(^|\\s)" + filter;
} }
if (filter.back() != '\\') { if (!symbols.contains(filter.right(1))) {
filter += "\\b"; filter += "\\b";
} else {
filter += "($|\\s)";
} }
} else { } else {
filter = QStringLiteral("\\b%1\\b").arg(filter); filter = QStringLiteral("\\b%1\\b").arg(filter);
} }
return filter; return filter;
}; }
}; };
#endif //SEARCHTYPES_H #endif //SEARCHTYPES_H