Difference between revisions of "FPC Unicode support"
Line 61: | Line 61: | ||
Full support of code page aware strings is not possible without breaking some existing code. The following list tries to summarize the most important user visible changes. | Full support of code page aware strings is not possible without breaking some existing code. The following list tries to summarize the most important user visible changes. | ||
− | + | * The string header has two new fields: encoding and element size. On 32 Bit platforms this increases the header size by 4 and on 64 bit by 8 bytes. | |
− | + | * WideCharLenToString and UnicodeCharLenToString return an UnicodeString instead of an Ansistring before. | |
==Roadmap of RTL Unicode support with UnicodeString== | ==Roadmap of RTL Unicode support with UnicodeString== |
Revision as of 11:49, 2 August 2009
Introduction
Free Pascal compiler and RTL/FCL should natively support Unicode. Upcoming Delphi release codenamed Tiburon will natively support Unicode as well. FPC must be compatible with Delphi in Unicode support.
Even if Tiburon is not released yet we can start to do background work for Unicode support in FPC.
Tiburon Unicode support
Currently we have some information about Tiburon's Unicode support implementation.
http://blogs.codegear.com/abauer/2008/01/09/38845
http://blogs.codegear.com/abauer/2008/07/16/38864
FPC Unicode support
FPC must have the following string types with transparent conversion between them (like current AnsiString <-> WideString conversion):
- shortstring
- ansistring
- widestring
- utf8string
- utf16string
- utf32string
- ucs2string (?)
- ucs4string (?)
Development and further maintenance of these string types must be as simple as possible. New string types must be easily added in future if needed.
Compiler uses generic structure and helper routines to handle all refcounted string types.
String header:
type TRefStringRec = packed record Encoding: word; // encoding of string ElementSize: byte; // size in bytes of string's element (1-4) Ref: SizeInt; // number of references Len: SizeInt; // number of elements is string end;
Helper routines will know how to handle string from its header.
Extra parameter with string type information is passed to some routines (like fpc_RefString_SetLength) to allow properly initialize new strings.
widestring type on Windows targets remains non-refcounted and OLE compatible. Minimal number of helper routines is used for it. On non-Windows targets widestring is alias to utf16string.
The compiler uses helpers for string type conversions like this:
procedure fpc_ansistring_to_utf16string(out dst: utf16string; const src: ansistring); procedure fpc_utf32string_to_utf16string(out dst: utf16string; const src: utf32string);
The compiler generates helper procedure name from type names. The compiler does not perform any string conversion handling by itself.
Status of Unicode support in FPC so far
Currently FPC 2.3.x has a new type called UnicodeString. This is similar to a WideString type. The difference being that UnicodeString is reference counted on all platforms.
All implementation work is currently done in a separate svn branch: http://svn.freepascal.org/svn/fpc/branches/cpstrnew
User visible changes
Full support of code page aware strings is not possible without breaking some existing code. The following list tries to summarize the most important user visible changes.
- The string header has two new fields: encoding and element size. On 32 Bit platforms this increases the header size by 4 and on 64 bit by 8 bytes.
- WideCharLenToString and UnicodeCharLenToString return an UnicodeString instead of an Ansistring before.
Roadmap of RTL Unicode support with UnicodeString
Topic | Status | Comments | Assigned To |
---|---|---|---|
Locale Variables | Not Implemented | Variables are all 1 byte in size and can't hold UnicodeChar size values. e.g.: The Russian thousand separator is a no-break space $00A0 which doesn't fit in the ThousandSeparator (standard Char type) variable. | |
TStrings | Not Implemented | There is no UnicodeString version of TStrings | |
TStringList | Not Implemented | There is no UnicodeString version of TStringList | |
Pos() | Working |
Roadmap of RTL Unicode support with UTF8String
Topic | Status | Comments | Assigned To |
---|---|---|---|
UTF8String | Not Implemented | Needs a real implementation. Is currently just an alias for ansistring. | |
TStrings | Not Implemented | There is no UTF8String version of TStrings | |
TStringList | Not Implemented | There is no UTF8String version of TStringList |