On 8 Jun '08, at 3:39 AM, Michael Ash wrote:

I never cared about the lack of regex support personally, although I
understand that people do use them. As far as a blessed solution goes,
"man regex" gives you a library that's in libSystem and is part of
POSIX, so it's as supported as you can get.

And (as discussed a few weeks ago) it's not Unicode-savvy, which could bite the unwary developer in the ass, especially when attempting to localize their app into non-Roman languages like Japanese.

I do this with a fair amount of regularity. NSString is unsuitable for
working with data whose encoding is unknown or doubtful, and NSData
doesn't have any string-like functionality, so the standard C str
functions can be very useful here.

Ouch. The problem with those is that, every time you call one, you've added a potential buffer overrun bug to your app. And if the data in the string came from an untrusted source like the network, that escalates to a potential security vulnerability.

Also, speaking of doubtful encodings, the regular C string functions will fail quite badly on 16-bit character encodings, where it's more than likely that every other byte is a zero.

My general tactic when dealing with unknown data whose encoding can't be determined is to just fall back on CP-1252 [though Aki Inoue suggested MacRoman], both of which are supersets of ascii that map every byte to a character. That way you'll always get a non-nil NSString, and any ascii text in the original will come out unscathed. That's a better result than you'll get with C string APIs.

—Jens

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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

This email sent to [EMAIL PROTECTED]

Reply via email to