Dynamic lowercase link setting - did request (#612)

* Added functionality of dynamic lowercase links

* fixed fourtfs request, lajamerr has a better solution though

* Fix matching and lowercasing of domain only.

* Update TwitchMessageBuilder.cpp

Added what fourtf asked in a good  way
NOTE: I removed a : from the regex since otherwise it would fuck up

* fixed stuff and removed debugs

* fixed stuff
This commit is contained in:
apa420
2018-08-06 16:40:12 +02:00
committed by fourtf
parent 5b64e9573b
commit 7e3292e900
5 changed files with 37 additions and 27 deletions
+22 -23
View File
@@ -220,35 +220,34 @@ MessagePtr TwitchMessageBuilder::build()
Link link;
if (linkString.isEmpty()) {
link = Link();
if (string.startsWith('@')) {
this->emplace<TextElement>(string, TextElement::BoldUsername, textColor,
FontStyle::ChatMediumBold);
this->emplace<TextElement>(string, TextElement::NonBoldUsername, textColor);
} else {
this->emplace<TextElement>(string, TextElement::Text, textColor);
}
} else {
if (app->settings->lowercaseLink) {
QRegularExpression httpRegex("\\bhttps?://",
QRegularExpression::CaseInsensitiveOption);
QRegularExpression ftpRegex("\\bftps?://",
QRegularExpression::CaseInsensitiveOption);
QRegularExpression getDomain("\\/\\/([^\\/]*)");
QString tempString = string;
static QRegularExpression domainRegex(
R"(^(?:(?:ftp|http)s?:\/\/)?([^\/:]+)(?:\/.*)?$)",
QRegularExpression::CaseInsensitiveOption);
if (!string.contains(httpRegex)) {
if (!string.contains(ftpRegex)) {
tempString.insert(0, "http://");
}
}
QString domain = getDomain.match(tempString).captured(1);
string.replace(domain, domain.toLower());
QString lowercaseLinkString;
auto match = domainRegex.match(string);
if (match.isValid()) {
lowercaseLinkString = string.mid(0, match.capturedStart(1)) +
match.captured(1).toLower() +
string.mid(match.capturedEnd(1));
} else {
lowercaseLinkString = string;
}
link = Link(Link::Url, linkString);
textColor = MessageColor(MessageColor::Link);
}
if (string.startsWith('@')) {
this->emplace<TextElement>(string, TextElement::BoldUsername, textColor,
FontStyle::ChatMediumBold) //
this->emplace<TextElement>(lowercaseLinkString, TextElement::LowercaseLink,
textColor)
->setLink(link);
this->emplace<TextElement>(string, TextElement::NonBoldUsername, textColor) //
->setLink(link);
} else {
this->emplace<TextElement>(string, TextElement::Text, textColor) //
this->emplace<TextElement>(string, TextElement::OriginalLink, textColor)
->setLink(link);
}