ObjFW  Check-in [062a052b50]

Overview
Comment:Don't return self where not necessary, return void or something useful.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 062a052b50e40b3be7455820b27e72d17c815d44e54ece468c87d173cbd3fe55
User & Date: js on 2010-04-17 15:46:34
Other Links: manifest | tags
Context
2010-04-17
15:56
Make applying a table a private method. check-in: baeb7b379a user: js tags: trunk
15:46
Don't return self where not necessary, return void or something useful. check-in: 062a052b50 user: js tags: trunk
13:44
Improve performance of OFArray's +[arrayWithCArray:]. check-in: 8c4adb2599 user: js tags: trunk
Changes

Modified src/OFApplication.h from [4689449381] to [9f252190f8].

79
80
81
82
83
84
85
86
87


88
89
90
91
92
93
94
79
80
81
82
83
84
85


86
87
88
89
90
91
92
93
94







-
-
+
+







 * Sets argc and argv.
 *
 * You should not call this directly! Use of_application_main instead!
 *
 * \param argc The number of arguments
 * \param argv The argument values
 */
-  setArgumentCount: (int)argc
  andArgumentValues: (char**)argv;
- (void)setArgumentCount: (int)argc
       andArgumentValues: (char**)argv;

/**
 * \return The name of the program (argv[0])
 */
- (OFString*)programName;

/**
102
103
104
105
106
107
108
109

110
111
112
113
114

115
116
117
118
119
120
121
102
103
104
105
106
107
108

109
110
111
112
113

114
115
116
117
118
119
120
121







-
+




-
+







- (id)delegate;

/**
 * Sets the delegate of the application.
 *
 * \param delegate The delegate for the application
 */
- setDelegate: (id)delegate;
- (void)setDelegate: (id)delegate;

/**
 * Starts the application after everything has been initialized.
 */
- run;
- (void)run;

/**
 * Terminates the application.
 */
- (void)terminate;

/**

Modified src/OFApplication.m from [0455fcfdbe] to [e27d763715].

84
85
86
87
88
89
90
91
92


93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126

127
128
129
130
131

132
133
134


135
136
137
138
139
140
141
142
143
144
145
146
84
85
86
87
88
89
90


91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106


107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123

124
125
126
127
128

129



130
131

132
133


134
135
136
137
138
139
140







-
-
+
+














-
-

















-
+




-
+
-
-
-
+
+
-


-
-







	self = [super init];

	atexit(atexit_handler);

	return self;
}

-  setArgumentCount: (int)argc
  andArgumentValues: (char**)argv
- (void)setArgumentCount: (int)argc
       andArgumentValues: (char**)argv
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	int i;

	[progname release];
	[arguments release];

	progname = [[OFString alloc] initWithCString: argv[0]];
	arguments = [[OFMutableArray alloc] init];

	for (i = 1; i < argc; i++)
		[arguments addObject: [OFString stringWithCString: argv[i]]];

	[pool release];

	return self;
}

- (OFString*)programName
{
	return [[progname retain] autorelease];
}

- (OFArray*)arguments
{
	return [[arguments retain] autorelease];
}

- (id)delegate
{
	return [[delegate retain] autorelease];
}

- setDelegate: (id)delegate_
- (void)setDelegate: (id)delegate_
{
	id old = delegate;
	delegate = [delegate_ retain];
	[old release];

}
	return self;
}


- (void)run
- run
{
	[delegate applicationDidFinishLaunching];

	return self;
}

- (void)terminate
{
	exit(0);
}

Modified src/OFArray.m from [f9679701a3] to [00e1708140].

387
388
389
390
391
392
393
394

395
396
397
398
399
400
401
402
403
404
387
388
389
390
391
392
393

394
395
396
397
398
399


400
401
402







-
+





-
-




	if (pos < count)
		return *(OFObject**)[array itemAtIndex: pos++];

	return nil;
}

- reset
- (void)reset
{
	if (mutations_ptr != NULL && *mutations_ptr != mutations)
		@throw [OFEnumerationMutationException newWithClass: isa];

	pos = 0;

	return self;
}
@end
/// \endcond

Modified src/OFAutoreleasePool.h from [6a7b6de75c] to [4c33f3246c].

38
39
40
41
42
43
44
45

46
47
48
49
50
51
52
53
54
55

56
57
58
59
60
61
62
38
39
40
41
42
43
44

45
46
47
48
49
50
51
52
53
54

55
56
57
58
59
60
61
62







-
+









-
+







+ (void)releaseAll;

/**
 * Adds an object to the specific autorelease pool.
 *
 * \param obj The object to add to the autorelease pool
 */
- addObject: (OFObject*)obj;
- (void)addObject: (OFObject*)obj;

/**
 * Releases all objects in the autorelease pool.
 *
 * If a garbage collector is added in the future, it will tell the GC that now
 * is a good time to clean up, as this is often used after a lot of objects
 * have been added to the pool that should be released before the next iteration
 * of a loop, which adds objects again. Thus, it is usually a clean up call.
 */
- releaseObjects;
- (void)releaseObjects;

/**
 * Releases all objects in the autorelease pool and deallocates the pool.
 */
- (void)release;

/**

Modified src/OFAutoreleasePool.m from [86ca3a0b16] to [e16884bf15].

14
15
16
17
18
19
20
21

22
23
24
25
26
27
28
14
15
16
17
18
19
20

21
22
23
24
25
26
27
28







-
+







#include <stdlib.h>

#import "OFAutoreleasePool.h"
#import "OFArray.h"
#import "OFExceptions.h"

#ifdef OF_THREADS
#import "threading.h"
# import "threading.h"

static of_tlskey_t first_key, last_key;
#else
static OFAutoreleasePool *first = nil, *last = nil;
#endif

@implementation OFAutoreleasePool
117
118
119
120
121
122
123


























124
125
126
127
128
129
130
117
118
119
120
121
122
123
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
152
153
154
155
156







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







	}

	if (prev != nil)
		prev->next = self;

	return self;
}

- (void)addObject: (OFObject*)obj
{
	if (objects == nil)
		objects = [[OFMutableArray alloc] init];

	[objects addObject: obj];
	[obj release];
}

- (void)releaseObjects
{
	[next releaseObjects];
	[objects release];
	objects = nil;
}

- (void)release
{
	[self dealloc];
}

- (void)drain
{
	[self dealloc];
}

- (void)dealloc
{
	[next dealloc];
	[objects release];

	/*
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
183
184
185
186
187
188
189


































190
191
192
193
194
195
196
197
198
199
200
201







-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-












	if (first == self)
		first = nil;
#endif

	[super dealloc];
}

- addObject: (OFObject*)obj
{
	if (objects == nil)
		objects = [[OFMutableArray alloc] init];

	[objects addObject: obj];
	[obj release];

	return self;
}

- releaseObjects
{
	[next releaseObjects];

	if (objects == nil)
		return self;

	[objects release];
	objects = nil;

	return self;
}

- (void)release
{
	[self dealloc];
}

- (void)drain
{
	[self dealloc];
}

- retain
{
	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];
}

- autorelease
{
	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];
}
@end

Modified src/OFConstString.m from [c022cc131e] to [948949780e].

84
85
86
87
88
89
90
91

92
93
94
95
96
97
98
84
85
86
87
88
89
90

91
92
93
94
95
96
97
98







-
+








- initWithString: (OFString*)str
{
	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];
}

- addMemoryToPool: (void*)ptr
- (void)addMemoryToPool: (void*)ptr
{
	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];
}

- (void*)allocMemoryWithSize: (size_t)size
{
118
119
120
121
122
123
124
125

126
127
128
129
130
131
132
118
119
120
121
122
123
124

125
126
127
128
129
130
131
132







-
+







	     toNItems: (size_t)nitems
	     withSize: (size_t)size
{
	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];
}

- freeMemory: (void*)ptr
- (void)freeMemory: (void*)ptr
{
	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];
}

- retain
{

Modified src/OFDataArray.h from [5bdcca6241] to [3674b3e199].

83
84
85
86
87
88
89
90

91
92
93
94
95
96
97
98
99


100
101
102
103
104
105
106
107
108


109
110
111
112
113
114
115
116
117
118
119



120
121
122
123
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
83
84
85
86
87
88
89

90
91
92
93
94
95
96
97


98
99
100
101
102
103
104
105
106


107
108
109
110
111
112
113
114
115
116



117
118
119
120
121
122
123
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







-
+







-
-
+
+







-
-
+
+








-
-
-
+
+
+






-
+






-
+







-
-
+
+







- (void*)lastItem;

/**
 * Adds an item to the OFDataArray.
 *
 * \param item A pointer to an arbitrary item
 */
- addItem: (void*)item;
- (void)addItem: (void*)item;

/**
 * Adds an item to the OFDataArray at the specified index.
 *
 * \param item A pointer to an arbitrary item
 * \param index The index where the item should be added
 */
- addItem: (void*)item
  atIndex: (size_t)index;
- (void)addItem: (void*)item
	atIndex: (size_t)index;

/**
 * Adds items from a C array to the OFDataArray.
 *
 * \param nitems The number of items to add
 * \param carray A C array containing the items to add
 */
-  addNItems: (size_t)nitems
  fromCArray: (void*)carray;
- (void)addNItems: (size_t)nitems
       fromCArray: (void*)carray;

/**
 * Adds items from a C array to the OFDataArray at the specified index.
 *
 * \param nitems The number of items to add
 * \param carray A C array containing the items to add
 * \param index The index where the items should be added
 */
-  addNItems: (size_t)nitems
  fromCArray: (void*)carray
     atIndex: (size_t)index;
- (void)addNItems: (size_t)nitems
       fromCArray: (void*)carray
	  atIndex: (size_t)index;

/**
 * Removes the item at the specified index.
 *
 * \param index The index of the item to remove
 */
- removeItemAtIndex: (size_t)index;
- (void)removeItemAtIndex: (size_t)index;

/**
 * Removes the specified amount of items from the end of the OFDataArray.
 *
 * \param nitems The number of items to remove
 */
- removeNItems: (size_t)nitems;
- (void)removeNItems: (size_t)nitems;

/**
 * Removes the specified amount of items at the specified index.
 *
 * \param nitems The number of items to remove
 * \param index The index at which the items are removed
 */
- removeNItems: (size_t)nitems
       atIndex: (size_t)index;
- (void)removeNItems: (size_t)nitems
	     atIndex: (size_t)index;
@end

/**
 * \brief A class for storing arbitrary big data in an array.
 *
 * The OFBigDataArray class is a class for storing arbitrary data in an array
 * and is designed to store large hunks of data. Therefore, it allocates

Modified src/OFDataArray.m from [7837bd842b] to [36d514b98b].

85
86
87
88
89
90
91
92

93
94
95
96
97
98
99
100
101
102
103
104

105
106

107
108
109


110
111
112
113



114
115
116
117


118
119
120
121
122
123
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
152

153
154
155


156
157
158

159
160
161
162
163
164
165
166
167
168
169
170
171
172
173

174
175

176
177
178


179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
85
86
87
88
89
90
91

92
93
94
95
96
97
98
99
100
101
102
103

104


105



106
107
108



109
110
111
112
113


114
115
116
117
118
119
120
121
122
123
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

152
153
154
155
156
157
158
159
160
161
162
163
164
165
166

167


168



169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186


187
188
189
190
191
192
193







-
+











-
+
-
-
+
-
-
-
+
+

-
-
-
+
+
+


-
-
+
+










-
+
-
-
+
-
-
-
-
+
+
+













-
+
-
-
+
-
-
+

-
-
+
+


-
+














-
+
-
-
+
-
-
-
+
+
















-
-







{
	if (data == NULL || count == 0)
		return NULL;

	return data + (count - 1) * itemsize;
}

- addItem: (void*)item
- (void)addItem: (void*)item
{
	if (SIZE_MAX - count < 1)
		@throw [OFOutOfRangeException newWithClass: isa];

	data = [self resizeMemory: data
			 toNItems: count + 1
			 withSize: itemsize];

	memcpy(data + count * itemsize, item, itemsize);

	count++;

}
	return self;
}


- addItem: (void*)item
  atIndex: (size_t)index
- (void)addItem: (void*)item
	atIndex: (size_t)index
{
	return [self addNItems: 1
		    fromCArray: item
		       atIndex: index];
	[self addNItems: 1
	     fromCArray: item
		atIndex: index];
}

-  addNItems: (size_t)nitems
  fromCArray: (void*)carray
- (void)addNItems: (size_t)nitems
       fromCArray: (void*)carray
{
	if (nitems > SIZE_MAX - count)
		@throw [OFOutOfRangeException newWithClass: isa];

	data = [self resizeMemory: data
			 toNItems: count + nitems
			 withSize: itemsize];

	memcpy(data + count * itemsize, carray, nitems * itemsize);
	count += nitems;

}
	return self;
}


- addNItems: (size_t)nitems
 fromCArray: (void*)carray
    atIndex: (size_t)index
- (void)addNItems: (size_t)nitems
       fromCArray: (void*)carray
	  atIndex: (size_t)index
{
	if (nitems > SIZE_MAX - count)
		@throw [OFOutOfRangeException newWithClass: isa];

	data = [self resizeMemory: data
			 toNItems: count + nitems
			 withSize: itemsize];

	memmove(data + (index + nitems) * itemsize, data + index * itemsize,
	    (count - index) * itemsize);
	memcpy(data + index * itemsize, carray, nitems * itemsize);

	count += nitems;

}
	return self;
}


- removeItemAtIndex: (size_t)index
- (void)removeItemAtIndex: (size_t)index
{
	return [self removeNItems: 1
			  atIndex: index];
	[self removeNItems: 1
		   atIndex: index];
}

- removeNItems: (size_t)nitems
- (void)removeNItems: (size_t)nitems
{
	if (nitems > count)
		@throw [OFOutOfRangeException newWithClass: isa];


	count -= nitems;
	@try {
		data = [self resizeMemory: data
				 toNItems: count
				 withSize: itemsize];
	} @catch (OFOutOfMemoryException *e) {
		/* We don't really care, as we only made it smaller */
		[e dealloc];
	}

}
	return self;
}


- removeNItems: (size_t)nitems
       atIndex: (size_t)index
- (void)removeNItems: (size_t)nitems
	     atIndex: (size_t)index
{
	if (nitems > count)
		@throw [OFOutOfRangeException newWithClass: isa];

	memmove(data + index * itemsize, data + (index + nitems) * itemsize,
	    (count - index - nitems) * itemsize);

	count -= nitems;
	@try {
		data = [self resizeMemory: data
				 toNItems: count
				 withSize: itemsize];
	} @catch (OFOutOfMemoryException *e) {
		/* We don't really care, as we only made it smaller */
		[e dealloc];
	}

	return self;
}

- (id)copy
{
	OFDataArray *new = [[OFDataArray alloc] initWithItemSize: itemsize];
	[new addNItems: count
	    fromCArray: data];
258
259
260
261
262
263
264
265

266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283

284
285

286
287
288


289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306

307
308

309
310
311
312



313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333

334
335

336
337

338
339
340
341
342
343
344
345
346
347
348
349
350
351
352

353
354

355
356
357


358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
248
249
250
251
252
253
254

255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272

273


274



275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293

294


295




296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318

319


320


321
322
323
324
325
326
327
328
329
330
331
332
333
334
335

336


337



338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356


357
358
359
360
361
362
363
364
365
366
367
368







-
+

















-
+
-
-
+
-
-
-
+
+

















-
+
-
-
+
-
-
-
-
+
+
+




















-
+
-
-
+
-
-
+














-
+
-
-
+
-
-
-
+
+

















-
-












	OF_HASH_FINALIZE(hash);

	return hash;
}
@end

@implementation OFBigDataArray
- addItem: (void*)item
- (void)addItem: (void*)item
{
	size_t nsize, lastpagebyte;

	if (SIZE_MAX - count < 1 || count + 1 > SIZE_MAX / itemsize)
		@throw [OFOutOfRangeException newWithClass: isa];

	lastpagebyte = of_pagesize - 1;
	nsize = ((count + 1) * itemsize + lastpagebyte) & ~lastpagebyte;

	if (size != nsize)
		data = [self resizeMemory: data
				   toSize: nsize];

	memcpy(data + count * itemsize, item, itemsize);

	count++;
	size = nsize;

}
	return self;
}


-  addNItems: (size_t)nitems
  fromCArray: (void*)carray
