ObjFW  Check-in [f977192a23]

Overview
Comment:Get rid of -[*FromIndex:toIndex:].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: f977192a233e204da718f03e7f01b134645c684a13f9e3907ebf6fbc97d6c73e
User & Date: js on 2011-08-04 16:48:32
Other Links: manifest | tags
Context
2011-08-04
17:18
Add a note about usage of super to OFMutableCArray. check-in: dc8b06a5aa user: js tags: trunk
16:48
Get rid of -[*FromIndex:toIndex:]. check-in: f977192a23 user: js tags: trunk
2011-08-03
16:25
Fix a few OFString tests. check-in: cc93f51348 user: js tags: trunk
Changes

Modified src/OFConstantString.m from [4fa86efffd] to [5745a4d78a].

465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
465
466
467
468
469
470
471










472
473
474
475
476
477
478







-
-
-
-
-
-
-
-
-
-







{
	if (initialized != SIZE_MAX)
		[self finishInitialization];

	return [super containsString: string];
}

- (OFString*)substringFromIndex: (size_t)start
			toIndex: (size_t)end
{
	if (initialized != SIZE_MAX)
		[self finishInitialization];

	return [super substringFromIndex: start
				 toIndex: end];
}

- (OFString*)substringWithRange: (of_range_t)range
{
	if (initialized != SIZE_MAX)
		[self finishInitialization];

	return [super substringWithRange: range];
}

Modified src/OFHTTPRequest.m from [6cdf31afd0] to [205f214213].

280
281
282
283
284
285
286
287
288


289
290
291
292
293
294
295
280
281
282
283
284
285
286


287
288
289
290
291
292
293
294
295







-
-
+
+







		 */
		line = [sock readLine];
		if (![line hasPrefix: @"HTTP/1.0 "] &&
		    ![line hasPrefix: @"HTTP/1.1 "])
			@throw [OFInvalidServerReplyException
			    newWithClass: isa];

		status = (int)[[line substringFromIndex: 9
						toIndex: 12] decimalValue];
		status = (int)[[line substringWithRange:
		    of_range(9, 3)] decimalValue];

		serverHeaders = [OFMutableDictionary dictionary];

		while ((line = [sock readLine]) != nil) {
			OFString *key, *value;
			const char *line_c = [line cString], *tmp;

Modified src/OFMutableString.h from [903f2cd12d] to [7e1d229b63].

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










125
126
127
128












129
130
131
132
133
134
135







-
-
-
-
-
-
-
-
-
-




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







 */
- (void)insertString: (OFString*)string
	     atIndex: (size_t)index;

/**
 * \brief Deletes 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!
 */
- (void)deleteCharactersFromIndex: (size_t)start
			  toIndex: (size_t)end;

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

/**
 * \brief Replaces the characters at the specified range.
 *
 * \param start The index where the replacement should be started
 * \param end The index until which the characters should be replaced.
 *	      This points BEHIND the last character!
 * \param replacement The string to the replace the characters with
 */
- (void)replaceCharactersFromIndex: (size_t)start
			   toIndex: (size_t)end
			withString: (OFString*)replacement;

/**
 * \brief Replaces the characters at the specified range.
 *
 * \param range The range of the characters which should be replaced
 * \param replacement The string to the replace the characters with
 */
- (void)replaceCharactersInRange: (of_range_t)range

Modified src/OFMutableString.m from [3c8f4c2bc5] to [f5b0d569c9].

429
430
431
432
433
434
435
436
437
438





439
440
441
442
443
444
445
429
430
431
432
433
434
435



436
437
438
439
440
441
442
443
444
445
446
447







-
-
-
+
+
+
+
+







	    string->s->cStringLength);
	s->cString[newCStringLength] = '\0';

	s->cStringLength = newCStringLength;
	s->length += string->s->length;
}

- (void)deleteCharactersFromIndex: (size_t)start
			  toIndex: (size_t)end
{
- (void)deleteCharactersInRange: (of_range_t)range
{
	size_t start = range.start;
	size_t end = range.start + range.length;

	if (start > end)
		@throw [OFInvalidArgumentException newWithClass: isa
						       selector: _cmd];

	if (end > s->length)
		@throw [OFOutOfRangeException newWithClass: isa];

461
462
463
464
465
466
467
468
469
470
471
472
473
474

475
476

477


478
479
480
481
482
483
484
463
464
465
466
467
468
469







470


471
472
473
474
475
476
477
478
479
480
481







-
-
-
-
-
-
-
+
-
-
+

+
+







					 toSize: s->cStringLength + 1];
	} @catch (OFOutOfMemoryException *e) {
		/* We don't really care, as we only made it smaller */
		[e release];
	}
}

