strings.tex 7.0 KB

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