[Lazarus] UTF8String and UTF8Delete

Bart bartjunk64 at gmail.com
Sat Dec 12 18:01:05 CET 2015


On 12/12/15, Sven Barth <pascaldragon at googlemail.com> wrote:

> Jonas has given me the following as a possible solution:
>
> === code begin ===
>
> procedure UTF8Delete(var s: UTF8String; StartCharIndex, CharCount: PtrInt);
>    begin
>      ...
>    end;
>
>
> procedure UTF8Delete(var s: String; StartCharIndex, CharCount: PtrInt);
>    var
>      orgcp: tsystemcodepage;
>      tmp: utf8string;
>    begin
>      orgcp:=StringCodePage(s);
>      { change code page without converting the data }
>      SetStringCodePage(s,CP_UTF8,false);
>      tmp:=s;
>      { keep refcount to 1 if it was 1, to avoid unnecessary copies }
>      s:='';
>      UTF8Delete(tmp,StartCharIndex,CharCount);
>      { same as above }
>      s:=tmp;
>      tmp:='';
>      SetStringCodePage(s,orgcp,false);
>    end;
>
> === code end ===

Which adds extra overhead for the default situation (not disableUtf8RTL).
But this may very well be neglectable (I'm far too lazy to test).

(Nitpicking: the entire second implementation needs then to be
ifdef-ed with IFnDEF NO_CP_RTL, beacuse if that define is true
Utf8String equals String)

Bart




More information about the Lazarus mailing list