From a2e8134b7c897762e3d8f248b7b9a237c41538ab Mon Sep 17 00:00:00 2001 From: Jonas Maebe Date: Sat, 11 Dec 2010 18:08:16 +0000 Subject: [PATCH] * 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 - --- rtl/unix/cwstring.pp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/rtl/unix/cwstring.pp b/rtl/unix/cwstring.pp index 3fb4d18c1e..2d0a91f0d7 100644 --- a/rtl/unix/cwstring.pp +++ b/rtl/unix/cwstring.pp @@ -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;