summaryrefslogtreecommitdiff
path: root/rtl/objpas/sysutils/sysansi.inc
blob: f99eb7b196bfd2fb83259af0300336b2c198f22a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
{
    *********************************************************************
    Copyright (C) 2002 by Florian Klaempfl

    See the file COPYING.FPC, included in this distribution,
    for details about the copyright.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

 **********************************************************************}

Function AnsiCompareFileName(const S1, S2: string): SizeInt;

begin
  If FileNameCaseSensitive then
    Result:=AnsiCompareStr(S1,S2) // Compare case sensitive
  else
    Result:=AnsiCompareText(S1,S2); // Compare case insensitive. No MBCS yet.
end;

Function SameFileName(const S1, S2: string): Boolean;

begin
  Result:=AnsiCompareFileName(S1,S2)=0;
end;

Function AnsiLowerCaseFileName(const S: string): string;

begin
  Result:=AnsiLowerCase(S); // No locale support or MBCS yet.
end;

Function AnsiUpperCaseFileName(const S: string): string;

begin
  Result:=AnsiUpperCase(S); // No locale support or MBCS yet.
end;

Function AnsiPos(const Substr, S: string): SizeInt;

begin
  Result:=Pos(Substr,S); // No MBCS yet.
end;

Function AnsiStrPos(Str, SubStr: PChar): PChar;

begin
  Result:=StrPos(Str,Substr);
end;

Function AnsiStrRScan(Str: PChar; Chr: Char): PChar;

begin
  Result:=StrRScan(Str,Chr);
end;

Function AnsiStrScan(Str: PChar; Chr: Char): PChar;

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;

function BytesOf(const Val: RawByteString): TBytes;
var
  Len:Integer;
begin
  Len:=Length(Val);
  SetLength(Result,Len);
  if Len>0 then
    Move(Val[1],Result[0],Len);
end;

function BytesOf(const Val: AnsiChar): TBytes;
begin
  SetLength(Result,1);
  Result[0]:=Byte(Val);
end;

Function CharInSet(Ch:AnsiChar;Const CSet : TSysCharSet) : Boolean; inline;
begin
  result:=ch in CSet;
end;