3 ms·
okay, i see some problems here ... why use the MacRoman character set? UTF8 is a much better default. also, the code uses CFStringGetCStringPtr() as if it can
by allenbrunson 16y ago
okay, i see some problems here ...
why use the MacRoman character set? UTF8 is a much better default.
also, the code uses CFStringGetCStringPtr() as if it can't ever fail. from the docs: "This function either returns the requested pointer immediately, with no memory allocations and no copying, in constant time, or returns NULL. If the latter is the result, call an alternative function such as the CFStringGetCString() function to extract the characters"
- mattmight 16y agoThanks for the tip. Fortunately, little Bobby Tables isn't one of my relatives. I'll update it to use UTF8 when I get a free moment.
- jessriedel 16y agoContext: http://xkcd.com/327/ http://xkcd.com/327/
- Zev 16y agoIf you're going for safety, you should check to make sure that the string can use the particular encoding, rather than assuming that it will work. CFStringIsEncodingAvailable() will do that for you :)
- allenbrunson 16y agono. CFStringIsEncodingAvailable() tells you whether a particular encoding is available on THE CURRENT COMPUTER, not for the given string. i brought up the CFStringGetCStringPtr() issue because my experience is that it works okay if you're using nothing but plain ascii for inputs and outputs, but tends to fail when anything more esoteric is involved. it is not just a theoretical concern, it has happened to me in the wild, with paying customers involved. on the other hand, i think it's reasonable to assume that every mac in existence will be able to handle UTF8. this episode is reminding me that far too many programmers assume ascii everywhere. be nice to foreigners, folks.