sysansi.inc 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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: PChar): PChar;
  35. begin
  36. Result:=StrPos(Str,Substr);
  37. end;
  38. Function AnsiStrRScan(Str: PChar; Chr: Char): PChar;
  39. begin
  40. Result:=StrRScan(Str,Chr);
  41. end;
  42. Function AnsiStrScan(Str: PChar; Chr: Char): PChar;
  43. begin
  44. Result:=StrScan(Str,Chr);
  45. end;
  46. Function HashName(Name: PAnsiChar): LongWord;
  47. Var
  48. thehash,g,I : LongWord;
  49. begin
  50. thehash:=0;
  51. For I:=1 to Length(Name) do { 0 terminated }
  52. begin
  53. thehash:=thehash shl 4;
  54. inc(theHash,Ord(UpCase(Name[i])));
  55. g:=thehash and LongWord($f shl 28);
  56. if g<>0 then
  57. begin
  58. thehash:=thehash xor (g shr 24);
  59. thehash:=thehash xor g;
  60. end;
  61. end;
  62. If theHash=0 then
  63. HashName:=$ffffffff
  64. else
  65. HashName:=TheHash;
  66. end;
  67. function BytesOf(const Val: RawByteString): TBytes;
  68. var
  69. Len:Integer;
  70. begin
  71. Len:=Length(Val);
  72. SetLength(Result,Len);
  73. if Len>0 then
  74. Move(Val[1],Result[0],Len);
  75. end;
  76. function BytesOf(const Val: AnsiChar): TBytes;
  77. begin
  78. SetLength(Result,1);
  79. Result[0]:=Byte(Val);
  80. end;
  81. Function CharInSet(Ch:AnsiChar;Const CSet : TSysCharSet) : Boolean; inline;
  82. begin
  83. result:=ch in CSet;
  84. end;