• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: (unicode -> shift-jis) encoding conversion bug?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: (unicode -> shift-jis) encoding conversion bug?


  • Subject: Re: (unicode -> shift-jis) encoding conversion bug?
  • From: Greg Titus <email@hidden>
  • Date: Thu, 24 Jan 2002 09:30:50 -0800

On Thursday, January 24, 2002, at 06:22 AM, Jody Fairchild wrote:

a situation in which converting characters from unicode to shift-jis
seems to produce incorrect (or at least counterintuitive) results, e.g:

let's run the following code snippetoid:

NSString *example;
unichar in, out;
NSString *s;
NSData *d;

for (i = 0; i < [length example]; i++)
{
uc = [example characterAtIndex:i];
s = [[NSString alloc] initWithCharacters:&in length:1];
d = [s dataUsingEncoding:NSShiftJISStringEncoding
allowLossyConversion:NO];
[d getBytes:&out];

NSLog(@"unicode = %X, sjis = %X",in,out);
}

I'm betting if you looked at [d length], that you'd find that the length is 1 in the case of plain 'a'. (I.e. a single byte whose value is 0x61.)

The bug is that you are just assuming that the length of the data is going to be 2 when you call getBytes:.

Hope this helps,
--Greg


References: 
 >(unicode -> shift-jis) encoding conversion bug? (From: email@hidden (Jody Fairchild))

  • Prev by Date: Re: (unicode -> shift-jis) encoding conversion bug?
  • Next by Date: Window-closing sequence in a Document-based App
  • Previous by thread: Re: (unicode -> shift-jis) encoding conversion bug?
  • Next by thread: NSPrintInfo paperSize - margins = printing area?
  • Index(es):
    • Date
    • Thread