> Is this a bug?
Kind of. It looks like MacRuby differs from Ruby 1.9(and 1.8) in that it does
not return ASCII-8BIT strings(or "byte" strings) from IO objects.
Encoding.default_external is set to UTF-8, where as in Ruby 1.9 it is set to
ASCII-8BIT. Encoding.default_internal is set to nil, which means
data sent to and received from an IO stream will leave and be received in a
UTF-8 encoded string.
> If I have to do a work around is there any way to tell what encodings are
> being seen by the Macruby loop so I can match them
Sure, some things you can try:
Encoding.default_external=
Encoding.default_internal=
(I explain below…)
IO#set_encoding
TCPSocket.new(…).set_encoding('external:internal')
'external' is the external encoding you want to interpret the IO stream in.
'internal' is the encoding you want data received from the string to be
transcoded to.
When you are writing to the socket, 'internal' must be transcoded to 'external'.
When you are reading from the socket, 'external' must be transcoded to
'internal'.
If 'internal' is nil, no transcoding takes place (unless the string is encoded
in an encoding that does not match the external encoding).
String#encode
If those options fail, you can fall back to String#encode.
a = TCPSocket.new(…)
a.write("stuff\r\n")
results = a.read.encode('ASCII-8BIT')
I hope this helps you,
Rob.
_______________________________________________
MacRuby-devel mailing list
[email protected]
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel