genstr.inc 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2000 by Carl-Eric Codere,
  4. member of the Free Pascal development team.
  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. {$ifndef FPC_UNIT_HAS_STREND}
  12. Function StrEnd(P: PChar): PChar;
  13. var
  14. counter: SizeInt;
  15. begin
  16. counter := 0;
  17. while P[counter] <> #0 do
  18. Inc(counter);
  19. StrEnd := @(P[Counter]);
  20. end;
  21. {$endif FPC_UNIT_HAS_STREND}
  22. {$ifndef FPC_UNIT_HAS_STRCOPY}
  23. Function StrCopy(Dest, Source:PChar): PChar;
  24. var
  25. counter : SizeInt;
  26. Begin
  27. counter := 0;
  28. while Source[counter] <> #0 do
  29. begin
  30. Dest[counter] := char(Source[counter]);
  31. Inc(counter);
  32. end;
  33. { terminate the string }
  34. Dest[counter] := #0;
  35. StrCopy := Dest;
  36. end;
  37. {$endif FPC_UNIT_HAS_STRCOPY}
  38. {$ifndef FPC_UNIT_HAS_STRUPPER}
  39. function StrUpper(P: PChar): PChar;
  40. var
  41. counter: SizeInt;
  42. begin
  43. counter := 0;
  44. while (P[counter] <> #0) do
  45. begin
  46. if P[Counter] in [#97..#122,#128..#255] then
  47. P[counter] := Upcase(P[counter]);
  48. Inc(counter);
  49. end;
  50. StrUpper := P;
  51. end;
  52. {$endif FPC_UNIT_HAS_STRUPPER}
  53. {$ifndef FPC_UNIT_HAS_STRLOWER}
  54. function StrLower(P: PChar): PChar;
  55. var
  56. counter: SizeInt;
  57. begin
  58. counter := 0;
  59. while (P[counter] <> #0) do
  60. begin
  61. if P[counter] in [#65..#90] then
  62. P[Counter] := chr(ord(P[Counter]) + 32);
  63. Inc(counter);
  64. end;
  65. StrLower := P;
  66. end;
  67. {$endif FPC_UNIT_HAS_STRLOWER}
  68. {$ifndef FPC_UNIT_HAS_STRSCAN}
  69. function StrScan(P: PChar; C: Char): PChar;
  70. Var
  71. count: SizeInt;
  72. Begin
  73. count := 0;
  74. { As in Borland Pascal , if looking for NULL return null }
  75. if C = #0 then
  76. begin
  77. StrScan := @(P[StrLen(P)]);
  78. exit;
  79. end;
  80. { Find first matching character of Ch in Str }
  81. while P[count] <> #0 do
  82. begin
  83. if C = P[count] then
  84. begin
  85. StrScan := @(P[count]);
  86. exit;
  87. end;
  88. Inc(count);
  89. end;
  90. { nothing found. }
  91. StrScan := nil;
  92. end;
  93. {$endif FPC_UNIT_HAS_STRSCAN}
  94. {$ifndef FPC_UNIT_HAS_STRRSCAN}
  95. function StrRScan(P: PChar; C: Char): PChar;
  96. Var
  97. count: SizeInt;
  98. index: SizeInt;
  99. Begin
  100. count := Strlen(P);
  101. { As in Borland Pascal , if looking for NULL return null }
  102. if C = #0 then
  103. begin
  104. StrRScan := @(P[count]);
  105. exit;
  106. end;
  107. Dec(count);
  108. for index := count downto 0 do
  109. begin
  110. if C = P[index] then
  111. begin
  112. StrRScan := @(P[index]);
  113. exit;
  114. end;
  115. end;
  116. { nothing found. }
  117. StrRScan := nil;
  118. end;
  119. {$endif FPC_UNIT_HAS_STRRSCAN}
  120. {$ifndef FPC_UNIT_HAS_STRECOPY}
  121. Function StrECopy(Dest, Source: PChar): PChar;
  122. { Equivalent to the following: }
  123. { strcopy(Dest,Source); }
  124. { StrECopy := StrEnd(Dest); }
  125. var
  126. counter : SizeInt;
  127. Begin
  128. counter := 0;
  129. while Source[counter] <> #0 do
  130. begin
  131. Dest[counter] := char(Source[counter]);
  132. Inc(counter);
  133. end;
  134. { terminate the string }
  135. Dest[counter] := #0;
  136. StrECopy:=@(Dest[counter]);
  137. end;
  138. {$endif FPC_UNIT_HAS_STRECOPY}
  139. {$ifndef FPC_UNIT_HAS_STRLCOPY}
  140. Function StrLCopy(Dest,Source: PChar; MaxLen: SizeInt): PChar;
  141. var
  142. counter: SizeInt;
  143. Begin
  144. counter := 0;
  145. { To be compatible with BP, on a null string, put two nulls }
  146. If Source[0] = #0 then
  147. Begin
  148. Dest[0]:=Source[0];
  149. Inc(counter);
  150. end;
  151. while (Source[counter] <> #0) and (counter < MaxLen) do
  152. Begin
  153. Dest[counter] := char(Source[counter]);
  154. Inc(counter);
  155. end;
  156. { terminate the string }
  157. Dest[counter] := #0;
  158. StrLCopy := Dest;
  159. end;
  160. {$endif FPC_UNIT_HAS_STRLCOPY}
  161. {$ifndef FPC_UNIT_HAS_STRCOMP}
  162. function StrComp(Str1, Str2 : PChar): SizeInt;
  163. var
  164. counter: SizeInt;
  165. Begin
  166. counter := 0;
  167. While str1[counter] = str2[counter] do
  168. Begin
  169. if (str2[counter] = #0) or (str1[counter] = #0) then
  170. break;
  171. Inc(counter);
  172. end;
  173. StrComp := ord(str1[counter]) - ord(str2[counter]);
  174. end;
  175. {$endif FPC_UNIT_HAS_STRCOMP}
  176. {$ifndef FPC_UNIT_HAS_STRICOMP}
  177. function StrIComp(Str1, Str2 : PChar): SizeInt;
  178. var
  179. counter: SizeInt;
  180. c1, c2: char;
  181. Begin
  182. counter := 0;
  183. c1 := upcase(str1[counter]);
  184. c2 := upcase(str2[counter]);
  185. While c1 = c2 do
  186. Begin
  187. if (c1 = #0) or (c2 = #0) then break;
  188. Inc(counter);
  189. c1 := upcase(str1[counter]);
  190. c2 := upcase(str2[counter]);
  191. end;
  192. StrIComp := ord(c1) - ord(c2);
  193. end;
  194. {$endif FPC_UNIT_HAS_STRICOMP}
  195. {$ifndef FPC_UNIT_HAS_STRLCOMP}
  196. function StrLComp(Str1, Str2 : PChar; L: SizeInt): SizeInt;
  197. var
  198. counter: SizeInt;
  199. c1, c2: char;
  200. Begin
  201. counter := 0;
  202. if L = 0 then
  203. begin
  204. StrLComp := 0;
  205. exit;
  206. end;
  207. Repeat
  208. c1 := str1[counter];
  209. c2 := str2[counter];
  210. if (c1 = #0) or (c2 = #0) then break;
  211. Inc(counter);
  212. Until (c1 <> c2) or (counter >= L);
  213. StrLComp := ord(c1) - ord(c2);
  214. end;
  215. {$endif FPC_UNIT_HAS_STRLCOMP}
  216. {$ifndef FPC_UNIT_HAS_STRLICOMP}
  217. function StrLIComp(Str1, Str2 : PChar; L: SizeInt): SizeInt;
  218. var
  219. counter: SizeInt;
  220. c1, c2: char;
  221. Begin
  222. counter := 0;
  223. if L = 0 then
  224. begin
  225. StrLIComp := 0;
  226. exit;
  227. end;
  228. Repeat
  229. c1 := upcase(str1[counter]);
  230. c2 := upcase(str2[counter]);
  231. if (c1 = #0) or (c2 = #0) then break;
  232. Inc(counter);
  233. Until (c1 <> c2) or (counter >= L);
  234. StrLIComp := ord(c1) - ord(c2);
  235. end;
  236. {$endif FPC_UNIT_HAS_STRLICOMP}