[MacRuby-devel] Strings, Encodings and IO

Vincent Isambart vincent.isambart at gmail.com
Tue Apr 7 05:44:41 PDT 2009


Hi again,

So plan B: We emulate Ruby 1.9 strings behavior on top of of NSString/NSData.

Internally we would use a NSData when the encoding is not valid or
it's binary, and NSString in the other cases (never both at the same
time). We would have a Ruby encoding that may be completely different
from the real encoding of the string (it's just a facade for Ruby).

force_encoding would transform back the string into NSData using the
Ruby encoding if the data is stored as a NSString, or use the NSData.
And then it would try to make a NSString from that data using the
encoding given to force_encoding. If it's successful, we use the
string, if not we use the NSData.

Of course, force_encoding would be slow, as would be accessing bytes
when it's a NSString. However accessing the nth character of a string
would probably be faster than in 1.9.

I am however a bit afraid it would not be very easy to implement. The
main problem is not implementing the string itself, but have something
that plays well with real NSStrings, and with Objective-C code that
waits for normal NSStrings of course. And well I do not know
CFString/NSString well.

As before it's just an idea. Comments are welcome. Implementation will
wait at least until a few people seems it could be useful (and anyone
wanting to do it would be welcome as personally I'm not sure I will
have the time necessary until May).


More information about the MacRuby-devel mailing list