Reading / Writing Unicode streams

BlitzMax Forums/BlitzMax Programming/Reading / Writing Unicode streams

Revised version, doesn't make any unneccessary calls to the stream's methods and doesn't use wrapper functions.

Function WriteStringW( stream:TStream, str:String )
  stream.WriteInt( str.Length )
  If str.Length = 0 Then Return
  Local shorts:Short Ptr = str.ToWString( )
  stream.WriteBytes( shorts, str.Length*2 )
  MemFree( shorts )
End Function

Function ReadStringW$( stream:TStream )
  Local ln% = stream.ReadInt( )
  If ln = 0 Then Return ""
  Local shorts:Short[ln]
  stream.ReadBytes( shorts, ln*2 )
  Return String.FromShorts( shorts, ln )
End Function