On 1 Aug 2012, at 09:50, Sebastian Reitenbach wrote:
> I "enhanced" my test program a bit, and compared output when running on Linux
> and OpenBSD:
>
> #import <Foundation/Foundation.h>
>
>
> int main(int argc, char *argv[]) {
> NSLog(@"Lowercase: %@", [[NSString stringWithString:@"TöÖst"]
> lowercaseString]);
>
> }
On closer inspection, there is a bug here, but not where you think it is...
Try this test case:
$ cat tolower.m #import <Foundation/Foundation.h>
#import <wctype.h>
int main(int argc, char *argv[]) {
[NSAutoreleasePool new];
NSString *l = [@"TöÖst" lowercaseString];
NSLog(@"Lowercase: %@", l);
NSLog(@"Lowercase: %s", [l UTF8String]);
for (int i=0 ; i<[l length] ; i++)
{
int c = [l characterAtIndex: i];
NSLog(@"%c %d", c,c);
}
}
$ clang tolower.m -lgnustep-base
$ ./a.out
2012-07-31 19:23:44.810 a.out[69751] Lowercase: t??st
2012-07-31 19:23:44.813 a.out[69751] Lowercase: tööst
2012-07-31 19:23:44.813 a.out[69751] t 116
2012-07-31 19:23:44.813 a.out[69751] ? 246
2012-07-31 19:23:44.814 a.out[69751] ? 246
2012-07-31 19:23:44.814 a.out[69751] s 115
2012-07-31 19:23:44.814 a.out[69751] t 116
The error appears to be in converting the 16-bit unicode string that is the
result of lowercaseString for display. Note the values that are being returned
in characterAtIndex: - these are the correct unicode values, but attempting to
display them is failing because the terminal is expecting UTF-8, not UCS16
(and 246 is not a valid 8-bit UTF-8 character). It seems that NSLog is just
truncating the string, rather than translating it into the string locale that
the terminal expects.
David
-- Sent from my STANTEC-ZEBRA
_______________________________________________
Discuss-gnustep mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/discuss-gnustep