[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: NSString and encodings: possible bug
From: |
Wolfgang Sourdeau |
Subject: |
Re: NSString and encodings: possible bug |
Date: |
Fri, 25 Mar 2005 00:45:01 -0500 |
User-agent: |
Mutt/1.3.28i |
> Sample code would be useful ... from your description it is not clear what
> you are doing.
>
> unichar ubuf[2];
> NSString *ascii;
> NSString *unicode;
>
> ubuf[0] = (unichar)'a';
> ubuf[1] = (unichar)'b';
>
> ascii = [[NSString alloc] initWithData: [NSData dataWithBytes: "ab"
> length: 2] encoding: NSASCIIStringEncoding];
> unicode = [[NSString alloc] initWithData: [NSData dataWithBytes: ubuf
> length: 4] encoding: NSUnicodeStringEncoding];
> NSLog(@"Comparison: %d", [ascii isEqual: unicode]);
>
> Should print out the meassage 'Comparison: 1'
Hi Richard,
You are right. I have tested my code a bit further and found out that
the strings that need conversion are ended with a pair of zeroes and that
those caracters were taken into account in the length.
So your test would not pass with ubuf[2] = (unichar)0 and the given
length set to 6 instead of 4 for the unicode string.
I don't know what the "normal" behaviour should be but this quite make
sense that way anyways.
Thank you!
Wolfgang
--
"An eye for an eye only makes the world blind." (Gandhi)