- (void)addNItems: (size_t)nitems
       fromCArray: (void*)carray
{
	size_t nsize, lastpagebyte;

	if (nitems > SIZE_MAX - count || count + nitems > SIZE_MAX / itemsize)
		@throw [OFOutOfRangeException newWithClass: isa];

	lastpagebyte = of_pagesize - 1;
	nsize = ((count + nitems) * itemsize + lastpagebyte) & ~lastpagebyte;

	if (size != nsize)
		data = [self resizeMemory: data
				   toSize: nsize];

	memcpy(data + count * itemsize, carray, nitems * itemsize);

	count += nitems;
	size = nsize;

}
	return self;
}


- addNItems: (size_t)nitems
 fromCArray: (void*)carray
    atIndex: (size_t)index
- (void)addNItems: (size_t)nitems
       fromCArray: (void*)carray
	  atIndex: (size_t)index
{
	size_t nsize, lastpagebyte;

	if (nitems > SIZE_MAX - count || count + nitems > SIZE_MAX / itemsize)
		@throw [OFOutOfRangeException newWithClass: isa];

	lastpagebyte = of_pagesize - 1;
	nsize = ((count + nitems) * itemsize + lastpagebyte) & ~lastpagebyte;

	if (size != nsize)
		data = [self resizeMemory: data
				 toNItems: nsize
				 withSize: itemsize];

	memmove(data + (index + nitems) * itemsize, data + index * itemsize,
	    (count - index) * itemsize);
	memcpy(data + index * itemsize, carray, nitems * itemsize);

	count += nitems;
	size = nsize;

}
	return self;
}


- removeNItems: (size_t)nitems
- (void)removeNItems: (size_t)nitems
{
	size_t nsize, lastpagebyte;

	if (nitems > count)
		@throw [OFOutOfRangeException newWithClass: isa];

	count -= nitems;
	lastpagebyte = of_pagesize - 1;
	nsize = (count * itemsize + lastpagebyte) & ~lastpagebyte;

	if (size != nsize)
		data = [self resizeMemory: data
				   toSize: nsize];
	size = nsize;

}
	return self;
}


- removeNItems: (size_t)nitems
       atIndex: (size_t)index
- (void)removeNItems: (size_t)nitems
	     atIndex: (size_t)index
{
	size_t nsize, lastpagebyte;

	if (nitems > count)
		@throw [OFOutOfRangeException newWithClass: isa];

	memmove(data + index * itemsize, data + (index + nitems) * itemsize,
	    (count - index - nitems) * itemsize);

	count -= nitems;
	lastpagebyte = of_pagesize - 1;
	nsize = (count * itemsize + lastpagebyte) & ~lastpagebyte;

	if (size != nsize)
		data = [self resizeMemory: data
				   toSize: nsize];
	size = nsize;

	return self;
}

- (id)copy
{
	OFDataArray *new = [[OFBigDataArray alloc] initWithItemSize: itemsize];

	[new addNItems: count
	    fromCArray: data];

	return new;
}
@end

Modified src/OFDictionary.m from [dccfd91447] to [c58e028e47].

692
693
694
695
696
697
698
699

700
701
702
703
704
705
706
707
708
709
710
711
712
713
692
693
694
695
696
697
698

699
700
701
702
703
704


705
706
707
708
709
710
711







-
+





-
-







	size = size_;
	mutations = *mutations_ptr_;
	mutations_ptr = mutations_ptr_;

	return self;
}

- reset
- (void)reset
{
	if (mutations_ptr != NULL && *mutations_ptr != mutations)
		@throw [OFEnumerationMutationException newWithClass: isa];

	pos = 0;

	return self;
}
@end

@implementation OFDictionaryObjectEnumerator
- (id)nextObject
{
	if (mutations_ptr != NULL && *mutations_ptr != mutations)

Modified src/OFEnumerator.h from [aacddc389e] to [78ba4330f0].

20
21
22
23
24
25
26
27

28
29
30
31
32
33
34
20
21
22
23
24
25
26

27
28
29
30
31
32
33
34







-
+







 */
- (id)nextObject;

/**
 * Resets the enumerator, so the next call to nextObject returns the first
 * object again.
 */
- reset;
- (void)reset;
@end

/*
 * This needs to be exactly like this because it's hardcoded in the compiler.
 *
 * We need this bad check to see if we already imported Cocoa, which defines
 * this as well.

Modified src/OFEnumerator.m from [34e5a244ab] to [d73a03ff14].

26
27
28
29
30
31
32
33

34
35
36
37
38
26
27
28
29
30
31
32

33
34
35
36
37
38







-
+






- (id)nextObject
{
	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];
}

- reset
- (void)reset
{
	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];
}
@end

Modified src/OFFile.m from [fef21b43fd] to [831a79cc1f].

372
373
374
375
376
377
378
379

380
381
382
383
384
385
386
387
388
389
390
391
372
373
374
375
376
377
378

379
380
381
382


383
384
385
386
387
388
389







-
+



-
-







	if (fd == -1 || eos || (ret = write(fd, buf, size)) < size)
		@throw [OFWriteFailedException newWithClass: isa
						       size: size];

	return ret;
}

- _seekToOffset: (off_t)offset
- (void)_seekToOffset: (off_t)offset
{
	if (lseek(fd, offset, SEEK_SET) == -1)
		@throw [OFSeekFailedException newWithClass: isa];

	return self;
}

- (size_t)_seekForwardWithOffset: (off_t)offset
{
	off_t ret;

	if ((ret = lseek(fd, offset, SEEK_CUR)) == -1)
400
401
402
403
404
405
406
407

408
409
410
411
412
413
414
415
416
417
418
419
420
398
399
400
401
402
403
404

405
406
407
408
409


410
411
412
413
414
415
416







-
+




-
-








	if ((ret = lseek(fd, offset, SEEK_END)) == -1)
		@throw [OFSeekFailedException newWithClass: isa];

	return ret;
}

- close
- (void)close
{
	if (fd != -1)
		close(fd);
	fd = -1;

	return self;
}

- (void)dealloc
{
	if (closable && fd != -1)
		close(fd);

Modified src/OFHashes.h from [4a1439959b] to [38b83da8c3].

36
37
38
39
40
41
42
43
44


45
46
47
48
49
50
51
36
37
38
39
40
41
42


43
44
45
46
47
48
49
50
51







-
-
+
+








/**
 * Adds a buffer to the hash to be calculated.
 *
 * \param buf The buffer which should be included into calculation.
 * \param size The size of the buffer
 */
- updateWithBuffer: (const char*)buf
	    ofSize: (size_t)size;
- (void)updateWithBuffer: (const char*)buf
		  ofSize: (size_t)size;

/**
 * \return A buffer containing the hash (OF_MD5_DIGEST_SIZE = 16 bytes).
 *	   The buffer is part of object's memory pool.
 */
- (uint8_t*)digest;
@end
70
71
72
73
74
75
76
77
78


79
80
81
82
83
84
85
70
71
72
73
74
75
76


77
78
79
80
81
82
83
84
85







-
-
+
+








/**
 * Adds a buffer to the hash to be calculated.
 *
 * \param buf The buffer which should be included into calculation.
 * \param size The size of the buffer
 */
- updateWithBuffer: (const char*)buf
	    ofSize: (size_t)size;
- (void)updateWithBuffer: (const char*)buf
		  ofSize: (size_t)size;

/**
 * \return A buffer containing the hash (OF_SHA1_DIGEST_SIZE = 20 bytes).
 *	   The buffer is part of object's memory pool.
 */
- (uint8_t*)digest;
@end

Modified src/OFHashes.m from [fd5490715b] to [a97ba49f22].

132
133
134
135
136
137
138
139
140


141
142
143
144
145

146
147
148
149
150
151
152
132
133
134
135
136
137
138


139
140
141
142
143
144

145
146
147
148
149
150
151
152







-
-
+
+




-
+







	buf[1] = 0xEFCDAB89;
	buf[2] = 0x98BADCFE;
	buf[3] = 0x10325476;

	return self;
}

- updateWithBuffer: (const char*)buffer
	    ofSize: (size_t)size
- (void)updateWithBuffer: (const char*)buffer
		  ofSize: (size_t)size
{
	uint32_t t;

	if (size == 0)
		return self;
		return;

	if (calculated)
		@throw [OFHashAlreadyCalculatedException newWithClass: isa];

	/* Update bitcount */
	t = bits[0];
	if ((bits[0] = t + ((uint32_t)size << 3)) < t)
161
162
163
164
165
166
167
168

169
170
171
172
173
174
175
161
162
163
164
165
166
167

168
169
170
171
172
173
174
175







-
+







	if (t) {
		uint8_t *p = in + t;

		t = 64 - t;

		if (size < t) {
			memcpy(p, buffer, size);
			return self;
			return;
		}

		memcpy(p, buffer, t);
		OF_BSWAP32_V_IF_BE((uint32_t*)in, 16);
		md5_transform(buf, (uint32_t*)in);

		buffer += t;
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
184
185
186
187
188
189
190


191
192
193
194
195
196
197







-
-








		buffer += 64;
		size -= 64;
	}

	/* Handle any remaining bytes of data. */
	memcpy(in, buffer, size);

	return self;
}

- (uint8_t*)digest
{
	uint8_t	*p;
	size_t	count;

374
375
376
377
378
379
380
381
382


383
384
385

386
387
388
389
390
391
392
393
394
395
396
397
398
399
372
373
374
375
376
377
378


379
380
381
382

383
384
385
386
387
388


389
390
391
392
393
394
395







-
-
+
+


-
+





-
-







	state[2] = 0x98BADCFE;
	state[3] = 0x10325476;
	state[4] = 0xC3D2E1F0;

	return self;
}

- updateWithBuffer: (const char*)buf
	    ofSize: (size_t)size
- (void)updateWithBuffer: (const char*)buf
		  ofSize: (size_t)size
{
	if (size == 0)
		return self;
		return;

	if (calculated)
		@throw [OFHashAlreadyCalculatedException newWithClass: isa];

	sha1_update(state, &count, buffer, buf, size);

	return self;
}

- (uint8_t*)digest
{
	size_t i;
	char   finalcount[8];

Modified src/OFList.h from [17a82cf29c] to [498c3c68bc].

96
97
98
99
100
101
102
103

104
105
106
107
108
109
96
97
98
99
100
101
102

103
104
105
106
107
108
109







-
+






		      after: (of_list_object_t*)listobj;

/**
 * Removes the object with the specified list object from the list.
 *
 * \param listobj The list object returned by append / prepend
 */
- remove: (of_list_object_t*)listobj;
- (void)remove: (of_list_object_t*)listobj;

/**
 * \return The number of items in the list.
 */
- (size_t)count;
@end

Modified src/OFList.m from [e4b8ec6a45] to [3d67d61610].

145
146
147
148
149
150
151
152

153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
145
146
147
148
149
150
151

152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168


169
170
171
172
173
174
175







-
+
















-
-







	count++;

	[obj retain];

	return o;
}

- remove: (of_list_object_t*)listobj
- (void)remove: (of_list_object_t*)listobj
{
	if (listobj->prev != NULL)
		listobj->prev->next = listobj->next;
	if (listobj->next != NULL)
		listobj->next->prev = listobj->prev;

	if (first == listobj)
		first = listobj->next;
	if (last == listobj)
		last = listobj->prev;

	count--;

	[listobj->object release];

	[self freeMemory: listobj];

	return self;
}

- (size_t)count
{
	return count;
}

Modified src/OFMutableArray.h from [abd2603d66] to [a3cee17e91].

20
21
22
23
24
25
26
27

28
29
30
31
32
33
34
35
36


37
38
39
40
41
42
43
44
45
46


47
48
49
50
51
52

53
54
55


56
57
58
59
60
61
62
63
64
65


66
67
68
69
70
71
72

73
74
75
76
77
78
79

80
81
82
83
84

85
86

87
88
89
90
91
92
93

94
95
96
97
98
99
100
101
102


103
20
21
22
23
24
25
26

27
28
29
30
31
32
33
34


35
36
37
38
39
40
41
42
43
44


45
46
47
48
49
50
51
52
53
54


55
56
57
58
59
60
61
62
63
64


65
66
67
68
69
70
71
72

73
74
75
76
77
78
79

80
81
82
83
84
85
86
87

88
89
90
91
92
93
94

95
96
97
98
99
100
101
102


103
104
105







-
+







-
-
+
+








-
-
+
+






+

-
-
+
+








-
-
+
+






-
+






-
+





+

-
+






-
+







-
-
+
+

}

/**
 * Adds an object to the OFArray.
 *
 * \param obj An object to add
 */
- addObject: (OFObject*)obj;
- (void)addObject: (OFObject*)obj;

/**
 * Adds an object to the OFArray at the specified index.
 *
 * \param obj An object to add
 * \param index The index where the object should be added
 */
- addObject: (OFObject*)obj
    atIndex: (size_t)index;
- (void)addObject: (OFObject*)obj
	  atIndex: (size_t)index;

/**
 * Replaces all objects equivalent to the first specified object with the
 * second specified object.
 *
 * \param old The object to replace
 * \param new The replacement object
 */
- replaceObject: (OFObject*)old
     withObject: (OFObject*)new;
- (void)replaceObject: (OFObject*)old
	   withObject: (OFObject*)new;

/**
 * Replaces the object at the specified index with the specified object.
 *
 * \param index The index of the object to replace
 * \param obj The replacement object
 * \return The old object, autoreleased
 */
- replaceObjectAtIndex: (size_t)index
	    withObject: (OFObject*)obj;
- (id)replaceObjectAtIndex: (size_t)index
		withObject: (OFObject*)obj;

/**
 * Replaces all objects that have the same address as the first specified object
 * with the second specified object.
 *
 * \param old The object to replace
 * \param new The replacement object
 */
- replaceObjectIdenticalTo: (OFObject*)old
		withObject: (OFObject*)new;
- (void)replaceObjectIdenticalTo: (OFObject*)old
		      withObject: (OFObject*)new;

/**
 * Removes all objects equivalent to the specified object.
 *
 * \param obj The object to remove
 */
- removeObject: (OFObject*)obj;
- (void)removeObject: (OFObject*)obj;

/**
 * Removes all objects that have the same address as the specified object.
 *
 * \param obj The object to remove
 */
- removeObjectIdenticalTo: (OFObject*)obj;
- (void)removeObjectIdenticalTo: (OFObject*)obj;

/**
 * Removes the object at the specified index.
 *
 * \param index The index of the object to remove
 * \return The object that was at the index, autoreleased
 */
- removeObjectAtIndex: (size_t)index;
- (id)removeObjectAtIndex: (size_t)index;

/**
 * Removes the specified amount of objects from the end of the OFArray.
 *
 * \param nobjects The number of objects to remove
 */
- removeNObjects: (size_t)nobjects;
- (void)removeNObjects: (size_t)nobjects;

/**
 * Removes the specified amount of objects at the specified index.
 *
 * \param nobjects The number of objects to remove
 * \param index The index at which the objects are removed
 */
- removeNObjects: (size_t)nobjects
	 atIndex: (size_t)index;
- (void)removeNObjects: (size_t)nobjects
	       atIndex: (size_t)index;
@end

Modified src/OFMutableArray.m from [c1712cbaa7] to [3a8b86073d].

32
33
34
35
36
37
38
39

40
41
42
43
44
45

46
47

48
49
50


51
52
53
54
55
56
57

58
59

60
61
62


63
64
65
66
67
68
69
70
71
72
73
74

75
76

77
78
79


80
81

82
83
84
85
86
87
88


89
90

91
92
93
94


95
96
97
98
99
100
101
102
103
104
105
106

107
108

109
110

111
112
113
114
115
116
117
32
33
34
35
36
37
38

39
40
41
42
43
44

45


46



47
48
49
50
51
52
53
54

55


56



57
58
59
60
61
62
63
64
65
66
67
68
69

70


71



72
73
74
75
76
77
78
79
80



81
82
83

84
85
86


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

100


101


102
103
104
105
106
107
108
109







-
+





-
+
-
-
+
-
-
-
+
+






-
+
-
-
+
-
-
-
+
+











-
+
-
-
+
-
-
-
+
+


+




-
-
-
+
+

-
+


-
-
+
+











-
+
-
-
+
-
-
+








	for (i = 0; i < count; i++)
		[objs[i] retain];

	return new;
}

- addObject: (OFObject*)obj
- (void)addObject: (OFObject*)obj
{
	[array addItem: &obj];
	[obj retain];

	mutations++;

}
	return self;
}


