ObjFW  Diff

Differences From Artifact [9492a9e3d8]:

  • File src/OFMutableString_UTF8.m — part of check-in [4d892e0db1] at 2013-07-04 20:49:52 on branch trunk — Fix -[replaceCharactersInRange:withString:].

    The resizing is now done before the memmove() if the new string is
    bigger and after the memmove() if the new string is shorter. The added
    comment explains why this is necessary.

    This also adds a test for -[replaceCharactersInRange:withString:] that
    makes the string bigger and another one that makes it smaller again. (user: js, size: 20151) [annotate] [blame] [check-ins using]

To Artifact [be6d727813]:


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

	tmp = [self allocMemoryWithSize: (length * 4) + 1];
	@try {
		size_t i, j = 0;
		bool isUTF8 = false;

		for (i = 0; i < length; i++) {
			char buffer[4];

			switch (of_string_utf8_encode(characters[i], buffer)) {
			case 1:
				tmp[j++] = buffer[0];
				break;
			case 2:
				isUTF8 = true;

				memcpy(tmp + j, buffer, 2);
				j += 2;

				break;
			case 3:
				isUTF8 = true;

				memcpy(tmp + j, buffer, 3);
				j += 3;

				break;
			case 4:
				isUTF8 = true;

				memcpy(tmp + j, buffer, 4);
				j += 4;

				break;
			default:
				@throw [OFInvalidEncodingException exception];
			}
		}

		tmp[j] = '\0';

		_s->hashed = false;
		_s->cString = [self resizeMemory: _s->cString
					    size: _s->cStringLength + j + 1];







<
<
|
<
|
<
<
<

<
|
|
<
<
<

<
<
|
<
<


<
|
<
<
<
<
<







391
392
393
394
395
396
397


398

399



400

401
402



403


404


405
406

407





408
409
410
411
412
413
414

	tmp = [self allocMemoryWithSize: (length * 4) + 1];
	@try {
		size_t i, j = 0;
		bool isUTF8 = false;

		for (i = 0; i < length; i++) {


			size_t len = of_string_utf8_encode(characters[i],

			    tmp + j);





			if (len == 0)
				@throw [OFInvalidEncodingException exception];






			if (len > 1)


				isUTF8 = true;


			j += len;





		}

		tmp[j] = '\0';

		_s->hashed = false;
		_s->cString = [self resizeMemory: _s->cString
					    size: _s->cStringLength + j + 1];