Use NSISOLatin1 encoding instead of ASCII

We used to fall back on the ASCII encoding if UTF-8 did not work out. However,
this causes its own problems; ASCII is only valid for the lower 7 bytes. We
solve this by using Latin-1, which should have a valid character for every
byte sequence
This commit is contained in:
Pieter de Bie
2008-12-25 20:03:53 +01:00
parent ed08bf64bd
commit f94ab0f5fe
3 changed files with 9 additions and 5 deletions
+2 -2
View File
@@ -49,7 +49,7 @@
buffer[bytesReceived-1] = '\0';
NSString* s = [NSString stringWithCString: buffer encoding: NSUTF8StringEncoding];
if ([s length] == 0)
s = [NSString stringWithCString: buffer encoding: NSASCIIStringEncoding];
s = [NSString stringWithCString: buffer encoding: NSISOLatin1StringEncoding];
return s;
case '\r':
bytesReceived--;
@@ -59,7 +59,7 @@
buffer[bytesReceived-1] = '\0';
NSString *retVal = [NSString stringWithCString: buffer encoding: NSUTF8StringEncoding];
if ([retVal length] == 0)
retVal = [NSString stringWithCString: buffer encoding: NSASCIIStringEncoding];
retVal = [NSString stringWithCString: buffer encoding: NSISOLatin1StringEncoding];
free(buffer);
return retVal;