On Sep 3, 2016, at 00:28 , Gerriet M. Denkmann <gerr...@mdenkmann.de> wrote:
> 
> I.e. the size parameter 9 seems to be ignored. (I kind of remember having the 
> same problem in Objective-C).

Yes, it’s an issue with %@, which is a non-IEEE specifier, unlike %s, which is. 
(http://pubs.opengroup.org/onlinepubs/009695399/functions/printf.html) %@ 
actually means to insert the result of ‘[argument description]’, which could be 
any length of string describing any kind of object, so perhaps Apple decided 
that it made no particular sense to try to jam it in a fixed width.

The other issue I can think of would be how to interpret the field width, since 
“real” strings can be counted in different ways. Would %9@ mean 9 UTF-16 code 
units? 9 Unicode code points? 9 grapheme clusters?

There’s probably a similar ambiguity with %9s. It apparently means 9 bytes 
from/including a C-string, which is not necessarily 9 of anything in a UTF-8 
string. Since you work with non-Roman character sets, you’ll probably run into 
this eventually, if you’re padding strings with spaces.

> let scom1 = String(format: "%9s", ("a" as NSString).UTF8String)       

It’s not important, but it’s UTF8String because you’re presumably using Xcode 
7.3. I tried it in Xcode 8 beta 6, where the name translation conventions for 
imported Obj-C SDK symbols are different. In Swift 3, the Obj-C method comes 
out as utf8String. (And, just for extra fun, the String version of the method 
comes out at utf8CString, and has a different type that doesn’t work as a 
vararg.)

Just a few of the many joys of the upcoming Swift 3 transition.

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to