- addObject: (OFObject*)obj
    atIndex: (size_t)index
- (void)addObject: (OFObject*)obj
	  atIndex: (size_t)index
{
	[array addItem: &obj
	       atIndex: index];
	[obj retain];

	mutations++;

}
	return self;
}


- replaceObject: (OFObject*)old
     withObject: (OFObject*)new
- (void)replaceObject: (OFObject*)old
	   withObject: (OFObject*)new
{
	OFObject **objs = [array cArray];
	size_t i, count = [array count];

	for (i = 0; i < count; i++) {
		if ([objs[i] isEqual: old]) {
			[new retain];
			[objs[i] release];
			objs[i] = new;
		}
	}

}
	return self;
}


- replaceObjectAtIndex: (size_t)index
	    withObject: (OFObject*)obj
- (id)replaceObjectAtIndex: (size_t)index
		withObject: (OFObject*)obj
{
	OFObject **objs = [array cArray];
	id old;

	if (index >= [array count])
		@throw [OFOutOfRangeException newWithClass: isa];

	[obj retain];
	[objs[index] release];
	objs[index] = obj;
	old = objs[index];
	objs[index] = [obj retain];

	return self;
	return [old autorelease];
}

- replaceObjectIdenticalTo: (OFObject*)old
		withObject: (OFObject*)new
- (void)replaceObjectIdenticalTo: (OFObject*)old
		      withObject: (OFObject*)new
{
	OFObject **objs = [array cArray];
	size_t i, count = [array count];

	for (i = 0; i < count; i++) {
		if (objs[i] == old) {
			[new retain];
			[objs[i] release];
			objs[i] = new;
		}
	}

}
	return self;
}


- removeObject: (OFObject*)obj
- (void)removeObject: (OFObject*)obj
{
	OFObject **objs = [array cArray];
	size_t i, count = [array count];

	for (i = 0; i < count; i++) {
		if ([objs[i] isEqual: obj]) {
			OFObject *obj = objs[i];
130
131
132
133
134
135
136
137

138
139

140
141

142
143
144
145
146
147
148
122
123
124
125
126
127
128

129


130


131
132
133
134
135
136
137
138







-
+
-
-
+
-
-
+







			 * decrease it.
			 */
			objs = [array cArray];
			count--;
			i--;
		}
	}

}
	return self;
}


- removeObjectIdenticalTo: (OFObject*)obj
- (void)removeObjectIdenticalTo: (OFObject*)obj
{
	OFObject **objs = [array cArray];
	size_t i, count = [array count];

	for (i = 0; i < count; i++) {
		if (objs[i] == obj) {
			[array removeItemAtIndex: i];
159
160
161
162
163
164
165
166

167
168
169
170
171
172
173
174
175
176












177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197

198
199

200
201
202


203
204
205
206
207
208
209
149
150
151
152
153
154
155

156










157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188

189


190



191
192
193
194
195
196
197
198
199







-
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+




















-
+
-
-
+
-
-
-
+
+







			 * decrease it.
			 */
			objs = [array cArray];
			count--;
			i--;
		}
	}

}
	return self;
}

- removeObjectAtIndex: (size_t)index
{
	return [self removeNObjects: 1
			    atIndex: index];
}

- removeNObjects: (size_t)nobjects

- (id)removeObjectAtIndex: (size_t)index
{
	id old = [self objectAtIndex: index];

	[self removeNObjects: 1
		     atIndex: index];

	return old;
}

- (void)removeNObjects: (size_t)nobjects
{
	OFObject **objs = [array cArray], **copy;
	size_t i, count = [array count];

	if (nobjects > count)
		@throw [OFOutOfRangeException newWithClass: isa];

	copy = [self allocMemoryForNItems: nobjects
				 withSize: sizeof(OFObject*)];
	memcpy(copy, objs + (count - nobjects), nobjects * sizeof(OFObject*));

	@try {
		[array removeNItems: nobjects];
		mutations++;

		for (i = 0; i < nobjects; i++)
			[copy[i] release];
	} @finally {
		[self freeMemory: copy];
	}

}
	return self;
}


- removeNObjects: (size_t)nobjects
	 atIndex: (size_t)index
- (void)removeNObjects: (size_t)nobjects
	       atIndex: (size_t)index
{
	OFObject **objs = [array cArray], **copy;
	size_t i, count = [array count];

	if (nobjects > count - index)
		@throw [OFOutOfRangeException newWithClass: isa];

217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
207
208
209
210
211
212
213


214
215
216
217
218
219
220







-
-







		mutations++;

		for (i = 0; i < nobjects; i++)
			[copy[i] release];
	} @finally {
		[self freeMemory: copy];
	}

	return self;
}

- (int)countByEnumeratingWithState: (of_fast_enumeration_state_t*)state
			   objects: (id*)objects
			     count: (int)count_
{
	size_t count = [array count];

Modified src/OFMutableDictionary.h from [486674aaa1] to [d7025a03e1].

20
21
22
23
24
25
26

27
28
29


30
31
32
33
34

35
36

37
20
21
22
23
24
25
26
27
28


29
30
31
32
33
34
35
36
37

38
39







+

-
-
+
+





+

-
+

}

/**
 * Sets a key to an object. A key can be any object.
 *
 * \param key The key to set
 * \param obj The object to set the key to
 * \return The old object, autoreleased
 */
- setObject: (OFObject*)obj
     forKey: (OFObject <OFCopying>*)key;
- (id)setObject: (OFObject*)obj
	 forKey: (OFObject <OFCopying>*)key;

/**
 * Remove the object with the given key from the dictionary.
 *
 * \param key The key whose object should be removed
 * \return The object that was stored for the key, autoreleased
 */
- removeObjectForKey: (OFObject*)key;
- (id)removeObjectForKey: (OFObject*)key;
@end

Modified src/OFMutableDictionary.m from [68b8ff9c5e] to [f5a5609e10].

75
76
77
78
79
80
81
82
83


84
85

86
87
88
89
90
91
92
75
76
77
78
79
80
81


82
83
84
85
86
87
88
89
90
91
92
93







-
-
+
+


+







	}

	[self freeMemory: data];
	data = newdata;
	size = newsize;
}

- setObject: (OFObject*)obj
     forKey: (OFObject <OFCopying>*)key
- (id)setObject: (OFObject*)obj
	 forKey: (OFObject <OFCopying>*)key
{
	uint32_t i, hash, last;
	id old;

	if (key == nil || obj == nil)
		@throw [OFInvalidArgumentException newWithClass: isa
						       selector: _cmd];

	hash = [key hash];
	last = size;
154
155
156
157
158
159
160
161

162
163
164
165
166


167
168

169
170
171

172
173

174
175
176
177
178
179
180
181
182
183
184
185
186


187
188
189
190
191
192
193
194
195
196

197
198
199
200
201

202
203
204
205
206
207
208
209
210


211
212
213
214
215
216
217
218
219
220

221
222
223
224

225
226
227
228
229
230
231
155
156
157
158
159
160
161

162
163
164



165
166
167

168
169
170

171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190

191
192
193
194
195
196
197

198
199
200
201
202

203
204
205
206
207
208
209
210
211
212
213
214
215

216
217
218
219
220
221
222

223
224
225
226

227
228
229
230
231
232
233
234







-
+


-
-
-
+
+

-
+


-
+


+













+
+

-







-
+




-
+









+
+

-







-
+



-
+








		b->key = key;
		b->object = obj;
		b->hash = hash;
		data[i] = b;
		count++;

		return self;
		return nil;
	}

	[obj retain];
	[data[i]->object release];
	data[i]->object = obj;
	old = data[i]->object;
	data[i]->object = [obj retain];

	return self;
	return [old autorelease];
}

- removeObjectForKey: (OFObject*)key
- (id)removeObjectForKey: (OFObject*)key
{
	uint32_t i, hash, last;
	id old;

	if (key == nil)
		@throw [OFInvalidArgumentException newWithClass: isa
						       selector: _cmd];

	hash = [key hash];
	last = size;

	for (i = hash & (size - 1); i < last && data[i] != NULL; i++) {
		if (data[i] == DELETED)
			continue;

		if ([data[i]->key isEqual: key]) {
			old = data[i]->object;

			[data[i]->key release];
			[data[i]->object release];
			[self freeMemory: data[i]];
			data[i] = DELETED;

			count--;
			mutations++;
			[self _resizeForCount: count];

			return self;
			return [old autorelease];
		}
	}

	if (i < last)
		return self;
		return nil;

	/* In case the last bucket is already used */
	last = hash & (size - 1);

	for (i = 0; i < last && data[i] != NULL; i++) {
		if (data[i] == DELETED)
			continue;

		if ([data[i]->key isEqual: key]) {
			old = data[i]->object;

			[data[i]->key release];
			[data[i]->object release];
			[self freeMemory: data[i]];
			data[i] = DELETED;

			count--;
			mutations++;
			[self _resizeForCount: count];

			return self;
			return [old autorelease];
		}
	}

	return self;
	return nil;
}

- (id)copy
{
	return [[OFDictionary alloc] initWithDictionary: self];
}

Modified src/OFMutableString.h from [ab2207f3d5] to [98b6def095].

19
20
21
22
23
24
25
26

27
28
29
30
31
32
33

34
35
36
37
38
39
40
41
42


43
44
45
46
47
48
49
50
51
52
53

54
55
56
57
58
59
60
61
62
63
64
65
66


67
68
69
70
71
72
73

74
75
76
77
78
79
80
81

82
83
84
85
86
87
88
89
90
91


92
93
94
95
96

97
98
99
100
101

102
103
104
105
106

107
108
109
110
111
112
113
114
115
116


117
118
119
120
121
122
123

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
19
20
21
22
23
24
25

26
27
28
29
30
31
32

33
34
35
36
37
38
39
40


41
42
43
44
45
46
47
48
49
50
51
52

53
54
55
56
57
58
59
60
61
62
63
64


65
66
67
68
69
70
71
72

73
74
75
76
77
78
79
80

81
82
83
84
85
86
87
88
89


90
91
92
93
94
95

96
97
98
99
100

101
102
103
104
105

106
107
108
109
110
111
112
113
114


115
116
117
118
119
120
121
122

123
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







-
+






-
+







-
-
+
+










-
+











-
-
+
+






-
+







-
+








-
-
+
+




-
+




-
+




-
+








-
-
+
+






-
+







-
-
+
+




-
+




-
+




-
+

 */
@interface OFMutableString: OFString {}
/**
 * Sets the OFString to the specified UTF-8 encoded C string.
 *
 * \param str A UTF-8 encoded C string to set the OFString to.
 */
- setToCString: (const char*)str;
- (void)setToCString: (const char*)str;

/**
 * Appends a UTF-8 encoded C string to the OFString.
 *
 * \param str A UTF-8 encoded C string to append
 */
- appendCString: (const char*)str;
- (void)appendCString: (const char*)str;

/**
 * Appends a UTF-8 encoded C string with the specified length to the OFString.
 *
 * \param str A UTF-8 encoded C string to append
 * \param len The length of the UTF-8 encoded C string
 */
- appendCString: (const char*)str
     withLength: (size_t)len;
- (void)appendCString: (const char*)str
	   withLength: (size_t)len;

/**
 * Appends a UTF-8 encoded C string to the OFString without checking whether it
 * is valid UTF-8.
 *
 * Only use this if you are 100% sure the string you append is either ASCII or
 * UTF-8!
 *
 * \param str A UTF-8 encoded C string to append
 */
- appendCStringWithoutUTF8Checking: (const char*)str;
- (void)appendCStringWithoutUTF8Checking: (const char*)str;

/**
 * Appends a UTF-8 encoded C string with the specified length to the OFString
 * without checking whether it is valid UTF-8.
 *
 * Only use this if you are 100% sure the string you append is either ASCII or
 * UTF-8!
 *
 * \param str A UTF-8 encoded C string to append
 * \param len The length of the UTF-8 encoded C string
 */
- appendCStringWithoutUTF8Checking: (const char*)str
			    length: (size_t)len;
- (void)appendCStringWithoutUTF8Checking: (const char*)str
				  length: (size_t)len;

/**
 * Appends another OFString to the OFString.
 *
 * \param str An OFString to append
 */
- appendString: (OFString*)str;
- (void)appendString: (OFString*)str;

/**
 * Appends a formatted UTF-8 encoded C string to the OFString.
 * See printf for the format syntax.
 *
 * \param fmt A format string which generates the string to append
 */
- appendFormat: (OFString*)fmt, ...;
- (void)appendFormat: (OFString*)fmt, ...;

/**
 * Appends a formatted UTF-8 encoded C string to the OFString.
 * See printf for the format syntax.
 *
 * \param fmt A format string which generates the string to append
 * \param args The arguments used in the format string
 */
-  appendFormat: (OFString*)fmt
  withArguments: (va_list)args;
- (void)appendFormat: (OFString*)fmt
       withArguments: (va_list)args;

/**
 * Reverse the OFString.
 */
- reverse;
- (void)reverse;

/**
 * Upper the OFString.
 */
- upper;
- (void)upper;

/**
 * Lower the OFString.
 */
- lower;
- (void)lower;

/**
 * Removes the characters at the specified range.
 *
 * \param start The index where the deletion should be started
 * \param end The index until which the characters should be deleted.
 *	      This points BEHIND the last character!
 */
- removeCharactersFromIndex: (size_t)start
		    toIndex: (size_t)end;
- (void)removeCharactersFromIndex: (size_t)start
			  toIndex: (size_t)end;

/**
 * Removes the characters at the specified range.
 *
 * \param range The range of the characters which should be removed
 */
- removeCharactersInRange: (of_range_t)range;
- (void)removeCharactersInRange: (of_range_t)range;

/**
 * Replaces all occurrences of a string with another string.
 *
 * \param str The string to replace
 * \param repl The string with which it should be replaced
 */
- replaceOccurrencesOfString: (OFString*)str
		  withString: (OFString*)repl;
- (void)replaceOccurrencesOfString: (OFString*)str
			withString: (OFString*)repl;

/**
 * Removes all whitespaces at the beginning of a string.
 */
- removeLeadingWhitespaces;
- (void)removeLeadingWhitespaces;

/**
 * Removes all whitespaces at the end of a string.
 */
- removeTrailingWhitespaces;
- (void)removeTrailingWhitespaces;

/**
 * Removes all whitespaces at the beginning and the end of a string.
 */
- removeLeadingAndTrailingWhitespaces;
- (void)removeLeadingAndTrailingWhitespaces;
@end

Modified src/OFMutableString.m from [e8c7a3fc62] to [702fa32298].

118
119
120
121
122
123
124
125

126
127
128
129
130
131
132
118
119
120
121
122
123
124

125
126
127
128
129
130
131
132







-
+








	[self freeMemory: *string];
	*string = nstr;
	*length = nlen;
}

@implementation OFMutableString
- setToCString: (const char*)str
- (void)setToCString: (const char*)str
{
	size_t len;

	[self freeMemory: string];

	len = strlen(str);

144
145
146
147
148
149
150
151

152
153

154
155

156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173

174
175

176
177
178


179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196

197
198

199
200

201
202
203
204
205
206
207
208
209

210
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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270

271
272

273
274

275
276
277
278
279
280
281
282
283
284
285
286
287
288
289

290
291
292
293
294
295
296
144
145
146
147
148
149
150

151


152


153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170

171


172



173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191

192


193


194
195
196
197
198
199
200
201
202

203


204



205
206
207
208
209
210
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
252
253
254

255


256


257
258
259
260
261
262
263
264
265
266
267
268
269
270
271

272
273
274
275
276
277
278
279







-
+
-
-
+
-
-
+

















-
+
-
-
+
-
-
-
+
+

















-
+
-
-
+
-
-
+








-
+
-
-
+
-
-
-
+
+









-
+
-
-
+
-
-
+


-
+
-
-
+
-
-
+

-



-
-
+
+

-
+
-
-
+
-
-
-
+
+




















-
+
-
-
+
-
-
+














-
+








		@throw [OFInvalidEncodingException newWithClass: isa];
	}

	length = len;
	string = [self allocMemoryWithSize: length + 1];
	memcpy(string, str, length + 1);

}
	return self;
}


