[fpc-devel] Re: new 27 page document describing Unicode support in D2009
graemeg.lists at gmail.com
Fri Nov 21 22:25:30 CET 2008
On Fri, Nov 21, 2008 at 11:08 PM, Graeme Geldenhuys
<graemeg.lists at gmail.com> wrote:
> I thought you guys might find this interesting. It's a new 27 page
> document describing Unicode support in D2009.
Seeing that I don't own D2009 and only read about it's Unicode support
I found some of the information interesting - and it was things we
argued about in this mailing list.
Length() returns the bytes for UTF8String
but Length() returns the elements (what we know as characters) for
String or UTF16 strings.
Length() also returns bytes for AnsiString.
str8 := 'Cantù';
Memo1.Lines.Add('Length: ' + IntToStr (Length (str8)));
Memo1.Lines.Add('5: ' + IntToStr (Ord (str8)));
Memo1.Lines.Add('6: ' + IntToStr (Ord (str8)));
str16 := str8;
Memo1.Lines.Add('Length: ' + IntToStr (Length (str16)));
Memo1.Lines.Add('5: ' + IntToStr (Ord (str16)));
As you might expect, the str8 string has a length of 6 (meaning 6
bytes), while the str16
string has a length of 5 (meaning 10 bytes, though). Notice that
Length invariably returns the
number of string elements, which in case of variable-length
representations don't match the
number of Unicode code points represented by the string. This is the
output of the program:
2... TStrings can now take an encoding parameter to specify how it
should load or save files.
The ReadFromFile and WriteToFile methods of the TStrings class can be
an encoding. If you write a string list to text file without providing
a specific encoding, the class
will use TEncoding.Default, which uses the internal DefaultEncoding in turn
extracted at the first occurrence by the current Windows code page. In
other words, if you save
a file you'll get the same ANSI file as before.
Of course, you can also easily force the file to a different format,
for example the UTF-16 format:
anyway, there are a lot more interesting facts in this document. Well
worth reading to get a better understanding of unicode.
- Graeme -
fpGUI - a cross-platform Free Pascal GUI toolkit
More information about the fpc-devel