ObjFW  Check-in [1aca64c18e]

Overview
Comment:OFString_UTF8: Fix BOM handling in no copy init
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | 0.90
Files: files | file ages | folders
SHA3-256: 1aca64c18ec6ecd89a1bf104372e6ea267a92cf2a15d633420c8f811b5c4d646
User & Date: js on 2017-11-04 20:58:46
Other Links: branch diff | manifest | tags
Context
2017-11-04
21:12
OFString: Improve freeWhenDone in case of error check-in: ca0621da09 user: js tags: 0.90
20:58
OFString_UTF8: Fix BOM handling in no copy init check-in: 1aca64c18e user: js tags: 0.90
20:57
-[OFXMLElement setChildren:]: Create mutable copy check-in: 810e9a1f43 user: js tags: 0.90
Changes

Modified src/OFString_UTF8.m from [fb6ee6e76b] to [77d4090528].

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
	      freeWhenDone: (bool)freeWhenDone
{
	self = [super init];

	@try {
		size_t UTF8StringLength = strlen(UTF8String);






		if (UTF8StringLength >= 3 &&
		    memcmp(UTF8String, "\xEF\xBB\xBF", 3) == 0) {
			UTF8String += 3;
			UTF8StringLength -= 3;
		}

		_s = &_storage;

		_s->cString = (char *)UTF8String;
		_s->cStringLength = UTF8StringLength;

		if (freeWhenDone)
			_s->freeWhenDone = UTF8String;

		switch (of_string_utf8_check(UTF8String, UTF8StringLength,
		    &_s->length)) {
		case 1:
			_s->isUTF8 = true;
			break;
		case -1:
			@throw [OFInvalidEncodingException exception];







>
>
>
>
>






<
<



<
<
<







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
	      freeWhenDone: (bool)freeWhenDone
{
	self = [super init];

	@try {
		size_t UTF8StringLength = strlen(UTF8String);

		_s = &_storage;

		if (freeWhenDone)
			_s->freeWhenDone = UTF8String;

		if (UTF8StringLength >= 3 &&
		    memcmp(UTF8String, "\xEF\xBB\xBF", 3) == 0) {
			UTF8String += 3;
			UTF8StringLength -= 3;
		}



		_s->cString = (char *)UTF8String;
		_s->cStringLength = UTF8StringLength;




		switch (of_string_utf8_check(UTF8String, UTF8StringLength,
		    &_s->length)) {
		case 1:
			_s->isUTF8 = true;
			break;
		case -1:
			@throw [OFInvalidEncodingException exception];