[fpc-devel] Unicode support (yet again)

Felipe Monteiro de Carvalho felipemonteiro.carvalho at gmail.com
Tue Sep 13 21:05:01 CEST 2011


Hello,

Following from a discussion on mac-pascal, I'd like to propose a
solution for Unicode support.

I know that hundreds of messages were already spent on the topic, but
was there any conclusion in the end?

Basically I think that we could support both choices (utf-8 and
unicode string or whatever it is called) by duplicating methods,
procedures and TStrings.

We could change:

Function FileOpen (Const FileName : string; Mode : Integer) : THandle;

into

Function FileOpen (Const FileName : utf8string; Mode : Integer) :
THandle; overload;
Function FileOpen (Const FileName : unicodestring; Mode : Integer) :
THandle; overload;

and similarly for other places and everyone should be happy. One of
the versions could be the real one and the other could use a
conversion. Each platform could decide for itself which is the real
version, so it would avoid unnecessary conversions.

It is not really that different from what Delphi did. They changed:
Function FileOpen (Const FileName : string; Mode : Integer) : THandle;
into: Function FileOpen (Const FileName : unicodestring; Mode :
Integer) : THandle;
We just support 1 more option.

The ansi version I would simply let it die. It's time people migrate
to Unicode anyway. The change from ansi to utf-8 is very easy.

TStrings seams a special case, because any implementation which
supports both will be extremely inefficient, so for it I propose
having 2 classes:

TStrings (for utf-8)
TWideStrings (for delphi-style)

For all others I think just overloading some methods should be fine.

Of course it is not a perfect solution, but I am convinced that there
is no perfect solution here.

-- 
Felipe Monteiro de Carvalho



More information about the fpc-devel mailing list