- appendCString: (const char*)str
- (void)appendCString: (const char*)str
{
	size_t strlength;

	strlength = strlen(str);

	switch (of_string_check_utf8(str, strlength)) {
	case 1:
		is_utf8 = YES;
		break;
	case -1:
		@throw [OFInvalidEncodingException newWithClass: isa];
	}

	string = [self resizeMemory: string
			     toSize: length + strlength + 1];
	memcpy(string + length, str, strlength + 1);
	length += strlength;

}
	return self;
}


- appendCString: (const char*)str
     withLength: (size_t)len
- (void)appendCString: (const char*)str
	   withLength: (size_t)len
{
	if (len > strlen(str))
		@throw [OFOutOfRangeException newWithClass: isa];

	switch (of_string_check_utf8(str, len)) {
	case 1:
		is_utf8 = YES;
		break;
	case -1:
		@throw [OFInvalidEncodingException newWithClass: isa];
	}

	string = [self resizeMemory: string
			     toSize: length + len + 1];
	memcpy(string + length, str, len);
	length += len;
	string[length] = 0;

}
	return self;
}


- appendCStringWithoutUTF8Checking: (const char*)str
- (void)appendCStringWithoutUTF8Checking: (const char*)str
{
	size_t strlength;

	strlength = strlen(str);
	string = [self resizeMemory: string
			     toSize: length + strlength + 1];
	memcpy(string + length, str, strlength + 1);
	length += strlength;

}
	return self;
}


- appendCStringWithoutUTF8Checking: (const char*)str
			    length: (size_t)len
- (void)appendCStringWithoutUTF8Checking: (const char*)str
				  length: (size_t)len
{
	if (len > strlen(str))
		@throw [OFOutOfRangeException newWithClass: isa];

	string = [self resizeMemory: string
			     toSize: length + len + 1];
	memcpy(string + length, str, len);
	length += len;
	string[length] = 0;

}
	return self;
}


- appendString: (OFString*)str
- (void)appendString: (OFString*)str
{
	[self appendCString: [str cString]];

}
	return self;
}


- appendFormat: (OFString*)fmt, ...
- (void)appendFormat: (OFString*)fmt, ...
{
	id ret;
	va_list args;

	va_start(args, fmt);
	ret = [self appendFormat: fmt
		   withArguments: args];
	[self appendFormat: fmt
	     withArguments: args];
	va_end(args);

}
	return ret;
}


-  appendFormat: (OFString*)fmt
  withArguments: (va_list)args
- (void)appendFormat: (OFString*)fmt
       withArguments: (va_list)args
{
	char *t;

	if (fmt == nil)
		@throw [OFInvalidArgumentException newWithClass: isa
						       selector: _cmd];

	if ((vasprintf(&t, [fmt cString], args)) == -1) {
		/*
		 * This is only the most likely error to happen. Unfortunately,
		 * there is no good way to check what really happened.
		 */
		@throw [OFOutOfMemoryException newWithClass: isa];
	}

	@try {
		[self appendCString: t];
	} @finally {
		free(t);
	}

}
	return self;
}


- reverse
- (void)reverse
{
	size_t i, j, len = length / 2;

	madvise(string, len, MADV_SEQUENTIAL);

	/* We reverse all bytes and restore UTF-8 later, if necessary */
	for (i = 0, j = length - 1; i < len; i++, j--) {
		string[i] ^= string[j];
		string[j] ^= string[i];
		string[i] ^= string[j];
	}

	if (!is_utf8) {
		madvise(string, len, MADV_NORMAL);
		return self;
		return;
	}

	for (i = 0; i < length; i++) {
		/* ASCII */
		if (OF_LIKELY(!(string[i] & 0x80)))
			continue;

354
355
356
357
358
359
360
361

362
363

364
365

366
367
368
369

370
371

372
373

374
375
376
377

378
379

380
381
382


383
384
385
386
387
388
389
337
338
339
340
341
342
343

344


345


346
347
348
349

350


351


352
353
354
355

356


357



358
359
360
361
362
363
364
365
366







-
+
-
-
+
-
-
+



-
+
-
-
+
-
-
+



-
+
-
-
+
-
-
-
+
+








		/* UTF-8 does not allow more than 4 bytes per character */
		madvise(string, len, MADV_NORMAL);
		@throw [OFInvalidEncodingException newWithClass: isa];
	}

	madvise(string, len, MADV_NORMAL);

}
	return self;
}


- upper
- (void)upper
{
	apply_table(self, isa, &string, &length, is_utf8,
	    of_unicode_upper_table, OF_UNICODE_UPPER_TABLE_SIZE);

}
	return self;
}


- lower
- (void)lower
{
	apply_table(self, isa, &string, &length, is_utf8,
	    of_unicode_lower_table, OF_UNICODE_LOWER_TABLE_SIZE);

}
	return self;
}


- removeCharactersFromIndex: (size_t)start
		    toIndex: (size_t)end
- (void)removeCharactersFromIndex: (size_t)start
			  toIndex: (size_t)end
{
	if (is_utf8) {
		start = of_string_index_to_position(string, start, length);
		end = of_string_index_to_position(string, end, length);
	}

	if (start > end)
400
401
402
403
404
405
406
407

408
409

410
411

412
413
414


415
416
417
418


419
420
421
422
423
424
425
426
427
428

429
430
431
432
433
434
435
377
378
379
380
381
382
383

384


385


386
387


388
389
390
391


392
393
394
395
396
397
398
399
400
401
402

403
404
405
406
407
408
409
410







-
+
-
-
+
-
-
+

-
-
+
+


-
-
+
+









-
+







	@try {
		string = [self resizeMemory: string
				     toSize: length + 1];
	} @catch (OFOutOfMemoryException *e) {
		/* We don't really care, as we only made it smaller */
		[e dealloc];
	}

}
	return self;
}


- removeCharactersInRange: (of_range_t)range
- (void)removeCharactersInRange: (of_range_t)range
{
	return [self removeCharactersFromIndex: range.start
				       toIndex: range.start + range.length];
	[self removeCharactersFromIndex: range.start
				toIndex: range.start + range.length];
}

- replaceOccurrencesOfString: (OFString*)str
		  withString: (OFString*)repl
- (void)replaceOccurrencesOfString: (OFString*)str
			withString: (OFString*)repl
{
	const char *str_c = [str cString];
	const char *repl_c = [repl cString];
	size_t str_len = [str cStringLength];
	size_t repl_len = [repl cStringLength];
	size_t i, last, tmp_len;
	char *tmp;

	if (str_len > length)
		return self;
		return;

	tmp = NULL;
	tmp_len = 0;

	for (i = 0, last = 0; i <= length - str_len; i++) {
		if (memcmp(string + i, str_c, str_len))
			continue;
459
460
461
462
463
464
465
466

467
468

469
470

471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490

491
492

493
494

495
496
497
498
499
500
501
434
435
436
437
438
439
440

441


442


443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462

463


464


465
466
467
468
469
470
471
472







-
+
-
-
+
-
-
+



















-
+
-
-
+
-
-
+







	memcpy(tmp + tmp_len, string + last, length - last);
	tmp_len += length - last;
	tmp[tmp_len] = 0;

	[self freeMemory: string];
	string = tmp;
	length = tmp_len;

}
	return self;
}


- removeLeadingWhitespaces
- (void)removeLeadingWhitespaces
{
	size_t i;

	for (i = 0; i < length; i++)
		if (string[i] != ' '  && string[i] != '\t' &&
		    string[i] != '\n' && string[i] != '\r')
			break;

	length -= i;
	memmove(string, string + i, length);
	string[length] = '\0';

	@try {
		string = [self resizeMemory: string
				     toSize: length + 1];
	} @catch (OFOutOfMemoryException *e) {
		/* We don't really care, as we only made it smaller */
		[e dealloc];
	}

}
	return self;
}


- removeTrailingWhitespaces
- (void)removeTrailingWhitespaces
{
	size_t d;
	char *p;

	d = 0;
	for (p = string + length - 1; p >= string; p--) {
		if (*p != ' ' && *p != '\t' && *p != '\n' && *p != '\r')
510
511
512
513
514
515
516
517

518
519

520
521

522
523
524
525
526
527
528
481
482
483
484
485
486
487

488


489


490
491
492
493
494
495
496
497







-
+
-
-
+
-
-
+







	@try {
		string = [self resizeMemory: string
				     toSize: length + 1];
	} @catch (OFOutOfMemoryException *e) {
		/* We don't really care, as we only made it smaller */
		[e dealloc];
	}

}
	return self;
}


- removeLeadingAndTrailingWhitespaces
- (void)removeLeadingAndTrailingWhitespaces
{
	size_t d, i;
	char *p;

	d = 0;
	for (p = string + length - 1; p >= string; p--) {
		if (*p != ' ' && *p != '\t' && *p != '\n' && *p != '\r')
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
515
516
517
518
519
520
521


522
523
524
525
526
527
528







-
-







	@try {
		string = [self resizeMemory: string
				     toSize: length + 1];
	} @catch (OFOutOfMemoryException *e) {
		/* We don't really care, as we only made it smaller */
		[e dealloc];
	}

	return self;
}

- (id)copy
{
	return [[OFString alloc] initWithString: self];
}
@end

Modified src/OFNumber.h from [44b277b096] to [35311fb8bd].

555
556
557
558
559
560
561
562

563
564

565
566
567
568

569
570

571
572
573
574

575
576

577
578
579
580

581
582

583
584
585
586
587
588
589
590

591
592

593
594
595
596
597
598
599
600

601
602

603
604
605
606
607
608
609
610

611
612

613
614
615
616
617
618
619
620
621


622
623

624
625
626
627
628
629
630
631
632


633
634

635
636
637

638
639

640
641
642

643
644

645
555
556
557
558
559
560
561

562
563

564
565
566
567

568
569

570
571
572
573

574
575

576
577
578
579

580
581

582
583
584
585
586
587
588
589

590
591

592
593
594
595
596
597
598
599

600
601

602
603
604
605
606
607
608
609

610
611

612
613
614
615
616
617
618
619
620

621
622
623

624
625
626
627
628
629
630
631
632

633
634
635

636
637
638

639
640

641
642
643

644
645

646
647







-
+

-
+



-
+

-
+



-
+

-
+



-
+

-
+







-
+

-
+







-
+

-
+







-
+

-
+








-
+
+

-
+








-
+
+

-
+


-
+

-
+


-
+

-
+

/**
 * \return The OFNumber as a double
 */
- (double)asDouble;

/**
 * \param num The OFNumber to add
 * \return The OFNumber added with the specified OFNumber
 * \return A new autoreleased OFNumber added with the specified OFNumber
 */
- add: (OFNumber*)num;
- (OFNumber*)add: (OFNumber*)num;

/**
 * \param num The OFNumber to substract
 * \return The OFNumber subtracted by the specified OFNumber
 * \return A new autoreleased OFNumber subtracted by the specified OFNumber
 */
- subtract: (OFNumber*)num;
- (OFNumber*)subtract: (OFNumber*)num;

/**
 * \param num The OFNumber to multiply with
 * \return The OFNumber multiplied with the specified OFNumber
 * \return A new autoreleased OFNumber multiplied with the specified OFNumber
 */
- multiplyWith: (OFNumber*)num;
- (OFNumber*)multiplyWith: (OFNumber*)num;

/**
 * \param num The OFNumber to divide by
 * \return The OFNumber devided by the specified OFNumber
 * \return A new autoreleased OFNumber devided by the specified OFNumber
 */
- divideBy: (OFNumber*)num;
- (OFNumber*)divideBy: (OFNumber*)num;

/**
 * ANDs two OFNumbers, returning a new one.
 *
 * Does not work with floating point types!
 *
 * \param num The number to AND with.
 * \return The OFNumber ANDed with the specified OFNumber
 * \return A new autoreleased OFNumber ANDed with the specified OFNumber
 */
- and: (OFNumber*)num;
- (OFNumber*)and: (OFNumber*)num;

/**
 * ORs two OFNumbers, returning a new one.
 *
 * Does not work with floating point types!
 *
 * \param num The number to OR with.
 * \return The OFNumber ORed with the specified OFNumber
 * \return A new autoreleased OFNumber ORed with the specified OFNumber
 */
- or: (OFNumber*)num;
- (OFNumber*)or: (OFNumber*)num;

/**
 * XORs two OFNumbers, returning a new one.
 *
 * Does not work with floating point types!
 *
 * \param num The number to XOR with.
 * \return The OFNumber XORed with the specified OFNumber
 * \return A new autoreleased OFNumber XORed with the specified OFNumber
 */
- xor: (OFNumber*)num;
- (OFNumber*)xor: (OFNumber*)num;

/**
 * Bitshifts the OFNumber to the left by the specified OFNumber, returning a new
 * one.
 *
 * Does not work with floating point types!
 *
 * \param num The number of bits to shift to the left
 * \return The OFNumber bitshifted to the left with the specified OFNumber
 * \return A new autoreleased OFNumber bitshifted to the left with the
 *	   specified OFNumber
 */
- shiftLeft: (OFNumber*)num;
- (OFNumber*)shiftLeft: (OFNumber*)num;

/**
 * Bitshifts the OFNumber to the right by the specified OFNumber, returning a
 * new one.
 *
 * Does not work with floating point types!
 *
 * \param num The number of bits to shift to the right
 * \return The OFNumber bitshifted to the right with the specified OFNumber
 * \return A new autoreleased OFNumber bitshifted to the right with the
 *	   specified OFNumber
 */
- shiftRight: (OFNumber*)num;
- (OFNumber*)shiftRight: (OFNumber*)num;

/**
 * \return The OFNumber increased by one.
 * \return A new autoreleased OFNumber with the value increased by one.
 */
- increase;
- (OFNumber*)increase;

/**
 * \return The OFNumber decreased by one.
 * \return A new autoreleased OFNumber with the value decreased by one.
 */
- decrease;
- (OFNumber*)decrease;
@end

Modified src/OFNumber.m from [c9d9078686] to [1856417314].

860
861
862
863
864
865
866
867

868
869
870
871
872

873
874
875
876
877

878
879
880
881
882

883
884
885
886
887

888
889
890
891
892

893
894
895
896
897

898
899
900
901
902

903
904
905
906
907

908
909
910
911
912

913
914
915
916
917

918
919
920
921
860
861
862
863
864
865
866

867
868
869
870
871

872
873
874
875
876

877
878
879
880
881

882
883
884
885
886

887
888
889
890
891

892
893
894
895
896

897
898
899
900
901

902
903
904
905
906

907
908
909
910
911

912
913
914
915
916

917
918
919
920
921







-
+




-
+




-
+




-
+




-
+




-
+




-
+




-
+




-
+




-
+




-
+





		return hash;
	default:
		return [self asUInt32];
	}
}

- add: (OFNumber*)num
- (OFNumber*)add: (OFNumber*)num
{
	CALCULATE(+, num)
}

- subtract: (OFNumber*)num
- (OFNumber*)subtract: (OFNumber*)num
{
	CALCULATE(-, num)
}

- multiplyWith: (OFNumber*)num
- (OFNumber*)multiplyWith: (OFNumber*)num
{
	CALCULATE(*, num)
}

- divideBy: (OFNumber*)num
- (OFNumber*)divideBy: (OFNumber*)num
{
	CALCULATE(/, num)
}

- and: (OFNumber*)num
- (OFNumber*)and: (OFNumber*)num
{
	CALCULATE2(&, num)
}

- or: (OFNumber*)num
- (OFNumber*)or: (OFNumber*)num
{
	CALCULATE2(|, num)
}

- xor: (OFNumber*)num
- (OFNumber*)xor: (OFNumber*)num
{
	CALCULATE2(^, num)
}

- shiftLeft: (OFNumber*)num
- (OFNumber*)shiftLeft: (OFNumber*)num
{
	CALCULATE2(<<, num)
}

- shiftRight: (OFNumber*)num
- (OFNumber*)shiftRight: (OFNumber*)num
{
	CALCULATE2(>>, num)
}

- increase
- (OFNumber*)increase
{
	CALCULATE3(+ 1)
}

- decrease
- (OFNumber*)decrease
{
	CALCULATE3(- 1)
}
@end

Modified src/OFObject.h from [2662d5b8c3] to [c207812c2a].

234
235
236
237
238
239
240
241

242
243
244
245
246
247
248
234
235
236
237
238
239
240

241
242
243
244
245
246
247
248







-
+







 * Adds a pointer to the object's memory pool.
 *
 * This is useful to add memory allocated by functions such as asprintf to the
 * pool so it gets free'd automatically when the object is deallocated.
 *
 * \param ptr A pointer to add to the memory pool
 */
