[Lazarus] UTF8String and UTF8Delete
Bart
bartjunk64 at gmail.com
Sat Dec 12 16:47:55 CET 2015
On 12/11/15, Sven Barth <pascaldragon at googlemail.com> wrote:
> Not necessarily. You can use SetCodePage() to change the code page of
> the string without triggering a codepage conversion by using the third
> parameter which is a Boolean that tells the function to either do a
> conversion (True; default) or not (False). You'd then need to declare
> the UTF8* routines as RawByteString and explicitly handle the type
> conversion.
That's not really an option since it will break every single program
using those functions.
AFAIK the Utf8* functions assume their input is UTF8 encoded (they do
not check), so something like this should work?
{$ifndef NO_CP_RTL}
procedure Utf8Delete(var S: Utf8String; StartCharIndex, CharCount:
PtrInt); overload;
var
Temp: String;
begin
SetLength(Temp, Length(S));
Move(S[1], Temp[1], Length(S));
//nex step might not be needed?
SetCodePage(RawBytestring(Temp), CP_UTF8, False);
UTF8Delete(Temp, StartCharIndex, CharCount);
SetLength(S, Length(Temp));
Move(Temp[1], S[1], Length(Temp));
end;
{$endif}
Anyhow, as stated before, there should be noneed to use the type
Utf8String in Lazarus programs.
Bart
More information about the Lazarus
mailing list