- (void)deleteCharactersInRange: (of_range_t)range
{
	[self deleteCharactersFromIndex: range.start
				toIndex: range.start + range.length];
}

- (void)replaceCharactersFromIndex: (size_t)start
- (void)replaceCharactersInRange: (of_range_t)range
			   toIndex: (size_t)end
			withString: (OFString*)replacement
		      withString: (OFString*)replacement
{
	size_t start = range.start;
	size_t end = range.start + range.length;
	size_t newCStringLength, newLength;

	if (start > end)
		@throw [OFInvalidArgumentException newWithClass: isa
						       selector: _cmd];

	if (end > s->length)
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
501
502
503
504
505
506
507








508
509
510
511
512
513
514







-
-
-
-
-
-
-
-







	    replacement->s->cStringLength);
	s->cString[newCStringLength] = '\0';

	s->cStringLength = newCStringLength;
	s->length = newLength;
}

- (void)replaceCharactersInRange: (of_range_t)range
		      withString: (OFString*)replacement
{
	[self replaceCharactersFromIndex: range.start
				 toIndex: range.start + range.length
			      withString: replacement];
}

- (void)replaceOccurrencesOfString: (OFString*)string
			withString: (OFString*)replacement
{
	const char *cString = [string cString];
	const char *replacementCString = [replacement cString];
	size_t cStringLength = string->s->cStringLength;
	size_t replacementCStringLength = replacement->s->cStringLength;

Modified src/OFString.h from [5a32f0ead2] to [f186440ce9].

570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
570
571
572
573
574
575
576









577
578
579
580
581
582
583







-
-
-
-
-
-
-
-
-








/**
 * \param string The string to search
 * \return Whether the string contains the specified string
 */
- (BOOL)containsString: (OFString*)string;

/**
 * \param start The index where the substring starts
 * \param end The index where the substring ends.
 *	      This points BEHIND the last character!
 * \return The substring as a new autoreleased OFString
 */
- (OFString*)substringFromIndex: (size_t)start
			toIndex: (size_t)end;

/**
 * \param range The range of the substring
 * \return The substring as a new autoreleased OFString
 */
- (OFString*)substringWithRange: (of_range_t)range;

/**

Modified src/OFString.m from [9e62f802e4] to [e16259c02d].

1394
1395
1396
1397
1398
1399
1400
1401

1402
1403
1404

1405
1406

1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1394
1395
1396
1397
1398
1399
1400

1401

1402

1403


1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419






1420
1421
1422
1423
1424
1425
1426







-
+
-

-
+
-
-
+















-
-
-
-
-
-







	for (i = 0; i <= s->cStringLength - cStringLength; i++)
		if (!memcmp(s->cString + i, cString, cStringLength))
			return YES;

	return NO;
}

- (OFString*)substringFromIndex: (size_t)start
- (OFString*)substringWithRange: (of_range_t)range
			toIndex: (size_t)end
{
	if (start > end)
	size_t start = range.start;
		@throw [OFInvalidArgumentException newWithClass: isa
						       selector: _cmd];
	size_t end = range.start + range.length;

	if (end > s->length)
		@throw [OFOutOfRangeException newWithClass: isa];

	if (s->isUTF8) {
		start = of_string_index_to_position(s->cString, start,
		    s->cStringLength);
		end = of_string_index_to_position(s->cString, end,
		    s->cStringLength);
	}

	return [OFString stringWithCString: s->cString + start
				    length: end - start];
}

- (OFString*)substringWithRange: (of_range_t)range
{
	return [self substringFromIndex: range.start
				toIndex: range.start + range.length];
}

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

	new = [OFMutableString stringWithString: self];
	[new appendString: string];

Modified src/OFXMLParser.m from [b84b15abc4] to [a92b6c9809].

72
73
74
75
76
77
78
79

80
81
82
83
84
85
86
87
72
73
74
75
76
77
78

79

80
81
82
83
84
85
86







-
+
-







			     withString: @"\n"];
	[ret replaceOccurrencesOfString: @"\r"
			     withString: @"\n"];

	if (cut > 0) {
		size_t length = [ret length];

		[ret deleteCharactersFromIndex: length - cut
		[ret deleteCharactersInRange: of_range(length - cut, cut)];
				       toIndex: length];
	}

	if (unescape)
		return [ret stringByXMLUnescapingWithDelegate: delegate];

	ret->isa = [OFString class];
	return ret;
395
396
397
398
399
400
401
402

403
404
405
406
407
408
409
410
394
395
396
397
398
399
400

401

402
403
404
405
406
407
408







-
+
-







	char piDelimiter = 0;

	if (!acceptProlog)
		return NO;

	acceptProlog = NO;

	pi = [pi substringFromIndex: 3
	pi = [pi substringWithRange: of_range(3, [pi length] - 3)];
			    toIndex: [pi length]];
	pi = [pi stringByDeletingEnclosingWhitespaces];

	cString = [pi cString];
	length = [pi cStringLength];

	for (i = last = 0; i < length; i++) {
		switch (piState) {

Modified tests/OFStringTests.m from [eb8775f0d6] to [570caa0b7f].

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
216
217
218
219
220
221
222


223
224


225

226

227


228


229


230






231
232
233
234
235
236
237







-
-
+
+
-
-
+
-

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








	TEST(@"-[indexOfLastOccurrenceOfString:]",
	    [@"π„žΓΆΓΆ" indexOfLastOccurrenceOfString: @"ΓΆΓΆ"] == 1 &&
	    [@"π„žΓΆΓΆ" indexOfLastOccurrenceOfString: @"ΓΆ"] == 2 &&
	    [@"π„žΓΆΓΆ" indexOfLastOccurrenceOfString: @"π„ž"] == 0 &&
	    [@"π„žΓΆΓΆ" indexOfLastOccurrenceOfString: @"x"] == OF_INVALID_INDEX)

	TEST(@"-[substringFromIndexToIndex:]",
	    [[@"π„žΓΆΓΆ" substringFromIndex: 1
	TEST(@"-[substringWithRange:]",
	    [[@"π„žΓΆΓΆ" substringWithRange: of_range(1, 1)] isEqual: @"ΓΆ"] &&
				toIndex: 2] isEqual: @"ΓΆ"] &&
	    [[@"π„žΓΆΓΆ" substringFromIndex: 3
	    [[@"π„žΓΆΓΆ" substringWithRange: of_range(3, 0)] isEqual: @""])
				toIndex: 3] isEqual: @""])

	EXPECT_EXCEPTION(@"Detect out of range in "
	EXPECT_EXCEPTION(@"Detect out of range in -[substringWithRange:] #1",
	    @"-[substringFromIndex:toIndex:] #1", OFOutOfRangeException,
	    [@"π„žΓΆΓΆ" substringFromIndex: 2
	    OFOutOfRangeException, [@"π„žΓΆΓΆ" substringWithRange: of_range(2, 2)])
			       toIndex: 4])
	EXPECT_EXCEPTION(@"Detect out of range in "
	EXPECT_EXCEPTION(@"Detect out of range in -[substringWithRange:] #2",
	    @"-[substringFromIndex:toIndex:] #2", OFOutOfRangeException,
	    [@"π„žΓΆΓΆ" substringFromIndex: 4
	    OFOutOfRangeException, [@"π„žΓΆΓΆ" substringWithRange: of_range(4, 0)])
			       toIndex: 4])

	EXPECT_EXCEPTION(@"Detect start > end in "
	    @"-[substringFromIndex:toIndex:]", OFInvalidArgumentException,
	    [@"π„žΓΆΓΆ" substringFromIndex: 2
			       toIndex: 0])

	TEST(@"-[stringByAppendingString:]",
	    [[@"foo" stringByAppendingString: @"bar"] isEqual: @"foobar"])

	TEST(@"-[stringByPrependingString:]",
	    [[@"foo" stringByPrependingString: @"bar"] isEqual: @"barfoo"])

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
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
473
474
475
476
477
478
479
480
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
447
448







-
+

-
+
-

-
+
-


-
+

-
+
-
-
+

-
+
-
-
+


-
-
+
+


-
+
-


-
-
-
+
+
+
-

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

-
+
-

-
+
-
-
+
-
-
-
-
-
-








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

	TEST(@"-[deleteCharactersFromIndex:toIndex:]",
	TEST(@"-[deleteCharactersInRange:]",
	    (s[0] = [OFMutableString stringWithString: @"π„žΓΆΓΆΓΆbÀ€"]) &&
	    R([s[0] deleteCharactersFromIndex: 1
	    R([s[0] deleteCharactersInRange: of_range(1, 3)]) &&
				       toIndex: 4]) &&
	    [s[0] isEqual: @"π„žbÀ€"] &&
	    R([s[0] deleteCharactersFromIndex: 0
	    R([s[0] deleteCharactersInRange: of_range(0, 4)]) &&
				      toIndex: 4]) &&
	    [s[0] isEqual: @""])

	TEST(@"-[replaceCharactersFromIndex:toIndex:withString:]",
	TEST(@"-[replaceCharactersInRange:withString:]",
	    (s[0] = [OFMutableString stringWithString: @"π„žΓΆΓΆΓΆbÀ€"]) &&
		   R([s[0] replaceCharactersFromIndex: 1
	    R([s[0] replaceCharactersInRange: of_range(1, 3)
					      toIndex: 4
					   withString: @"Àâü"]) &&
				  withString: @"Àâü"]) &&
	    [s[0] isEqual: @"π„žΓ€ΓΆΓΌbÀ€"] &&
	    R([s[0] replaceCharactersFromIndex: 0
	    R([s[0] replaceCharactersInRange: of_range(0, 7)
				       toIndex: 7
				    withString: @""]) &&
				  withString: @""]) &&
	    [s[0] isEqual: @""])

	EXPECT_EXCEPTION(@"Detect OoR in "
	    @"-[deleteCharactersFromIndex:toIndex:] #1", OFOutOfRangeException,
	EXPECT_EXCEPTION(@"Detect OoR in -[deleteCharactersInRange:] #1",
	    OFOutOfRangeException,
	    {
		s[0] = [OFMutableString stringWithString: @"π„žΓΆΓΆ"];
		[s[0] deleteCharactersFromIndex: 2
		[s[0] deleteCharactersInRange: of_range(2, 2)];
					toIndex: 4];
	    })

	EXPECT_EXCEPTION(@"Detect OoR in "
	    @"-[deleteCharactersFromIndex:toIndex:] #2", OFOutOfRangeException,
	    [s[0] deleteCharactersFromIndex: 4
	EXPECT_EXCEPTION(@"Detect OoR in -[deleteCharactersInRange:] #2",
	    OFOutOfRangeException,
	    [s[0] deleteCharactersInRange: of_range(4, 0)])
				    toIndex: 4])

	EXPECT_EXCEPTION(@"Detect s > e in "
	EXPECT_EXCEPTION(@"Detect OoR in -[replaceCharactersInRange:withString:] #1",
	    @"-[deleteCharactersFromIndex:toIndex:]",
	    OFInvalidArgumentException,
	    OFOutOfRangeException,
	    [s[0] deleteCharactersFromIndex: 2
				    toIndex: 0])

	EXPECT_EXCEPTION(@"OoR "
	    @"-[replaceCharactersFromIndex:toIndex:withString:] #1",
	    OFOutOfRangeException, [s[0] replaceCharactersFromIndex: 2
	    [s[0] replaceCharactersInRange: of_range(2, 2)
							    toIndex: 4
							 withString: @""])
				withString: @""])

	EXPECT_EXCEPTION(@"OoR "
	EXPECT_EXCEPTION(@"Detect OoR in -[replaceCharactersInRange:withString:] #2",
	    @"-[replaceCharactersFromIndex:toIndex:withString:] #2",
	    OFOutOfRangeException,
	    [s[0] replaceCharactersFromIndex: 4
	    [s[0] replaceCharactersInRange: of_range(4, 0)
				     toIndex: 4
				  withString: @""])
				withString: @""])

	EXPECT_EXCEPTION(@"s>e in "
	    @"-[replaceCharactersFromIndex:toIndex:withString:]",
	    OFInvalidArgumentException, [s[0] replaceCharactersFromIndex: 2
								 toIndex: 0
							      withString: @""])

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