- addMemoryToPool: (void*)ptr;
- (void)addMemoryToPool: (void*)ptr;

/**
 * Allocates memory and stores it in the object's memory pool so it can be
 * free'd automatically when the object is deallocated.
 *
 * \param size The size of the memory to allocate
 * \return A pointer to the allocated memory
286
287
288
289
290
291
292
293

294
295
296
297
298
299
300
286
287
288
289
290
291
292

293
294
295
296
297
298
299
300







-
+








/**
 * Frees allocated memory and removes it from the object's memory pool.
 * Does nothing if ptr is NULL.
 *
 * \param ptr A pointer to the allocated memory
 */
- freeMemory: (void*)ptr;
- (void)freeMemory: (void*)ptr;

/**
 * Increases the retain count.
 *
 * Each time an object is released, the retain count gets decreased and the
 * object deallocated if it reaches 0.
 */

Modified src/OFObject.m from [6d2f924ac1] to [224d3accf3].

395
396
397
398
399
400
401
402

403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
395
396
397
398
399
400
401

402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420


421
422
423
424
425
426
427







-
+


















-
-








- (uint32_t)hash
{
	/* Classes containing data should reimplement this! */
	return (uint32_t)(uintptr_t)self;
}

- addMemoryToPool: (void*)ptr
- (void)addMemoryToPool: (void*)ptr
{
	void **memchunks;
	size_t memchunks_size;

	memchunks_size = PRE_IVAR->memchunks_size + 1;

	if (SIZE_MAX - PRE_IVAR->memchunks_size < 1 ||
	    memchunks_size > SIZE_MAX / sizeof(void*))
		@throw [OFOutOfRangeException newWithClass: isa];

	if ((memchunks = realloc(PRE_IVAR->memchunks,
	    memchunks_size * sizeof(void*))) == NULL)
		@throw [OFOutOfMemoryException newWithClass: isa
						       size: memchunks_size];

	PRE_IVAR->memchunks = memchunks;
	PRE_IVAR->memchunks[PRE_IVAR->memchunks_size] = ptr;
	PRE_IVAR->memchunks_size = memchunks_size;

	return self;
}

- (void*)allocMemoryWithSize: (size_t)size
{
	void *ptr, **memchunks;
	size_t memchunks_size;

513
514
515
516
517
518
519
520

521
522
523
524
525
526

527
528
529
530
531
532
533
511
512
513
514
515
516
517

518
519
520
521
522
523

524
525
526
527
528
529
530
531







-
+





-
+







	if (nitems > SIZE_MAX / size)
		@throw [OFOutOfRangeException newWithClass: isa];

	return [self resizeMemory: ptr
			   toSize: nitems * size];
}

- freeMemory: (void*)ptr;
- (void)freeMemory: (void*)ptr;
{
	void **iter, *last, **memchunks;
	size_t i, memchunks_size;

	if (ptr == NULL)
		return self;
		return;

	iter = PRE_IVAR->memchunks + PRE_IVAR->memchunks_size;
	i = PRE_IVAR->memchunks_size;

	while (iter-- > PRE_IVAR->memchunks) {
		i--;

541
542
543
544
545
546
547
548

549
550
551
552
553
554
555
556
557
558

559
560
561
562

563
564
565
566
567
568
569
539
540
541
542
543
544
545

546
547
548
549
550
551
552
553
554
555

556
557
558
559

560
561
562
563
564
565
566
567







-
+









-
+



-
+







			if (OF_UNLIKELY(memchunks_size == 0)) {
				free(ptr);
				free(PRE_IVAR->memchunks);

				PRE_IVAR->memchunks = NULL;
				PRE_IVAR->memchunks_size = 0;

				return self;
				return;
			}

			free(ptr);
			PRE_IVAR->memchunks[i] = last;
			PRE_IVAR->memchunks_size = memchunks_size;

			if (OF_UNLIKELY((memchunks = realloc(
			    PRE_IVAR->memchunks, memchunks_size *
			    sizeof(void*))) == NULL))
				return self;
				return;

			PRE_IVAR->memchunks = memchunks;

			return self;
			return;
		}
	}

	@throw [OFMemoryNotPartOfObjectException newWithClass: isa
						      pointer: ptr];
}

642
643
644
645
646
647
648
649

650
651
652
653
654
655
656
640
641
642
643
644
645
646

647
648
649
650
651
652
653
654







-
+







	return [(id)self mutableCopy];
}

/*
 * Those are needed as the root class is the superclass of the root class's
 * metaclass and thus instance methods can be sent to class objects as well.
 */
+ addMemoryToPool: (void*)ptr
+ (void)addMemoryToPool: (void*)ptr
{
	@throw [OFNotImplementedException newWithClass: self
					      selector: _cmd];
}

+ (void*)allocMemoryWithSize: (size_t)size
{
676
677
678
679
680
681
682
683

684
685
686
687
688
689
690
674
675
676
677
678
679
680

681
682
683
684
685
686
687
688







-
+







	     toNItems: (size_t)nitems
	     withSize: (size_t)size
{
	@throw [OFNotImplementedException newWithClass: self
					      selector: _cmd];
}

+ freeMemory: (void*)ptr
+ (void)freeMemory: (void*)ptr
{
	@throw [OFNotImplementedException newWithClass: self
					      selector: _cmd];
}

+ retain
{

Modified src/OFSeekableStream.h from [1d030f1b22] to [8903116140].

25
26
27
28
29
30
31
32

33
34
35
36
37
38
39
25
26
27
28
29
30
31

32
33
34
35
36
37
38
39







-
+







 */
@interface OFSeekableStream: OFStream
/**
 * Seeks to the specified absolute offset.
 *
 * \param offset The offset in bytes
 */
- seekToOffset: (off_t)offset;
- (void)seekToOffset: (off_t)offset;

/**
 * Seeks to the specified offset, relative to the current location.
 *
 * \param offset The offset relative to the current location
 * \return The absolute offset
 */

Modified src/OFSeekableStream.m from [8a407eb24d] to [ebbb4dbb54].

9
10
11
12
13
14
15
16

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
9
10
11
12
13
14
15

16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

34
35
36
37
38
39
40
41


42
43
44
45
46
47
48







-
+

















-
+







-
-







 * the packaging of this file.
 */

#import "OFSeekableStream.h"
#import "OFExceptions.h"

@implementation OFSeekableStream
- _seekToOffset: (off_t)offset
- (void)_seekToOffset: (off_t)offset
{
	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];
}

- (off_t)_seekForwardWithOffset: (off_t)offset
{
	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];
}

- (off_t)_seekToOffsetRelativeToEnd: (off_t)offset
{
	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];
}

- seekToOffset: (off_t)offset
- (void)seekToOffset: (off_t)offset
{
	[self flushWriteBuffer];
	[self _seekToOffset: offset];

	[self freeMemory: cache];
	cache = NULL;
	cache_len = 0;

	return self;
}

- (off_t)seekForwardWithOffset: (off_t)offset
{
	off_t ret;

	[self flushWriteBuffer];

Modified src/OFSocket.h from [353d35e521] to [cc8482609a].

33
34
35
36
37
38
39
40

41
33
34
35
36
37
38
39

40
41







-
+

 * \return A new autoreleased OFTCPSocket
 */
+ socket;

/**
 * Enables/disables non-blocking I/O.
 */
- setBlocking: (BOOL)enable;
- (void)setBlocking: (BOOL)enable;
@end

Modified src/OFSocket.m from [eff73867f1] to [7d46692d8a].

93
94
95
96
97
98
99
100

101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121

122
123
124
93
94
95
96
97
98
99

100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120

121


122







-
+




















-
+
-
-

		@throw [OFWriteFailedException newWithClass: isa
						       size: size];

	/* This is safe, as we already checked for -1 */
	return ret;
}

- setBlocking: (BOOL)enable
- (void)setBlocking: (BOOL)enable
{
#ifndef _WIN32
	int flags;

	if ((flags = fcntl(sock, F_GETFL)) == -1)
		@throw [OFSetOptionFailedException newWithClass: isa];

	if (enable)
		flags &= ~O_NONBLOCK;
	else
		flags |= O_NONBLOCK;

	if (fcntl(sock, F_SETFL, flags) == -1)
		@throw [OFSetOptionFailedException newWithClass: isa];
#else
	u_long v = enable;

	if (ioctlsocket(sock, FIONBIO, &v) == SOCKET_ERROR)
		@throw [OFSetOptionFailedException newWithClass: isa];
#endif

}
	return self;
}
@end

Modified src/OFStream.h from [d0c23abdf8] to [fde24b0fcf].

166
167
168
169
170
171
172
173

174
175
176
177
178

179
180
181
182
183
184
185
166
167
168
169
170
171
172

173
174
175
176
177

178
179
180
181
182
183
184
185







-
+




-
+







 */
- (OFString*)readTillDelimiter: (OFString*)delimiter
		  withEncoding: (enum of_string_encoding)encoding;

/**
 * Buffer all writes until flushWriteBuffer is called.
 */
- bufferWrites;
- (void)bufferWrites;

/**
 * Writes everything in the write cache to the stream.
 */
- flushWriteBuffer;
- (void)flushWriteBuffer;

/**
 * Writes from a buffer into the stream.
 *
 * \param buf The buffer from which the data is written to the stream
 * \param size The size of the data that should be written
 * \return The number of bytes written
277
278
279
280
281
282
283
284

285
277
278
279
280
281
282
283

284
285







-
+

 */
- (size_t)writeFormat: (OFString*)fmt
	withArguments: (va_list)args;

/**
 * Closes the stream.
 */
- close;
- (void)close;
@end

Modified src/OFStream.m from [426e5fd1b8] to [86b9b6684c].

493
494
495
496
497
498
499
500

501
502
503

504
505

506
507

508
509
510

511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
493
494
495
496
497
498
499

500
501
502

503


504


505
506
507

508
509
510
511
512
513
514
515
516


517
518
519
520
521
522
523







-
+


-
+
-
-
+
-
-
+


-
+








-
-







		[self freeMemory: tmp];
	}

	/* Get rid of a warning, never reached anyway */
	assert(0);
}

- bufferWrites
- (void)bufferWrites
{
	use_wbuffer = YES;

}
	return self;
}


- flushWriteBuffer
- (void)flushWriteBuffer
{
	if (wbuffer == NULL)
		return self;
		return;

	[self _writeNBytes: wbuffer_len
		fromBuffer: wbuffer];

	[self freeMemory: wbuffer];
	wbuffer = NULL;
	wbuffer_len = 0;
	use_wbuffer = NO;

	return self;
}

- (size_t)writeNBytes: (size_t)size
	   fromBuffer: (const char*)buf
{
	if (!use_wbuffer)
		return [self _writeNBytes: size
648
649
650
651
652
653
654
655

656
657
658
659
660
644
645
646
647
648
649
650

651
652
653
654
655
656







-
+





		free(t);
	}

	/* Get rid of a warning, never reached anyway */
	assert(0);
}

- close
- (void)close
{
	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];
}
@end

Modified src/OFString.m from [4bb745a125] to [228bd6589d].

902
903
904
905
906
907
908


909




910
911
912
913
914
915
916
902
903
904
905
906
907
908
909
910

911
912
913
914
915
916
917
918
919
920
921







+
+
-
+
+
+
+







{
	return [self substringFromIndex: range.start
				toIndex: range.start + range.length];
}

- (OFString*)stringByAppendingString: (OFString*)str
{
	OFMutableString *new;

	return [[OFMutableString stringWithString: self] appendString: str];
	new = [OFMutableString stringWithString: self];
	[new appendString: str];

	return new;
}

- (BOOL)hasPrefix: (OFString*)prefix
{
	size_t len = [prefix cStringLength];

	if (len > length)

Modified src/OFTCPSocket.h from [337485173f] to [bc6d0d6e26].

34
35
36
37
38
39
40
41
42


43
44
45
46
47
48
49
50
51
52
53



54
55
56
57
58
59
60

61
62
63
64
65

66
67
68
69
70
71
72
73
74
75
76

77
78
79
80
81
82
83
84
34
35
36
37
38
39
40


41
42
43
44
45
46
47
48
49
50



51
52
53
54
55
56
57
58
59

60
61
62
63
64

65
66
67
68
69
70
71
72
73
74
75

76
77
78
79
80
81
82
83
84







-
-
+
+








-
-
-
+
+
+






-
+




-
+










-
+









/**
 * Connect the OFTCPSocket to the specified destination.
 *
 * \param service The service on the node to connect to
 * \param node The node to connect to
 */
- connectToService: (OFString*)service
	    onNode: (OFString*)node;
- (void)connectToService: (OFString*)service
		  onNode: (OFString*)node;

/**
 * Bind socket on the specified node and service.
 *
 * \param service The service to bind
 * \param node The node to bind to
 * \param family The family to use (AF_INET for IPv4 or AF_INET6 for IPv6)
 */
- bindService: (OFString*)service
       onNode: (OFString*)node
   withFamily: (int)family;
- (void)bindService: (OFString*)service
	     onNode: (OFString*)node
	 withFamily: (int)family;

/**
 * Listen on the socket.
 *
 * \param backlog Maximum length for the queue of pending connections.
 */
- listenWithBackLog: (int)backlog;
- (void)listenWithBackLog: (int)backlog;

/**
 * Listen on the socket.
 */
- listen;
- (void)listen;

/**
 * Accept an incoming connection.
 * \return An autoreleased OFTCPSocket for the accepted connection.
 */
- (OFTCPSocket*)accept;

/**
 * Enable or disable keep alives for the connection.
 */
- enableKeepAlives: (BOOL)enable;
- (void)setKeepAlivesEnabled: (BOOL)enable;

/**
 * Returns the remote address of the socket. Only works with accepted sockets!
 *
 * \return The remote address as a string.
 */
- (OFString*)remoteAddress;
@end

Modified src/OFTCPSocket.m from [0f7c2e2900] to [fe6d461e93].

54
55
56
57
58
59
60
61
62


63
64
65
66
67
68
69
54
55
56
57
58
59
60


61
62
63
64
65
66
67
68
69







-
-
+
+








	sock = INVALID_SOCKET;
	saddr = NULL;

	return self;
}

- connectToService: (OFString*)service
	    onNode: (OFString*)node
- (void)connectToService: (OFString*)service
		  onNode: (OFString*)node
{
	if (sock != INVALID_SOCKET)
		@throw [OFAlreadyConnectedException newWithClass: isa];

#ifdef HAVE_THREADSAFE_GETADDRINFO
	struct addrinfo hints, *res, *res0;

184
185
186
187
188
189
190
191

192
193

194
195
196
197



198
199
200
201
202
203
204
184
185
186
187
188
189
190

191


192




193
194
195
196
197
198
199
200
201
202







-
+
-
-
+
-
-
-
-
+
+
+







	}
#endif

	if (sock == INVALID_SOCKET)
		@throw [OFConnectionFailedException newWithClass: isa
							    node: node
							 service: service];

}
	return self;
}


- bindService: (OFString*)service
       onNode: (OFString*)node
   withFamily: (int)family
- (void)bindService: (OFString*)service
	     onNode: (OFString*)node
	 withFamily: (int)family
{
	if (sock != INVALID_SOCKET)
		@throw [OFAlreadyConnectedException newWithClass: isa];

#ifndef HAVE_THREADSAFE_GETADDRINFO
	if (family != AF_INET)
		@throw [OFBindFailedException newWithClass: isa
302
303
304
305
306
307
308
309

310
311

312
313

314
315
316
317
318
319
320
321

322
323

324
325

326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
300
301
302
303
304
305
306

307


308


309
310
311
312
313
314
315
316

317


318


319
320
321
322
323
324
325
326


327
328
329
330
331
332
333







-
+
-
-
+
-
-
+







-
+
-
-
+
-
-
+







-
-







		sock = INVALID_SOCKET;
		@throw [OFBindFailedException newWithClass: isa
						      node: node
						   service: service
						    family: family];
	}
#endif

}
	return self;
}


- listenWithBackLog: (int)backlog
- (void)listenWithBackLog: (int)backlog
{
	if (sock == INVALID_SOCKET)
		@throw [OFNotConnectedException newWithClass: isa];

	if (listen(sock, backlog) == -1)
		@throw [OFListenFailedException newWithClass: isa
						     backLog: backlog];

}
	return self;
}


