[bedevtalk] BFile::Read and foreign characters

Marco Nelissen marcone at xs4all.nl
Fri Jan 20 14:00:00 BRST 2006


>By the way any one knows how read lines from a text file that uses not 
>only english letters? I have problem with the BFile::Read() the swedish 
>letters ÅÄÖ are not reqognised

This is not a problem with BFile, since BFile has nothing to do with
character encoding. What's happening is that the file you are reading
and copying into the BString is not in UTF-8 encoding, whereas BString
(and pretty much the rest of the system too) expects the data to be
UTF-8 encoded.
The best way to fix this is to convert the data before copying it into
the BString using the convert_to_utf8() function in the support kit.
Note that with the code you posted, there is an edge-case where things
could potentially go wrong, namely if there is a UTF-8 multibyte
character right on a buffer-boundary. In that case convert_to_utf8()
won't be able to convert that last character, because it doesn't have
all the bytes for it. You will have to take into account how many bytes
convert_to_utf8() actually used when doing the next Read().

Marco






More information about the bedevtalk mailing list