ObjFW  Check-in [a9ff126697]

Overview
Comment:Add -[removeCharactersFromIndex:toIndex:] to OFMutableString.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: a9ff1266976eecdefdcbe02cb7c34ea85293aa023e515bc582747cc8c66b319f
User & Date: js on 2009-08-27 17:52:48
Other Links: manifest | tags
Context
2009-08-27
20:40
Cache the number of items in an OFList. check-in: 768108a960 user: js tags: trunk
17:52
Add -[removeCharactersFromIndex:toIndex:] to OFMutableString. check-in: a9ff126697 user: js tags: trunk
2009-08-26
19:54
More documentation improvements. check-in: d6b9b175b7 user: js tags: trunk
Changes

Modified src/OFMutableString.h from [722b2ff321] to [f2ca005cbe].

101
102
103
104
105
106
107










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







+
+
+
+
+
+
+
+
+
+







- upper;

/**
 * Lower the OFString.
 */
- 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;

/**
 * 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

Modified src/OFMutableString.m from [0296655a87] to [c9b26460ed].

284
285
286
287
288
289
290

























291
292
293
294
295
296
297
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







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







	char *p = string + length;

	if (is_utf8)
		@throw [OFInvalidEncodingException newWithClass: isa];

	while (--p >= string)
		*p = tolower((int)*p);

	return self;
}

- removeCharactersFromIndex: (size_t)start
		    toIndex: (size_t)end
{
	if (start > end)
		@throw [OFInvalidArgumentException newWithClass: isa
						       selector: _cmd];

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

	memmove(string + start, string + end, length - end);
	length -= end - start;
	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;
}

- replaceOccurrencesOfString: (OFString*)str
		  withString: (OFString*)repl
{

Modified src/OFString.h from [070cca9ea4] to [4c61fdeaf5].

268
269
270
271
272
273
274


275
276
277
278
279
280
281
282
283
284
285
286
287
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289







+
+













- appendString: (OFString*)str;
- appendWithFormat: (OFString*)fmt, ...;
- appendWithFormat: (OFString*)fmt
	 arguments: (va_list)args;
- reverse;
- upper;
- lower;
- removeCharactersFromIndex: (size_t)start
		    toIndex: (size_t)end;
- replaceOccurrencesOfString: (OFString*)str
		  withString: (OFString*)repl;
- removeLeadingWhitespaces;
- removeTrailingWhitespaces;
- removeLeadingAndTrailingWhitespaces;
@end

#import "OFConstString.h"
#import "OFMutableString.h"
#import "OFHashes.h"
#import "OFURLEncoding.h"
#import "OFXMLElement.h"
#import "OFXMLParser.h"

Modified src/OFString.m from [7a4ce00abf] to [99eed6fe4d].

682
683
684
685
686
687
688







689
690
691
692
693
694
695
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702







+
+
+
+
+
+
+







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

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

- removeCharactersFromIndex: (size_t)start
		    toIndex: (size_t)end
{
	@throw [OFNotImplementedException newWithClass: isa
					      selector: _cmd];
}

- replaceOccurrencesOfString: (OFString*)str
		  withString: (OFString*)repl

Modified src/OFXMLParser.m from [a3249dff8b] to [7614e5646f].

148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
148
149
150
151
152
153
154

155
156
157
158
159
160
161







-







						  withLength: len];

				if ([cache length] > 0) {
					OFString *str;

					pool = [[OFAutoreleasePool alloc] init];
					str = transform_string(cache, self);
					str = [[str copy] autorelease];
					[delegate xmlParser: self
						foundString: str];
					[pool release];
				}

				[cache setToCString: ""];

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
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







-
+



+


-
-
-
-
+
+
+

-
+







			break;
		case OF_XMLPARSER_IN_COMMENT_3:
			if (buf[i] == '-')
				state = OF_XMLPARSER_IN_COMMENT_4;
			break;
		case OF_XMLPARSER_IN_COMMENT_4:
			if (buf[i] == '-') {
				OFString *str;
				size_t cache_len;

				[cache appendCString: buf + last
					  withLength: i - last];
				cache_len = [cache length];

				pool = [[OFAutoreleasePool alloc] init];
				str = [OFMutableString
				    stringWithCString: [cache cString]
					       length: [cache length] - 1];
				[str removeLeadingAndTrailingWhitespaces];
				[cache removeCharactersFromIndex: cache_len - 1
							 toIndex: cache_len];
				[cache removeLeadingAndTrailingWhitespaces];
				[delegate xmlParser: self
				       foundComment: str];
				       foundComment: cache];
				[pool release];

				[cache setToCString: ""];

				last = i + 1;
				state = OF_XMLPARSER_EXPECT_CLOSE;
			} else

Modified tests/OFString/OFString.m from [6aa5e1d043] to [9c8a9cddc0].

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







-
+








#ifndef _WIN32
#define ZD "%zd"
#else
#define ZD "%u"
#endif

#define NUM_TESTS 71
#define NUM_TESTS 73
#define SUCCESS								\
	printf("\r\033[1;%dmTests successful: " ZD "/%d\033[0m",	\
	    (i == NUM_TESTS - 1 ? 32 : 33), i + 1, NUM_TESTS);		\
	fflush(stdout);
#define FAIL								\
	printf("\r\033[K\033[1;31mTest " ZD "/%d failed!\033[m\n",	\
	    i + 1, NUM_TESTS);						\
187
188
189
190
191
192
193









194
195
196
197
198
199
200
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209







+
+
+
+
+
+
+
+
+







	CHECK([[@"foo%20bar%22+%24" stringByURLDecoding]
	    isEqual: @"foo bar\" $"])
	CHECK_EXCEPT([@"foo%bar" stringByURLDecoding],
	    OFInvalidEncodingException)
	CHECK_EXCEPT([@"foo%FFbar" stringByURLDecoding],
	    OFInvalidEncodingException)

	/* Remove tests */
	s1 = [@"fooobar" mutableCopy];
	[s1 removeCharactersFromIndex: 1
			      toIndex: 4];
	CHECK([s1 isEqual: @"fbar"])
	[s1 removeCharactersFromIndex: 0
			      toIndex: 4];
	CHECK([s1 isEqual: @""])

	/* Replace tests */
	s1 = [@"asd fo asd fofo asd" mutableCopy];
	[s1 replaceOccurrencesOfString: @"fo"
			    withString: @"foo"];
	CHECK([s1 isEqual: @"asd foo asd foofoo asd"])
	s1 = [@"XX" mutableCopy];
	[s1 replaceOccurrencesOfString: @"X"