ObjFW  Diff

Differences From Artifact [be8ebf571d]:

To Artifact [d6a602d281]:


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#import "OFInvalidFormatException.h"
#import "OFOutOfMemoryException.h"
#import "OFOutOfRangeException.h"

#import "of_asprintf.h"
#import "unicode.h"

extern const char16_t of_iso_8859_2_table[];
extern const size_t of_iso_8859_2_table_offset;
extern const char16_t of_iso_8859_3_table[];
extern const size_t of_iso_8859_3_table_offset;
extern const char16_t of_iso_8859_15_table[];
extern const size_t of_iso_8859_15_table_offset;
extern const char16_t of_windows_1251_table[];
extern const size_t of_windows_1251_table_offset;
extern const char16_t of_windows_1252_table[];
extern const size_t of_windows_1252_table_offset;
extern const char16_t of_codepage_437_table[];
extern const size_t of_codepage_437_table_offset;
extern const char16_t of_codepage_850_table[];
extern const size_t of_codepage_850_table_offset;
extern const char16_t of_codepage_858_table[];
extern const size_t of_codepage_858_table_offset;
extern const char16_t of_mac_roman_table[];
extern const size_t of_mac_roman_table_offset;
extern const char16_t of_koi8_r_table[];
extern const size_t of_koi8_r_table_offset;
extern const char16_t of_koi8_u_table[];
extern const size_t of_koi8_u_table_offset;

static inline int
memcasecmp(const char *first, const char *second, size_t length)
{
	for (size_t i = 0; i < length; i++) {
		unsigned char f = first[i];







|

|

|

|

|

|

|

|

|

|

|







36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#import "OFInvalidFormatException.h"
#import "OFOutOfMemoryException.h"
#import "OFOutOfRangeException.h"

#import "of_asprintf.h"
#import "unicode.h"

extern const of_char16_t of_iso_8859_2_table[];
extern const size_t of_iso_8859_2_table_offset;
extern const of_char16_t of_iso_8859_3_table[];
extern const size_t of_iso_8859_3_table_offset;
extern const of_char16_t of_iso_8859_15_table[];
extern const size_t of_iso_8859_15_table_offset;
extern const of_char16_t of_windows_1251_table[];
extern const size_t of_windows_1251_table_offset;
extern const of_char16_t of_windows_1252_table[];
extern const size_t of_windows_1252_table_offset;
extern const of_char16_t of_codepage_437_table[];
extern const size_t of_codepage_437_table_offset;
extern const of_char16_t of_codepage_850_table[];
extern const size_t of_codepage_850_table_offset;
extern const of_char16_t of_codepage_858_table[];
extern const size_t of_codepage_858_table_offset;
extern const of_char16_t of_mac_roman_table[];
extern const size_t of_mac_roman_table_offset;
extern const of_char16_t of_koi8_r_table[];
extern const size_t of_koi8_r_table_offset;
extern const of_char16_t of_koi8_u_table[];
extern const size_t of_koi8_u_table_offset;

static inline int
memcasecmp(const char *first, const char *second, size_t length)
{
	for (size_t i = 0; i < length; i++) {
		unsigned char f = first[i];
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
- (instancetype)initWithCString: (const char *)cString
		       encoding: (of_string_encoding_t)encoding
			 length: (size_t)cStringLength
{
	self = [super init];

	@try {
		const char16_t *table;
		size_t tableOffset, j;

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







|







230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
- (instancetype)initWithCString: (const char *)cString
		       encoding: (of_string_encoding_t)encoding
			 length: (size_t)cStringLength
{
	self = [super init];

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

		if (encoding == OF_STRING_ENCODING_UTF_8 &&
		    cStringLength >= 3 &&
		    memcmp(cString, "\xEF\xBB\xBF", 3) == 0) {
			cString += 3;
			cStringLength -= 3;
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
		[self release];
		@throw e;
	}

	return self;
}

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

	@try {
		size_t j;







|







510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
		[self release];
		@throw e;
	}

	return self;
}

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

	@try {
		size_t j;
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
			size_t len;

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

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

				if (length <= i + 1)
					@throw [OFInvalidEncodingException
					    exception];

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







|







546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
			size_t len;

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

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

				if (length <= i + 1)
					@throw [OFInvalidEncodingException
					    exception];

				nextCharacter = (swap
				    ? OF_BSWAP16(string[i + 1])
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
		[self release];
		@throw e;
	}

	return self;
}

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

	@try {
		size_t j;







|







595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
		[self release];
		@throw e;
	}

	return self;
}

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

	@try {
		size_t j;
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
		ret[j++] = c;
		i += cLen;
	}

	return ret;
}

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

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

	i = j = 0;








|


|







1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
		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;