fixed a problem with cut and advancing past the end of a string with an iterator r=waterson

git-svn-id: svn://10.0.0.236/trunk@70026 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
scc%netscape.com
2000-05-16 10:13:23 +00:00
parent bef09d5490
commit 21439a6da2
7 changed files with 43 additions and 6 deletions

View File

@@ -190,6 +190,7 @@ class nsReadingIterator
while ( n )
{
difference_type one_hop = NS_MIN(n, size_forward());
NS_ASSERTION(one_hop>0, "Infinite loop: can't advance a readable iterator beyond the end of a string");
mPosition += one_hop;
normalize_forward();
n -= one_hop;
@@ -207,6 +208,7 @@ class nsReadingIterator
while ( n )
{
difference_type one_hop = NS_MIN(n, size_backward());
NS_ASSERTION(one_hop>0, "Infinite loop: can't advance (backward) a readable iterator beyond the end of a string");
mPosition -= one_hop;
normalize_backward();
n -= one_hop;

View File

@@ -155,6 +155,7 @@ class nsWritingIterator
while ( n )
{
difference_type one_hop = NS_MIN(n, size_forward());
NS_ASSERTION(one_hop>0, "Infinite loop: can't advance a writable iterator beyond the end of a string");
mPosition += one_hop;
normalize_forward();
n -= one_hop;
@@ -172,6 +173,7 @@ class nsWritingIterator
while ( n )
{
difference_type one_hop = NS_MIN(n, size_backward());
NS_ASSERTION(one_hop>0, "Infinite loop: can't advance (backward) a writable iterator beyond the end of a string");
mPosition -= one_hop;
normalize_backward();
n -= one_hop;
@@ -622,8 +624,12 @@ template <class CharT>
void
basic_nsAWritableString<CharT>::Cut( PRUint32 cutStart, PRUint32 cutLength )
{
copy_string(BeginReading(cutStart+cutLength), EndReading(), BeginWriting(cutStart));
SetLength(Length()-cutLength);
PRUint32 myLength = Length();
cutLength = NS_MIN(cutLength, myLength-cutStart);
PRUint32 cutEnd = cutStart + cutLength;
if ( cutEnd < myLength )
copy_string(BeginReading(cutEnd), EndReading(), BeginWriting(cutStart));
SetLength(myLength-cutLength);
}