Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2006-10

Default strings encoding

4 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Felipe Monteiro de Carvalho

Hello,

If I have a ansistring, and cast that to a WideString, fpc is converting from which encoding to which encoding?

ansistring can hold utf-8 also, not only iso. I'm not sure what WideString holds. Maybe UTF-16? Or a limited UTF-16 with only 2 bytes characters.

thanks,

Felipe Monteiro de Carvalho

Reply by email

Daniël Mantione
to Felipe Monteiro de Carvalho

Op Tue, 10 Oct 2006, schreef Felipe Monteiro de Carvalho:

Hello, If I have a ansistring, and cast that to a WideString, fpc is converting from which encoding to which encoding?

Without widestring manager, it converts iso-8859-1 to UCS-2.

ansistring can hold utf-8 also, not only iso.

Yes, but in that case, declare it as UTF8string. There exist functions UTF8encode and UTF8decode to convert between an UTF8string and a widestring.

I'm not sure what WideString holds. Maybe UTF-16? Or a limited UTF-16 with only 2 bytes characters.

UCS-2. Basically this is UTF-16 with only 2-byte characters, allthough there are small differences in the high regions; UCS-2 is code points $0..$ffff, while UTF-16 has facilities to allow for multiword characters.

Daniël

Reply by email

peter green
to Daniël Mantione
Show quoted text 8 lines
> I'm not sure what > WideString holds. Maybe UTF-16? Or a limited UTF-16 with only 2 bytes > characters. UCS-2. Basically this is UTF-16 with only 2-byte characters, allthough there are small differences in the high regions; UCS-2 is code points $0..$ffff, while UTF-16 has facilities to allow for multiword characters.

there is nothing intrinsic about how widestring is implemented that stops it holding UTF-16 multiword characters, its just a matter of whether the routines its passed to do (on windows i belive surrogate support depends on a registry setting and is disabled by default on western editions).

Reply by email

peter green
to Felipe Monteiro de Carvalho: If I have a ansistring, and cast that to a WideString, fpc is converting from which…
If I have a ansistring, and cast that to a WideString, fpc is converting from which encoding to which encoding?

the default is ISO-8859-1 to UCS-2/UTF-16 (the only difference between the two being UTF-16 support for surrogates), however this can be changed by registering a widestring manager.

personally if you wan't good internationalisation support i would advise avoiding the implicit conversion between ansistrings and widestrings and thinking through exactly what conversion you wan't in a particular situation, after all as you say an ansistring can hold anything.

for example if writing a html interperter you would base your conversion on the charset part of the content type.

Would the devs consider adding a compile option to disable implicit conversions between ansistrings and widestrings (as i belive in applications working with multiple encodings accidental use of them could be a major source of bigs)?

Reply by email