From 9e9085258b2193d95e884a8575fdc215471f38fb Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Sat, 10 Sep 2011 13:13:52 +0200 Subject: Fix endianness flakiness in string streams. --- MLKStringInputStream.m | 11 +++++++++-- 1 file 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; } -- cgit v1.2.3