ObjFW  Check-in [a5aed6da30]

Overview
Comment:Treat \n and \r as whitespaces in whitespace removing methods.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: a5aed6da301f09f83c243e2372456e51e272a4563b2330ded9c5d305db5a1bdd
User & Date: js on 2009-08-14 01:01:23
Other Links: manifest | tags
Context
2009-08-14
01:14
Remove leading and trailing whitespaces in XML data. check-in: 164d9d84f2 user: js tags: trunk
01:01
Treat \n and \r as whitespaces in whitespace removing methods. check-in: a5aed6da30 user: js tags: trunk
2009-08-12
16:55
New way for handling and storing XML attributes. check-in: 6f001b8016 user: js tags: trunk
Changes

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

346
347
348
349
350
351
352
353


354
355
356
357
358
359
360
346
347
348
349
350
351
352

353
354
355
356
357
358
359
360
361







-
+
+







}

- removeLeadingWhitespaces
{
	size_t i;

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

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

	@try {
371
372
373
374
375
376
377
378

379
380
381
382
383
384
385
372
373
374
375
376
377
378

379
380
381
382
383
384
385
386







-
+







- removeTrailingWhitespaces
{
	size_t d;
	char *p;

	d = 0;
	for (p = string + length - 1; p >= string; p--) {
		if (*p != ' ' && *p != '\t')
		if (*p != ' ' && *p != '\t' && *p != '\n' && *p != '\r')
			break;

		*p = '\0';
		d++;
	}

	length -= d;
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
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







-
+









-
+
+







- removeLeadingAndTrailingWhitespaces
{
	size_t d, i;
	char *p;

	d = 0;
	for (p = string + length - 1; p >= string; p--) {
		if (*p != ' ' && *p != '\t')
		if (*p != ' ' && *p != '\t' && *p != '\n' && *p != '\r')
			break;

		*p = '\0';
		d++;
	}

	length -= d;

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

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

	@try {

Modified tests/OFString/OFString.m from [2fbf2def3c] to [6aa5e1d043].

198
199
200
201
202
203
204
205

206
207
208
209


210
211
212
213
214
215
216
198
199
200
201
202
203
204

205
206
207


208
209
210
211
212
213
214
215
216







-
+


-
-
+
+







	CHECK([s1 isEqual: @"asd foo asd foofoo asd"])
	s1 = [@"XX" mutableCopy];
	[s1 replaceOccurrencesOfString: @"X"
			    withString: @"XX"];
	CHECK([s1 isEqual: @"XXXX"])

	/* Whitespace removing tests */
	s1 = [@"  \t\t \tasd  \t \t\t" mutableCopy];
	s1 = [@" \r \t\n\t \tasd  \t \t\t\r\n" mutableCopy];
	s2 = [s1 mutableCopy];
	s3 = [s1 mutableCopy];
	CHECK([[s1 removeLeadingWhitespaces] isEqual: @"asd  \t \t\t"])
	CHECK([[s2 removeTrailingWhitespaces] isEqual: @"  \t\t \tasd"])
	CHECK([[s1 removeLeadingWhitespaces] isEqual: @"asd  \t \t\t\r\n"])
	CHECK([[s2 removeTrailingWhitespaces] isEqual: @" \r \t\n\t \tasd"])
	CHECK([[s3 removeLeadingAndTrailingWhitespaces] isEqual: @"asd"])

	s1 = [@" \t\t  \t\t  \t \t" mutableCopy];
	s2 = [s1 mutableCopy];
	s3 = [s1 mutableCopy];
	CHECK([[s1 removeLeadingWhitespaces] isEqual: @""])
	CHECK([[s2 removeTrailingWhitespaces] isEqual: @""])