ObjFW  Diff

Differences From Artifact [c16c78a6d7]:

To Artifact [5a1fe9d9fc]:

  • File src/OFString_UTF8.m — part of check-in [545b6f740e] at 2013-01-13 13:07:52 on branch trunk — Add of_char{16,32}_t.

    For ObjC++, these are defined to char{16,32}_t if C++11 is used. This
    means passing e.g. a C++11 UTF-16 string to -[initWithUTF16String:]
    works without a warning.

    For C11, this is not necessary, as char{16,32}_t are just typedef'd to
    uint_least{16,32}_t in <uchar.h> and thus compatible to the definition
    of of_char{16,32}_t. The reason for not defining of_char{16,32}_t to
    char{16,32}_t when using C11 is that <uchar.h> might be missing and that
    char{16,32}_t are not required to be UTF-{16,32}, whereas in C++, they
    are required to be UTF-{16,32}. (user: js, size: 30912) [annotate] [blame] [check-ins using]


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#import "OFOutOfRangeException.h"

#import "autorelease.h"
#import "macros.h"
#import "of_asprintf.h"
#import "unicode.h"

extern const uint16_t of_iso_8859_15[256];
extern const uint16_t of_windows_1252[256];

static inline int
memcasecmp(const char *first, const char *second, size_t length)
{
	size_t i;

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







|
|







35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#import "OFOutOfRangeException.h"

#import "autorelease.h"
#import "macros.h"
#import "of_asprintf.h"
#import "unicode.h"

extern const of_char16_t of_iso_8859_15[256];
extern const of_char16_t of_windows_1252[256];

static inline int
memcasecmp(const char *first, const char *second, size_t length)
{
	size_t i;

	for (i = 0; i < length; i++) {
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
	 encoding: (of_string_encoding_t)encoding
	   length: (size_t)cStringLength
{
	self = [super init];

	@try {
		size_t i, j;
		const uint16_t *table;

		if (encoding == OF_STRING_ENCODING_UTF_8 &&
		    cStringLength >= 3 && !memcmp(cString, "\xEF\xBB\xBF", 3)) {
			cString += 3;
			cStringLength -= 3;
		}








|







209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
	 encoding: (of_string_encoding_t)encoding
	   length: (size_t)cStringLength
{
	self = [super init];

	@try {
		size_t i, j;
		const of_char16_t *table;

		if (encoding == OF_STRING_ENCODING_UTF_8 &&
		    cStringLength >= 3 && !memcmp(cString, "\xEF\xBB\xBF", 3)) {
			cString += 3;
			cStringLength -= 3;
		}

462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
		[self release];
		@throw e;
	}

	return self;
}

- initWithUTF16String: (const uint16_t*)string
	       length: (size_t)length
	    byteOrder: (of_byte_order_t)byteOrder
{
	self = [super init];

	@try {
		size_t i, j = 0;







|







462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
		[self release];
		@throw e;
	}

	return self;
}

- initWithUTF16String: (const of_char16_t*)string
	       length: (size_t)length
	    byteOrder: (of_byte_order_t)byteOrder
{
	self = [super init];

	@try {
		size_t i, j = 0;
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514

			/* Missing high surrogate */
			if ((character & 0xFC00) == 0xDC00)
				@throw [OFInvalidEncodingException
				    exceptionWithClass: [self class]];

			if ((character & 0xFC00) == 0xD800) {
				uint16_t nextCharacter;

				if (length <= i + 1)
					@throw [OFInvalidEncodingException
					    exceptionWithClass: [self class]];

				nextCharacter = (swap
				    ? OF_BSWAP16(string[i + 1])







|







500
501
502
503
504
505
506
507
508
509
510
511
512
513
514

			/* Missing high surrogate */
			if ((character & 0xFC00) == 0xDC00)
				@throw [OFInvalidEncodingException
				    exceptionWithClass: [self class]];

			if ((character & 0xFC00) == 0xD800) {
				of_char16_t nextCharacter;

				if (length <= i + 1)
					@throw [OFInvalidEncodingException
					    exceptionWithClass: [self class]];

				nextCharacter = (swap
				    ? OF_BSWAP16(string[i + 1])
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
		[self release];
		@throw e;
	}

	return self;
}

- initWithUTF32String: (const of_unichar_t*)characters
	       length: (size_t)length
	    byteOrder: (of_byte_order_t)byteOrder
{
	self = [super init];

	@try {
		size_t i, j = 0;







|







574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
		[self release];
		@throw e;
	}

	return self;
}

- initWithUTF32String: (const of_char32_t*)characters
	       length: (size_t)length
	    byteOrder: (of_byte_order_t)byteOrder
{
	self = [super init];

	@try {
		size_t i, j = 0;
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
		ret[j++] = c;
		i += cLen;
	}

	return ret;
}

- (const of_unichar_t*)UTF32StringWithByteOrder: (of_byte_order_t)byteOrder
{
	OFObject *object = [[[OFObject alloc] init] autorelease];
	of_unichar_t *ret;
	size_t i, j;

	ret = [object allocMemoryWithSize: sizeof(of_unichar_t)
				    count: s->length + 1];

	i = j = 0;








|


|







1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
		ret[j++] = c;
		i += cLen;
	}

	return ret;
}

- (const of_char32_t*)UTF32StringWithByteOrder: (of_byte_order_t)byteOrder
{
	OFObject *object = [[[OFObject alloc] init] autorelease];
	of_char32_t *ret;
	size_t i, j;

	ret = [object allocMemoryWithSize: sizeof(of_unichar_t)
				    count: s->length + 1];

	i = j = 0;