- listen
- (void)listen
{
	if (sock == INVALID_SOCKET)
		@throw [OFNotConnectedException newWithClass: isa];

	if (listen(sock, 5) == -1)
		@throw [OFListenFailedException newWithClass: isa
						     backLog: 5];

	return self;
}

- (OFTCPSocket*)accept
{
	OFTCPSocket *newsock;
	struct sockaddr *addr;
	socklen_t addrlen;
359
360
361
362
363
364
365
366

367
368
369
370
371
372
373
374
375
376
377
378
379
380
351
352
353
354
355
356
357

358
359
360
361
362
363


364
365
366
367
368
369
370







-
+





-
-







	newsock->sock = s;
	newsock->saddr = addr;
	newsock->saddr_len = addrlen;

	return newsock;
}

- enableKeepAlives: (BOOL)enable
- (void)setKeepAlivesEnabled: (BOOL)enable
{
	int v = enable;

	if (setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (char*)&v, sizeof(v)))
		@throw [OFSetOptionFailedException newWithClass: isa];

	return self;
}

- (OFString*)remoteAddress
{
	if (saddr == NULL || saddr_len == 0)
		@throw [OFInvalidArgumentException newWithClass: isa
						       selector: _cmd];
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416


417
418
419
420
421
422
423
424

425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
378
379
380
381
382
383
384



385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408


409
410

411
412
413
414
415
416
417
418
419
420
421


422
423
424
425
426
427
428
429
430
431







-
-
-



















+
+



-
-


-
+










-
-










			@throw [OFAddressTranslationFailedException
			    newWithClass: isa];

		return [OFString stringWithCString: node];
	} @finally {
		[self freeMemory: node];
	}

	/* Get rid of a warning, never reached anyway */
	assert(0);
#else
	char *node;

# ifdef OF_THREADS
	[mutex lock];

	@try {
# endif
		node = inet_ntoa(((struct sockaddr_in*)saddr)->sin_addr);

		if (node == NULL)
			@throw [OFAddressTranslationFailedException
			    newWithClass: isa];

		return [OFString stringWithCString: node];
# ifdef OF_THREADS
	} @finally {
		[mutex unlock];
	}
# endif
#endif

	/* Get rid of a warning, never reached anyway */
	assert(0);
# endif
#endif
}

- close
- (void)close
{
	if (sock == INVALID_SOCKET)
		@throw [OFNotConnectedException newWithClass: isa];

	close(sock);
	sock = INVALID_SOCKET;

	[self freeMemory: saddr];
	saddr = NULL;
	saddr_len = 0;

	return self;
}

- (void)dealloc
{
	if (sock != INVALID_SOCKET)
		[self close];

	[super dealloc];
}
@end

Modified src/OFThread.h from [25914ccb95] to [fb94c5b01e].

81
82
83
84
85
86
87

88
89
90


91
92
93
94
95
96
97
81
82
83
84
85
86
87
88
89


90
91
92
93
94
95
96
97
98







+

-
-
+
+







 *
 * The specified object is first retained and then the object stored before is
 * released. You can specify nil as object if you want the old object to be
 * released and don't want any new object for the TLS key.
 *
 * \param key The Thread Local Storage key
 * \param obj The object the Thread Local Storage key will be set to
 * \return The old object, autoreleased
 */
+ setObject: (OFObject*)obj
  forTLSKey: (OFTLSKey*)key;
+ (id)setObject: (OFObject*)obj
      forTLSKey: (OFTLSKey*)key;

/**
 * Returns the object for the specified Thread Local Storage key.
 *
 * \param key The Thread Local Storage key
 */
+ (id)objectForTLSKey: (OFTLSKey*)key;
145
146
147
148
149
150
151
152

153
154
155
156
157
158
159
146
147
148
149
150
151
152

153
154
155
156
157
158
159
160







-
+







 * or terminate has been called.
 */
- (void)handleTermination;

/**
 * Starts the thread.
 */
- start;
- (void)start;

/**
 * Joins a thread.
 *
 * \return The object returned by the main method of the thread.
 */
- (id)join;
171
172
173
174
175
176
177
178

179
180
181
182
183
184
185
186
187
188
189
190
191

192
172
173
174
175
176
177
178

179
180
181
182
183
184
185
186
187
188
189
190
191

192
193







-
+












-
+

 * \return A new autoreleased mutex.
 */
+ mutex;

/**
 * Locks the mutex.
 */
- lock;
- (void)lock;

/**
 * Tries to lock the mutex and returns a boolean whether the mutex could be
 * acquired.
 *
 * \return A boolean whether the mutex could be acquired
 */
- (BOOL)tryLock;

/**
 * Unlocks the mutex.
 */
- unlock;
- (void)unlock;
@end

Modified src/OFThread.m from [06743d152c] to [e64db843c5].

64
65
66
67
68
69
70
71
72


73
74
75
76
77
78
79
80
81
82

83
84
85
86
87
88
89
64
65
66
67
68
69
70


71
72
73
74
75
76
77
78
79



80
81
82
83
84
85
86
87







-
-
+
+







-
-
-
+







}

+ threadWithObject: (id)obj
{
	return [[[self alloc] initWithObject: obj] autorelease];
}

+ setObject: (OFObject*)obj
  forTLSKey: (OFTLSKey*)key
+ (id)setObject: (OFObject*)obj
      forTLSKey: (OFTLSKey*)key
{
	id old = of_tlskey_get(key->key);

	if (!of_tlskey_set(key->key, [obj retain]))
		@throw [OFInvalidArgumentException newWithClass: self
						       selector: _cmd];

	[old release];

	return self;
	return [old autorelease];
}

+ (id)objectForTLSKey: (OFTLSKey*)key
{
	return [[of_tlskey_get(key->key) retain] autorelease];
}

158
159
160
161
162
163
164
165

166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
156
157
158
159
160
161
162

163
164
165
166
167
168
169
170
171
172
173
174
175


176
177
178
179
180
181
182







-
+












-
-







	return nil;
}

- (void)handleTermination
{
}

- start
- (void)start
{
	if (running == OF_THREAD_RUNNING)
		@throw [OFThreadStillRunningException newWithClass: isa];

	[self retain];

	if (!of_thread_new(&thread, call_main, self)) {
		[self release];
		@throw [OFThreadStartFailedException newWithClass: isa];
	}

	running = OF_THREAD_RUNNING;

	return self;
}

- (id)join
{
	if (running == OF_THREAD_NOT_RUNNING || !of_thread_join(thread))
		@throw [OFThreadJoinFailedException newWithClass: isa];

299
300
301
302
303
304
305
306

307
308
309
310
311
312
313
314
315
316
317
318
319

320
321
322
323
324
325
326
327
328
329
330
331
332
333
295
296
297
298
299
300
301

302
303
304
305


306
307
308
309
310
311
312

313
314
315
316


317
318
319
320
321
322
323
324
325







-
+



-
-







-
+



-
-









		[self dealloc];
		@throw [OFInitializationFailedException newWithClass: c];
	}

	return self;
}

- lock
- (void)lock
{
	if (!of_mutex_lock(&mutex))
		@throw [OFMutexLockFailedException newWithClass: isa];

	return self;
}

- (BOOL)tryLock
{
	return of_mutex_trylock(&mutex);
}

- unlock
- (void)unlock
{
	if (!of_mutex_unlock(&mutex))
		@throw [OFMutexUnlockFailedException newWithClass: isa];

	return self;
}

- (void)dealloc
{
	of_mutex_free(&mutex);

	[super dealloc];
}
@end

Modified src/OFXMLElement.h from [249d4d5c34] to [4b04a1a1a1].

131
132
133
134
135
136
137
138

139
140
141
142
143
144
145
146
147


148
149
150
151
152
153
154

155
156
157
158
159
160
161
162
163
164
165
166

167
131
132
133
134
135
136
137

138
139
140
141
142
143
144
145


146
147
148
149
150
151
152
153

154
155
156
157
158
159
160
161
162
163
164
165

166
167







-
+







-
-
+
+






-
+











-
+

- (OFString*)string;

/**
 * Adds the specified attribute.
 *
 * \param attr The attribute to add
 */
- addAttribute: (OFXMLAttribute*)attr;
- (void)addAttribute: (OFXMLAttribute*)attr;

/**
 * Adds the specified attribute with the specified value.
 *
 * \param name The name of the attribute
 * \param value The value of the attribute
 */
- addAttributeWithName: (OFString*)name
	   stringValue: (OFString*)value;
- (void)addAttributeWithName: (OFString*)name
		 stringValue: (OFString*)value;

/**
 * Adds a child to the OFXMLElement.
 *
 * \param child Another OFXMLElement which is added as a child
 */
- addChild: (OFXMLElement*)child;
- (void)addChild: (OFXMLElement*)child;
@end

/**
 * \brief A category to escape strings for use in an XML document.
 */
@interface OFString (OFXMLEscaping)
/**
 * Escapes a string for use in an XML document.
 *
 * \return A new autoreleased string
 */
- stringByXMLEscaping;
- (OFString*)stringByXMLEscaping;
@end

Modified src/OFXMLElement.m from [a65668b812] to [748986426d].

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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276

277
278
279
280
281
282
283
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
252
253
254
255


256
257
258
259
260
261
262
263
264
265
266
267
268
269

270
271
272
273
274
275
276
277







-
+







-
+
-
-
+
-
-
-
+
+







-
-





-
+









-
-














-
+







					   length: len];
	} @finally {
		[self freeMemory: str_c];
	}
	return ret;
}

- addAttribute: (OFXMLAttribute*)attr
- (void)addAttribute: (OFXMLAttribute*)attr
{
	if (attrs == nil)
		attrs = [[OFMutableArray alloc] init];

	/* FIXME: Prevent having it twice! */

	[attrs addObject: attr];

}
	return self;
}


- addAttributeWithName: (OFString*)name_
	   stringValue: (OFString*)value
- (void)addAttributeWithName: (OFString*)name_
		 stringValue: (OFString*)value
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	[self addAttribute: [OFXMLAttribute attributeWithName: name_
						       prefix: nil
						    namespace: nil
						  stringValue: value]];
	[pool release];

	return self;
}

/* TODO: Replace attribute */
/* TODO: Remove attribute */

- addChild: (OFXMLElement*)child
- (void)addChild: (OFXMLElement*)child
{
	if (stringval != nil)
		@throw [OFInvalidArgumentException newWithClass: isa
						       selector: _cmd];

	if (children == nil)
		children = [[OFMutableArray alloc] init];

	[children addObject: child];

	return self;
}

- (void)dealloc
{
	[name release];
	[attrs release];
	[stringval release];
	[children release];

	[super dealloc];
}
@end

@implementation OFString (OFXMLEscaping)
- stringByXMLEscaping
- (OFString*)stringByXMLEscaping
{
	char *str_c, *append, *tmp;
	size_t len, append_len;
	size_t i, j;
	OFString *ret;

	j = 0;

Modified src/OFXMLParser.h from [ea9ce9aac1] to [28112670e4].

146
147
148
149
150
151
152
153

154
155
156
157
158
159
160
161
162


163
164
165
166
167
168
169
170
171
172

173
174
175
176
177
178
179

180

181
182
183
184
146
147
148
149
150
151
152

153
154
155
156
157
158
159
160


161
162
163
164
165
166
167
168
169
170
171

172
173
174
175
176
177
178
179
180

181
182
183
184
185







-
+







-
-
+
+









-
+







+
-
+




- (id)delegate;

/**
 * Sets the delegate the OFXMLParser should use.
 *
 * \param delegate The delegate to use
 */
- setDelegate: (OFObject <OFXMLParserDelegate>*)delegate;
- (void)setDelegate: (OFObject <OFXMLParserDelegate>*)delegate;

/**
 * Parses a buffer with the specified size.
 *
 * \param buf The buffer to parse
 * \param size The size of the buffer
 */
- parseBuffer: (const char*)buf
     withSize: (size_t)size;
- (void)parseBuffer: (const char*)buf
	   withSize: (size_t)size;
@end

/**
 * \brief A category for unescaping XML in strings.
 */
@interface OFString (OFXMLUnescaping)
/**
 * Unescapes XML in the string.
 */
- stringByXMLUnescaping;
- (OFString*)stringByXMLUnescaping;

/**
 * Unescapes XML in the string and uses the specified handler for unknown
 * entities.
 *
 * \param h An OFXMLUnescapingDelegate as a handler for unknown entities
 */
- (OFString*)stringByXMLUnescapingWithHandler:
- stringByXMLUnescapingWithHandler: (OFObject <OFXMLUnescapingDelegate>*)h;
    (OFObject <OFXMLUnescapingDelegate>*)h;
@end

@interface OFObject (OFXMLParserDelegate) <OFXMLParserDelegate>
@end

Modified src/OFXMLParser.m from [d44a79d5fd] to [6ad29027d7].

119
120
121
122
123
124
125
126

127
128
129
130
131

132
133

134
135
136


137
138
139
140
141
142
143
119
120
121
122
123
124
125

126
127
128
129
130

131


132



133
134
135
136
137
138
139
140
141







-
+




-
+
-
-
+
-
-
-
+
+







}

- (id)delegate
{
	return [[delegate retain] autorelease];
}

- setDelegate: (OFObject <OFXMLParserDelegate>*)delegate_
- (void)setDelegate: (OFObject <OFXMLParserDelegate>*)delegate_
{
	[delegate_ retain];
	[delegate release];
	delegate = delegate_;

}
	return self;
}


- parseBuffer: (const char*)buf
     withSize: (size_t)size
- (void)parseBuffer: (const char*)buf
	   withSize: (size_t)size
{
	OFAutoreleasePool *pool;
	size_t i, last, len;

	last = 0;

	for (i = 0; i < size; i++) {
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504

505
506
507
508

509

510
511
512
513
514
515
516
483
484
485
486
487
488
489


490
491
492
493
494
495
496
497
498
499

500
501
502
503
504
505

506
507
508
509
510
511
512
513







-
-










-
+




+
-
+







	}

	len = size - last;
	/* In OF_XMLPARSER_IN_TAG, there can be only spaces */
	if (len > 0 && state != OF_XMLPARSER_IN_TAG)
		[cache appendCString: buf + last
			  withLength: len];

	return self;
}

- (OFString*)foundUnknownEntityNamed: (OFString*)entity
{
	return [delegate xmlParser: self
	   foundUnknownEntityNamed: entity];
}
@end

@implementation OFString (OFXMLUnescaping)
- stringByXMLUnescaping
- (OFString*)stringByXMLUnescaping
{
	return [self stringByXMLUnescapingWithHandler: nil];
}

