ObjFW  Check-in [3dad5e5803]

Overview
Comment:Make it possible to specify the byte order for Unicode / UTF-16.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 3dad5e580386677fcc20dddeca4121116407c6b1c81b7f41c55c5926f5f01246
User & Date: js on 2011-05-15 17:00:14
Other Links: manifest | tags
Context
2011-05-19
00:47
Add +[OFArray arrayWithArray:]. check-in: 1e249becdf user: js tags: trunk
2011-05-15
17:00
Make it possible to specify the byte order for Unicode / UTF-16. check-in: 3dad5e5803 user: js tags: trunk
00:32
configure.ac: Fix two tests that would fail with Clang + new ABI. check-in: 56b1009167 user: js tags: trunk
Changes

Modified src/OFObject.h from [dcd1dc9c0c] to [441f3c4a6d].

54
55
56
57
58
59
60








61
62
63
64
65
66
67
typedef struct of_range_t {
	/// The start of the range
	size_t start;
	/// The length of the range
	size_t length;
} of_range_t;









@class OFString;

/**
 * \brief The protocol which all root classes implement.
 */
@protocol OFObject
/**







>
>
>
>
>
>
>
>







54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
typedef struct of_range_t {
	/// The start of the range
	size_t start;
	/// The length of the range
	size_t length;
} of_range_t;

/**
 * \brief An enum for storing endianess.
 */
typedef enum of_endianess_t {
	OF_ENDIANESS_BIG_ENDIAN,
	OF_ENDIANESS_LITTLE_ENDIAN
} of_endianess_t;

@class OFString;

/**
 * \brief The protocol which all root classes implement.
 */
@protocol OFObject
/**

Modified src/OFString.h from [fd1c48329e] to [f063331312].

121
122
123
124
125
126
127











128
129
130
131
132
133
134
135
136
137













138
139
140
141
142
143
144
145
146











147
148
149
150












151
152
153
154

155
156
157
158
159
160
161
 * Creates a new OFString from a unicode string.
 *
 * \param string The unicode string
 * \return A new autoreleased OFString
 */
+ stringWithUnicodeString: (of_unichar_t*)string;












/**
 * Creates a new OFString from a unicode string with the specified length.
 *
 * \param string The unicode string
 * \param length The length of the unicode string
 * \return A new autoreleased OFString
 */
+ stringWithUnicodeString: (of_unichar_t*)string
		   length: (size_t)length;














/**
 * Creates a new OFString from a UTF-16 encoded string.
 *
 * \param string The UTF-16 string
 * \return A new autoreleased OFString
 */
+ stringWithUTF16String: (uint16_t*)string;

/**











 * Creates a new OFString from a UTF-16 encoded string with the specified
 * length.
 *
 * \param string The UTF-16 string












 * \param length The length of the unicode string
 * \return A new autoreleased OFString
 */
+ stringWithUTF16String: (uint16_t*)string

		 length: (size_t)length;

/**
 * Creates a new OFString from a format string.
 * See printf for the format syntax.
 *
 * \param format A string used as format to initialize the OFString







>
>
>
>
>
>
>
>
>
>
>










>
>
>
>
>
>
>
>
>
>
>
>
>









>
>
>
>
>
>
>
>
>
>
>




>
>
>
>
>
>
>
>
>
>
>
>




>







121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
 * Creates a new OFString from a unicode string.
 *
 * \param string The unicode string
 * \return A new autoreleased OFString
 */
+ stringWithUnicodeString: (of_unichar_t*)string;

/**
 * Creates a new OFString from a unicode string, assuming the specified byte
 * order if no BOM is found.
 *
 * \param string The unicode string
 * \param byteOrder The byte order to assume if there is no BOM
 * \return A new autoreleased OFString
 */
+ stringWithUnicodeString: (of_unichar_t*)string
		byteOrder: (of_endianess_t)byteOrder;

/**
 * Creates a new OFString from a unicode string with the specified length.
 *
 * \param string The unicode string
 * \param length The length of the unicode string
 * \return A new autoreleased OFString
 */
