diff options
author | Edward Welbourne <edward.welbourne@theqtcompany.com> | 2016-03-30 19:26:29 +0200 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2016-07-12 10:22:17 +0000 |
commit | 9a3bcd1c3d4914a9594d80dc0c3812fd88be42c3 (patch) | |
tree | 48d8b6f9e2951f438b8a396d1eeae5a1bc6e69b0 /src | |
parent | 7a2f53647bad30a95692bb2d32a9a080f948a20a (diff) |
QString::replace(): Commentary clarifications.
Also skip doing a += 0 when we had to test whether the relevant rhs
was zero anyway (because we want to ++ there instead of +=ing).
Change-Id: Ibd5f21eb9aaf410b09c9db8450b2d61618e628fc
Reviewed-by: Robin Burchell <robin.burchell@viroteck.net>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/tools/qstring.cpp | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index 3d63a540dd..68681a90d0 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -2488,19 +2488,19 @@ QString &QString::replace(const QChar *before, int blen, if (index == -1) break; indices[pos++] = index; - index += blen; - // avoid infinite loop - if (!blen) + if (blen) // Step over before: + index += blen; + else // Only count one instance of empty between any two characters: index++; } - if (!pos) + if (!pos) // Nothing to replace break; replace_helper(indices, pos, blen, after, alen); - if (index == -1) + if (index == -1) // Nothing left to replace break; - // index has to be adjusted in case we get back into the loop above. + // The call to replace_helper just moved what index points at: index += pos*(alen-blen); } @@ -2545,14 +2545,14 @@ QString& QString::replace(QChar ch, const QString &after, Qt::CaseSensitivity cs index++; } } - if (!pos) + if (!pos) // Nothing to replace break; replace_helper(indices, pos, 1, after.constData(), after.d->size); - if (index == -1) + if (index == -1) // Nothing left to replace break; - // index has to be adjusted in case we get back into the loop above. + // The call to replace_helper just moved what index points at: index += pos*(after.d->size - 1); } return *this; |