- (OFString*)stringByXMLUnescapingWithHandler:
- stringByXMLUnescapingWithHandler: (OFObject <OFXMLUnescapingDelegate>*)h
    (OFObject <OFXMLUnescapingDelegate>*)h
{
	size_t i, last;
	BOOL in_entity;
	OFMutableString *ret;

	last = 0;
	in_entity = NO;

Modified tests/OFArrayTests.m from [004dd7f704] to [0fbf78cb38].

45
46
47
48
49
50
51
52
53


54
55
56


57
58
59
60
61
62
63
45
46
47
48
49
50
51


52
53
54


55
56
57
58
59
60
61
62
63







-
-
+
+

-
-
+
+







	TEST(@"+[arrayWithCArray:]", (a[1] = [OFArray arrayWithCArray: c_ary]))

	TEST(@"+[arrayWithCArray:length:]",
	    (a[2] = [OFArray arrayWithCArray: c_ary
				      length: 3]) &&
	    [a[2] isEqual: a[1]])

	TEST(@"-[addObject:]", [m[0] addObject: c_ary[0]] &&
	    [m[0] addObject: c_ary[2]])
	TEST(@"-[addObject:]", R([m[0] addObject: c_ary[0]]) &&
	    R([m[0] addObject: c_ary[2]]))

	TEST(@"-[addObject:atIndex:]", [m[0] addObject: c_ary[1]
					       atIndex: 1])
	TEST(@"-[addObject:atIndex:]", R([m[0] addObject: c_ary[1]
						 atIndex: 1]))

	TEST(@"-[count]", [m[0] count] == 3 && [a[0] count] == 3 &&
	    [a[1] count] == 3)

	TEST(@"-[isEqual:]", [m[0] isEqual: a[0]] && [a[0] isEqual: a[1]])

	TEST(@"-[objectAtIndex:]",
73
74
75
76
77
78
79
80
81


82
83
84
85
86
87
88


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

102
103
104

105
106
107
108

109
110
111
112
113
114
115
116
117


118
119
120
121
122
123
124
73
74
75
76
77
78
79


80
81
82
83
84
85
86


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

101
102
103

104
105
106
107

108
109
110
111
112
113
114
115


116
117
118
119
120
121
122
123
124







-
-
+
+





-
-
+
+












-
+


-
+



-
+







-
-
+
+








	TEST(@"-[indexOfObject:]", [a[0] indexOfObject: c_ary[1]] == 1)

	TEST(@"-[indexOfObjectIdenticalTo:]",
	    [a[1] indexOfObjectIdenticalTo: c_ary[1]] == 1)

	TEST(@"-[replaceObject:withObject:]",
	    [m[0] replaceObject: c_ary[1]
		     withObject: c_ary[0]] &&
	    R([m[0] replaceObject: c_ary[1]
		       withObject: c_ary[0]]) &&
	    [[m[0] objectAtIndex: 0] isEqual: c_ary[0]] &&
	    [[m[0] objectAtIndex: 1] isEqual: c_ary[0]] &&
	    [[m[0] objectAtIndex: 2] isEqual: c_ary[2]])

	TEST(@"-[replaceObject:identicalTo:]",
	    [m[0] replaceObjectIdenticalTo: c_ary[0]
				withObject: c_ary[1]] &&
	    R([m[0] replaceObjectIdenticalTo: c_ary[0]
				  withObject: c_ary[1]]) &&
	    [[m[0] objectAtIndex: 0] isEqual: c_ary[1]] &&
	    [[m[0] objectAtIndex: 1] isEqual: c_ary[1]] &&
	    [[m[0] objectAtIndex: 2] isEqual: c_ary[2]])

	TEST(@"-[replaceObjectAtIndex:withObject:]",
	    [m[0] replaceObjectAtIndex: 0
			    withObject: c_ary[0]] &&
	    [[m[0] objectAtIndex: 0] isEqual: c_ary[0]] &&
	    [[m[0] objectAtIndex: 1] isEqual: c_ary[1]] &&
	    [[m[0] objectAtIndex: 2] isEqual: c_ary[2]])

	TEST(@"-[removeObject:]",
	    [m[0] removeObject: c_ary[1]] && [m[0] count] == 2)
	    R([m[0] removeObject: c_ary[1]]) && [m[0] count] == 2)

	TEST(@"-[removeObjectIdenticalTo:]",
	    [m[0] removeObjectIdenticalTo: c_ary[2]] && [m[0] count] == 1)
	    R([m[0] removeObjectIdenticalTo: c_ary[2]]) && [m[0] count] == 1)

	[m[0] addObject: c_ary[0]];
	[m[0] addObject: c_ary[1]];
	TEST(@"-[removeNObjects:]", [m[0] removeNObjects: 2] &&
	TEST(@"-[removeNObjects:]", R([m[0] removeNObjects: 2]) &&
	    [m[0] count] == 1 && [[m[0] objectAtIndex: 0] isEqual: c_ary[0]])

	m[1] = [[a[0] mutableCopy] autorelease];
	TEST(@"-[removeObjectAtIndex:]", [m[1] removeObjectAtIndex: 1] &&
	    [m[1] count] == 2 && [[m[1] objectAtIndex: 1] isEqual: c_ary[2]])

	m[1] = [[a[0] mutableCopy] autorelease];
	TEST(@"-[removeNObjects:atIndex:]", [m[1] removeNObjects: 2
							 atIndex: 0] &&
	TEST(@"-[removeNObjects:atIndex:]", R([m[1] removeNObjects: 2
							   atIndex: 0]) &&
	    [m[1] count] == 1 && [[m[1] objectAtIndex: 0] isEqual: c_ary[2]])

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

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

Modified tests/OFDataArrayTests.m from [106dfbcd0f] to [5734e9a210].

34
35
36
37
38
39
40
41
42


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57


58
59

60
61
62
63
64
65
66
67
68
69
70

71
72
73
74
75
76
77
78
79
80
81

82
83
84
85
86
87


88
89
90
91
92
93



94
95
96
97
98
99


100
101
102
103
104
105
106
34
35
36
37
38
39
40


41
42
43
44
45
46
47
48
49
50
51
52
53
54
55


56
57
58

59
60
61
62
63
64
65
66
67
68
69

70
71
72
73
74
75
76
77
78
79
80

81
82
83
84
85


86
87
88
89
90



91
92
93
94
95
96
97


98
99
100
101
102
103
104
105
106







-
-
+
+













-
-
+
+

-
+










-
+










-
+




-
-
+
+



-
-
-
+
+
+




-
-
+
+







	    (array[0] = [class dataArrayWithItemSize: 4096]))

	data[0] = [array[0] allocMemoryWithSize: 4096];
	data[1] = [array[0] allocMemoryWithSize: 4096];
	memset(data[0], 0xFF, 4096);
	memset(data[1], 0x42, 4096);

	TEST(@"-[addItem:]", [array[0] addItem: data[0]] &&
	    [array[0] addItem: data[1]])
	TEST(@"-[addItem:]", R([array[0] addItem: data[0]]) &&
	    R([array[0] addItem: data[1]]))

	TEST(@"-[itemAtIndex:]",
	    !memcmp([array[0] itemAtIndex: 0], data[0], 4096) &&
	    !memcmp([array[0] itemAtIndex: 1], data[1], 4096))

	TEST(@"-[lastItem]", !memcmp([array[0] lastItem], data[1], 4096))

	TEST(@"-[count]", [array[0] count] == 2)

	other = (class == [OFDataArray class]
	    ? [OFBigDataArray class]
	    : [OFDataArray class]);
	TEST(@"-[isEqual:]", (array[1] = [other dataArrayWithItemSize: 4096]) &&
	    [array[1] addNItems: [array[0] count]
		     fromCArray: [array[0] cArray]] &&
	    R([array[1] addNItems: [array[0] count]
		       fromCArray: [array[0] cArray]]) &&
	    [array[1] isEqual: array[0]] &&
	    [array[1] removeNItems: 1] && ![array[0] isEqual: array[1]])
	    R([array[1] removeNItems: 1]) && ![array[0] isEqual: array[1]])

	TEST(@"-[copy]", (array[1] = [[array[0] copy] autorelease]) &&
	    [array[0] isEqual: array[1]])

	array[2] = [OFDataArray dataArrayWithItemSize: 1];
	array[3] = [OFDataArray dataArrayWithItemSize: 1];
	[array[2] addItem: "a"];
	[array[2] addItem: "a"];
	[array[3] addItem: "z"];
	TEST(@"-[compare]", [array[0] compare: array[1]] == 0 &&
	    [array[1] removeNItems: 1] &&
	    R([array[1] removeNItems: 1]) &&
	    [array[0] compare: array[1]] == OF_ORDERED_DESCENDING &&
	    [array[1] compare: array[0]] == OF_ORDERED_ASCENDING &&
	    [array[2] compare: array[3]] == OF_ORDERED_ASCENDING)

	TEST(@"-[hash]", [array[0] hash] == 0xC54621B6)

	array[0] = [class dataArrayWithItemSize: 1];
	[array[0] addNItems: 6
		 fromCArray: "abcdef"];

	TEST(@"-[removeNItems:]", [array[0] removeNItems: 1] &&
	TEST(@"-[removeNItems:]", R([array[0] removeNItems: 1]) &&
	    [array[0] count] == 5 &&
	    !memcmp([array[0] cArray], "abcde", 5))

	TEST(@"-[removeNItems:atIndex:]",
	    [array[0] removeNItems: 2
			   atIndex: 1] && [array[0] count] == 3 &&
	    R([array[0] removeNItems: 2
			     atIndex: 1]) && [array[0] count] == 3 &&
	    !memcmp([array[0] cArray], "ade", 3))

	TEST(@"-[addNItems:atIndex:]",
	    [array[0] addNItems: 2
		     fromCArray: "bc"
			atIndex: 1] && [array[0] count] == 5 &&
	    R([array[0] addNItems: 2
		       fromCArray: "bc"
			  atIndex: 1]) && [array[0] count] == 5 &&
	    !memcmp([array[0] cArray], "abcde", 5))

	TEST(@"Building strings",
	    (array[0] = [class dataArrayWithItemSize: 1]) &&
	    [array[0] addNItems: 6
		     fromCArray: (void*)str] && [array[0] addItem: ""] &&
	    R([array[0] addNItems: 6
		       fromCArray: (void*)str]) && R([array[0] addItem: ""]) &&
	    !strcmp([array[0] cArray], str))

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

	EXPECT_EXCEPTION(@"Detect out of range in -[addNItems:fromCArray:]",
	    OFOutOfRangeException, [array[0] addNItems: SIZE_MAX

Modified tests/OFDictionaryTests.m from [3031e7357f] to [09fd546f0f].

124
125
126
127
128
129
130
131
132


133
134
135


136
137
138
139
140
141
142
124
125
126
127
128
129
130


131
132
133


134
135
136
137
138
139
140
141
142







-
-
+
+

-
-
+
+








	dict2 = dict;
	TEST(@"-[mutableCopy]",
	    (dict = [[dict mutableCopy] autorelease]) &&
	    [dict count] == [dict2 count] &&
	    [[dict objectForKey: keys[0]] isEqual: values[0]] &&
	    [[dict objectForKey: keys[1]] isEqual: values[1]] &&
	    [dict setObject: @"value3"
		     forKey: @"key3"] &&
	    R([dict setObject: @"value3"
		       forKey: @"key3"]) &&
	    [[dict objectForKey: @"key3"] isEqual: @"value3"] &&
	    [dict setObject: @"foo"
		     forKey: keys[0]] &&
	    [[dict setObject: @"foo"
		      forKey: keys[0]] isEqual: values[0]] &&
	    [[dict objectForKey: keys[0]] isEqual: @"foo"])

	TEST(@"-[removeObjectForKey:]",
	    [dict removeObjectForKey: keys[0]] &&
	    [dict objectForKey: keys[0]] == nil)

	[dict setObject: @"foo"

Modified tests/OFListTests.m from [20f31495db] to [f36ba55454].

41
42
43
44
45
46
47
48

49
50

51
52
53
54
55
56
57
41
42
43
44
45
46
47

48
49

50
51
52
53
54
55
56
57







-
+

-
+







	TEST(@"-[first]->next",
	    [[list first]->next->object isEqual: strings[1]])

	TEST(@"-[last]", [[list last]->object isEqual: strings[2]])

	TEST(@"-[last]->prev", [[list last]->prev->object isEqual: strings[1]])

	TEST(@"-[remove:]", [list remove: [list last]] &&
	TEST(@"-[remove:]", R([list remove: [list last]]) &&
	    [[list last]->object isEqual: strings[1]] &&
	    [list remove: [list first]] &&
	    R([list remove: [list first]]) &&
	    [[list first]->object isEqual: [list last]->object])

	TEST(@"-[insert:before:]", [list insert: strings[0]
					 before: [list last]] &&
	    [[list last]->prev->object isEqual: strings[0]])


Modified tests/OFObjectTests.m from [d56cd335e9] to [961f87c192].

28
29
30
31
32
33
34
35

36
37
38
39
40
41
42
43

44

45
46
47
48
49
50
51
28
29
30
31
32
33
34

35
36
37
38
39
40
41
42
43
44

45
46
47
48
49
50
51
52







-
+








+
-
+








	EXPECT_EXCEPTION(@"Detect freeing of memory not allocated by object",
	    OFMemoryNotPartOfObjectException, [obj freeMemory: (void*)1])

	TEST(@"Allocating 4096 bytes",
	    (p = [obj allocMemoryWithSize: 4096]) != NULL)

	TEST(@"Freeing memory", [obj freeMemory: p])
	TEST(@"Freeing memory", R([obj freeMemory: p]))

	EXPECT_EXCEPTION(@"Detect freeing of memory twice",
	    OFMemoryNotPartOfObjectException, [obj freeMemory: p])

	TEST(@"Allocating and freeing 4096 bytes 3 times",
	    (p = [obj allocMemoryWithSize: 4096]) != NULL &&
	    (q = [obj allocMemoryWithSize: 4096]) != NULL &&
	    (r = [obj allocMemoryWithSize: 4096]) != NULL &&
	    R([obj freeMemory: p]) && R([obj freeMemory: q]) &&
	    [obj freeMemory: p] && [obj freeMemory: q] && [obj freeMemory: r])
	    R([obj freeMemory: r]))

	EXPECT_EXCEPTION(@"Detect out of memory on alloc",
	    OFOutOfMemoryException, [obj allocMemoryWithSize: SIZE_MAX])

	EXPECT_EXCEPTION(@"Detect out of memory on resize",
	    OFOutOfMemoryException,
	    {

Modified tests/OFStringTests.m from [ef1e54d79a] to [de363dd9e3].

70
71
72
73
74
75
76
77
78


79
80
81
82
83
84
85
86
87
88
89
90
91
92

93
94
95
96
97


98
99
100


101
102
103
104
105
106
107
108
109
110
111
112
113
114


115
116
117
118
119
120
121
122
123
124
125


126
127
128
129
130
131
132
70
71
72
73
74
75
76


77
78
79
80
81
82
83
84
85
86
87
88
89
90
91

92
93
94
95


96
97
98


99
100
101
102
103
104
105
106
107
108
109
110
111
112


113
114
115
116
117
118
119
120
121
122
123


124
125
126
127
128
129
130
131
132







-
-
+
+













-
+



-
-
+
+

-
-
+
+












-
-
+
+









-
-
+
+







	    [@"ß" caseInsensitiveCompare: @"→"] == OF_ORDERED_ASCENDING &&
	    [@"AA" caseInsensitiveCompare: @"z"] == OF_ORDERED_ASCENDING)

	TEST(@"-[hash] is the same if -[isEqual:] is YES",
	    [s[0] hash] == [s[2] hash])

	TEST(@"-[appendString:] and -[appendCString:]",
	    [s[1] appendCString: "1𝄞"] && [s[1] appendString: @"3"] &&
	    [[s[0] appendString: s[1]] isEqual: @"täs€1𝄞3"])
	    R([s[1] appendCString: "1𝄞"]) && R([s[1] appendString: @"3"]) &&
	    R([s[0] appendString: s[1]]) && [s[0] isEqual: @"täs€1𝄞3"])

	TEST(@"-[length]", [s[0] length] == 7)
	TEST(@"-[cStringLength]", [s[0] cStringLength] == 13)
	TEST(@"-[hash]", [s[0] hash] == 0x8AC1EEF6)

	TEST(@"-[characterAtIndex:]", [s[0] characterAtIndex: 0] == 't' &&
	    [s[0] characterAtIndex: 1] == 0xE4 &&
	    [s[0] characterAtIndex: 3] == 0x20AC &&
	    [s[0] characterAtIndex: 5] == 0x1D11E)

	EXPECT_EXCEPTION(@"Detect out of range in -[characterAtIndex:]",
	    OFOutOfRangeException, [s[0] characterAtIndex: 7])

	TEST(@"-[reverse]", [[s[0] reverse] isEqual: @"3𝄞1€sät"])
	TEST(@"-[reverse]", R([s[0] reverse]) && [s[0] isEqual: @"3𝄞1€sät"])

	s[1] = [OFMutableString stringWithString: @"abc"];

	TEST(@"-[upper]", [[s[0] upper] isEqual: @"3𝄞1€SÄT"] &&
	    [[s[1] upper] isEqual: @"ABC"])
	TEST(@"-[upper]", R([s[0] upper]) && [s[0] isEqual: @"3𝄞1€SÄT"] &&
	    R([s[1] upper]) && [s[1] isEqual: @"ABC"])

	TEST(@"-[lower]", [[s[0] lower] isEqual: @"3𝄞1€sät"] &&
	    [[s[1] lower] isEqual: @"abc"])
	TEST(@"-[lower]", R([s[0] lower]) && [s[0] isEqual: @"3𝄞1€sät"] &&
	    R([s[1] lower]) && [s[1] isEqual: @"abc"])

	TEST(@"+[stringWithCString:length:]",
	    (s[0] = [OFMutableString stringWithCString: "foobar"
					      length: 3]) &&
	    [s[0] isEqual: @"foo"])

	TEST(@"+[stringWithContentsOfFile:encoding]", (s[1] = [OFString
	    stringWithContentsOfFile: @"testfile.txt"
			    encoding: OF_STRING_ENCODING_ISO_8859_1]) &&
	    [s[1] isEqual: @"testäöü"])

	TEST(@"-[appendCStringWithLength:]",
	    [[s[0] appendCString: "foobarqux" + 3
		      withLength: 3] isEqual: @"foobar"])
	    R([s[0] appendCString: "foobarqux" + 3
		       withLength: 3]) && [s[0] isEqual: @"foobar"])

	EXPECT_EXCEPTION(@"Detection of invalid UTF-8 encoding #1",
	    OFInvalidEncodingException,
	    [OFString stringWithCString: "\xE0\x80"])
	EXPECT_EXCEPTION(@"Detection of invalid UTF-8 encoding #2",
	    OFInvalidEncodingException,
	    [OFString stringWithCString: "\xF0\x80\x80\xC0"])

	TEST(@"-[reverse] on UTF-8 strings",
	    (s[0] = [[OFMutableString stringWithCString: "äöü€𝄞"] reverse]) &&
	    [s[0] isEqual: @"𝄞€üöä"])
	    (s[0] = [OFMutableString stringWithCString: "äöü€𝄞"]) &&
	    R([s[0] reverse]) && [s[0] isEqual: @"𝄞€üöä"])

	TEST(@"Conversion of ISO 8859-1 to UTF-8",
	    [[OFString stringWithCString: "\xE4\xF6\xFC"
				encoding: OF_STRING_ENCODING_ISO_8859_1]
	    isEqual: @"äöü"])

	TEST(@"Conversion of ISO 8859-15 to UTF-8",
142
143
144
145
146
147
148




149
150

151
152

153
154

155
156
157


158
159
160
161
162
163
164
165
166
167
142
143
144
145
146
147
148
149
150
151
152
153

154
155

156
157

158
159


160
161



162
163
164
165
166
167
168







+
+
+
+

-
+

-
+

-
+

-
-
+
+
-
-
-







				encoding: OF_STRING_ENCODING_WINDOWS_1252]
	    isEqual: @"€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ"])

	TEST(@"+[stringWithFormat:]",
	    [(s[0] = [OFMutableString stringWithFormat: @"%s: %d", "test", 123])
	    isEqual: @"test: 123"])

	TEST(@"-[appendFormat:]",
	    R(([s[0] appendFormat: @"%02X", 15])) &&
	    [s[0] isEqual: @"test: 1230F"])

	TEST(@"+[stringWithPath:]",
	    (s[1] = [OFString stringWithPath: @"foo", @"bar", @"baz", nil]) &&
	    (s[0] = [OFString stringWithPath: @"foo", @"bar", @"baz", nil]) &&
#ifndef _WIN32
	    [s[1] isEqual: @"foo/bar/baz"] &&
	    [s[0] isEqual: @"foo/bar/baz"] &&
#else
	    [s[1] isEqual: @"foo\\bar\\baz"] &&
	    [s[0] isEqual: @"foo\\bar\\baz"] &&
#endif
	    (s[1] = [OFString stringWithPath: @"foo", nil]) &&
	    [s[1] isEqual: @"foo"])
	    (s[0] = [OFString stringWithPath: @"foo", nil]) &&
	    [s[0] isEqual: @"foo"])

	TEST(@"-[appendFormat:]",
	    [([s[0] appendFormat: @"%02X", 15]) isEqual: @"test: 1230F"])

	TEST(@"-[indexOfFirstOccurrenceOfString:]",
	    [@"𝄞öö" indexOfFirstOccurrenceOfString: @"öö"] == 1 &&
	    [@"𝄞öö" indexOfFirstOccurrenceOfString: @"ö"] == 1 &&
	    [@"𝄞öö" indexOfFirstOccurrenceOfString: @"𝄞"] == 0 &&
	    [@"𝄞öö" indexOfFirstOccurrenceOfString: @"x"] == SIZE_MAX)

