wutils.pas 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. {
  2. $Id$
  3. This file is part of the Free Pascal Integrated Development Environment
  4. Copyright (c) 1998 by Berczi Gabor
  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. unit WUtils;
  12. interface
  13. uses Objects;
  14. type
  15. PByteArray = ^TByteArray;
  16. TByteArray = array[0..65520] of byte;
  17. PUnsortedStringCollection = ^TUnsortedStringCollection;
  18. TUnsortedStringCollection = object(TCollection)
  19. function At(Index: Integer): PString;
  20. procedure FreeItem(Item: Pointer); virtual;
  21. end;
  22. function Min(A,B: longint): longint;
  23. function Max(A,B: longint): longint;
  24. function CharStr(C: char; Count: byte): string;
  25. function Trim(S: string): string;
  26. function UpcaseStr(S: string): string;
  27. function RExpand(S: string; MinLen: byte): string;
  28. function LTrim(S: string): string;
  29. function RTrim(S: string): string;
  30. function IntToStr(L: longint): string;
  31. function StrToInt(S: string): longint;
  32. function GetStr(P: PString): string;
  33. function EatIO: integer;
  34. const LastStrToIntResult : integer = 0;
  35. implementation
  36. function Min(A,B: longint): longint; begin if A<B then Min:=A else Min:=B; end;
  37. function Max(A,B: longint): longint; begin if A>B then Max:=A else Max:=B; end;
  38. function CharStr(C: char; Count: byte): string;
  39. var S: string;
  40. begin S[0]:=chr(Count); if Count>0 then FillChar(S[1],Count,C); CharStr:=S; end;
  41. function UpcaseStr(S: string): string;
  42. var I: integer;
  43. begin
  44. for I:=1 to length(S) do
  45. S[I]:=Upcase(S[I]);
  46. UpcaseStr:=S;
  47. end;
  48. function RExpand(S: string; MinLen: byte): string;
  49. begin
  50. if length(S)<MinLen then
  51. S:=S+CharStr(' ',MinLen-length(S));
  52. RExpand:=S;
  53. end;
  54. function LTrim(S: string): string;
  55. begin
  56. while copy(S,1,1)=' ' do Delete(S,1,1);
  57. LTrim:=S;
  58. end;
  59. function RTrim(S: string): string;
  60. begin
  61. while copy(S,length(S),1)=' ' do Delete(S,length(S),1);
  62. RTrim:=S;
  63. end;
  64. function Trim(S: string): string;
  65. begin
  66. Trim:=RTrim(LTrim(S));
  67. end;
  68. function IntToStr(L: longint): string;
  69. var S: string;
  70. begin
  71. Str(L,S);
  72. IntToStr:=S;
  73. end;
  74. function StrToInt(S: string): longint;
  75. var L: longint;
  76. C: integer;
  77. begin
  78. Val(S,L,C); if C<>0 then L:=-1;
  79. LastStrToIntResult:=C;
  80. StrToInt:=L;
  81. end;
  82. function GetStr(P: PString): string;
  83. begin
  84. if P=nil then GetStr:='' else GetStr:=P^;
  85. end;
  86. function EatIO: integer;
  87. begin
  88. EatIO:=IOResult;
  89. end;
  90. function TUnsortedStringCollection.At(Index: Integer): PString;
  91. begin
  92. At:=inherited At(Index);
  93. end;
  94. procedure TUnsortedStringCollection.FreeItem(Item: Pointer);
  95. begin
  96. if Item<>nil then DisposeStr(Item);
  97. end;
  98. END.
  99. {
  100. $Log$
  101. Revision 1.1 1999-03-01 15:51:43 peter
  102. + Log
  103. }