Fix bug shifting indexes

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@28701 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2009-09-17 14:18:13 +00:00
parent 447a3d1c69
commit fd54363e2c
2 changed files with 30 additions and 1 deletions

View file

@ -1,3 +1,9 @@
2009-09-17 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSIndexSet.m:
([-shiftIndexesStartingAtIndex:by:]) fix to properly merge index
ranges when shifting left.
2009-09-15 Richard Frith-Macdonald <rfm@gnu.org>
* Headers/Additions/GNUstepBase/GSMime.h:

View file

@ -52,7 +52,14 @@ static void sanity(GSIArray array)
{
NSRange r = GSIArrayItemAtIndex(array, i).ext;
NSCAssert(r.location >= last, @"Overlap ranges");
if (i > 0)
{
NSCAssert(r.location > last, @"Overlap or touching ranges");
}
else
{
NSCAssert(r.location >= last, @"Overlap ranges");
}
NSCAssert(NSMaxRange(r) > r.location, @"Bad range length");
last = NSMaxRange(r);
}
@ -1228,6 +1235,22 @@ static NSUInteger posForIndex(GSIArray array, NSUInteger index)
GSIArraySetItemAtIndex(_array, (GSIArrayItem)r, c);
}
}
if (pos > 0)
{
c = GSIArrayCount(_array);
if (pos < c)
{
NSRange r0 = GSIArrayItemAtIndex(_array, pos - 1).ext;
NSRange r1 = GSIArrayItemAtIndex(_array, pos).ext;
if (NSMaxRange(r0) == r1.location)
{
r0.length += r1.length;
GSIArraySetItemAtIndex(_array, (GSIArrayItem)r0, pos - 1);
GSIArrayRemoveItemAtIndex(_array, pos);
}
}
}
}
}
SANITY();