genstr.inc 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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_STRISCAN}
  95. function StrIScan(P: PChar; C: Char): PChar;
  96. Var
  97. count: SizeInt;
  98. UC: Char;
  99. Begin
  100. UC := upcase(C);
  101. count := 0;
  102. { As in Borland Pascal , if looking for NULL return null }
  103. if UC = #0 then
  104. begin
  105. StrIScan := @(P[StrLen(P)]);
  106. exit;
  107. end;
  108. { Find first matching character of Ch in Str }
  109. while P[count] <> #0 do
  110. begin
  111. if UC = upcase(P[count]) then
  112. begin
  113. StrIScan := @(P[count]);
  114. exit;
  115. end;
  116. Inc(count);
  117. end;
  118. { nothing found. }
  119. StrIScan := nil;
  120. end;
  121. {$endif FPC_UNIT_HAS_STRSCAN}
  122. {$ifndef FPC_UNIT_HAS_STRRSCAN}
  123. function StrRScan(P: PChar; C: Char): PChar;
  124. Var
  125. count: SizeInt;
  126. index: SizeInt;
  127. Begin
  128. count := Strlen(P);
  129. { As in Borland Pascal , if looking for NULL return null }
  130. if C = #0 then
  131. begin
  132. StrRScan := @(P[count]);
  133. exit;
  134. end;
  135. Dec(count);
  136. for index := count downto 0 do
  137. begin
  138. if C = P[index] then
  139. begin
  140. StrRScan := @(P[index]);
  141. exit;
  142. end;
  143. end;
  144. { nothing found. }
  145. StrRScan := nil;
  146. end;
  147. {$endif FPC_UNIT_HAS_STRRSCAN}
  148. {$ifndef FPC_UNIT_HAS_STRRISCAN}
  149. function StrRIScan(P: PChar; C: Char): PChar;
  150. Var
  151. count: SizeInt;
  152. index: SizeInt;
  153. UC: Char;
  154. Begin
  155. UC := upcase(C);
  156. count := Strlen(P);
  157. { As in Borland Pascal , if looking for NULL return null }
  158. if UC = #0 then
  159. begin
  160. StrRIScan := @(P[count]);
  161. exit;
  162. end;
  163. Dec(count);
  164. for index := count downto 0 do
  165. begin
  166. if UC = upcase(P[index]) then
  167. begin
  168. StrRIScan := @(P[index]);
  169. exit;
  170. end;
  171. end;
  172. { nothing found. }
  173. StrRIScan := nil;
  174. end;
  175. {$endif FPC_UNIT_HAS_STRRSCAN}
  176. {$ifndef FPC_UNIT_HAS_STRECOPY}
  177. Function StrECopy(Dest, Source: PChar): PChar;
  178. { Equivalent to the following: }
  179. { strcopy(Dest,Source); }
  180. { StrECopy := StrEnd(Dest); }
  181. var
  182. counter : SizeInt;
  183. Begin
  184. counter := 0;
  185. while Source[counter] <> #0 do
  186. begin
  187. Dest[counter] := char(Source[counter]);
  188. Inc(counter);
  189. end;
  190. { terminate the string }
  191. Dest[counter] := #0;
  192. StrECopy:=@(Dest[counter]);
  193. end;
  194. {$endif FPC_UNIT_HAS_STRECOPY}
  195. {$ifndef FPC_UNIT_HAS_STRLCOPY}
  196. Function StrLCopy(Dest,Source: PChar; MaxLen: SizeInt): PChar;
  197. var
  198. counter: SizeInt;
  199. Begin
  200. counter := 0;
  201. { To be compatible with BP, on a null string, put two nulls }
  202. If Source[0] = #0 then
  203. Begin
  204. Dest[0]:=Source[0];
  205. Inc(counter);
  206. end;
  207. while (Source[counter] <> #0) and (counter < MaxLen) do
  208. Begin
  209. Dest[counter] := char(Source[counter]);
  210. Inc(counter);
  211. end;
  212. { terminate the string }
  213. Dest[counter] := #0;
  214. StrLCopy := Dest;
  215. end;
  216. {$endif FPC_UNIT_HAS_STRLCOPY}
  217. {$ifndef FPC_UNIT_HAS_STRCOMP}
  218. function StrComp(Str1, Str2 : PChar): SizeInt;
  219. var
  220. counter: SizeInt;
  221. Begin
  222. counter := 0;
  223. While str1[counter] = str2[counter] do
  224. Begin
  225. if (str2[counter] = #0) or (str1[counter] = #0) then
  226. break;
  227. Inc(counter);
  228. end;
  229. StrComp := ord(str1[counter]) - ord(str2[counter]);
  230. end;
  231. {$endif FPC_UNIT_HAS_STRCOMP}
  232. {$ifndef FPC_UNIT_HAS_STRICOMP}
  233. function StrIComp(Str1, Str2 : PChar): SizeInt;
  234. var
  235. counter: SizeInt;
  236. c1, c2: char;
  237. Begin
  238. counter := 0;
  239. c1 := upcase(str1[counter]);
  240. c2 := upcase(str2[counter]);
  241. While c1 = c2 do
  242. Begin
  243. if (c1 = #0) or (c2 = #0) then break;
  244. Inc(counter);
  245. c1 := upcase(str1[counter]);
  246. c2 := upcase(str2[counter]);
  247. end;
  248. StrIComp := ord(c1) - ord(c2);
  249. end;
  250. {$endif FPC_UNIT_HAS_STRICOMP}
  251. {$ifndef FPC_UNIT_HAS_STRLCOMP}
  252. function StrLComp(Str1, Str2 : PChar; L: SizeInt): SizeInt;
  253. var
  254. counter: SizeInt;
  255. c1, c2: char;
  256. Begin
  257. counter := 0;
  258. if L = 0 then
  259. begin
  260. StrLComp := 0;
  261. exit;
  262. end;
  263. Repeat
  264. c1 := str1[counter];
  265. c2 := str2[counter];
  266. if (c1 = #0) or (c2 = #0) then break;
  267. Inc(counter);
  268. Until (c1 <> c2) or (counter >= L);
  269. StrLComp := ord(c1) - ord(c2);
  270. end;
  271. {$endif FPC_UNIT_HAS_STRLCOMP}
  272. {$ifndef FPC_UNIT_HAS_STRLICOMP}
  273. function StrLIComp(Str1, Str2 : PChar; L: SizeInt): SizeInt;
  274. var
  275. counter: SizeInt;
  276. c1, c2: char;
  277. Begin
  278. counter := 0;
  279. if L = 0 then
  280. begin
  281. StrLIComp := 0;
  282. exit;
  283. end;
  284. Repeat
  285. c1 := upcase(str1[counter]);
  286. c2 := upcase(str2[counter]);
  287. if (c1 = #0) or (c2 = #0) then break;
  288. Inc(counter);
  289. Until (c1 <> c2) or (counter >= L);
  290. StrLIComp := ord(c1) - ord(c2);
  291. end;
  292. {$endif FPC_UNIT_HAS_STRLICOMP}