[fpc-pascal] Read lines into UnicodeString variable from UCS2 (UTF-16) encoded text file

LacaK lacak at zoznam.sk
Wed Sep 4 07:39:16 CEST 2019


Hi *,

is there any smart way how to read string data line by line from UCS2 
encoded text files (lines delimited by $0A00).

Using ReadLn(TextFile, UnicodeStringVariable) does not work as per 
comment in text.inc:

// all standard input is assumed to be ansi-encoded

Nor reading into WideChar varible does not work.
Nor setting SetTextCodePage to CP_UTF16 helped.

I wonder if Delphi supports ReadLn() for UTF-16 encoded text files ...?
Is there way how to add support for it in FPC? May be if there will be 
set TextRec(T).CodePage=CP_UTF16 then any of the fpc_Read_Text_* 
procedures will assume that input file is utf-16 encoded and not ansi?

Now I work-around by reading two chars into array[0..1] of Char and then 
cast it to UnicodeChar.
(I know that it is not safe for UTF-16, but for UCS2 it works)

Thanks

-Laco.



More information about the fpc-pascal mailing list