Textoutputstream's and encodings

Since I cant post there
@Alberto
re : (https://forum.xojo.com/conversation/post/490074)

Create a new module
Add an extension method for TextOutputStream

  Sub writeEncoded(extends tos as Textoutputstream, value as string)
      tos.encoding = value.Encoding
      tos.write value
  end sub

now you could probably write ANY number of different encodings into a file but it would be a mess without some other meta data being written into the file to know what encoding you are about to read / write

an alternative would be to write this extensions as

  sub writeEncoded(extends tos as Textoutputstream, value as string)
      if tos.encoding is nil then
        tos.write value
     else
        tos.write ConvertEncoding(value, tos.encoding)
     end if
  end sub

FWIW - feedback://showreport?report_id=11140

1 Like

It looks like tos.encoding is never Nil but UTF8 by default.

It may be
I wrote the entire thing in the editor here without referring to the language reference etc
I suppose you could just do

 sub writeEncoded(extends tos as Textoutputstream, value as string)
        tos.write ConvertEncoding(value, tos.encoding)
  end sub