[Lazarus] UTF8String and UTF8Delete
Mattias Gaertner
nc-gaertnma at netcologne.de
Sun Dec 13 02:45:57 CET 2015
On Sat, 12 Dec 2015 16:58:38 +0100
Sven Barth <pascaldragon at googlemail.com> wrote:
>[...]
> 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;
Thanks for the example.
Mattias
More information about the Lazarus
mailing list