• 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: printing Utf8
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: printing Utf8


  • Subject: Re: printing Utf8
  • From: Ken Thomases <email@hidden>
  • Date: Wed, 31 Oct 2012 10:15:29 -0500

On Oct 31, 2012, at 9:41 AM, Gerriet M. Denkmann wrote:

> I print strings like:
> 	NSString *s = @"ร่วมรส";
> 	fprintf(stderr, "%s\n", [ s UTF8String]);
> and usually it just works.
>
> But sometimes it does not and I get garbage like:
> ร่ว\340\270\241รส
>
> Converting these numbers to hex one gets: 0xe0 0xb8 0xa1 which is the Utf8-code for THAI CHARACTER MO MA.
> So why does it not print (as it should):
> ร่วมรส ?
>
> This is not really reproducible, but happens in about 3% of all lines.
>
> Known error, or my mistake?

I have a couple of guesses:

* A bug in Terminal.app.  Does it happen in other terminal apps like iTerm (if you've tried)?  I assume it is never the case that the octal escape sequences get written out to file, if you redirect stderr.  Is that correct?  (That is, I don't think your program is actually writing out the octal sequence.  I think it's just a display issue.)

* Perhaps there's an issue with the stdio buffer breaking the sequence of UTF-8 code units for a code point into two separate writes.  In your example code, that wouldn't happen because a) you're writing short lines and b) stderr is unbuffered by default.  However, if your real code that exhibits the problem might be fully buffered (or line buffered if you're writing lines long enough to exceed the buffer size), then this might happen.  If the sequence does get split into multiple writes, that still shouldn't be a problem unless the program receiving the data doesn't handle that case.  So, this would really just be a specific explanation of a possible Terminal bug.

Regards,
Ken


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Follow-Ups:
    • Re: printing Utf8
      • From: "Gerriet M. Denkmann" <email@hidden>
    • Re: printing Utf8
      • From: "Gerriet M. Denkmann" <email@hidden>
References: 
 >printing Utf8 (From: "Gerriet M. Denkmann" <email@hidden>)

  • Prev by Date: printing Utf8
  • Next by Date: Re: printing Utf8
  • Previous by thread: printing Utf8
  • Next by thread: Re: printing Utf8
  • Index(es):
    • Date
    • Thread