On 17-Dec-06, at 4:27 PM, Charles Yeomans wrote:
TextInputStream allows you to specify an encoding. If you specify
UTF-16, then the BOM is part of the encoding and so the
TextInputStream should do the right thing. If it doesn't, then you
should consider a feedback report.
I guess that's part of the question here. Is the BOM part of the
encoding? I would think not since it's only a trick used to hint at
the endianness of a file contents and we can't expect a BOM to be
prepended to every string.
In the list archives I read Joe Strout explain in the "RB Text
Encoding FAQ" that BOM handling is something that developers have to
handle manually.
<http://support.realsoftware.com/listarchives/realbasic-nug/2004-02/
msg00615.html>
That post dates from 2004 so this might have changed since then but
that's the only info I have to work with at this point. The example
code given says:
When reading the file back in, be sure to check whether the first
character of the first line equals the BOM character, and if so,
strip it off like so:
data = inp.ReadAll
if left(data,1) = Encodings.UTF8.Chr(&hFEFF) then
data = Mid(data,2)
end if
This code is not helpful in dealing with endianness because I need to
know the endianness before I read in the data, not after. Right now
my code calling ReadAll(Encodings.UTF16) returns a gibberish string
because it assumes big-endian but the file is little-endian. I can
check the endianness using the trick above, but TextInputStream does
not give a way to specify it, hence I thought BinaryStream would help.
This still leaves the question of whether BinaryStream implements the
Readable interface, which is what the documentation says but the
compiler says it doesn't. If it doesn't, then I guess I can try
reading the file content in a loop with a buffer.
Steve
--
Steve Roy
<http://homepage.mac.com/sroy>
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>