sysansi.inc 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. {%MainUnit sysutils.pp}
  2. {
  3. *********************************************************************
  4. Copyright (C) 2002 by Florian Klaempfl
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. Function AnsiCompareFileName(const S1, S2: string): SizeInt;
  12. begin
  13. If FileNameCaseSensitive then
  14. Result:=AnsiCompareStr(S1,S2) // Compare case sensitive
  15. else
  16. Result:=AnsiCompareText(S1,S2); // Compare case insensitive. No MBCS yet.
  17. end;
  18. Function SameFileName(const S1, S2: string): Boolean;
  19. begin
  20. Result:=AnsiCompareFileName(S1,S2)=0;
  21. end;
  22. Function AnsiLowerCaseFileName(const S: string): string;
  23. begin
  24. Result:=AnsiLowerCase(S); // No locale support or MBCS yet.
  25. end;
  26. Function AnsiUpperCaseFileName(const S: string): string;
  27. begin
  28. Result:=AnsiUpperCase(S); // No locale support or MBCS yet.
  29. end;
  30. Function AnsiPos(const Substr, S: string): SizeInt;
  31. begin
  32. Result:=Pos(Substr,S); // No MBCS yet.
  33. end;
  34. Function AnsiStrPos(Str, SubStr: PAnsiChar): PAnsiChar;
  35. begin
  36. Result:=StrPos(Str,Substr);
  37. end;
  38. Function AnsiStrRScan(Str: PAnsiChar; Chr: AnsiChar): PAnsiChar;
  39. begin
  40. Result:=StrRScan(Str,Chr);
  41. end;
  42. Function AnsiStrScan(Str: PAnsiChar; Chr: AnsiChar): PAnsiChar;
  43. begin
  44. Result:=StrScan(Str,Chr);
  45. end;
  46. Function HashName(Name: PAnsiChar): LongWord;
  47. Var
  48. thehash,g : LongWord;
  49. I : SizeInt;
  50. begin
  51. thehash:=0;
  52. For I:=0 to StrLen(Name)-1 do { 0 terminated }
  53. begin
  54. thehash:=thehash shl 4;
  55. inc(theHash,Ord(UpCase(Name[i])));
  56. g:=thehash and LongWord($f shl 28);
  57. if g<>0 then
  58. begin
  59. thehash:=thehash xor (g shr 24);
  60. thehash:=thehash xor g;
  61. end;
  62. end;
  63. If theHash=0 then
  64. HashName:=$ffffffff
  65. else
  66. HashName:=TheHash;
  67. end;
  68. function BytesOf(const Val: RawByteString): TBytes;
  69. var
  70. Len:Integer;
  71. begin
  72. Len:=Length(Val);
  73. SetLength(Result,Len);
  74. if Len>0 then
  75. Move(Val[1],Result[0],Len);
  76. end;
  77. function BytesOf(const Val: AnsiChar): TBytes;
  78. begin
  79. SetLength(Result,1);
  80. Result[0]:=Byte(Val);
  81. end;
  82. Function CharInSet(Ch:AnsiChar;Const CSet : TSysCharSet) : Boolean; inline;
  83. begin
  84. result:=ch in CSet;
  85. end;