267
268
269
270
271
272
273
274
275


276
277
278


279
280
281
282
283
284
285
268
269
270
271
272
273
274


275
276
277


278
279
280
281
282
283
284
285
286







-
-
+
+

-
-
+
+







	    @"#1", OFInvalidEncodingException, [@"foo%bar" stringByURLDecoding])
	EXPECT_EXCEPTION(@"Detect invalid encoding in -[stringByURLDecoding] "
	    @"#2", OFInvalidEncodingException,
	    [@"foo%FFbar" stringByURLDecoding])

	TEST(@"-[removeCharactersFromIndex:toIndex:]",
	    (s[0] = [OFMutableString stringWithString: @"𝄞öööbä€"]) &&
	    [s[0] removeCharactersFromIndex: 1
				    toIndex: 4] &&
	    R([s[0] removeCharactersFromIndex: 1
				      toIndex: 4]) &&
	    [s[0] isEqual: @"𝄞bä€"] &&
	    [s[0] removeCharactersFromIndex: 0
				    toIndex: 4] &&
	    R([s[0] removeCharactersFromIndex: 0
				      toIndex: 4]) &&
	    [s[0] isEqual: @""])

	EXPECT_EXCEPTION(@"Detect OoR in "
	    @"-[removeCharactersFromIndex:toIndex:] #1", OFOutOfRangeException,
	    {
		s[0] = [OFMutableString stringWithString: @"𝄞öö"];
		[s[0] substringFromIndex: 2
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308









309
310
311

312

313
314

315
316
317

318

319
320

321
322
323
324


325
326


327
328
329

330
331
332
333
334
335
336
295
296
297
298
299
300
301








302
303
304
305
306
307
308
309
310
311
312
313
314

315
316

317
318
319
320
321

322
323

324
325
326
327

328
329
330

331
332
333
334

335
336
337
338
339
340
341
342







-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+



+
-
+

-
+



+
-
+

-
+



-
+
+

-
+
+


-
+







	EXPECT_EXCEPTION(@"Detect s > e in "
	    @"-[removeCharactersFromIndex:toIndex:]",
	    OFInvalidArgumentException,
	    [s[0] substringFromIndex: 2
			     toIndex: 0])

	TEST(@"-[replaceOccurrencesOfString:withString:]",
	    [[[OFMutableString stringWithString: @"asd fo asd fofo asd"]
	    replaceOccurrencesOfString: @"fo"
			    withString: @"foo"]
	    isEqual: @"asd foo asd foofoo asd"] &&
	    [[[OFMutableString stringWithString: @"XX"]
	    replaceOccurrencesOfString: @"X"
			    withString: @"XX"]
	    isEqual: @"XXXX"])
	    (s[0] = [OFMutableString stringWithString:
	    @"asd fo asd fofo asd"]) &&
	    R([s[0] replaceOccurrencesOfString: @"fo"
				    withString: @"foo"]) &&
	    [s[0] isEqual: @"asd foo asd foofoo asd"] &&
	    (s[0] = [OFMutableString stringWithString: @"XX"]) &&
	    R([s[0] replaceOccurrencesOfString: @"X"
				    withString: @"XX"]) &&
	    [s[0] isEqual: @"XXXX"])

	TEST(@"-[removeLeadingWhitespaces]",
	    (s[0] = [OFMutableString stringWithString: whitespace[0]]) &&
	    R([s[0] removeLeadingWhitespaces]) &&
	    [[s[0] removeLeadingWhitespaces] isEqual: @"asd  \t \t\t\r\n"] &&
	    [s[0] isEqual: @"asd  \t \t\t\r\n"] &&
	    (s[0] = [OFMutableString stringWithString: whitespace[1]]) &&
	    [[s[0] removeLeadingWhitespaces] isEqual: @""])
	    R([s[0] removeLeadingWhitespaces]) && [s[0] isEqual: @""])

	TEST(@"-[removeTrailingWhitespaces]",
	    (s[0] = [OFMutableString stringWithString: whitespace[0]]) &&
	    R([s[0] removeTrailingWhitespaces]) &&
	    [[s[0] removeTrailingWhitespaces] isEqual: @" \r \t\n\t \tasd"] &&
	    [s[0] isEqual: @" \r \t\n\t \tasd"] &&
	    (s[0] = [OFMutableString stringWithString: whitespace[1]]) &&
	    [[s[0] removeTrailingWhitespaces] isEqual: @""])
	    R([s[0] removeTrailingWhitespaces]) && [s[0] isEqual: @""])

	TEST(@"-[removeLeadingAndTrailingWhitespaces]",
	    (s[0] = [OFMutableString stringWithString: whitespace[0]]) &&
	    [[s[0] removeLeadingAndTrailingWhitespaces] isEqual: @"asd"] &&
	    R([s[0] removeLeadingAndTrailingWhitespaces]) &&
	    [s[0] isEqual: @"asd"] &&
	    (s[0] = [OFMutableString stringWithString: whitespace[1]]) &&
	    [[s[0] removeLeadingAndTrailingWhitespaces] isEqual: @""])
	    R([s[0] removeLeadingAndTrailingWhitespaces]) &&
	    [s[0] isEqual: @""])

	TEST(@"-[stringByXMLEscaping]",
	    (s[0] = [@"<hello> &world'\"!&" stringByXMLEscaping]) &&
	    (s[0] = (id)[@"<hello> &world'\"!&" stringByXMLEscaping]) &&
	    [s[0] isEqual: @"&lt;hello&gt; &amp;world&apos;&quot;!&amp;"])

	TEST(@"-[stringByXMLUnescaping]",
	    [[s[0] stringByXMLUnescaping] isEqual: @"<hello> &world'\"!&"] &&
	    [[@"&#x79;" stringByXMLUnescaping] isEqual: @"y"] &&
	    [[@"&#xe4;" stringByXMLUnescaping] isEqual: @"ä"] &&
	    [[@"&#8364;" stringByXMLUnescaping] isEqual: @"€"] &&
347
348
349
350
351
352
353
354
355


356
357
358
359
353
354
355
356
357
358
359


360
361
362
363
364
365







-
-
+
+




	EXPECT_EXCEPTION(@"Detect invalid entities in -[stringByXMLUnescaping] "
	    @"#5", OFInvalidEncodingException, [@"&#g;" stringByXMLUnescaping])
	EXPECT_EXCEPTION(@"Detect invalid entities in -[stringByXMLUnescaping] "
	    @"#6", OFInvalidEncodingException, [@"&#xg;" stringByXMLUnescaping])

	TEST(@"-[stringByXMLUnescapingWithHandler:]",
	    (h = [[[EntityHandler alloc] init] autorelease]) &&
	    (s[0] = [@"x&foo;y" stringByXMLUnescapingWithHandler: h]) &&
	    [s[0] isEqual: @"xbary"])
	    [[@"x&foo;y" stringByXMLUnescapingWithHandler: h]
	    isEqual: @"xbary"])

	[pool drain];
}
@end

Modified tests/OFTCPSocketTests.m from [a3ffe30f8b] to [bc5647851d].

41
42
43
44
45
46
47
48
49
50



51
52

53
54
55
56


57
58
59
60
61
62
63
41
42
43
44
45
46
47



48
49
50
51

52
53
54


55
56
57
58
59
60
61
62
63







-
-
-
+
+
+

-
+


-
-
+
+







	service = [OFString stringWithFormat: @"%d", port];

	TEST(@"+[socket]", (server = [OFTCPSocket socket]) &&
	    (client = [OFTCPSocket socket]))

	msg = [OFString stringWithFormat:
	    @"-[bindService:onNode:withFamily:] (port %d)", port];
	TEST(msg, [server bindService: service
			       onNode: @"localhost"
			   withFamily: AF_INET])
	TEST(msg, R([server bindService: service
				 onNode: @"localhost"
			     withFamily: AF_INET]))

	TEST(@"-[listen]", [server listen])
	TEST(@"-[listen]", R([server listen]))

	TEST(@"-[connectToService:onNode:]",
	    [client connectToService: service
			      onNode: @"localhost"])
	    R([client connectToService: service
				onNode: @"localhost"]))

	TEST(@"-[accept]", (accepted = [server accept]))

	TEST(@"-[remoteAddress]",
	    [[accepted remoteAddress] isEqual: @"127.0.0.1"])

	TEST(@"-[writeString:]", [client writeString: @"Hello!"])

Modified tests/OFThreadTests.m from [167800b2db] to [c4069ad79c].

39
40
41
42
43
44
45
46

47
48
49
50
51
52
53





54
55
56
57
58
59
60
39
40
41
42
43
44
45

46
47
48
49
50
51


52
53
54
55
56
57
58
59
60
61
62
63







-
+





-
-
+
+
+
+
+







	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	TestThread *t;
	OFTLSKey *key;

	TEST(@"+[threadWithObject:]",
	    (t = [TestThread threadWithObject: @"foo"]))

	TEST(@"-[start]", [t start])
	TEST(@"-[start]", R([t start]))

	TEST(@"-[join]", [[t join] isEqual: @"success"])

	TEST(@"OFTLSKey's +[tlsKey]", (key = [OFTLSKey tlsKey]))

	TEST(@"+[setObject:forTLSKey:]", [OFThread setObject: @"foo"
						   forTLSKey: key])
	TEST(@"+[setObject:forTLSKey:]",
	    R([OFThread setObject: @"setme"
			forTLSKey: key]) &&
	    [[OFThread setObject: @"foo"
		       forTLSKey: key] isEqual: @"setme"])

	TEST(@"+[objectForTLSKey:]",
	    [[OFThread objectForTLSKey: key] isEqual: @"foo"])

	[pool drain];
}
@end

Modified tests/OFXMLElementTests.m from [df22df1a10] to [a0a019906c].

34
35
36
37
38
39
40
41
42


43
44
45


46
47
48
49

50
51
52
53
54
34
35
36
37
38
39
40


41
42
43


44
45
46
47
48

49
50
51
52
53
54







-
-
+
+

-
-
+
+



-
+






	TEST(@"+[elementWithName:stringValue:]",
	    (elem[1] = [OFXMLElement elementWithName: @"foo"
					 stringValue: @"b&ar"]) &&
	    [[elem[1] string] isEqual: @"<foo>b&amp;ar</foo>"])

	TEST(@"-[addAttributeWithName:stringValue:]",
	    [elem[0] addAttributeWithName: @"foo"
			      stringValue: @"b&ar"] &&
	    R([elem[0] addAttributeWithName: @"foo"
				stringValue: @"b&ar"]) &&
	    [[elem[0] string] isEqual: @"<foo foo='b&amp;ar'/>"] &&
	    [elem[1] addAttributeWithName: @"foo"
			      stringValue: @"b&ar"] &&
	    R([elem[1] addAttributeWithName: @"foo"
				stringValue: @"b&ar"]) &&
	    [[elem[1] string] isEqual: @"<foo foo='b&amp;ar'>b&amp;ar</foo>"])

	TEST(@"-[addChild:]",
	    [elem[0] addChild: [OFXMLElement elementWithName: @"bar"]] &&
	    R([elem[0] addChild: [OFXMLElement elementWithName: @"bar"]]) &&
	    [[elem[0] string] isEqual: @"<foo foo='b&amp;ar'><bar/></foo>"])

	[pool drain];
}
@end

Modified tests/OFXMLParserTests.m from [23648ec2a7] to [d66604b68c].

190
191
192
193
194
195
196
197

198
199
200
201
202
203
204
190
191
192
193
194
195
196

197
198
199
200
201
202
203
204







-
+







	const char *str = "bar<foo:bar  bar='b&amp;az'  qux:qux=\" quux \">\r\n"
	    "foo&lt;bar<qux  >bar <baz name='' test='&foo;'/>  quxbar\r\n</qux>"
	    "</foo:bar><!-- foo bär-baz -->";
	size_t j, len;

	TEST(@"+[xmlParser]", (parser = [OFXMLParser xmlParser]))

	TEST(@"-[setDelegate:]", [parser setDelegate: self])
	TEST(@"-[setDelegate:]", R([parser setDelegate: self]))

	/* Simulate a stream where we only get chunks */
	len = strlen(str);

	for (j = 0; j < len; j+= 2) {
		if (j + 2 > len)
			[parser parseBuffer: str + j

Modified tests/TestsAppDelegate.h from [e3e2ff48b8] to [f1bc853ff8].

44
45
46
47
48
49
50

51
52
53
54
55
56
57
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58







+







				   inModule: module];	\
		else {					\
			[self outputFailure: test	\
				   inModule: module];	\
			fails++;			\
		}					\
	}
#define R(x) (x, 1)

@class OFString;

@interface TestsAppDelegate: OFObject
{
	int fails;
}