genstr.inc 6.3 KB

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