• 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: what encoding does sprintf() expect?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: what encoding does sprintf() expect?


  • Subject: Re: what encoding does sprintf() expect?
  • From: Alastair Houghton <email@hidden>
  • Date: Mon, 12 Dec 2005 18:55:05 +0000

On 12 Dec 2005, at 08:14, Ken Turkowski wrote:

I'm pretty sure that sprintf will work with any character encoding that is an extension of ASCII. This includes MacRoman, Latin-1 aka ISO-8859-1, Windows aka ANSI, and UTF-8. Beware of trying to limit the field size, when the field contains multi-byte UTF-8 characters, e.g.
sprintf(buf, "%.4s" uniStr);

It's more something to be aware of, rather than to beware of, since the two most common uses for this feature of sprintf() are:

(a) To ensure that a field doesn't overflow the buffer (this is equivalent
to neatly formatting information in many cases).

(b) To format strings that have no terminating NUL

Since the buffers for both are likely to be specified as a count of the number of chars (i.e. bytes) and not character counts, the behaviour of sprintf() in this regard makes sense.

Also, I believe UTF-8 does *not* support six-byte character sequences; the longest acceptable sequence is four bytes in length (see RFC3629, which updated RFC2279 on this point, amongst other things).

Kind regards,

Alastair.

--
http://www.alastairs-place.net


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
References: 
 >Re: what encoding does sprintf() expect? (From: Ken Turkowski <email@hidden>)

  • Prev by Date: Core Data: NSArrayController's MOC vs NSPersistentDocument's MOC
  • Next by Date: Re: NSObject Exercise comments?
  • Previous by thread: Re: what encoding does sprintf() expect?
  • Next by thread: call an action of another class
  • Index(es):
    • Date
    • Thread