Use static QRegularExpression
This commit is contained in:
@@ -46,6 +46,7 @@ QUrl AzLyricsComLyricsProvider::Url(const LyricsSearchRequest &request) {
|
||||
|
||||
QString AzLyricsComLyricsProvider::StringFixup(const QString &text) {
|
||||
|
||||
return Utilities::Transliterate(text).remove(QRegularExpression(QStringLiteral("[^\\w0-9\\-]"))).toLower();
|
||||
static const QRegularExpression regex_words_numbers_and_dash(QStringLiteral("[^\\w0-9\\-]"));
|
||||
return Utilities::Transliterate(text).remove(regex_words_numbers_and_dash).toLower();
|
||||
|
||||
}
|
||||
|
||||
@@ -46,9 +46,12 @@ QUrl ElyricsNetLyricsProvider::Url(const LyricsSearchRequest &request) {
|
||||
|
||||
QString ElyricsNetLyricsProvider::StringFixup(const QString &text) {
|
||||
|
||||
static const QRegularExpression regex_illegal_characters(QStringLiteral("[^\\w0-9_,&\\-\\(\\) ]"));
|
||||
static const QRegularExpression regex_duplicate_whitespaces(QStringLiteral(" {2,}"));
|
||||
|
||||
return Utilities::Transliterate(text)
|
||||
.replace(QRegularExpression(QStringLiteral("[^\\w0-9_,&\\-\\(\\) ]")), QStringLiteral("_"))
|
||||
.replace(QRegularExpression(QStringLiteral(" {2,}")), QStringLiteral(" "))
|
||||
.replace(regex_illegal_characters, QStringLiteral("_"))
|
||||
.replace(regex_duplicate_whitespaces, QStringLiteral(" "))
|
||||
.simplified()
|
||||
.replace(QLatin1Char(' '), QLatin1Char('-'))
|
||||
.toLower();
|
||||
|
||||
@@ -156,15 +156,21 @@ QString HtmlLyricsProvider::ParseLyricsFromHTML(const QString &content, const QR
|
||||
if (!lyrics.isEmpty()) {
|
||||
lyrics.append(QLatin1Char('\n'));
|
||||
}
|
||||
static const QRegularExpression regex_html_tag_a(QStringLiteral("<a [^>]*>[^<]*</a>"));
|
||||
static const QRegularExpression regex_html_tag_script(QStringLiteral("<script>[^>]*</script>"));
|
||||
static const QRegularExpression regex_html_tag_div(QStringLiteral("<div [^>]*>×</div>"));
|
||||
static const QRegularExpression regex_html_tag_br(QStringLiteral("<br[^>]*>"));
|
||||
static const QRegularExpression regex_html_tag_p_close(QStringLiteral("</p>"));
|
||||
static const QRegularExpression regex_html_tags(QStringLiteral("<[^>]*>"));
|
||||
lyrics.append(content.mid(start_lyrics_idx, end_lyrics_idx - start_lyrics_idx)
|
||||
.remove(QLatin1Char('\r'))
|
||||
.remove(QLatin1Char('\n'))
|
||||
.remove(QRegularExpression(QStringLiteral("<a [^>]*>[^<]*</a>")))
|
||||
.remove(QRegularExpression(QStringLiteral("<script>[^>]*</script>")))
|
||||
.remove(QRegularExpression(QStringLiteral("<div [^>]*>×</div>")))
|
||||
.replace(QRegularExpression(QStringLiteral("<br[^>]*>")), QStringLiteral("\n"))
|
||||
.replace(QRegularExpression(QStringLiteral("</p>")), QStringLiteral("\n\n"))
|
||||
.remove(QRegularExpression(QStringLiteral("<[^>]*>")))
|
||||
.remove(regex_html_tag_a)
|
||||
.remove(regex_html_tag_script)
|
||||
.remove(regex_html_tag_div)
|
||||
.replace(regex_html_tag_br, QStringLiteral("\n"))
|
||||
.replace(regex_html_tag_p_close, QStringLiteral("\n\n"))
|
||||
.remove(regex_html_tags)
|
||||
.trimmed());
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -47,9 +47,12 @@ QUrl LetrasLyricsProvider::Url(const LyricsSearchRequest &request) {
|
||||
|
||||
QString LetrasLyricsProvider::StringFixup(const QString &text) {
|
||||
|
||||
static const QRegularExpression regex_illegal_characters(QStringLiteral("[^\\w0-9_,&\\-\\(\\) ]"));
|
||||
static const QRegularExpression regex_multiple_whitespaces(QStringLiteral(" {2,}"));
|
||||
|
||||
return QString::fromLatin1(QUrl::toPercentEncoding(Utilities::Transliterate(text)
|
||||
.replace(QRegularExpression(QStringLiteral("[^\\w0-9_,&\\-\\(\\) ]")), QStringLiteral("_"))
|
||||
.replace(QRegularExpression(QStringLiteral(" {2,}")), QStringLiteral(" "))
|
||||
.replace(regex_illegal_characters, QStringLiteral("_"))
|
||||
.replace(regex_multiple_whitespaces, QStringLiteral(" "))
|
||||
.simplified()
|
||||
.replace(QLatin1Char(' '), QLatin1Char('-'))
|
||||
.toLower()
|
||||
|
||||
@@ -62,9 +62,12 @@ QUrl LyricFindLyricsProvider::Url(const LyricsSearchRequest &request) {
|
||||
|
||||
QString LyricFindLyricsProvider::StringFixup(const QString &text) {
|
||||
|
||||
static const QRegularExpression regex_illegal_characters(QStringLiteral("[^\\w0-9_\\- ]"));
|
||||
static const QRegularExpression regex_multiple_whitespaces(QStringLiteral(" {2,}"));
|
||||
|
||||
return Utilities::Transliterate(text)
|
||||
.remove(QRegularExpression(QStringLiteral("[^\\w0-9_\\- ]")))
|
||||
.replace(QRegularExpression(QStringLiteral(" {2,}")), QStringLiteral(" "))
|
||||
.remove(regex_illegal_characters)
|
||||
.replace(regex_multiple_whitespaces, QStringLiteral(" "))
|
||||
.simplified()
|
||||
.replace(QLatin1Char(' '), QLatin1Char('-'))
|
||||
.toLower();
|
||||
|
||||
@@ -315,7 +315,8 @@ void MusixmatchLyricsProvider::HandleLyricsReply(QNetworkReply *reply, LyricsSea
|
||||
return;
|
||||
}
|
||||
|
||||
if (content_json.contains(QRegularExpression(QStringLiteral("<[^>]*>")))) { // Make sure it's not HTML code.
|
||||
static const QRegularExpression regex_html_tag(QStringLiteral("<[^>]*>"));
|
||||
if (content_json.contains(regex_html_tag)) { // Make sure it's not HTML code.
|
||||
EndSearch(search, url);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -45,13 +45,17 @@ QUrl SongLyricsComLyricsProvider::Url(const LyricsSearchRequest &request) {
|
||||
|
||||
QString SongLyricsComLyricsProvider::StringFixup(QString text) {
|
||||
|
||||
static const QRegularExpression regex_illegal_characters(QStringLiteral("[^\\w0-9\\- ]"));
|
||||
static const QRegularExpression regex_multiple_whitespaces(QStringLiteral(" {2,}"));
|
||||
static const QRegularExpression regex_multiple_dashes(QStringLiteral("(-)\\1+"));
|
||||
|
||||
return text.replace(QLatin1Char('/'), QLatin1Char('-'))
|
||||
.replace(QLatin1Char('\''), QLatin1Char('-'))
|
||||
.remove(QRegularExpression(QStringLiteral("[^\\w0-9\\- ]")))
|
||||
.replace(QRegularExpression(QStringLiteral(" {2,}")), QStringLiteral(" "))
|
||||
.remove(regex_illegal_characters)
|
||||
.replace(regex_multiple_whitespaces, QStringLiteral(" "))
|
||||
.simplified()
|
||||
.replace(QLatin1Char(' '), QLatin1Char('-'))
|
||||
.replace(QRegularExpression(QStringLiteral("(-)\\1+")), QStringLiteral("-"))
|
||||
.replace(regex_multiple_dashes, QStringLiteral("-"))
|
||||
.toLower();
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user