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();
QTextCharFormat format;
format.setBackground(QBrush(QColor("#ff7626")));
format.setBackground(QBrush(colorHighlight));
cursor.mergeCharFormat(format);
regenerate();

View File

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

View File

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

View File

@ -2,6 +2,7 @@
#define SEARCHTYPES_H
#include <QDate>
#include <QRegularExpression>
enum class FilterSearch {
None,
@ -39,24 +40,34 @@ struct ParameterSearch {
class SearchExtraFunctions {
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) {
QString filter = phrase;
QString filter = QRegularExpression::escape(phrase);
if (filter.contains("\\")) {
filter.replace("\\", "\\\\");
QString symbols = {"\\[]/^$.|?*+(){}"};
if (filter.front() != '\\') {
if (filter != phrase) {
if (filter.left(1) != QLatin1String("\\")) {
filter = "\\b" + filter;
} else {
filter = "(^|\\s)" + filter;
}
if (filter.back() != '\\') {
if (!symbols.contains(filter.right(1))) {
filter += "\\b";
} else {
filter += "($|\\s)";
}
} else {
filter = QStringLiteral("\\b%1\\b").arg(filter);
}
return filter;
};
}
};
#endif //SEARCHTYPES_H