Commit fbfcb9d9 authored by scc%netscape.com's avatar scc%netscape.com
Browse files

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

parent bc286d32
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -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;
+8 −2
Original line number Diff line number Diff line
@@ -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);
  }


+2 −0
Original line number Diff line number Diff line
@@ -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;
+8 −2
Original line number Diff line number Diff line
@@ -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);
  }


+2 −0
Original line number Diff line number Diff line
@@ -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;
Loading