[fpc-devel] Unit for handling UTF-8 strings

Paul Ishenin ip at kmiac.ru
Wed Apr 10 02:15:49 CEST 2013

09.04.2013 18:09, Mattias Gaertner пишет:

> Creating a patch is not hard. The lazutf8 already contains the code. But I have
> no idea how the the interface should look like. TCharacter is a Delphi class and
> Delphi does not have UTF-8 functions. Michael wrote that these functions are
> "implicit", so maybe these functions need to fit some form?
> In other words:
> Are there any suggestions, recommendations how the UTF-8 functions should look
> like?

Let's see.

The next function should stay as is. Compiler will add required implicit 
conversion when you assign result to UTF8String variable.

function ConvertFromUtf32(AChar : UCS4Char) : UnicodeString;

Here you can add UTF8String overloads if needed:

function ConvertToUtf32(const AString : UnicodeString; AIndex : Integer) 
: UCS4Char; overload;
function ConvertToUtf32(const AString : UnicodeString; AIndex : Integer; 
out ACharLength : Integer) : UCS4Char; overload;

At the same time even without UTF8 overloads compiler will insert 
implicit conversion from UTF8String to UnicodeString when you pass it to 
that functions. So UTF8 overloads can only increase spead by removing 1 
implicit conversion.

Best regards,
Paul Ishenin

More information about the fpc-devel mailing list