mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 16:50:58 +00:00
([NSArray -isEqualToArray:]): Fix typo; reverse test before returning no.
([NSArray -arrayByAddingObject:]): New function, from Scott Christley. ([NSArray -arrayByAddingObjectsFromArray:]): Likewise. ([NSArray -subarrayWithRange:]): Implemented by Scott Christely. ([NSMutableArray -removeObjectIdenticalTo:]): Don't fail if the object is not present. ([NSMutableArray -removeObject:]): Likewise. ([NSMutableArray -removeAllObjects]): Implemented by Scott Christley. ([NSMutableArray -setArray:]): New function, from Scott Christley. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@1304 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
674f7c6e4c
commit
7c3fd4aafc
1 changed files with 78 additions and 9 deletions
|
@ -135,6 +135,42 @@ static Class NSMutableArray_concrete_class;
|
||||||
autorelease];
|
autorelease];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSArray*) arrayByAddingObject: anObject
|
||||||
|
{
|
||||||
|
id na;
|
||||||
|
int i, c;
|
||||||
|
id *objects;
|
||||||
|
|
||||||
|
c = [self count];
|
||||||
|
OBJC_MALLOC (objects, id, c+1);
|
||||||
|
for (i = 0; i < c; i++)
|
||||||
|
objects[i] = [self objectAtIndex: i];
|
||||||
|
objects[c] = anObject;
|
||||||
|
na = [[NSArray alloc] initWithObjects: objects count: c+1];
|
||||||
|
OBJC_FREE (objects);
|
||||||
|
return na;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSArray*) arrayByAddingObjectsFromArray: (NSArray*)anotherArray
|
||||||
|
{
|
||||||
|
id na;
|
||||||
|
int i, c, l;
|
||||||
|
id *objects;
|
||||||
|
|
||||||
|
c = [self count];
|
||||||
|
l = [anotherArray count];
|
||||||
|
OBJC_MALLOC (objects, id, c+l);
|
||||||
|
for (i = 0; i < c; i++)
|
||||||
|
objects[i] = [self objectAtIndex: i];
|
||||||
|
for (i = c; i < c+l; i++)
|
||||||
|
objects[i] = [anotherArray objectAtIndex: i-c];
|
||||||
|
na = [[NSArray alloc] initWithObjects: objects count: c+l];
|
||||||
|
OBJC_FREE (objects);
|
||||||
|
return na;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* This is the designated initializer for NSArray. */
|
/* This is the designated initializer for NSArray. */
|
||||||
- initWithObjects: (id*)objects count: (unsigned)count
|
- initWithObjects: (id*)objects count: (unsigned)count
|
||||||
{
|
{
|
||||||
|
@ -250,7 +286,7 @@ static Class NSMutableArray_concrete_class;
|
||||||
if (c != [otherArray count])
|
if (c != [otherArray count])
|
||||||
return NO;
|
return NO;
|
||||||
for (i = 0; i < c; i++)
|
for (i = 0; i < c; i++)
|
||||||
if ([[self objectAtIndex:i] isEqual:[otherArray objectAtIndex:i]])
|
if (![[self objectAtIndex: i] isEqual: [otherArray objectAtIndex: i]])
|
||||||
return NO;
|
return NO;
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
@ -317,10 +353,36 @@ static Class NSMutableArray_concrete_class;
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSArray*)subarrayWithRange: (NSRange)range
|
- (NSArray*) subarrayWithRange: (NSRange)range
|
||||||
{
|
{
|
||||||
[self notImplemented:_cmd];
|
id na;
|
||||||
return nil;
|
id *objects;
|
||||||
|
unsigned c = [self count];
|
||||||
|
unsigned i, j, k;
|
||||||
|
|
||||||
|
// If array is empty or start is beyond end of array
|
||||||
|
// then return an empty array
|
||||||
|
if (([self count] == 0) || (range.location > (c-1)))
|
||||||
|
return [NSArray array];
|
||||||
|
|
||||||
|
// Obtain bounds
|
||||||
|
i = range.location;
|
||||||
|
// Check if length extends beyond end of array
|
||||||
|
if ((range.location + range.length) > (c-1))
|
||||||
|
j = c-1;
|
||||||
|
else
|
||||||
|
j = range.location + range.length - 1;
|
||||||
|
|
||||||
|
// Copy the ids from the range into a temporary array
|
||||||
|
OBJC_MALLOC(objects, id, j-i+1);
|
||||||
|
for (k = i; k <= j; k++)
|
||||||
|
objects[k-i] = [self objectAtIndex:k];
|
||||||
|
|
||||||
|
// Create the new array
|
||||||
|
na = [[NSArray alloc] initWithObjects:objects count:j-i+1];
|
||||||
|
OBJC_FREE(objects);
|
||||||
|
return na;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSEnumerator*) objectEnumerator
|
- (NSEnumerator*) objectEnumerator
|
||||||
|
@ -440,20 +502,21 @@ static Class NSMutableArray_concrete_class;
|
||||||
- (void) removeObjectIdenticalTo: anObject
|
- (void) removeObjectIdenticalTo: anObject
|
||||||
{
|
{
|
||||||
int i = [self indexOfObjectIdenticalTo:anObject];
|
int i = [self indexOfObjectIdenticalTo:anObject];
|
||||||
assert (i != NSNotFound); /* xxx should raise an NSException instead */
|
if (i != NSNotFound)
|
||||||
[self removeObjectAtIndex:i];
|
[self removeObjectAtIndex: i];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) removeObject: anObject
|
- (void) removeObject: anObject
|
||||||
{
|
{
|
||||||
int i = [self indexOfObject:anObject];
|
int i = [self indexOfObject:anObject];
|
||||||
assert (i != NSNotFound); /* xxx should raise an NSException instead */
|
if (i != NSNotFound)
|
||||||
[self removeObjectAtIndex:i];
|
[self removeObjectAtIndex:i];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) removeAllObjects
|
- (void) removeAllObjects
|
||||||
{
|
{
|
||||||
[self subclassResponsibility:_cmd];
|
while ([self count])
|
||||||
|
[self removeLastObject];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) addObjectsFromArray: (NSArray*)otherArray
|
- (void) addObjectsFromArray: (NSArray*)otherArray
|
||||||
|
@ -464,6 +527,12 @@ static Class NSMutableArray_concrete_class;
|
||||||
[self addObject:[otherArray objectAtIndex:i]];
|
[self addObject:[otherArray objectAtIndex:i]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void) setArray:(NSArray *)otherArray
|
||||||
|
{
|
||||||
|
[self removeAllObjects];
|
||||||
|
[self addObjectsFromArray:otherArray];
|
||||||
|
}
|
||||||
|
|
||||||
- (void) removeObjectsFromIndices: (unsigned*)indices
|
- (void) removeObjectsFromIndices: (unsigned*)indices
|
||||||
numIndices: (unsigned)count
|
numIndices: (unsigned)count
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue