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:
rfm 2009-09-17 14:18:13 +00:00
parent 1c97fb7e67
commit 7b0573fc9f
2 changed files with 30 additions and 1 deletions

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();