[fpc-devel] Unicode and UTF8String

Luiz Americo Pereira Camara pascalive at bol.com.br
Mon Dec 1 18:33:56 CET 2008


Martin Friebe escreveu:
> All the code
>  Widestring := RtlFunction;
>  Utf8string := RtlFunction;
> will run, it may just perform badly.

Yes and no.

Let's assume the platforms windows and unix having UnicodeString 
(UTF-16) and UTF8String as native types respectively.
You choose to use UnicodeString type in your app.

Using the rtlstring approach you get:

Under windows: the native string type of platform is the same as you are 
using no conversion is taken. Good.
Under unix: the native string type of platform is NOT the same as you 
are using ONE conversion is taken. Bad.

Now let's assume that fpc team decided to use a fixed unicode encoding 
for the RTL. Let's say a UnicodeString RTL.
You choose to use UnicodeString type in your app.

Under windows no conversions. Everything is UTF16. Good.
Under unix the RTL must internally convert from the native type (UTF8) 
to UTF16. Bad.

The same result as above.

But someone else wants/needs to use UTF8 strings in your project.

Under windows you will get one conversion: UTF16 -> UTF8. Bad.
Under unix you will get TWO conversions: UTF8 -> UTF16 -> UTF8. Very Bad.

Luiz



More information about the fpc-devel mailing list