strings.tex 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. %
  2. % $Id$
  3. % This file is part of the FPC documentation.
  4. % Copyright (C) 1997, by Michael Van Canneyt
  5. %
  6. % The FPC documentation is free text; you can redistribute it and/or
  7. % modify it under the terms of the GNU Library General Public License as
  8. % published by the Free Software Foundation; either version 2 of the
  9. % License, or (at your option) any later version.
  10. %
  11. % The FPC Documentation is distributed in the hope that it will be useful,
  12. % but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. % Library General Public License for more details.
  15. %
  16. % You should have received a copy of the GNU Library General Public
  17. % License along with the FPC documentation; see the file COPYING.LIB. If not,
  18. % write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  19. % Boston, MA 02111-1307, USA.
  20. %
  21. \chapter{The STRINGS unit.}
  22. This chapter describes the \var{STRINGS} unit for \fpc. This unit is system
  23. independent, and therefore works on all supported platforms.
  24. Since the unit only provides some procedures and functions, there is
  25. only one section, which gives the declarations of these functions, together
  26. with an explanation.
  27. \section{Functions and procedures.}
  28. \begin{function}{StrAlloc}
  29. \Declaration
  30. Function StrAlloc (Len : Longint);PChar
  31. \Description
  32. \var{StrAlloc} reserves memory on the heap for a string with length \var{Len},
  33. terminating \var{\#0} included, and returns a pointer to it.
  34. \Errors
  35. If there is not enough memory, a run-time error occurs.
  36. \SeeAlso
  37. \seef{StrNew}, \seef{StrPCopy}.
  38. \end{function}
  39. \begin{function}{StrCat}
  40. \Declaration
  41. Function StrCat (Dest,Source : PChar) : PChar;
  42. \Description
  43. Attaches \var{Source} to \var{Dest} and returns \var{Dest}.
  44. \Errors
  45. No length checking is performed.
  46. \SeeAlso
  47. \seem{Concat}{}
  48. \end{function}
  49. \latex{\lstinputlisting{stringex/ex11.pp}}
  50. \html{\input{stringex/ex11.tex}}
  51. \begin{function}{StrComp}
  52. \Declaration
  53. Function StrComp (S1,S2 : PChar) : Longint;
  54. \Description
  55. Compares the null-terminated strings \var{S1} and \var{S2}.
  56. The result is
  57. \begin{itemize}
  58. \item A negative \var{Longint} when \var{S1<S2}.
  59. \item 0 when \var{S1=S2}.
  60. \item A positive \var{Longint} when \var{S1>S2}.
  61. \end{itemize}
  62. \Errors
  63. None.
  64. \SeeAlso
  65. \seef{StrLComp}, \seef{StrIComp}, \seef{StrLIComp}
  66. \end{function}
  67. For an example, see \seef{StrLComp}.
  68. \begin{function}{StrCopy}
  69. \Declaration
  70. Function StrCopy (Dest,Source : PChar) : PChar;
  71. \Description
  72. Copy the null terminated string in \var{Source} to \var{Dest}, and
  73. returns a pointer to \var{Dest}. \var{Dest} needs enough room to contain
  74. \var{Source}, i.e. \var{StrLen(Source)+1} bytes.
  75. \Errors
  76. No length checking is performed.
  77. \SeeAlso
  78. \seef{StrPCopy}, \seef{StrLCopy}, \seef{StrECopy}
  79. \end{function}
  80. \latex{\lstinputlisting{stringex/ex4.pp}}
  81. \html{\input{stringex/ex4.tex}}
  82. \begin{procedure}{StrDispose}
  83. \Declaration
  84. Procedure StrDispose (P : PChar);
  85. \Description
  86. Removes the string in \var{P} from the heap and releases the memory.
  87. \Errors
  88. None.
  89. \SeeAlso
  90. \seem{Dispose}{}, \seef{StrNew}
  91. \end{procedure}
  92. \latex{\lstinputlisting{stringex/ex17.pp}}
  93. \html{\input{stringex/ex17.tex}}
  94. \begin{function}{StrECopy}
  95. \Declaration
  96. Function StrECopy (Dest,Source : PChar) : PChar;
  97. \Description
  98. Copies the Null-terminated string in \var{Source} to \var{Dest}, and
  99. returns a pointer to the end (i.e. the terminating Null-character) of the
  100. copied string.
  101. \Errors
  102. No length checking is performed.
  103. \SeeAlso
  104. \seef{StrLCopy}, \seef{StrCopy}
  105. \end{function}
  106. \latex{\lstinputlisting{stringex/ex6.pp}}
  107. \html{\input{stringex/ex6.tex}}
  108. \begin{function}{StrEnd}
  109. \Declaration
  110. Function StrEnd (P : PChar) : PChar;
  111. \Description
  112. Returns a pointer to the end of \var{P}. (i.e. to the terminating
  113. null-character.
  114. \Errors
  115. None.
  116. \SeeAlso
  117. \seef{StrLen}
  118. \end{function}
  119. \latex{\lstinputlisting{stringex/ex7.pp}}
  120. \html{\input{stringex/ex7.tex}}
  121. \begin{function}{StrIComp}
  122. \Declaration
  123. Function StrIComp (S1,S2 : PChar) : Longint;
  124. \Description
  125. Compares the null-terminated strings \var{S1} and \var{S2}, ignoring case.
  126. The result is
  127. \begin{itemize}
  128. \item A negative \var{Longint} when \var{S1<S2}.
  129. \item 0 when \var{S1=S2}.
  130. \item A positive \var{Longint} when \var{S1>S2}.
  131. \end{itemize}
  132. \Errors
  133. None.
  134. \SeeAlso
  135. \seef{StrLComp}, \seef{StrComp}, \seef{StrLIComp}
  136. \end{function}
  137. \latex{\lstinputlisting{stringex/ex8.pp}}
  138. \html{\input{stringex/ex8.tex}}
  139. \begin{function}{StrLCat}
  140. \Declaration
  141. Function StrLCat (Dest,Source : PChar; MaxLen : Longint) : PChar;
  142. \Description
  143. Adds \var{MaxLen} characters from \var{Source} to \var{Dest}, and adds a
  144. terminating null-character. Returns \var{Dest}.
  145. \Errors
  146. None.
  147. \SeeAlso
  148. \seef{StrCat}
  149. \end{function}
  150. \latex{\lstinputlisting{stringex/ex12.pp}}
  151. \html{\input{stringex/ex12.tex}}
  152. \begin{function}{StrLComp}
  153. \Declaration
  154. Function StrLComp (S1,S2 : PChar; L : Longint) : Longint;
  155. \Description
  156. Compares maximum \var{L} characters of the null-terminated strings
  157. \var{S1} and \var{S2}.
  158. The result is
  159. \begin{itemize}
  160. \item A negative \var{Longint} when \var{S1<S2}.
  161. \item 0 when \var{S1=S2}.
  162. \item A positive \var{Longint} when \var{S1>S2}.
  163. \end{itemize}
  164. \Errors
  165. None.
  166. \SeeAlso
  167. \seef{StrComp}, \seef{StrIComp}, \seef{StrLIComp}
  168. \end{function}
  169. \latex{\lstinputlisting{stringex/ex8.pp}}
  170. \html{\input{stringex/ex8.tex}}
  171. \begin{function}{StrLCopy}
  172. \Declaration
  173. Function StrLCopy (Dest,Source : PChar; MaxLen : Longint) : PChar;
  174. \Description
  175. Copies \var{MaxLen} characters from \var{Source} to \var{Dest}, and makes
  176. \var{Dest} a null terminated string.
  177. \Errors
  178. No length checking is performed.
  179. \SeeAlso
  180. \seef{StrCopy}, \seef{StrECopy}
  181. \end{function}
  182. \latex{\lstinputlisting{stringex/ex5.pp}}
  183. \html{\input{stringex/ex5.tex}}
  184. \begin{function}{StrLen}
  185. \Declaration
  186. Function StrLen (p : PChar) : Longint;
  187. \Description
  188. Returns the length of the null-terminated string \var{P}.
  189. \Errors
  190. None.
  191. \SeeAlso
  192. \seem{Length}{}
  193. \end{function}
  194. \latex{\lstinputlisting{stringex/ex1.pp}}
  195. \html{\input{stringex/ex1.tex}}
  196. \begin{function}{StrLIComp}
  197. \Declaration
  198. Function StrLIComp (S1,S2 : PChar; L : Longint) : Longint;
  199. \Description
  200. Compares maximum \var{L} characters of the null-terminated strings \var{S1}
  201. and \var{S2}, ignoring case.
  202. The result is
  203. \begin{itemize}
  204. \item A negative \var{Longint} when \var{S1<S2}.
  205. \item 0 when \var{S1=S2}.
  206. \item A positive \var{Longint} when \var{S1>S2}.
  207. \end{itemize}
  208. \Errors
  209. None.
  210. \SeeAlso
  211. \seef{StrLComp}, \seef{StrComp}, \seef{StrIComp}
  212. \end{function}
  213. For an example, see \seef{StrIComp}
  214. \begin{function}{StrLower}
  215. \Declaration
  216. Function StrLower (P : PChar) : PChar;
  217. \Description
  218. Converts \var{P} to an all-lowercase string. Returns \var{P}.
  219. \Errors
  220. None.
  221. \SeeAlso
  222. \seem{Upcase}{}, \seef{StrUpper}
  223. \end{function}
  224. \latex{\lstinputlisting{stringex/ex14.pp}}
  225. \html{\input{stringex/ex14.tex}}
  226. \begin{function}{StrMove}
  227. \Declaration
  228. Function StrMove (Dest,Source : PChar; MaxLen : Longint) : PChar;
  229. \Description
  230. Copies \var{MaxLen} characters from \var{Source} to \var{Dest}. No
  231. terminating null-character is copied.
  232. Returns \var {Dest}.
  233. \Errors
  234. None.
  235. \SeeAlso
  236. \seef{StrLCopy}, \seef{StrCopy}
  237. \end{function}
  238. \latex{\lstinputlisting{stringex/ex10.pp}}
  239. \html{\input{stringex/ex10.tex}}
  240. \begin{function}{StrNew}
  241. \Declaration
  242. Function StrNew (P : PChar) : PChar;
  243. \Description
  244. Copies \var{P} to the Heap, and returns a pointer to the copy.
  245. \Errors
  246. Returns \var{Nil} if no memory was available for the copy.
  247. \SeeAlso
  248. \seem{New}{}, \seef{StrCopy}, \seep{StrDispose}
  249. \end{function}
  250. \latex{\lstinputlisting{stringex/ex16.pp}}
  251. \html{\input{stringex/ex16.tex}}
  252. \begin{function}{StrPas}
  253. \Declaration
  254. Function StrPas (P : PChar) : String;
  255. \Description
  256. Converts a null terminated string in \var{P} to a Pascal string, and returns
  257. this string. The string is truncated at 255 characters.
  258. \Errors
  259. None.
  260. \SeeAlso
  261. \seef{StrPCopy}
  262. \end{function}
  263. \latex{\lstinputlisting{stringex/ex3.pp}}
  264. \html{\input{stringex/ex3.tex}}
  265. \begin{function}{StrPCopy}
  266. \Declaration
  267. Function StrPCopy (Dest : PChar; Const Source : String) : PChar;
  268. \Description
  269. Converts the Pascal string in \var{Source} to a Null-terminated
  270. string, and copies it to \var{Dest}. \var{Dest} needs enough room to contain
  271. the string \var{Source}, i.e. \var{Length(Source)+1} bytes.
  272. \Errors
  273. No length checking is performed.
  274. \SeeAlso
  275. \seef{StrPas}
  276. \end{function}
  277. \latex{\lstinputlisting{stringex/ex2.pp}}
  278. \html{\input{stringex/ex2.tex}}
  279. \begin{function}{StrPos}
  280. \Declaration
  281. Function StrPos (S1,S2 : PChar) : PChar;
  282. \Description
  283. Returns a pointer to the first occurrence of \var{S2} in \var{S1}.
  284. If \var{S2} does not occur in \var{S1}, returns \var{Nil}.
  285. \Errors
  286. None.
  287. \SeeAlso
  288. \seem{Pos}{}, \seef{StrScan}, \seef{StrRScan}
  289. \end{function}
  290. \latex{\lstinputlisting{stringex/ex15.pp}}
  291. \html{\input{stringex/ex15.tex}}
  292. \begin{function}{StrRScan}
  293. \Declaration
  294. Function StrRScan (P : PChar; C : Char) : PChar;
  295. \Description
  296. Returns a pointer to the last occurrence of the character \var{C} in the
  297. null-terminated string \var{P}. If \var{C} does not occur, returns
  298. \var{Nil}.
  299. \Errors
  300. None.
  301. \SeeAlso
  302. \seem{Pos}{}, \seef{StrScan}, \seef{StrPos}
  303. \end{function}
  304. For an example, see \seef{StrScan}.
  305. \begin{function}{StrScan}
  306. \Declaration
  307. Function StrScan (P : PChar; C : Char) : PChar;
  308. \Description
  309. Returns a pointer to the first occurrence of the character \var{C} in the
  310. null-terminated string \var{P}. If \var{C} does not occur, returns
  311. \var{Nil}.
  312. \Errors
  313. None.
  314. \SeeAlso
  315. \seem{Pos}{}, \seef{StrRScan}, \seef{StrPos}
  316. \end{function}
  317. \latex{\lstinputlisting{stringex/ex13.pp}}
  318. \html{\input{stringex/ex13.tex}}
  319. \begin{function}{StrUpper}
  320. \Declaration
  321. Function StrUpper (P : PChar) : PChar;
  322. \Description
  323. Converts \var{P} to an all-uppercase string. Returns \var{P}.
  324. \Errors
  325. None.
  326. \SeeAlso
  327. \seem{Upcase}{}, \seef{StrLower}
  328. \end{function}
  329. For an example, see \seef{StrLower}