• 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: Fritz Anderson <email@hidden>
  • Date: Wed, 31 Oct 2012 15:28:47 -0500

I ran into something similar in my own work, but my solution may not fit your needs.

printf() won't work reliably for you. My conjecture is that printf buffers its work byte-by-byte, and if an encoded character falls across a buffer boundary, the two parts are output as escaped-decimal, because each looks like a broken encoding in isolation.

The way I solved it was to use -[NSString writeToFile:atomically:encoding:error:]. Obviously, that may not be an easy substitution for you, but unlike stdio, NSString knows about Unicode all the way down.

Or, as you say, the buffering problem may be with Xcode. In fact, that's more likely.

	— F

On 31 Oct 2012, at 9:41 AM, Gerriet M. Denkmann <email@hidden> 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?
> Or some well meant attempt to prevent any form of indecency appearing on my screen (ร่วมรส = copulate)?
>
> Gerriet.
>
>
> _______________________________________________
>
> 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


_______________________________________________

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


References: 
 >printing Utf8 (From: "Gerriet M. Denkmann" <email@hidden>)

  • Prev by Date: Re: printing Utf8
  • Next by Date: Re: Event loop expiration date insight
  • Previous by thread: Re: printing Utf8
  • Next by thread: Drawing customized window
  • Index(es):
    • Date
    • Thread