Re: cString vs UTF8String (memory question)
Re: cString vs UTF8String (memory question)
- Subject: Re: cString vs UTF8String (memory question)
- From: Alastair Houghton <email@hidden>
- Date: Fri, 12 Dec 2003 16:42:00 +0000
On 12 Dec 2003, at 14:54, Greg Hurrell wrote:
>
In short, my question is, can I basically go through my code and
>
replace all calls to -cString or -lossyCString with calls to
>
-UTF8String instead? Are there going to be any unforeseen
>
consequences? (In my case the only C strings I work with tend to be
>
filesystem paths, for which I am already using
>
-fileSystemRepresentation, and arguments to command-line tools.)
As long as you are passing the results to functions that expect either
US-ASCII (i.e. no characters with the top bit set) or UTF8, you can
change -cString and -lossyCString to -UTF8String. All of the BSD APIs
use UTF8, and all of the C library functions are compatible with UTF8
even where they don't actually understand it.
[snip]
>
And are calls to -UTF8String and -fileSystemRepresentation basically
>
interchangeable? The docs say that the latter returns a "canonical
>
UTF-8 encoding". Is the representation returned by -UTF8String any
>
different?
The point of -fileSystemRepresentation is that because there's more
than one way to encode some characters in Unicode (e.g. accented
characters can be precomposed [i.e. a single character] or represented
as a base character plus an accent character), it is necessary for
various reasons to standardise the representation used by the
filesystem. -UTF8String can return *any* valid UTF8 encoding of the
string, and may change from release to release, whereas
-fileSystemRepresentation is guaranteed to return the same
representation, independent of the version of the Unicode
standard/version of Foundation.
Looking at the docs, it also seems that in the past (when Cocoa was
portable), -fileSystemRepresentation might have made other
transformations on the basis that what it was dealing with was a
pathname (e.g. changing '/' to '\').
>
At least in the case of -fileSystemRepresentation, the docs do say
>
that the result is automatically freed, so my only memory-related
>
doubt is in connection with -UTF8String.
-UTF8String works just like -fileSystemRepresentation and -cString from
the point of view of memory management.
Kind regards,
Alastair.
[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.