On 4 December 2011 17:48, <jcm@...> wrote:
> Is there a tutorial somewhere on writing non-ascii characters to a file?
> I have latin-1 encoded characters in a db, and I'm not sure how to write
> those out. I can use flexi-streams:string-to-octets and back, but how can
> I use with-open-file to write the correct characters to a text file?
So, first you get stuff from the DB.
If it arrives as raw octets you can just use pass :ELEMENT-TYPE
'(UNSIGNED-BYTE 8) WITH-OPEN-FILE to write it to file using its
original (in this case latin-1) encoding. If you must write it in, say
:UTF-8 instead, you need to first convert it to a string using eg.
SB-EXT:OCTETS-TO-STRING with :EXTERNAL-FORMAT :LATIN-1 and then
proceed as in the next paragraph.
If it arrives as correctly decoded string, pass :EXTERNAL-FORMAT
:UTF-8 to WITH-OPEN-FILE instead. (Or :LATIN-1, or whatever encoding
you want to write it in.)
If it arrives as an /incorrectly/ decoded string, then you need to
figure out where it goes wrong, and make sure the right external
format is used there.