From 191c86fdf66cea0b17e90ee02a99a299e5c0c916 Mon Sep 17 00:00:00 2001 From: mattias Date: Thu, 4 Dec 2014 16:27:01 +0000 Subject: [PATCH] lazutils: paswstring: fixed CharLengthPChar git-svn-id: trunk@47096 - --- components/lazutils/paswstring.pas | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/components/lazutils/paswstring.pas b/components/lazutils/paswstring.pas index 538df7f852..3eb75d8596 100644 --- a/components/lazutils/paswstring.pas +++ b/components/lazutils/paswstring.pas @@ -174,9 +174,19 @@ begin end; function CharLengthPChar(const Str: PChar): PtrInt; +// return the number of codepoints (including invalid codepoints) +var + p: PChar; + l: Integer; begin {$ifdef PASWSTRING_VERBOSE}WriteLn('CharLengthPChar START');{$endif} - Result := UTF8CharacterLength(Str); + p:=Str; + if p=nil then exit(0); + while p^<>#0 do begin + l:=UTF8CharacterLength(p); + inc(Result); + inc(p,l); + end; end; function AnsiCompareStr(const s1, s2: ansistring): PtrInt;