View | Details | Raw Unified | Return to issue 97002
Collapse All | Expand All

(-)basic/source/runtime/methods.cxx (-14 / +21 lines)
Lines 1403-1428 RTLFUNC(Replace) Link Here
1403
		if ( nArgCount == 6 )
1403
		if ( nArgCount == 6 )
1404
			bTextMode = rPar.Get(6)->GetInteger();
1404
			bTextMode = rPar.Get(6)->GetInteger();
1405
1405
1406
		USHORT nStrLen = aExpStr.Len();
1406
		USHORT nExpStrLen = aExpStr.Len();
1407
		USHORT nFindStrLen = aFindStr.Len();
1408
		USHORT nReplaceStrLen = aReplaceStr.Len();
1407
1409
1408
		if( lStartPos <= nStrLen )
1410
		if( lStartPos <= nExpStrLen )
1409
		{
1411
		{
1410
			String aSrcStr( aExpStr );
1412
			USHORT nPos = static_cast<USHORT>( lStartPos - 1 );
1411
			if( bTextMode )
1413
			USHORT nCounts = 0;
1414
			while( lCount == -1 || lCount > nCounts )
1412
			{
1415
			{
1416
				String aSrcStr( aExpStr );
1417
				if( bTextMode )
1418
				{
1413
					aSrcStr.ToUpperAscii();
1419
					aSrcStr.ToUpperAscii();
1414
					aFindStr.ToUpperAscii();
1420
					aFindStr.ToUpperAscii();
1415
			}
1421
				}
1416
			
1417
			USHORT nPos = aSrcStr.Search( aFindStr, static_cast<USHORT>( lStartPos - 1 ) );
1418
			USHORT nCounts = 0;
1419
			USHORT nReplaceLength = aReplaceStr.Len() ? aReplaceStr.Len():1;
1420
			while( nPos != STRING_NOTFOUND && (lCount == -1 || lCount > nCounts) )
1421
			{
1422
				aExpStr.Replace( nPos, aFindStr.Len(), aReplaceStr );
1423
				nPos = nPos + nReplaceLength;
1424
				nPos = aSrcStr.Search( aFindStr, nPos );
1422
				nPos = aSrcStr.Search( aFindStr, nPos );
1425
				nCounts++;
1423
				if( nPos != STRING_NOTFOUND )
1424
				{
1425
					aExpStr.Replace( nPos, nFindStrLen, aReplaceStr );
1426
					nPos = nPos - nFindStrLen + nReplaceStrLen + 1;
1427
					nCounts++;
1428
				}
1429
				else
1430
				{
1431
					break;
1432
				}
1426
			}
1433
			}
1427
		}
1434
		}
1428
		rPar.Get(0)->PutString( aExpStr.Copy( static_cast<USHORT>(lStartPos - 1) )  );
1435
		rPar.Get(0)->PutString( aExpStr.Copy( static_cast<USHORT>(lStartPos - 1) )  );

Return to issue 97002