[fpc-pascal] RTL and Unicode Strings

Jonas Maebe jonas.maebe at elis.ugent.be
Wed May 11 10:21:11 CEST 2016


Mazo Winst wrote:
> Suppose that my app needs to read a file encoded with UTF-8. Suppose
> that my app runs on Windows, where the system codepage is most likely to
> be Windows ANSI. As RTL will use the system codepage, Windows ANSI
> doesn't support the full range of unicode chars and need to use RTL to
> read the file, what should i do to prevent data loss?

If by reading you mean read/readln, then you can use 
http://www.freepascal.org/docs-html/rtl/system/settextcodepage.html to 
specify to the RTL what the encoding is of the text file you are reading.

In other cases, like LacaK said, you will have to read the data as plain 
bytes into e.g. a RawByteString and next use 
http://www.freepascal.org/docs-html/rtl/system/setcodepage.html (with 
the last parameter set to "false") to afterwards specify the code page 
this data has.


Jonas



More information about the fpc-pascal mailing list