Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
fix: fixed wrong formatting for multiple URL's in one message
Browse files Browse the repository at this point in the history
Fix #4275
I did not consider that replacing one substring with another will point
to shifting position of next URL found with regexp. That's the behavior
of Qt's "QRegularExpression" class - it takes a string into constructor
and seems to make its copy inside so changing source string does not
affect this regex object
  • Loading branch information
noavarice committed Mar 22, 2017
1 parent d34ac1e commit 08208e9
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/chatlog/textformatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,17 @@ static bool isTagIntersection(const QString& str)
*/
static void processUrl(QString& str, std::function<QString(QString&)> func)
{
int startLength = str.length();
int offset = 0;
for (QRegularExpression exp : urlPatterns) {
QRegularExpressionMatchIterator iter = exp.globalMatch(str);
while (iter.hasNext()) {
QRegularExpressionMatch match = iter.next();
int startPos = match.capturedStart();
int startPos = match.capturedStart() + offset;
int length = match.capturedLength();
QString url = str.mid(startPos, length);
str.replace(startPos, length, func(url));
offset = str.length() - startLength;
}
}
}
Expand Down

0 comments on commit 08208e9

Please sign in to comment.