rtl: add HashName function based on implementation of Hash() from objpas. It uses case case-insensitive hash generation. This function is added for compatibility with delphi (although it generates different hash in delphi and fpc for same strings). It is also needed for codepage search in hash array.

git-svn-id: trunk@19353 -
This commit is contained in:
paul 2011-10-04 04:54:42 +00:00
parent 8fc6af7fde
commit 0bfb83b06c
2 changed files with 22 additions and 1 deletions

View File

@ -69,3 +69,24 @@ begin
Result:=StrScan(Str,Chr);
end;
Function HashName(Name: PAnsiChar): LongWord;
Var
thehash,g,I : LongWord;
begin
thehash:=0;
For I:=1 to Length(Name) do { 0 terminated }
begin
thehash:=thehash shl 4;
inc(theHash,Ord(UpCase(Name[i])));
g:=thehash and LongWord($f shl 28);
if g<>0 then
begin
thehash:=thehash xor (g shr 24);
thehash:=thehash xor g;
end;
end;
If theHash=0 then
HashName:=$ffffffff
else
HashName:=TheHash;
end;

View File

@ -25,4 +25,4 @@ function AnsiPos(const substr,s : string) : SizeInt;
function AnsiStrPos(str,substr : PChar) : PChar;
function AnsiStrRScan(Str : PChar;Chr : Char) : PChar;
function AnsiStrScan(Str : PChar;Chr: Char) : PChar;
function HashName(Name: PAnsiChar): LongWord;