* part of r16533, forgot to commit

* also fixes CharLengthPChar() for non-BeOS by initialising the mbstate
    parameter passed to mbrlen() to 0 (otherwise its contents are interpreted
    as already valid, containing information about the current shiftstate etc)

git-svn-id: trunk@16552 -
This commit is contained in:
Jonas Maebe 2010-12-11 18:08:16 +00:00
parent 2f5f98d7e5
commit a2e8134b7c

View File

@ -566,6 +566,9 @@ function CharLengthPChar(const Str: PChar): PtrInt;
begin
result:=0;
s:=str;
{$ifndef beos}
fillchar(mbstate,sizeof(mbstate),0);
{$endif not beos}
repeat
{$ifdef beos}
nextlen:=ptrint(mblen(str,MB_CUR_MAX));
@ -581,6 +584,26 @@ function CharLengthPChar(const Str: PChar): PtrInt;
end;
function CodePointLength(const Str: PChar; maxlookahead: ptrint): PtrInt;
var
nextlen: ptrint;
{$ifndef beos}
mbstate: mbstate_t;
{$endif not beos}
begin
{$ifdef beos}
result:=ptrint(mblen(str,maxlookahead));
{$else beos}
fillchar(mbstate,sizeof(mbstate),0);
result:=ptrint(mbrlen(str,maxlookahead,@mbstate));
{ mbrlen can also return -2 for "incomplete but potially valid character
and data has been processed" }
if result<0 then
result:=-1;
{$endif beos}
end;
function StrCompAnsiIntern(s1,s2 : PChar; len1, len2: PtrInt; canmodifys1, canmodifys2: boolean): PtrInt;
var
a,b: pchar;
@ -758,6 +781,7 @@ begin
CompareTextWideStringProc:=@CompareTextWideString;
CharLengthPCharProc:=@CharLengthPChar;
CodePointLengthProc:=@CodePointLength;
UpperAnsiStringProc:=@UpperAnsiString;
LowerAnsiStringProc:=@LowerAnsiString;