From 04c60f4472a61b1a0e7b5e2add1de79d42b51c30 Mon Sep 17 00:00:00 2001 From: Oliver Tappe Date: Tue, 23 Aug 2011 19:59:50 +0000 Subject: [PATCH] * fix stuck loops in Replace...() on single chars in case the old and new character are the same (Eclipse was complaining about 'assignment to self', which got me looking at the code ...) git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42682 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/support/String.cpp | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/src/kits/support/String.cpp b/src/kits/support/String.cpp index e1be1c00a4..2550bb94c6 100644 --- a/src/kits/support/String.cpp +++ b/src/kits/support/String.cpp @@ -1389,13 +1389,8 @@ BString::ReplaceAll(char replaceThis, char withThis, int32 fromOffset) // detach and set first match if (pos >= 0 && _MakeWritable() == B_OK) { - fPrivateData[pos] = withThis; - for (pos = pos;;) { - pos = FindFirst(replaceThis, pos); - if (pos < 0) - break; + for( ; pos >= 0; pos = FindFirst(replaceThis, pos + 1)) fPrivateData[pos] = withThis; - } } return *this; } @@ -1409,13 +1404,10 @@ BString::Replace(char replaceThis, char withThis, int32 maxReplaceCount, int32 pos = FindFirst(replaceThis, fromOffset); if (maxReplaceCount > 0 && pos >= 0 && _MakeWritable() == B_OK) { - maxReplaceCount--; - fPrivateData[pos] = withThis; - for (pos = pos; maxReplaceCount > 0; maxReplaceCount--) { - pos = FindFirst(replaceThis, pos); - if (pos < 0) - break; + for( ; maxReplaceCount > 0 && pos >= 0; + pos = FindFirst(replaceThis, pos + 1)) { fPrivateData[pos] = withThis; + maxReplaceCount--; } } return *this; @@ -1546,13 +1538,8 @@ BString::IReplaceAll(char replaceThis, char withThis, int32 fromOffset) int32 pos = _IFindAfter(tmp, fromOffset, 1); if (pos >= 0 && _MakeWritable() == B_OK) { - fPrivateData[pos] = withThis; - for (pos = pos;;) { - pos = _IFindAfter(tmp, pos, 1); - if (pos < 0) - break; + for( ; pos >= 0; pos = _IFindAfter(tmp, pos + 1, 1)) fPrivateData[pos] = withThis; - } } return *this; } @@ -1567,13 +1554,10 @@ BString::IReplace(char replaceThis, char withThis, int32 maxReplaceCount, int32 pos = _IFindAfter(tmp, fromOffset, 1); if (maxReplaceCount > 0 && pos >= 0 && _MakeWritable() == B_OK) { - fPrivateData[pos] = withThis; - maxReplaceCount--; - for (pos = pos; maxReplaceCount > 0; maxReplaceCount--) { - pos = _IFindAfter(tmp, pos, 1); - if (pos < 0) - break; + for( ; maxReplaceCount > 0 && pos >= 0; + pos = _IFindAfter(tmp, pos + 1, 1)) { fPrivateData[pos] = withThis; + maxReplaceCount--; } }