2016-07-28 17:01:08 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-07-28 17:01:08 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2016-07-28 17:01:08 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2017-08-31 16:28:58 +00:00
|
|
|
#include "base/flags.h"
|
|
|
|
|
2016-07-28 17:01:08 +00:00
|
|
|
namespace qthelp {
|
|
|
|
|
|
|
|
class RegularExpressionMatch {
|
|
|
|
public:
|
2017-09-17 11:28:20 +00:00
|
|
|
RegularExpressionMatch(const QRegularExpressionMatch &other) = delete;
|
|
|
|
RegularExpressionMatch(const RegularExpressionMatch &other) = delete;
|
2017-02-21 13:45:56 +00:00
|
|
|
RegularExpressionMatch(QRegularExpressionMatch &&match) : data_(std::move(match)) {
|
2016-07-28 17:01:08 +00:00
|
|
|
}
|
2017-02-21 13:45:56 +00:00
|
|
|
RegularExpressionMatch(RegularExpressionMatch &&other) : data_(std::move(other.data_)) {
|
2016-07-28 17:01:08 +00:00
|
|
|
}
|
2017-09-17 11:28:20 +00:00
|
|
|
RegularExpressionMatch &operator=(const QRegularExpressionMatch &match) = delete;
|
|
|
|
RegularExpressionMatch &operator=(const RegularExpressionMatch &other) = delete;
|
2016-12-20 13:03:51 +00:00
|
|
|
RegularExpressionMatch &operator=(QRegularExpressionMatch &&match) {
|
2017-02-21 13:45:56 +00:00
|
|
|
data_ = std::move(match);
|
2016-12-20 13:03:51 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
RegularExpressionMatch &operator=(RegularExpressionMatch &&other) {
|
2017-02-21 13:45:56 +00:00
|
|
|
data_ = std::move(other.data_);
|
2016-12-20 13:03:51 +00:00
|
|
|
return *this;
|
|
|
|
}
|
2016-07-28 17:01:08 +00:00
|
|
|
QRegularExpressionMatch *operator->() {
|
|
|
|
return &data_;
|
|
|
|
}
|
|
|
|
const QRegularExpressionMatch *operator->() const {
|
|
|
|
return &data_;
|
|
|
|
}
|
|
|
|
explicit operator bool() const {
|
|
|
|
return data_.hasMatch();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
QRegularExpressionMatch data_;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class RegExOption {
|
|
|
|
None = QRegularExpression::NoPatternOption,
|
|
|
|
CaseInsensitive = QRegularExpression::CaseInsensitiveOption,
|
|
|
|
DotMatchesEverything = QRegularExpression::DotMatchesEverythingOption,
|
|
|
|
Multiline = QRegularExpression::MultilineOption,
|
|
|
|
ExtendedSyntax = QRegularExpression::ExtendedPatternSyntaxOption,
|
|
|
|
InvertedGreediness = QRegularExpression::InvertedGreedinessOption,
|
|
|
|
DontCapture = QRegularExpression::DontCaptureOption,
|
|
|
|
UseUnicodeProperties = QRegularExpression::UseUnicodePropertiesOption,
|
2016-08-30 05:24:16 +00:00
|
|
|
#ifndef OS_MAC_OLD
|
2016-07-28 17:01:08 +00:00
|
|
|
OptimizeOnFirstUsage = QRegularExpression::OptimizeOnFirstUsageOption,
|
|
|
|
DontAutomaticallyOptimize = QRegularExpression::DontAutomaticallyOptimizeOption,
|
2016-08-30 05:24:16 +00:00
|
|
|
#endif // OS_MAC_OLD
|
2016-07-28 17:01:08 +00:00
|
|
|
};
|
2017-08-31 16:28:58 +00:00
|
|
|
using RegExOptions = base::flags<RegExOption>;
|
|
|
|
inline constexpr auto is_flag_type(RegExOption) { return true; };
|
2016-07-28 17:01:08 +00:00
|
|
|
|
|
|
|
inline RegularExpressionMatch regex_match(const QString &string, const QString &subject, RegExOptions options = 0) {
|
|
|
|
auto qtOptions = QRegularExpression::PatternOptions(static_cast<int>(options));
|
|
|
|
return RegularExpressionMatch(QRegularExpression(string, qtOptions).match(subject));
|
|
|
|
}
|
|
|
|
|
|
|
|
inline RegularExpressionMatch regex_match(const QString &string, const QStringRef &subjectRef, RegExOptions options = 0) {
|
|
|
|
auto qtOptions = QRegularExpression::PatternOptions(static_cast<int>(options));
|
2016-08-30 05:24:16 +00:00
|
|
|
#ifndef OS_MAC_OLD
|
2016-07-28 17:01:08 +00:00
|
|
|
return RegularExpressionMatch(QRegularExpression(string, qtOptions).match(subjectRef));
|
2016-08-30 05:24:16 +00:00
|
|
|
#else // OS_MAC_OLD
|
|
|
|
return RegularExpressionMatch(QRegularExpression(string, qtOptions).match(subjectRef.toString()));
|
|
|
|
#endif // OS_MAC_OLD
|
2016-07-28 17:01:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace qthelp
|