sysstr.inc 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. {
  2. *********************************************************************
  3. $Id$
  4. Copyright (C) 1997, 1998 Gertjan Schouten
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. *********************************************************************
  17. System Utilities For Free Pascal
  18. }
  19. { string manipulation functions }
  20. function setLength(var s:string; newLength:longint):longint;
  21. begin
  22. if (newLength > 255) then
  23. newLength := 255;
  24. s[0] := char(newLength);
  25. setLength := ord(s[0]);
  26. end ;
  27. function UpperCase(s: string): string;
  28. var l:longint;
  29. begin
  30. l := Length(S);
  31. while l <> 0 do begin
  32. if (s[l] in ['a'..'z']) then s[l] := char(byte(s[l]) - 32);
  33. dec(l);
  34. end;
  35. uppercase := s;
  36. end;
  37. function LowerCase(s: string): string;
  38. var l:longint;
  39. begin
  40. l := Length(S);
  41. while l <> 0 do begin
  42. if (s[l] in ['A'..'Z']) then s[l] := char(byte(s[l]) + 32);
  43. dec(l);
  44. end;
  45. LowerCase := s;
  46. end;
  47. {!$I ANSI.PPI}
  48. function AnsiUpperCase(s: string):string;
  49. begin
  50. end ;
  51. function AnsiLowerCase(s: string):string;
  52. begin
  53. end ;
  54. function left(s: string;i:Longint): string;
  55. begin
  56. left := copy(s,1,i);
  57. end ;
  58. function right(s: string;i:Longint): string;
  59. begin
  60. right := copy(s,1 + length(s)-i,i);
  61. end ;
  62. function trim(s: string):string;
  63. var i,l:longint;
  64. begin
  65. l := length(s);
  66. while (s[l] = ' ') and (l > 0) do dec(l);
  67. setLength(s, l);
  68. i := 1;
  69. while (s[i] = ' ') and (i <= l) do inc(i);
  70. trim := copy(s, i, l);
  71. end ;
  72. function trimleft(s:string):string;
  73. var i,l:longint;
  74. begin
  75. l := length(s);
  76. i := 1;
  77. while (s[i] = ' ') and (i <= l) do inc(i);
  78. trimleft := copy(s, i, l);
  79. end ;
  80. function trimright(s:string):string;
  81. var l:longint;
  82. begin
  83. l := length(s);
  84. while (s[l] = ' ') and (l > 0) do dec(l);
  85. setLength(s, l);
  86. trimright := s;
  87. end ;
  88. { Conversion stuff }
  89. function IntToStr(l:longint):string;
  90. var result:string;
  91. begin
  92. system.str(l,result);
  93. inttostr := result;
  94. end ;
  95. function StrToInt(s:string):longint;
  96. var result:longint;c:word;
  97. begin
  98. val(s, result, c);
  99. strtoint := result;
  100. end ;
  101. function IntToHex(Value: longint; Digits: longint): string;
  102. var result:string;i:longint;
  103. begin
  104. result := ' ';
  105. setLength(result, digits);
  106. for i := 0 to digits - 1 do begin
  107. result[digits - i] := HexDigits[value and 15];
  108. value := value shr 4;
  109. end ;
  110. inttohex := result;
  111. end ;
  112. {
  113. $Log$
  114. Revision 1.1 1998-04-10 15:17:46 michael
  115. + Initial implementation; Donated by Gertjan Schouten
  116. His file was split into several files, to keep it a little bit structured.
  117. }