strings.tex 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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
  23. \fpc.
  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. \procedure{StrAlloc}{(Len : Longint)}{PChar}
  29. {
  30. \var{StrAlloc} reserves memory on the heap for a string with length \var{Len},
  31. terminating \var{\#0} included, and returns a pointer to it.
  32. }
  33. For an example, see \seef{StrPCopy}.
  34. \function{StrCat}{(Dest,Source : PChar)}{PChar}
  35. {
  36. Attaches \var{Source} to \var{Dest} and returns \var{Dest}.
  37. }
  38. {No length checking is performed.}
  39. {\seem{Concat}{}}
  40. \latex{\inputlisting{stringex/ex11.pp}}
  41. \html{\input{stringex/ex11.tex}}
  42. \function{StrComp}{(S1,S2 : PChar)}{Longint}
  43. {
  44. Compares the null-terminated strings \var{S1} and \var{S2}.
  45. The result is
  46. \begin{itemize}
  47. \item A negative \var{Longint} when \var{S1<S2}.
  48. \item 0 when \var{S1=S2}.
  49. \item A positive \var{Longint} when \var{S1>S2}.
  50. \end{itemize}
  51. }
  52. {None.}{\seef{StrLComp}, \seef{StrIComp}, \seef{StrLIComp}}
  53. For an example, see \seef{StrLComp}.
  54. \function {StrCopy}{(Dest,Source : PChar)}{PChar}
  55. {
  56. Copy the null terminated string in \var{Source} to \var{Dest}, and
  57. returns a pointer to \var{Dest}. \var{Dest} needs enough room to contain
  58. \var{Source}, i.e. \var{StrLen(Source)+1} bytes.
  59. }
  60. {No length checking is performed.}{ \seef{StrPCopy}, \seef{StrLCopy}, \seef{StrECopy}}
  61. \latex{\inputlisting{stringex/ex4.pp}}
  62. \html{\input{stringex/ex4.tex}}
  63. \procedure{StrDispose}{(P : PChar)}
  64. {
  65. Removes the string in \var{P} from the heap and releases the memory.
  66. }
  67. {None.}{\seem{Dispose}{}, \seef{StrNew}}
  68. \latex{\inputlisting{stringex/ex17.pp}}
  69. \html{\input{stringex/ex17.tex}}
  70. \function{StrECopy}{(Dest,Source : PChar)}{PChar}
  71. {
  72. Copies the Null-terminated string in \var{Source} to \var{Dest}, and
  73. returns a pointer to the end (i.e. the terminating Null-character) of the
  74. copied string.
  75. }
  76. {No length checking is performed.}
  77. {\seef{StrLCopy}, \seef{StrCopy}}
  78. \latex{\inputlisting{stringex/ex6.pp}}
  79. \html{\input{stringex/ex6.tex}}
  80. \function{StrEnd}{(P : PChar)}{PChar}
  81. {
  82. Returns a pointer to the end of \var{P}. (i.e. to the terminating
  83. null-character.
  84. }
  85. {None.}{\seef{StrLen}}
  86. \latex{\inputlisting{stringex/ex7.pp}}
  87. \html{\input{stringex/ex7.tex}}
  88. \function{StrIComp}{(S1,S2 : PChar)}{Longint}
  89. {
  90. Compares the null-terminated strings \var{S1} and \var{S2}, ignoring case.
  91. The result is
  92. \begin{itemize}
  93. \item A negative \var{Longint} when \var{S1<S2}.
  94. \item 0 when \var{S1=S2}.
  95. \item A positive \var{Longint} when \var{S1>S2}.
  96. \end{itemize}
  97. }
  98. {None.}{\seef{StrLComp}, \seef{StrComp}, \seef{StrLIComp}}
  99. \latex{\inputlisting{stringex/ex8.pp}}
  100. \html{\input{stringex/ex8.tex}}
  101. \function{StrLCat}{(Dest,Source : PChar; MaxLen : Longint)}{PChar}
  102. {
  103. Adds \var{MaxLen} characters from \var{Source} to \var{Dest}, and adds a
  104. terminating null-character. Returns \var{Dest}.
  105. }
  106. {None.}{\seef{StrCat}}
  107. \latex{\inputlisting{stringex/ex12.pp}}
  108. \html{\input{stringex/ex12.tex}}
  109. \function{StrLComp}{(S1,S2 : PChar; L : Longint)}{Longint}
  110. {
  111. Compares maximum \var{L} characters of the null-terminated strings
  112. \var{S1} and \var{S2}.
  113. The result is
  114. \begin{itemize}
  115. \item A negative \var{Longint} when \var{S1<S2}.
  116. \item 0 when \var{S1=S2}.
  117. \item A positive \var{Longint} when \var{S1>S2}.
  118. \end{itemize}
  119. }
  120. {None.}{\seef{StrComp}, \seef{StrIComp}, \seef{StrLIComp}}
  121. \latex{\inputlisting{stringex/ex8.pp}}
  122. \html{\input{stringex/ex8.tex}}
  123. \function{StrLCopy}{(Dest,Source : PChar; MaxLen : Longint)}{PChar}
  124. {
  125. Copies \var{MaxLen} characters from \var{Source} to \var{Dest}, and makes
  126. \var{Dest} a null terminated string.
  127. }
  128. {No length checking is performed.}
  129. {\seef{StrCopy}, \seef{StrECopy}}
  130. \latex{\inputlisting{stringex/ex5.pp}}
  131. \html{\input{stringex/ex5.tex}}
  132. \function{StrLen}{(p : PChar)}{Longint}
  133. {
  134. Returns the length of the null-terminated string \var{P}.
  135. }
  136. {None.}{\seem{Length}{}}
  137. \latex{\inputlisting{stringex/ex1.pp}}
  138. \html{\input{stringex/ex1.tex}}
  139. \function{StrLIComp}{(S1,S2 : PChar; L : Longint)}{Longint}
  140. {
  141. Compares maximum \var{L} characters of the null-terminated strings \var{S1}
  142. and \var{S2}, ignoring case.
  143. The result is
  144. \begin{itemize}
  145. \item A negative \var{Longint} when \var{S1<S2}.
  146. \item 0 when \var{S1=S2}.
  147. \item A positive \var{Longint} when \var{S1>S2}.
  148. \end{itemize}
  149. }
  150. {None.}{\seef{StrLComp}, \seef{StrComp}, \seef{StrIComp}}
  151. For an example, see \seef{StrIComp}
  152. \function{StrLower}{(P : PChar)}{PChar}
  153. {
  154. Converts \var{P} to an all-lowercase string. Returns \var{P}.
  155. }
  156. {None.}{\seem{Upcase}{}, \seef{StrUpper}}
  157. \latex{\inputlisting{stringex/ex14.pp}}
  158. \html{\input{stringex/ex14.tex}}
  159. \function{StrMove}{(Dest,Source : PChar; MaxLen : Longint)}{PChar}
  160. {
  161. Copies \var{MaxLen} characters from \var{Source} to \var{Dest}. No
  162. terminating null-character is copied.
  163. Returns \var {Dest}.
  164. }
  165. {None.}{\seef{StrLCopy}, \seef{StrCopy}}
  166. \latex{\inputlisting{stringex/ex10.pp}}
  167. \html{\input{stringex/ex10.tex}}
  168. \function{StrNew}{(P : PChar)}{PChar}
  169. {
  170. Copies \var{P} to the Heap, and returns a pointer to the copy.
  171. }
  172. {Returns \var{Nil} if no memory was available for the copy.}
  173. {\seem{New}{}, \seef{StrCopy}, \seep{StrDispose}}
  174. \latex{\inputlisting{stringex/ex16.pp}}
  175. \html{\input{stringex/ex16.tex}}
  176. \function {StrPas}{(P : PChar)}{String}
  177. {
  178. Converts a null terminated string in \var{P} to a Pascal string, and returns
  179. this string. The string is truncated at 255 characters.
  180. }
  181. {None.}{ \seef{StrPCopy}}
  182. \latex{\inputlisting{stringex/ex3.pp}}
  183. \html{\input{stringex/ex3.tex}}
  184. \function{StrPCopy}{(Dest : PChar; Const Source : String)}{PChar}
  185. {
  186. Converts the Pascal string in \var{Source} to a Null-terminated
  187. string, and copies it to \var{Dest}. \var{Dest} needs enough room to contain
  188. the string \var{Source}, i.e. \var{Length(Source)+1} bytes.
  189. }
  190. {No length checking is performed.}{ \seef{StrPas}}
  191. \latex{\inputlisting{stringex/ex2.pp}}
  192. \html{\input{stringex/ex2.tex}}
  193. \function{StrPos}{(S1,S2 : PChar)}{PChar}
  194. {
  195. Returns a pointer to the first occurrence of \var{S2} in \var{S1}.
  196. If \var{S2} does not occur in \var{S1}, returns \var{Nil}.
  197. }
  198. {None.}{\seem{Pos}{}, \seef{StrScan}, \seef{StrRScan}}
  199. \latex{\inputlisting{stringex/ex15.pp}}
  200. \html{\input{stringex/ex15.tex}}
  201. \function{StrRScan}{(P : PChar; C : Char)}{PChar}
  202. {
  203. Returns a pointer to the last occurrence of the character \var{C} in the
  204. null-terminated string \var{P}. If \var{C} does not occur, returns
  205. \var{Nil}.
  206. }
  207. {None.}{\seem{Pos}{}, \seef{StrScan}, \seef{StrPos}}
  208. For an example, see \seef{StrScan}.
  209. \function{StrScan}{(P : PChar; C : Char)}{PChar}
  210. {
  211. Returns a pointer to the first occurrence of the character \var{C} in the
  212. null-terminated string \var{P}. If \var{C} does not occur, returns
  213. \var{Nil}.
  214. }
  215. {None.}{\seem{Pos}{}, \seef{StrRScan}, \seef{StrPos}}
  216. \latex{\inputlisting{stringex/ex13.pp}}
  217. \html{\input{stringex/ex13.tex}}
  218. \function{StrUpper}{(P : PChar)}{PChar}
  219. {
  220. Converts \var{P} to an all-uppercase string. Returns \var{P}.
  221. }
  222. {None.}{\seem{Upcase}{}, \seef{StrLower}}
  223. For an example, see \seef{StrLower}