1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

fix: fixed wrong formatting for multiple URL's in one message

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
This commit is contained in:
noavarice 2017-03-22 14:11:49 +03:00
parent d34ac1e396
commit 08208e9aa5

View File

@ -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;
}
}
}