Re: [Pyobjc-dev] Re: [ pyobjc-Bugs-679748 ] NSMutableString gets converted to Python string
Brought to you by:
ronaldoussoren
From: David E. <epp...@ic...> - 2003-02-04 00:12:09
|
On 2/3/03 6:19 PM -0500 Bob Ippolito <bo...@re...> wrote: >> Currently, because of the 7-bit possibility, if you want a unicode >> string from a value s that came from the objc side, you need to call >> unicode(s). I hope and assume that whatever happens with strings, >> unicode(s) will still work. > > unicode(s) works for any str or unicode instance, or any instance that > otherwise implements __str__ and/or __unicode__. If it's a str or > __str__ that has 8-bit characters, you have to specify an encoding. > Optionally you may also specify a way to handle errors ('strict', > 'ignore', or 'replace'). So I guess my point is that if NSStrings with 8-bit characters stopped being converted to unicodes automatically, an appropriate implementation of __unicode__ should be added. It would be bad to go through __str__ and force an encoding to be specified explicitly, because an encoding is already determined for this kind of object. On 2/4/03 12:24 AM +0100 Just van Rossum <ju...@le...> wrote: >> Currently, because of the 7-bit possibility, if you want a unicode >> string from a value s that came from the objc side, you need to call >> unicode(s). I hope and assume that whatever happens with strings, >> unicode(s) will still work. > > I'm curious: if the string is known to be 7-bit ascii, in what situation > does an 8-bit string not work where a unicde string does? I had some code of the form unicode(s).encode('utf8') because I thought it didn't make sense to encode something that wasn't already unicode. But looking at it again, I guess encode works equally well on 7-bit strings... > Btw. while peeking around I came across the thing Bill warned for: > [NSString stringWithCString:] returns an instance of NSCFString, which > is a subclass of -- tada -- NSMutableString. This doesn't mean it _is_ > mutable: I get an exception if I try. So _inheritance_ can't be used to > determine mutability. Does anyone know off hand what can? Any idea whether it reuses the storage of the C string, or copies it? If it reuses it, it could be mutable by the C code... -- David Eppstein UC Irvine Dept. of Information & Computer Science epp...@ic... http://www.ics.uci.edu/~eppstein/ |