[Substrate-commits] SF.net SVN: substrate: [296] trunk
Brought to you by:
landonf
|
From: <la...@us...> - 2006-09-02 00:10:55
|
Revision: 296
http://svn.sourceforge.net/substrate/?rev=296&view=rev
Author: landonf
Date: 2006-09-01 17:10:46 -0700 (Fri, 01 Sep 2006)
Log Message:
-----------
r304@bluefish: landonf | 2006-09-01 14:59:27 -0700
UTF-16-LE as the canonical byte ordering was a lie. Apple's runtime returns strings in the host's byte ordering, and now we do the same.
Modified Paths:
--------------
trunk/Foundation/NSUnicodeString.m
trunk/Tests/NSUnicodeString.m
Property Changed:
----------------
trunk/
Property changes on: trunk
___________________________________________________________________
Name: svk:merge
- 11572a18-12fc-0310-9209-f8edcc8181a7:/local/substrate/trunk:5716
9c4e9a82-0035-45cc-8f88-5282b51d5481:/local/substrate/trunk:303
+ 11572a18-12fc-0310-9209-f8edcc8181a7:/local/substrate/trunk:5716
9c4e9a82-0035-45cc-8f88-5282b51d5481:/local/substrate/trunk:304
Modified: trunk/Foundation/NSUnicodeString.m
===================================================================
--- trunk/Foundation/NSUnicodeString.m 2006-09-02 00:10:41 UTC (rev 295)
+++ trunk/Foundation/NSUnicodeString.m 2006-09-02 00:10:46 UTC (rev 296)
@@ -427,9 +427,13 @@
case NSProprietaryStringEncoding: /* Fall through to UTF-16 */
/* Canonical encoding for NSString objects (UTF-16). */
case NSUnicodeStringEncoding:
- /* UTF-16-LE is the canonical byte ordering for UTF-16 strings in
- * both Substrate and Apple's Foundation */
+ /* Apple's Foundation returns the string encoded in the host's
+ * byte order. We'll do the same */
+#ifdef WORDS_BIGENDIAN
+ conv = ucnv_open("UTF-16-BE", &err);
+#else
conv = ucnv_open("UTF-16-LE", &err);
+#endif /* WORDS_BIGENDIAN */
allocSize = _length;
break;
Modified: trunk/Tests/NSUnicodeString.m
===================================================================
--- trunk/Tests/NSUnicodeString.m 2006-09-02 00:10:41 UTC (rev 295)
+++ trunk/Tests/NSUnicodeString.m 2006-09-02 00:10:46 UTC (rev 296)
@@ -102,10 +102,16 @@
0xb9, 0x74, 0x69, 0x6e, 0x79
};
-/* English UTF-16-LE "Hello, Universe", assembled by byte
- * UTF-16-LE is the canonical UTF-16 string encoding for both Substrate
- * and Apple's foundation. */
-static const unsigned char NSUnicodeStringEncoding_data[] = {
+/* Apple's NSUnicodeStringEncoding returns a string encodeded in host-byte
+ * order, with the BOM set There is no API for requesting anything else */
+#ifdef WORDS_BIGENDIAN
+# define NSUnicodeStringEncoding_data NSUnicodeStringEncodingBE_data
+#else
+# define NSUnicodeStringEncoding_data NSUnicodeStringEncodingLE_data
+#endif
+
+/* English UTF-16-LE "Hello, Universe", assembled by byte */
+static const unsigned char NSUnicodeStringEncodingLE_data[] = {
0xff, 0xfe, 0x48, 0x00, 0x65, 0x00, 0x6c, 0x00, 0x6c, 0x00, 0x6f, 0x00,
0x2c, 0x00, 0x20, 0x00, 0x55, 0x00, 0x6e, 0x00, 0x69, 0x00, 0x76, 0x00,
0x65, 0x00, 0x72, 0x00, 0x73, 0x00, 0x65, 0x00, 0x0, 0x0
@@ -214,7 +220,7 @@
[string release];
/* No free, UTF-16-LE */
- string = [[NSString alloc] initWithBytesNoCopy: (void *) NSUnicodeStringEncoding_data length: sizeof(NSUnicodeStringEncoding_data) encoding: NSUnicodeStringEncoding freeWhenDone: NO];
+ string = [[NSString alloc] initWithBytesNoCopy: (void *) NSUnicodeStringEncodingLE_data length: sizeof(NSUnicodeStringEncodingLE_data) encoding: NSUnicodeStringEncoding freeWhenDone: NO];
fail_if(string == nil, "-[NSString initWithBytesNoCopy: length: encoding: freeWhenDone: NO] returned nil with a UTF-16-LE encoded string.");
[string release];
@@ -226,9 +232,9 @@
[string release];
/* Free, UTF-16-LE */
- bytes = malloc(sizeof(NSUnicodeStringEncoding_data));
- memcpy(bytes, NSUnicodeStringEncoding_data, sizeof(NSUnicodeStringEncoding_data));
- string = [[NSString alloc] initWithBytesNoCopy: bytes length: sizeof(NSUnicodeStringEncoding_data) encoding: NSUnicodeStringEncoding freeWhenDone: YES];
+ bytes = malloc(sizeof(NSUnicodeStringEncodingLE_data));
+ memcpy(bytes, NSUnicodeStringEncodingLE_data, sizeof(NSUnicodeStringEncodingLE_data));
+ string = [[NSString alloc] initWithBytesNoCopy: bytes length: sizeof(NSUnicodeStringEncodingLE_data) encoding: NSUnicodeStringEncoding freeWhenDone: YES];
fail_if(string == nil, "-[NSString initWithBytesNoCopy: length: encoding: freeWhenDone: YES] returned nil with a UTF-16-LE encoded string.");
[string release];
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|