[fpc-pascal] Adding file to string to the RTL

Michael Van Canneyt michael at freepascal.org
Tue Oct 6 19:30:48 CEST 2020



On Tue, 6 Oct 2020, Bart via fpc-pascal wrote:

> On Tue, Oct 6, 2020 at 10:12 AM Michael Van Canneyt via fpc-pascal
> <fpc-pascal at lists.freepascal.org> wrote:
>
>
>> // Assume TEncoding.SystemEncoding
>> Function GetFileAsString(Const aFileName : RawByteString) : RawByteString;
>> // Specify encoding
>> Function GetFileAsString(Const aFileName : RawByteString; aEncoding : TEncoding) : RawByteString;
>> // Assume TEncoding.Unicode contents
>> Function GetFileAsString(Const aFileName : UnicodeString) : UnicodeString;
>> // Specify encoding, return Unicode string.
>> Function GetFileAsString(Const aFileName : UnicodeString; aEncoding : TEncoding) : UnicodeString;
>
> Now I want to get the contents of a file, which contains either UTF8
> or some single-byte encoding, and the filename is NOT in my locale
> (e.g. it may be chinese, which I cannot represent in RawByteString),

Of course you can. That is why we use RawByteString for file opening
functions.  You specify it as UTF8 in that case, the RTL will do the rest.

The whole of lazarus works on this principle.

Michael.


More information about the fpc-pascal mailing list