+ stringWithUnicodeString: (of_unichar_t*)string
		   length: (size_t)length;

/**
 * Creates a new OFString from a unicode string with the specified length,
 * assuming the specified byte order if no BOM is found.
 *
 * \param string The unicode string
 * \param byteOrder The byte order to assume if there is no BOM
 * \param length The length of the unicode string
 * \return A new autoreleased OFString
 */
+ stringWithUnicodeString: (of_unichar_t*)string
		byteOrder: (of_endianess_t)byteOrder
		   length: (size_t)length;

/**
 * Creates a new OFString from a UTF-16 encoded string.
 *
 * \param string The UTF-16 string
 * \return A new autoreleased OFString
 */
+ stringWithUTF16String: (uint16_t*)string;

/**
 * Creates a new OFString from a UTF-16 encoded string, assuming the specified
 * byte order if no BOM is found.
 *
 * \param string The UTF-16 string
 * \param byteOrder The byte order to assume if there is no BOM
 * \return A new autoreleased OFString
 */
+ stringWithUTF16String: (uint16_t*)string
	      byteOrder: (of_endianess_t)byteOrder;

/**
 * Creates a new OFString from a UTF-16 encoded string with the specified
 * length.
 *
 * \param string The UTF-16 string
 * \param length The length of the unicode string
 * \return A new autoreleased OFString
 */
+ stringWithUTF16String: (uint16_t*)string
		 length: (size_t)length;

/**
 * Creates a new OFString from a UTF-16 encoded string with the specified
 * length, assuming the specified byte order if no BOM is found.
 *
 * \param string The UTF-16 string
 * \param byteOrder The byte order to assume if there is no BOM
 * \param length The length of the unicode string
 * \return A new autoreleased OFString
 */
+ stringWithUTF16String: (uint16_t*)string
	      byteOrder: (of_endianess_t)byteOrder
		 length: (size_t)length;

/**
 * Creates a new OFString from a format string.
 * See printf for the format syntax.
 *
 * \param format A string used as format to initialize the OFString
270
271
272
273
274
275
276











277
278
279
280
281
282
283
284
285
286
287













288
289
290
291
292
293
294
295











296
297
298
299
300
301
302
303
304
305
306













307
308
309
310
311
312
313
 * Initializes an already allocated OFString with a unicode string.
 *
 * \param string The unicode string
 * \return An initialized OFString
 */
- initWithUnicodeString: (of_unichar_t*)string;












/**
 * Initializes an already allocated OFString with a unicode string with the
 * specified length.
 *
 * \param string The unicode string
 * \param length The length of the unicode string
 * \return An initialized OFString
 */
- initWithUnicodeString: (of_unichar_t*)string
		 length: (size_t)length;














/**
 * Initializes an already allocated OFString with a UTF-16 string.
 *
 * \param string The UTF-16 string
 * \return An initialized OFString
 */
- initWithUTF16String: (uint16_t*)string;












/**
 * Initializes an already allocated OFString with a UTF-16 string with the
 * specified length.
 *
 * \param string The UTF-16 string
 * \param length The length of the UTF-16 string
 * \return An initialized OFString
 */
- initWithUTF16String: (uint16_t*)string
	       length: (size_t)length;














/**
 * Initializes an already allocated OFString with a format string.
 * See printf for the format syntax.
 *
 * \param format A string used as format to initialize the OFString
 * \return An initialized OFString
 */







>
>
>
>
>
>
>
>
>
>
>











>
>
>
>
>
>
>
>
>
>
>
>
>








>
>
>
>
>
>
>
>
>
>
>











>
>
>
>
>
>
>
>
>
>
>
>
>







318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
 * Initializes an already allocated OFString with a unicode string.
 *
 * \param string The unicode string
 * \return An initialized OFString
 */
- initWithUnicodeString: (of_unichar_t*)string;

/**
 * Initializes an already allocated OFString with a unicode string, assuming the
 * specified byte order if no BOM is found.
 *
 * \param string The unicode string
 * \param byteOrder The byte order to assume if there is no BOM
 * \return An initialized OFString
 */
