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