util.inc 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. {
  2. $Id$
  3. This file is part of the Free Component Library (FCL)
  4. Copyright (c) 1999-2000 by Michael Van Canneyt and 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 IntToStr (I : Longint) : String;
  12. begin
  13. Str(I,Result);
  14. end;
  15. function IsValidIdent(const Ident: string): Boolean;
  16. begin
  17. Result:=True;
  18. end;
  19. procedure BinToHex(BinValue, HexValue: PChar; BinBufSize: Integer);
  20. Const
  21. HexDigits='0123456789ABCDEF';
  22. var
  23. i : longint;
  24. begin
  25. for i:=0 to binbufsize-1 do
  26. begin
  27. HexValue[0]:=hexdigits[(ord(binvalue^) and 15)];
  28. HexValue[1]:=hexdigits[(ord(binvalue^) shr 4)];
  29. inc(hexvalue,2);
  30. inc(binvalue);
  31. end;
  32. end;
  33. function HexToBin(HexValue, BinValue: PChar; BinBufSize: Integer): Integer;
  34. // more complex, have to accept more than bintohex
  35. // A..F 1000001
  36. // a..f 1100001
  37. // 0..9 110000
  38. var
  39. i,j : integer;
  40. begin
  41. i:=binbufsize;
  42. while (i>0) do
  43. begin
  44. if hexvalue^ IN ['A'..'F','a'..'f'] then
  45. j:=(ord(hexvalue^)+9) and 15
  46. else
  47. if hexvalue^ IN ['0'..'9'] then
  48. j:=(ord(hexvalue^)) and 15
  49. else
  50. break;
  51. inc(hexvalue);
  52. if hexvalue^ IN ['A'..'F','a'..'f'] then
  53. j:=j+((ord(hexvalue^)+9) and 15) shl 4
  54. else
  55. if hexvalue^ IN ['0'..'9'] then
  56. j:=j+((ord(hexvalue^)) and 15) shl 4
  57. else
  58. break;
  59. inc(hexvalue);
  60. binvalue^:=chr(j);
  61. inc(binvalue);
  62. dec(i);
  63. end;
  64. result:=binbufsize-i;
  65. end;
  66. {
  67. $Log$
  68. Revision 1.2 2005-02-03 20:17:05 florian
  69. + BinToHex and HexToBin from Marco added
  70. Revision 1.1 2003/10/06 21:01:06 peter
  71. * moved classes unit to rtl
  72. Revision 1.3 2002/09/07 15:15:26 peter
  73. * old logs removed and tabs fixed
  74. }