- initWithUnicodeString: (of_unichar_t*)string
	      byteOrder: (of_endianess_t)byteOrder;

/**
 * Initializes an already allocated OFString with a unicode string with the
 * specified length.
 *
 * \param string The unicode string
 * \param length The length of the unicode string
 * \return An initialized OFString
 */
- initWithUnicodeString: (of_unichar_t*)string
		 length: (size_t)length;

/**
 * Initializes an already allocated OFString with a unicode string with the
 * specified length, assuming the specified byte order if no BOM is found.
 *
 * \param string The unicode string
 * \param byteOrder The byte order to assume if there is no BOM
 * \param length The length of the unicode string
 * \return An initialized OFString
 */
- initWithUnicodeString: (of_unichar_t*)string
	      byteOrder: (of_endianess_t)byteOrder
		 length: (size_t)length;

/**
 * Initializes an already allocated OFString with a UTF-16 string.
 *
 * \param string The UTF-16 string
 * \return An initialized OFString
 */
- initWithUTF16String: (uint16_t*)string;

/**
 * Initializes an already allocated OFString with a UTF-16 string, assuming the
 * specified byte order if no BOM is found.
 *
 * \param string The UTF-16 string
 * \param byteOrder The byte order to assume if there is no BOM
 * \return An initialized OFString
 */
- initWithUTF16String: (uint16_t*)string
	    byteOrder: (of_endianess_t)byteOrder;

/**
 * Initializes an already allocated OFString with a UTF-16 string with the
 * specified length.
 *
 * \param string The UTF-16 string
 * \param length The length of the UTF-16 string
 * \return An initialized OFString
 */
- initWithUTF16String: (uint16_t*)string
	       length: (size_t)length;

/**
 * Initializes an already allocated OFString with a UTF-16 string with the
 * specified length, assuming the specified byte order if no BOM is found.
 *
 * \param string The UTF-16 string
 * \param byteOrder The byte order to assume if there is no BOM
 * \param length The length of the UTF-16 string
 * \return An initialized OFString
 */
- initWithUTF16String: (uint16_t*)string
	    byteOrder: (of_endianess_t)byteOrder
	       length: (size_t)length;

/**
 * Initializes an already allocated OFString with a format string.
 * See printf for the format syntax.
 *
 * \param format A string used as format to initialize the OFString
 * \return An initialized OFString
 */

Modified src/OFString.m from [3c842a2c2f] to [581a424007].

308
309
310
311
312
313
314















315
316
317

318
319
320
321
322
323
324
325
326















327
328
329

330
331
332
333
334
335
336

+ stringWithUnicodeString: (of_unichar_t*)string
{
	return [[[self alloc] initWithUnicodeString: string] autorelease];
}

+ stringWithUnicodeString: (of_unichar_t*)string















		   length: (size_t)length
{
	return [[[self alloc] initWithUnicodeString: string

					     length: length] autorelease];
}

+ stringWithUTF16String: (uint16_t*)string
{
	return [[[self alloc] initWithUTF16String: string] autorelease];
}

+ stringWithUTF16String: (uint16_t*)string















		 length: (size_t)length
{
	return [[[self alloc] initWithUTF16String: string

					   length: length] autorelease];
}

