diff options
author | Matthias Andreas Benkard <code@mail.matthias.benkard.de> | 2011-09-10 13:13:52 +0200 |
---|---|---|
committer | Matthias Andreas Benkard <code@mail.matthias.benkard.de> | 2011-09-10 13:13:52 +0200 |
commit | 9e9085258b2193d95e884a8575fdc215471f38fb (patch) | |
tree | f40c59ed1f1973765d8ae08bf63727b800724bb6 | |
parent | 4a37588e1e747a128b2ec39abacaf2530004b64e (diff) |
Fix endianness flakiness in string streams.
-rw-r--r-- | MLKStringInputStream.m | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/MLKStringInputStream.m b/MLKStringInputStream.m index c8d7a38..0701d79 100644 --- a/MLKStringInputStream.m +++ b/MLKStringInputStream.m @@ -33,14 +33,21 @@ -(MLKStringInputStream *) initWithString:(NSString *)string { + // We used to use NSUnicodeStringEncoding here, but Mac OS X has + // the strange habit of using a byte-order mark in internal string + // representations. This complicates matters: -readCharNoCache + // will correctly read the first character of a string, since the + // beginning of the string includes the BOM, but subsequent + // characters may or may not be read correctly depending on the + // host's default endianness. MLKStreamStream *binstream = LAUTORELEASE ([[MLKStreamStream alloc] initWithInputStream: [NSInputStream inputStreamWithData: [string dataUsingEncoding: - NSUnicodeStringEncoding]]]); + NSUTF8StringEncoding]]]); self = (id) [super initWithBinaryStream:binstream - encoding:NSUnicodeStringEncoding]; + encoding:NSUTF8StringEncoding]; return self; } |