diff --git a/mozilla/string/public/nsAReadableString.h b/mozilla/string/public/nsAReadableString.h index 56b695d4d9d..d11b375ec03 100644 --- a/mozilla/string/public/nsAReadableString.h +++ b/mozilla/string/public/nsAReadableString.h @@ -196,7 +196,35 @@ class nsReadingIterator return mPosition - mFragment.mStart; } - nsReadingIterator& advance( difference_type ); + nsReadingIterator& + advance( difference_type n ) + { + while ( n > 0 ) + { + difference_type one_hop = NS_MIN(n, size_forward()); + + NS_ASSERTION(one_hop>0, "Infinite loop: can't advance a reading iterator beyond the end of a string"); + // perhaps I should |break| if |!one_hop|? + + mPosition += one_hop; + normalize_forward(); + n -= one_hop; + } + + while ( n < 0 ) + { + normalize_backward(); + difference_type one_hop = NS_MAX(n, -size_backward()); + + NS_ASSERTION(one_hop<0, "Infinite loop: can't advance (backward) a reading iterator beyond the end of a string"); + // perhaps I should |break| if |!one_hop|? + + mPosition += one_hop; + n -= one_hop; + } + + return *this; + } /** * Really don't want to call these two operations |+=| and |-=|. @@ -217,6 +245,7 @@ class nsReadingIterator } }; +#if 0 template nsReadingIterator& nsReadingIterator::advance( difference_type n ) @@ -247,6 +276,7 @@ nsReadingIterator::advance( difference_type n ) return *this; } +#endif template inline diff --git a/mozilla/string/public/nsAWritableString.h b/mozilla/string/public/nsAWritableString.h index 96be8c84ee3..5079d020342 100644 --- a/mozilla/string/public/nsAWritableString.h +++ b/mozilla/string/public/nsAWritableString.h @@ -156,7 +156,35 @@ class nsWritingIterator return mPosition - mFragment.mStart; } - nsWritingIterator& advance( difference_type ); + nsWritingIterator& + advance( difference_type n ) + { + while ( n > 0 ) + { + difference_type one_hop = NS_MIN(n, size_forward()); + + NS_ASSERTION(one_hop>0, "Infinite loop: can't advance a writing iterator beyond the end of a string"); + // perhaps I should |break| if |!one_hop|? + + mPosition += one_hop; + normalize_forward(); + n -= one_hop; + } + + while ( n < 0 ) + { + normalize_backward(); + difference_type one_hop = NS_MAX(n, -size_backward()); + + NS_ASSERTION(one_hop<0, "Infinite loop: can't advance (backward) a writing iterator beyond the end of a string"); + // perhaps I should |break| if |!one_hop|? + + mPosition += one_hop; + n -= one_hop; + } + + return *this; + } /** * Really don't want to call these two operations |+=| and |-=|. @@ -188,6 +216,7 @@ class nsWritingIterator } }; +#if 0 template nsWritingIterator& nsWritingIterator::advance( difference_type n ) @@ -218,7 +247,7 @@ nsWritingIterator::advance( difference_type n ) return *this; } - +#endif /* This file defines the abstract interfaces |nsAWritableString| and diff --git a/mozilla/xpcom/ds/nsAReadableString.h b/mozilla/xpcom/ds/nsAReadableString.h index 56b695d4d9d..d11b375ec03 100644 --- a/mozilla/xpcom/ds/nsAReadableString.h +++ b/mozilla/xpcom/ds/nsAReadableString.h @@ -196,7 +196,35 @@ class nsReadingIterator return mPosition - mFragment.mStart; } - nsReadingIterator& advance( difference_type ); + nsReadingIterator& + advance( difference_type n ) + { + while ( n > 0 ) + { + difference_type one_hop = NS_MIN(n, size_forward()); + + NS_ASSERTION(one_hop>0, "Infinite loop: can't advance a reading iterator beyond the end of a string"); + // perhaps I should |break| if |!one_hop|? + + mPosition += one_hop; + normalize_forward(); + n -= one_hop; + } + + while ( n < 0 ) + { + normalize_backward(); + difference_type one_hop = NS_MAX(n, -size_backward()); + + NS_ASSERTION(one_hop<0, "Infinite loop: can't advance (backward) a reading iterator beyond the end of a string"); + // perhaps I should |break| if |!one_hop|? + + mPosition += one_hop; + n -= one_hop; + } + + return *this; + } /** * Really don't want to call these two operations |+=| and |-=|. @@ -217,6 +245,7 @@ class nsReadingIterator } }; +#if 0 template nsReadingIterator& nsReadingIterator::advance( difference_type n ) @@ -247,6 +276,7 @@ nsReadingIterator::advance( difference_type n ) return *this; } +#endif template inline diff --git a/mozilla/xpcom/ds/nsAWritableString.h b/mozilla/xpcom/ds/nsAWritableString.h index 96be8c84ee3..5079d020342 100644 --- a/mozilla/xpcom/ds/nsAWritableString.h +++ b/mozilla/xpcom/ds/nsAWritableString.h @@ -156,7 +156,35 @@ class nsWritingIterator return mPosition - mFragment.mStart; } - nsWritingIterator& advance( difference_type ); + nsWritingIterator& + advance( difference_type n ) + { + while ( n > 0 ) + { + difference_type one_hop = NS_MIN(n, size_forward()); + + NS_ASSERTION(one_hop>0, "Infinite loop: can't advance a writing iterator beyond the end of a string"); + // perhaps I should |break| if |!one_hop|? + + mPosition += one_hop; + normalize_forward(); + n -= one_hop; + } + + while ( n < 0 ) + { + normalize_backward(); + difference_type one_hop = NS_MAX(n, -size_backward()); + + NS_ASSERTION(one_hop<0, "Infinite loop: can't advance (backward) a writing iterator beyond the end of a string"); + // perhaps I should |break| if |!one_hop|? + + mPosition += one_hop; + n -= one_hop; + } + + return *this; + } /** * Really don't want to call these two operations |+=| and |-=|. @@ -188,6 +216,7 @@ class nsWritingIterator } }; +#if 0 template nsWritingIterator& nsWritingIterator::advance( difference_type n ) @@ -218,7 +247,7 @@ nsWritingIterator::advance( difference_type n ) return *this; } - +#endif /* This file defines the abstract interfaces |nsAWritableString| and diff --git a/mozilla/xpcom/string/public/nsAReadableString.h b/mozilla/xpcom/string/public/nsAReadableString.h index 56b695d4d9d..d11b375ec03 100644 --- a/mozilla/xpcom/string/public/nsAReadableString.h +++ b/mozilla/xpcom/string/public/nsAReadableString.h @@ -196,7 +196,35 @@ class nsReadingIterator return mPosition - mFragment.mStart; } - nsReadingIterator& advance( difference_type ); + nsReadingIterator& + advance( difference_type n ) + { + while ( n > 0 ) + { + difference_type one_hop = NS_MIN(n, size_forward()); + + NS_ASSERTION(one_hop>0, "Infinite loop: can't advance a reading iterator beyond the end of a string"); + // perhaps I should |break| if |!one_hop|? + + mPosition += one_hop; + normalize_forward(); + n -= one_hop; + } + + while ( n < 0 ) + { + normalize_backward(); + difference_type one_hop = NS_MAX(n, -size_backward()); + + NS_ASSERTION(one_hop<0, "Infinite loop: can't advance (backward) a reading iterator beyond the end of a string"); + // perhaps I should |break| if |!one_hop|? + + mPosition += one_hop; + n -= one_hop; + } + + return *this; + } /** * Really don't want to call these two operations |+=| and |-=|. @@ -217,6 +245,7 @@ class nsReadingIterator } }; +#if 0 template nsReadingIterator& nsReadingIterator::advance( difference_type n ) @@ -247,6 +276,7 @@ nsReadingIterator::advance( difference_type n ) return *this; } +#endif template inline diff --git a/mozilla/xpcom/string/public/nsAWritableString.h b/mozilla/xpcom/string/public/nsAWritableString.h index 96be8c84ee3..5079d020342 100644 --- a/mozilla/xpcom/string/public/nsAWritableString.h +++ b/mozilla/xpcom/string/public/nsAWritableString.h @@ -156,7 +156,35 @@ class nsWritingIterator return mPosition - mFragment.mStart; } - nsWritingIterator& advance( difference_type ); + nsWritingIterator& + advance( difference_type n ) + { + while ( n > 0 ) + { + difference_type one_hop = NS_MIN(n, size_forward()); + + NS_ASSERTION(one_hop>0, "Infinite loop: can't advance a writing iterator beyond the end of a string"); + // perhaps I should |break| if |!one_hop|? + + mPosition += one_hop; + normalize_forward(); + n -= one_hop; + } + + while ( n < 0 ) + { + normalize_backward(); + difference_type one_hop = NS_MAX(n, -size_backward()); + + NS_ASSERTION(one_hop<0, "Infinite loop: can't advance (backward) a writing iterator beyond the end of a string"); + // perhaps I should |break| if |!one_hop|? + + mPosition += one_hop; + n -= one_hop; + } + + return *this; + } /** * Really don't want to call these two operations |+=| and |-=|. @@ -188,6 +216,7 @@ class nsWritingIterator } }; +#if 0 template nsWritingIterator& nsWritingIterator::advance( difference_type n ) @@ -218,7 +247,7 @@ nsWritingIterator::advance( difference_type n ) return *this; } - +#endif /* This file defines the abstract interfaces |nsAWritableString| and