ObjFW  Check-in [fb651428aa]

Overview
Comment:Add -[componentsJoinedByString:] to OFArray.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: fb651428aad2c67a8618c739f424253843ab6de3544e03b00bb4b479c7f3ffed
User & Date: js on 2009-12-03 11:51:17
Other Links: manifest | tags
Context
2009-12-03
18:50
Make OFStream caching invisible to the programmer. check-in: fc0b2500b9 user: js tags: trunk
11:51
Add -[componentsJoinedByString:] to OFArray. check-in: fb651428aa user: js tags: trunk
10:29
More documentation improvements. check-in: 012cee4f80 user: js tags: trunk
Changes

Modified src/OFArray.h from [41841f3a03] to [42a4f34f59].

10
11
12
13
14
15
16


17
18
19
20
21
22
23
 */

#include <stdarg.h>

#import "OFObject.h"
#import "OFDataArray.h"



/**
 * The OFArray class provides a class for storing objects in an array.
 */
@interface OFArray: OFObject <OFCopying, OFMutableCopying>
{
	OFDataArray *array;
}







>
>







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 */

#include <stdarg.h>

#import "OFObject.h"
#import "OFDataArray.h"

@class OFString;

/**
 * The OFArray class provides a class for storing objects in an array.
 */
@interface OFArray: OFObject <OFCopying, OFMutableCopying>
{
	OFDataArray *array;
}
122
123
124
125
126
127
128








129
130
131
132
133
134
135
136
137
138
139
140

- (id)firstObject;

/**
 * \return The last object of the OFArray or nil
 */
- (id)lastObject;









- addObject: (OFObject*)obj;
- addObject: (OFObject*)obj
    atIndex: (size_t)index;
- removeObject: (OFObject*)obj;
- removeObjectIdenticalTo: (OFObject*)obj;
- removeObjectAtIndex: (size_t)index;
- removeNObjects: (size_t)nobjects;
- removeNObjects: (size_t)nobjects
	 atIndex: (size_t)index;
@end

#import "OFMutableArray.h"








>
>
>
>
>
>
>
>












>
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
- (id)firstObject;

/**
 * \return The last object of the OFArray or nil
 */
- (id)lastObject;

/**
 * Creates a string by joining all objects of the array.
 *
 * \param separator The string with which the objects should be joined
 * \return A string containing all objects joined by the separator
 */
- (OFString*)componentsJoinedByString: (OFString*)separator;

- addObject: (OFObject*)obj;
- addObject: (OFObject*)obj
    atIndex: (size_t)index;
- removeObject: (OFObject*)obj;
- removeObjectIdenticalTo: (OFObject*)obj;
- removeObjectAtIndex: (size_t)index;
- removeNObjects: (size_t)nobjects;
- removeNObjects: (size_t)nobjects
	 atIndex: (size_t)index;
@end

#import "OFMutableArray.h"
#import "OFString.h"

Modified src/OFArray.m from [3d6ca823bb] to [29164ac41a].

211
212
213
214
215
216
217



























218
219
220
221
222
223
224

- (id)lastObject
{
	id *last = [array lastItem];

	return (last != NULL ? *last : nil);
}




























- (BOOL)isEqual: (OFObject*)obj
{
	OFObject **objs, **objs2;
	size_t i, count, count2;

	if (![obj isKindOfClass: [OFArray class]])







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251

- (id)lastObject
{
	id *last = [array lastItem];

	return (last != NULL ? *last : nil);
}

- (OFString*)componentsJoinedByString: (OFString*)separator
{
	OFString *str;
	OFString **objs = [array cArray];
	size_t i, count = [array count];
	IMP append;

	if (count == 0)
		return [OFString string];

	str = [[OFMutableString alloc] init];
	@try {
		append = [str methodForSelector: @selector(appendString:)];

		for (i = 0; i < count - 1; i++) {
			append(str, @selector(appendString:), objs[i]);
			append(str, @selector(appendString:), separator);
		}
		append(str, @selector(appendString:), objs[i]);
	} @catch (OFException *e) {
		[str release];
		@throw e;
	}

	return [str autorelease];
}

- (BOOL)isEqual: (OFObject*)obj
{
	OFObject **objs, **objs2;
	size_t i, count, count2;

	if (![obj isKindOfClass: [OFArray class]])

Modified tests/OFArray.m from [f0cc929efd] to [4179341566].

88
89
90
91
92
93
94




95
96

	EXPECT_EXCEPTION(@"Detect out of range in -[objectAtIndex:]",
	    OFOutOfRangeException, [a[0] objectAtIndex: [a[0] count]])

	EXPECT_EXCEPTION(@"Detect out of range in -[removeNItems:]",
	    OFOutOfRangeException, [a[0] removeNObjects: [a[0] count] + 1])





	[pool drain];
}







>
>
>
>


88
89
90
91
92
93
94
95
96
97
98
99
100

	EXPECT_EXCEPTION(@"Detect out of range in -[objectAtIndex:]",
	    OFOutOfRangeException, [a[0] objectAtIndex: [a[0] count]])

	EXPECT_EXCEPTION(@"Detect out of range in -[removeNItems:]",
	    OFOutOfRangeException, [a[0] removeNObjects: [a[0] count] + 1])

	a[0] = [OFArray arrayWithObjects: @"foo", @"bar", @"baz", nil];
	TEST(@"-[componentsJoinedByString:]",
	    [[a[0] componentsJoinedByString: @" "] isEqual: @"foo bar baz"])

	[pool drain];
}