+ stringWithFormat: (OFString*)format, ...
{
	id ret;
	va_list arguments;







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>



>









>
>
>
>
>
>
>
>
>
>
>
>
>
>
>



>







308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368

+ stringWithUnicodeString: (of_unichar_t*)string
{
	return [[[self alloc] initWithUnicodeString: string] autorelease];
}

+ stringWithUnicodeString: (of_unichar_t*)string
		byteOrder: (of_endianess_t)byteOrder
{
	return [[[self alloc] initWithUnicodeString: string
					  byteOrder: byteOrder] autorelease];
}

+ stringWithUnicodeString: (of_unichar_t*)string
		   length: (size_t)length
{
	return [[[self alloc] initWithUnicodeString: string
					     length: length] autorelease];
}

+ stringWithUnicodeString: (of_unichar_t*)string
		byteOrder: (of_endianess_t)byteOrder
		   length: (size_t)length
{
	return [[[self alloc] initWithUnicodeString: string
					  byteOrder: byteOrder
					     length: length] autorelease];
}

+ stringWithUTF16String: (uint16_t*)string
{
	return [[[self alloc] initWithUTF16String: string] autorelease];
}

+ stringWithUTF16String: (uint16_t*)string
	      byteOrder: (of_endianess_t)byteOrder
{
	return [[[self alloc] initWithUTF16String: string
					byteOrder: byteOrder] autorelease];
}

+ stringWithUTF16String: (uint16_t*)string
		 length: (size_t)length
{
	return [[[self alloc] initWithUTF16String: string
					   length: length] autorelease];
}

+ stringWithUTF16String: (uint16_t*)string
	      byteOrder: (of_endianess_t)byteOrder
		 length: (size_t)length
{
	return [[[self alloc] initWithUTF16String: string
					byteOrder: byteOrder
					   length: length] autorelease];
}

+ stringWithFormat: (OFString*)format, ...
{
	id ret;
	va_list arguments;
571
572
573
574
575
576
577









578
579
580
581
582









583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600

601
602
603
604
605
606
607

	return self;
}

- initWithUnicodeString: (of_unichar_t*)string_
{
	return [self initWithUnicodeString: string_









				    length: of_unicode_string_length(string_)];
}

- initWithUnicodeString: (of_unichar_t*)string_
		 length: (size_t)length_









{
	self = [super init];

	@try {
		char buffer[4];
		size_t i, j = 0;
		BOOL swap = NO;

		if (*string_ == 0xFEFF) {
			string_++;
			length_--;
		}

		if (*string_ == 0xFFFE0000) {
			swap = YES;
			string_++;
			length_--;
		}


		length = length_;
		string = [self allocMemoryWithSize: (length * 4) + 1];

		for (i = 0; i < length_; i++) {
			size_t characterLen = of_string_unicode_to_utf8(
			    (swap ? of_bswap32(string_[i]) : string_[i]),







>
>
>
>
>
>
>
>
>





>
>
>
>
>
>
>
>
>








|


<
<
|



|
>







603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643


644
645
646
647
648
649
650
651
652
653
654
655
656

	return self;
}

- initWithUnicodeString: (of_unichar_t*)string_
{
	return [self initWithUnicodeString: string_
				 byteOrder: OF_ENDIANESS_NATIVE
				    length: of_unicode_string_length(string_)];
}

- initWithUnicodeString: (of_unichar_t*)string_
	      byteOrder: (of_endianess_t)byteOrder
{
	return [self initWithUnicodeString: string_
				 byteOrder: byteOrder
				    length: of_unicode_string_length(string_)];
}

- initWithUnicodeString: (of_unichar_t*)string_
		 length: (size_t)length_
{
	return [self initWithUnicodeString: string_
				 byteOrder: OF_ENDIANESS_NATIVE
				    length: length_];
}

- initWithUnicodeString: (of_unichar_t*)string_
	      byteOrder: (of_endianess_t)byteOrder
		 length: (size_t)length_
{
	self = [super init];

	@try {
		char buffer[4];
		size_t i, j = 0;
		BOOL swap = NO;

		if (length_ > 0 && *string_ == 0xFEFF) {
			string_++;
			length_--;


		} else if (length_ > 0 && *string_ == 0xFFFE0000) {
			swap = YES;
			string_++;
			length_--;
		} else if (byteOrder != OF_ENDIANESS_NATIVE)
			swap = YES;

		length = length_;
		string = [self allocMemoryWithSize: (length * 4) + 1];

		for (i = 0; i < length_; i++) {
			size_t characterLen = of_string_unicode_to_utf8(
			    (swap ? of_bswap32(string_[i]) : string_[i]),
657
658
659
660
661
662
663









664
665
666
667
668









669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686

687
688
689
690
691
692
693

	return self;
}

- initWithUTF16String: (uint16_t*)string_
{
	return [self initWithUTF16String: string_









				  length: of_utf16_string_length(string_)];
}

- initWithUTF16String: (uint16_t*)string_
	       length: (size_t)length_









{
	self = [super init];

	@try {
		char buffer[4];
		size_t i, j = 0;
		BOOL swap = NO;

		if (*string_ == 0xFEFF) {
			string_++;
			length_--;
		}

		if (*string_ == 0xFFFE) {
			swap = YES;
			string_++;
			length_--;
		}


		length = length_;
		string = [self allocMemoryWithSize: (length * 4) + 1];

		for (i = 0; i < length_; i++) {
			of_unichar_t character =
			    (swap ? of_bswap16(string_[i]) : string_[i]);







>
>
>
>
>
>
>
>
>





>
>
>
>
>
>
>
>
>








|


<
<
|



|
>







706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746


747
748
749
750
751
752
753
754
755
756
757
758
759

	return self;
}

- initWithUTF16String: (uint16_t*)string_
{
	return [self initWithUTF16String: string_
			       byteOrder: OF_ENDIANESS_NATIVE
				  length: of_utf16_string_length(string_)];
}

- initWithUTF16String: (uint16_t*)string_
	    byteOrder: (of_endianess_t)byteOrder
{
	return [self initWithUTF16String: string_
			       byteOrder: byteOrder
				  length: of_utf16_string_length(string_)];
}

- initWithUTF16String: (uint16_t*)string_
	       length: (size_t)length_
{
	return [self initWithUTF16String: string_
			       byteOrder: OF_ENDIANESS_NATIVE
				  length: length_];
}

- initWithUTF16String: (uint16_t*)string_
	    byteOrder: (of_endianess_t)byteOrder
	       length: (size_t)length_
{
	self = [super init];

	@try {
		char buffer[4];
		size_t i, j = 0;
		BOOL swap = NO;

		if (length_ > 0 && *string_ == 0xFEFF) {
			string_++;
			length_--;


		} else if (length_ > 0 && *string_ == 0xFFFE) {
			swap = YES;
			string_++;
			length_--;
		} else if (byteOrder != OF_ENDIANESS_NATIVE)
			swap = YES;

		length = length_;
		string = [self allocMemoryWithSize: (length * 4) + 1];

		for (i = 0; i < length_; i++) {
			of_unichar_t character =
			    (swap ? of_bswap16(string_[i]) : string_[i]);

Modified src/macros.h from [9fafdeca9d] to [6f620278d4].

46
47
48
49
50
51
52



53
54
55
56
57
58
59
#if __BIG_ENDIAN__ || __LITTLE_ENDIAN__
# if __BIG_ENDIAN__ && __LITTLE_ENDIAN__
#  error __BIG_ENDIAN__ and __LITTLE_ENDIAN__ defined!
# endif
# undef OF_BIG_ENDIAN
# if __BIG_ENDIAN__
#  define OF_BIG_ENDIAN



# endif
#endif

#ifdef __GNUC__
# if defined(__amd64__) || defined(__x86_64__)
#  define OF_AMD64_ASM
# elif defined(__i386__)







>
>
>







46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#if __BIG_ENDIAN__ || __LITTLE_ENDIAN__
# if __BIG_ENDIAN__ && __LITTLE_ENDIAN__
#  error __BIG_ENDIAN__ and __LITTLE_ENDIAN__ defined!
# endif
# undef OF_BIG_ENDIAN
# if __BIG_ENDIAN__
#  define OF_BIG_ENDIAN
#  define OF_ENDIANESS_NATIVE OF_ENDIANESS_BIG_ENDIAN
# else
#  define OF_ENDIANESS_NATIVE OF_ENDIANESS_LITTLE_ENDIAN
# endif
#endif

#ifdef __GNUC__
# if defined(__amd64__) || defined(__x86_64__)
#  define OF_AMD64_ASM
# elif defined(__i386__)