strings.tex 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  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. \label{ch:strings}
  23. \FPCexampledir{stringex}
  24. This chapter describes the \var{STRINGS} unit for \fpc. This unit is system
  25. independent, and therefore works on all supported platforms.
  26. Since the unit only provides some procedures and functions, there is
  27. only one section, which gives the declarations of these functions, together
  28. with an explanation.
  29. \section{Functions and procedures.}
  30. \begin{function}{StrAlloc}
  31. \Declaration
  32. Function StrAlloc (Len : Longint) : PChar;
  33. \Description
  34. \var{StrAlloc} reserves memory on the heap for a string with length \var{Len},
  35. terminating \var{\#0} included, and returns a pointer to it.
  36. \Errors
  37. If there is not enough memory, a run-time error occurs.
  38. \SeeAlso
  39. \seef{StrNew}, \seef{StrPCopy}.
  40. \end{function}
  41. \begin{function}{StrCat}
  42. \Declaration
  43. Function StrCat (Dest,Source : PChar) : PChar;
  44. \Description
  45. Attaches \var{Source} to \var{Dest} and returns \var{Dest}.
  46. \Errors
  47. No length checking is performed.
  48. \SeeAlso
  49. \seem{Concat}{}
  50. \end{function}
  51. \FPCexample{ex11}
  52. \begin{function}{StrComp}
  53. \Declaration
  54. Function StrComp (S1,S2 : PChar) : Longint;
  55. \Description
  56. Compares the null-terminated strings \var{S1} and \var{S2}.
  57. The result is
  58. \begin{itemize}
  59. \item A negative \var{Longint} when \var{S1<S2}.
  60. \item 0 when \var{S1=S2}.
  61. \item A positive \var{Longint} when \var{S1>S2}.
  62. \end{itemize}
  63. \Errors
  64. None.
  65. \SeeAlso
  66. \seef{StrLComp}, \seef{StrIComp}, \seef{StrLIComp}
  67. \end{function}
  68. For an example, see \seef{StrLComp}.
  69. \begin{function}{StrCopy}
  70. \Declaration
  71. Function StrCopy (Dest,Source : PChar) : PChar;
  72. \Description
  73. Copy the null terminated string in \var{Source} to \var{Dest}, and
  74. returns a pointer to \var{Dest}. \var{Dest} needs enough room to contain
  75. \var{Source}, i.e. \var{StrLen(Source)+1} bytes.
  76. \Errors
  77. No length checking is performed.
  78. \SeeAlso
  79. \seef{StrPCopy}, \seef{StrLCopy}, \seef{StrECopy}
  80. \end{function}
  81. \FPCexample{ex4}
  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. \FPCexample{ex17}
  93. \begin{function}{StrECopy}
  94. \Declaration
  95. Function StrECopy (Dest,Source : PChar) : PChar;
  96. \Description
  97. Copies the Null-terminated string in \var{Source} to \var{Dest}, and
  98. returns a pointer to the end (i.e. the terminating Null-character) of the
  99. copied string.
  100. \Errors
  101. No length checking is performed.
  102. \SeeAlso
  103. \seef{StrLCopy}, \seef{StrCopy}
  104. \end{function}
  105. \FPCexample{ex6}
  106. \begin{function}{StrEnd}
  107. \Declaration
  108. Function StrEnd (P : PChar) : PChar;
  109. \Description
  110. Returns a pointer to the end of \var{P}. (i.e. to the terminating
  111. null-character.
  112. \Errors
  113. None.
  114. \SeeAlso
  115. \seef{StrLen}
  116. \end{function}
  117. \FPCexample{ex7}
  118. \begin{function}{StrIComp}
  119. \Declaration
  120. Function StrIComp (S1,S2 : PChar) : Longint;
  121. \Description
  122. Compares the null-terminated strings \var{S1} and \var{S2}, ignoring case.
  123. The result is
  124. \begin{itemize}
  125. \item A negative \var{Longint} when \var{S1<S2}.
  126. \item 0 when \var{S1=S2}.
  127. \item A positive \var{Longint} when \var{S1>S2}.
  128. \end{itemize}
  129. \Errors
  130. None.
  131. \SeeAlso
  132. \seef{StrLComp}, \seef{StrComp}, \seef{StrLIComp}
  133. \end{function}
  134. \FPCexample{ex8}
  135. \begin{function}{StrLCat}
  136. \Declaration
  137. Function StrLCat (Dest,Source : PChar; MaxLen : Longint) : PChar;
  138. \Description
  139. Adds \var{MaxLen} characters from \var{Source} to \var{Dest}, and adds a
  140. terminating null-character. Returns \var{Dest}.
  141. \Errors
  142. None.
  143. \SeeAlso
  144. \seef{StrCat}
  145. \end{function}
  146. \FPCexample{ex12}
  147. \begin{function}{StrLComp}
  148. \Declaration
  149. Function StrLComp (S1,S2 : PChar; L : Longint) : Longint;
  150. \Description
  151. Compares maximum \var{L} characters of the null-terminated strings
  152. \var{S1} and \var{S2}.
  153. The result is
  154. \begin{itemize}
  155. \item A negative \var{Longint} when \var{S1<S2}.
  156. \item 0 when \var{S1=S2}.
  157. \item A positive \var{Longint} when \var{S1>S2}.
  158. \end{itemize}
  159. \Errors
  160. None.
  161. \SeeAlso
  162. \seef{StrComp}, \seef{StrIComp}, \seef{StrLIComp}
  163. \end{function}
  164. \FPCexample{ex8}
  165. \begin{function}{StrLCopy}
  166. \Declaration
  167. Function StrLCopy (Dest,Source : PChar; MaxLen : Longint) : PChar;
  168. \Description
  169. Copies \var{MaxLen} characters from \var{Source} to \var{Dest}, and makes
  170. \var{Dest} a null terminated string.
  171. \Errors
  172. No length checking is performed.
  173. \SeeAlso
  174. \seef{StrCopy}, \seef{StrECopy}
  175. \end{function}
  176. \FPCexample{ex5}
  177. \begin{function}{StrLen}
  178. \Declaration
  179. Function StrLen (p : PChar) : Longint;
  180. \Description
  181. Returns the length of the null-terminated string \var{P}.
  182. \Errors
  183. None.
  184. \SeeAlso
  185. \seem{Length}{}
  186. \end{function}
  187. \FPCexample{ex1}
  188. \begin{function}{StrLIComp}
  189. \Declaration
  190. Function StrLIComp (S1,S2 : PChar; L : Longint) : Longint;
  191. \Description
  192. Compares maximum \var{L} characters of the null-terminated strings \var{S1}
  193. and \var{S2}, ignoring case.
  194. The result is
  195. \begin{itemize}
  196. \item A negative \var{Longint} when \var{S1<S2}.
  197. \item 0 when \var{S1=S2}.
  198. \item A positive \var{Longint} when \var{S1>S2}.
  199. \end{itemize}
  200. \Errors
  201. None.
  202. \SeeAlso
  203. \seef{StrLComp}, \seef{StrComp}, \seef{StrIComp}
  204. \end{function}
  205. For an example, see \seef{StrIComp}
  206. \begin{function}{StrLower}
  207. \Declaration
  208. Function StrLower (P : PChar) : PChar;
  209. \Description
  210. Converts \var{P} to an all-lowercase string. Returns \var{P}.
  211. \Errors
  212. None.
  213. \SeeAlso
  214. \seem{Upcase}{}, \seef{StrUpper}
  215. \end{function}
  216. \FPCexample{ex14}
  217. \begin{function}{StrMove}
  218. \Declaration
  219. Function StrMove (Dest,Source : PChar; MaxLen : Longint) : PChar;
  220. \Description
  221. Copies \var{MaxLen} characters from \var{Source} to \var{Dest}. No
  222. terminating null-character is copied.
  223. Returns \var {Dest}.
  224. \Errors
  225. None.
  226. \SeeAlso
  227. \seef{StrLCopy}, \seef{StrCopy}
  228. \end{function}
  229. \FPCexample{ex10}
  230. \begin{function}{StrNew}
  231. \Declaration
  232. Function StrNew (P : PChar) : PChar;
  233. \Description
  234. Copies \var{P} to the Heap, and returns a pointer to the copy.
  235. \Errors
  236. Returns \var{Nil} if no memory was available for the copy.
  237. \SeeAlso
  238. \seem{New}{}, \seef{StrCopy}, \seep{StrDispose}
  239. \end{function}
  240. \FPCexample{ex16}
  241. \begin{function}{StrPas}
  242. \Declaration
  243. Function StrPas (P : PChar) : String;
  244. \Description
  245. Converts a null terminated string in \var{P} to a Pascal string, and returns
  246. this string. The string is truncated at 255 characters.
  247. \Errors
  248. None.
  249. \SeeAlso
  250. \seef{StrPCopy}
  251. \end{function}
  252. \FPCexample{ex3}
  253. \begin{function}{StrPCopy}
  254. \Declaration
  255. Function StrPCopy (Dest : PChar; Const Source : String) : PChar;
  256. \Description
  257. Converts the Pascal string in \var{Source} to a Null-terminated
  258. string, and copies it to \var{Dest}. \var{Dest} needs enough room to contain
  259. the string \var{Source}, i.e. \var{Length(Source)+1} bytes.
  260. \Errors
  261. No length checking is performed.
  262. \SeeAlso
  263. \seef{StrPas}
  264. \end{function}
  265. \FPCexample{ex2}
  266. \begin{function}{StrPos}
  267. \Declaration
  268. Function StrPos (S1,S2 : PChar) : PChar;
  269. \Description
  270. Returns a pointer to the first occurrence of \var{S2} in \var{S1}.
  271. If \var{S2} does not occur in \var{S1}, returns \var{Nil}.
  272. \Errors
  273. None.
  274. \SeeAlso
  275. \seem{Pos}{}, \seef{StrScan}, \seef{StrRScan}
  276. \end{function}
  277. \FPCexample{ex15}
  278. \begin{function}{StrRScan}
  279. \Declaration
  280. Function StrRScan (P : PChar; C : Char) : PChar;
  281. \Description
  282. Returns a pointer to the last occurrence of the character \var{C} in the
  283. null-terminated string \var{P}. If \var{C} does not occur, returns
  284. \var{Nil}.
  285. \Errors
  286. None.
  287. \SeeAlso
  288. \seem{Pos}{}, \seef{StrScan}, \seef{StrPos}
  289. \end{function}
  290. For an example, see \seef{StrScan}.
  291. \begin{function}{StrScan}
  292. \Declaration
  293. Function StrScan (P : PChar; C : Char) : PChar;
  294. \Description
  295. Returns a pointer to the first occurrence of the character \var{C} in the
  296. null-terminated string \var{P}. If \var{C} does not occur, returns
  297. \var{Nil}.
  298. \Errors
  299. None.
  300. \SeeAlso
  301. \seem{Pos}{}, \seef{StrRScan}, \seef{StrPos}
  302. \end{function}
  303. \FPCexample{ex13}
  304. \begin{function}{StrUpper}
  305. \Declaration
  306. Function StrUpper (P : PChar) : PChar;
  307. \Description
  308. Converts \var{P} to an all-uppercase string. Returns \var{P}.
  309. \Errors
  310. None.
  311. \SeeAlso
  312. \seem{Upcase}{}, \seef{StrLower}
  313. \end{function}
  314. For an example, see \seef{StrLower}