[fpc-pascal] Unicode filenames

Graeme Geldenhuys graemeg.lists at gmail.com
Sun Jun 29 18:27:15 CEST 2008


2008/6/29 Vincent Snijders <vsnijders at quicknet.nl>:
> How does the RTL support using unicode filenames (e.g. file names that
> cannot be represented by the ansi char set)?
>
> For example the FileExists function takes a string which is encoded in the
> system char set. If the system char set is UTF8, like most linuxes and Mac
> OS X, then there is no problem. But on windows using a western european
> charset, I cannot check for existence of a file with cyrilic characters,
> even though I can enter them in the windows explorer and create such files.

In fpGUI we use UTF-8 for everything. We have wrapper file access
functions which replaces the RTL ones. The unit is called
gfx_utils.pas

eg:

function fpgFileExists(const FileName: TfpgString): Boolean;
begin
  Result := FileExists(fpgToOSEncoding(FileName));
end;

fpgToOSEncoding() is then implemented in platform dependent include
files (like FPC also does with many functions).


Linux & *BSD X11:
---------------------------
// yes we assume UTF-8. Only very old Linux versions don't use UTF-8,
but that is very rare now.
function fpgToOSEncoding(aString: TfpgString): string;
begin
  Result := aString;
end;


Windows GDI:
-------
function fpgToOSEncoding(aString: TfpgString): string;
begin
  Result := Utf8ToAnsi(aString);
end;


Regards,
 - Graeme -


_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/



More information about the fpc-pascal mailing list