File: strings.tex

package info (click to toggle)
fpc 1.9.4-5
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 63,532 kB
  • ctags: 93,677
  • sloc: pascal: 675,850; makefile: 219,089; xml: 9,242; perl: 7,703; yacc: 3,074; ansic: 2,275; lex: 711; sh: 406; asm: 71; csh: 34; sed: 33; cpp: 26; tcl: 7
file content (364 lines) | stat: -rw-r--r-- 8,981 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
%
%   $Id: strings.tex,v 1.2 2002/12/30 09:19:32 michael Exp $
%   This file is part of the FPC documentation.
%   Copyright (C) 1997, by Michael Van Canneyt
%
%   The FPC documentation is free text; you can redistribute it and/or
%   modify it under the terms of the GNU Library General Public License as
%   published by the Free Software Foundation; either version 2 of the
%   License, or (at your option) any later version.
%
%   The FPC Documentation is distributed in the hope that it will be useful,
%   but WITHOUT ANY WARRANTY; without even the implied warranty of
%   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
%   Library General Public License for more details.
%
%   You should have received a copy of the GNU Library General Public
%   License along with the FPC documentation; see the file COPYING.LIB.  If not,
%   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
%   Boston, MA 02111-1307, USA. 
%
\chapter{The STRINGS unit.}
\label{ch:strings}
\FPCexampledir{stringex}

This chapter describes the \var{STRINGS} unit for \fpc. This unit is system
independent, and therefore works on all supported platforms.

Since the unit only provides some procedures and functions, there is
only one section, which gives the declarations of these functions, together
with an explanation. 

\section{Functions and procedures.}

\begin{function}{StrAlloc}
\Declaration
Function StrAlloc (Len : Longint) : PChar;
\Description
\var{StrAlloc} reserves memory on the heap for a string with length \var{Len},
terminating \var{\#0} included, and returns a pointer to it.
\Errors
If there is not enough memory, a run-time error occurs.
\SeeAlso
\seef{StrNew}, \seef{StrPCopy}.
\end{function}


\begin{function}{StrCat}
\Declaration
Function StrCat (Dest,Source : PChar) : PChar;
\Description
Attaches \var{Source} to \var{Dest} and returns \var{Dest}.
\Errors
No length checking is performed.
\SeeAlso
\seem{Concat}{}
\end{function}

\FPCexample{ex11}

\begin{function}{StrComp}
\Declaration
Function StrComp (S1,S2 : PChar) : Longint;
\Description
Compares the null-terminated strings \var{S1} and \var{S2}.
The result is 
\begin{itemize}
\item A negative \var{Longint} when \var{S1<S2}.
\item 0 when \var{S1=S2}.
\item A positive \var{Longint} when \var{S1>S2}.
\end{itemize}
\Errors
None.
\SeeAlso
\seef{StrLComp}, \seef{StrIComp}, \seef{StrLIComp}
\end{function}

For an example, see \seef{StrLComp}.

\begin{function}{StrCopy}
\Declaration
Function StrCopy (Dest,Source : PChar) : PChar;
\Description
Copy the null terminated string in \var{Source} to \var{Dest}, and
returns a pointer to \var{Dest}. \var{Dest} needs enough room to contain
\var{Source}, i.e. \var{StrLen(Source)+1} bytes.
\Errors
No length checking is performed.
\SeeAlso
 \seef{StrPCopy}, \seef{StrLCopy}, \seef{StrECopy}
\end{function}

\FPCexample{ex4}

\begin{procedure}{StrDispose}
\Declaration
Procedure StrDispose (P : PChar);
\Description
Removes the string in \var{P} from the heap and releases the memory.
\Errors
None.
\SeeAlso
\seem{Dispose}{}, \seef{StrNew}
\end{procedure}

\FPCexample{ex17}

\begin{function}{StrECopy}
\Declaration
Function StrECopy (Dest,Source : PChar) : PChar;
\Description
Copies the Null-terminated string in \var{Source} to \var{Dest}, and
returns a pointer to the end (i.e. the terminating Null-character) of the
copied string.
\Errors
No length checking is performed.
\SeeAlso
\seef{StrLCopy}, \seef{StrCopy}
\end{function}

\FPCexample{ex6}

\begin{function}{StrEnd}
\Declaration
Function StrEnd (P : PChar) : PChar;
\Description
Returns a pointer to the end of \var{P}. (i.e. to the terminating
null-character.
\Errors
None.
\SeeAlso
\seef{StrLen}
\end{function}

\FPCexample{ex7}

\begin{function}{StrIComp}
\Declaration
Function StrIComp (S1,S2 : PChar) : Longint;
\Description
Compares the null-terminated strings \var{S1} and \var{S2}, ignoring case.
The result is 
\begin{itemize}
\item A negative \var{Longint} when \var{S1<S2}.
\item 0 when \var{S1=S2}.
\item A positive \var{Longint} when \var{S1>S2}.
\end{itemize}
\Errors
None.
\SeeAlso
\seef{StrLComp}, \seef{StrComp}, \seef{StrLIComp}
\end{function}

\FPCexample{ex8}

\begin{function}{StrLCat}
\Declaration
Function StrLCat (Dest,Source : PChar; MaxLen : Longint) : PChar;
\Description
Adds \var{MaxLen} characters from \var{Source} to \var{Dest}, and adds a
terminating null-character. Returns \var{Dest}.
\Errors
None.
\SeeAlso
\seef{StrCat}
\end{function}

\FPCexample{ex12}

\begin{function}{StrLComp}
\Declaration
Function StrLComp (S1,S2 : PChar; L : Longint) : Longint;
\Description
Compares maximum \var{L} characters of the null-terminated strings 
\var{S1} and \var{S2}. 
The result is 
\begin{itemize}
\item A negative \var{Longint} when \var{S1<S2}.
\item 0 when \var{S1=S2}.
\item A positive \var{Longint} when \var{S1>S2}.
\end{itemize}
\Errors
None.
\SeeAlso
\seef{StrComp}, \seef{StrIComp}, \seef{StrLIComp}
\end{function}

\FPCexample{ex8}

\begin{function}{StrLCopy}
\Declaration
Function StrLCopy (Dest,Source : PChar; MaxLen : Longint) : PChar;
\Description
Copies \var{MaxLen} characters from \var{Source} to \var{Dest}, and makes
\var{Dest} a null terminated string. 
\Errors
No length checking is performed.
\SeeAlso
\seef{StrCopy}, \seef{StrECopy}
\end{function}

\FPCexample{ex5}

\begin{function}{StrLen}
\Declaration
Function StrLen (p : PChar) : Longint;
\Description
Returns the length of the null-terminated string \var{P}.
\Errors
None.
\SeeAlso
\seem{Length}{}
\end{function}

\FPCexample{ex1}

\begin{function}{StrLIComp}
\Declaration
Function StrLIComp (S1,S2 : PChar; L : Longint) : Longint;
\Description
Compares maximum \var{L} characters of the null-terminated strings \var{S1} 
and \var{S2}, ignoring case.
The result is 
\begin{itemize}
\item A negative \var{Longint} when \var{S1<S2}.
\item 0 when \var{S1=S2}.
\item A positive \var{Longint} when \var{S1>S2}.
\end{itemize}
\Errors
None.
\SeeAlso
\seef{StrLComp}, \seef{StrComp}, \seef{StrIComp}
\end{function}

For an example, see \seef{StrIComp}

\begin{function}{StrLower}
\Declaration
Function StrLower (P : PChar) : PChar;
\Description
Converts \var{P} to an all-lowercase string. Returns \var{P}.
\Errors
None.
\SeeAlso
\seem{Upcase}{}, \seef{StrUpper}
\end{function}

\FPCexample{ex14}

\begin{function}{StrMove}
\Declaration
Function StrMove (Dest,Source : PChar; MaxLen : Longint) : PChar;
\Description
Copies \var{MaxLen} characters from \var{Source} to \var{Dest}. No
terminating null-character is copied.
Returns \var {Dest}.
\Errors
None.
\SeeAlso
\seef{StrLCopy}, \seef{StrCopy}
\end{function}

\FPCexample{ex10}

\begin{function}{StrNew}
\Declaration
Function StrNew (P : PChar) : PChar;
\Description
Copies \var{P} to the Heap, and returns a pointer to the copy.
\Errors
Returns \var{Nil} if no memory was available for the copy.
\SeeAlso
\seem{New}{}, \seef{StrCopy}, \seep{StrDispose}
\end{function}

\FPCexample{ex16}

\begin{function}{StrPas}
\Declaration
Function StrPas (P : PChar) : String;
\Description
Converts a null terminated string in \var{P} to a Pascal string, and returns
this string. The string is truncated at 255 characters.
\Errors
None.
\SeeAlso
 \seef{StrPCopy}
\end{function}

\FPCexample{ex3}

\begin{function}{StrPCopy}
\Declaration
Function StrPCopy (Dest : PChar; Const Source : String) : PChar;
\Description
Converts the Pascal string in \var{Source} to a Null-terminated 
string, and copies it to \var{Dest}. \var{Dest} needs enough room to contain
the string \var{Source}, i.e. \var{Length(Source)+1} bytes.
\Errors
No length checking is performed.
\SeeAlso
 \seef{StrPas}
\end{function}

\FPCexample{ex2}

\begin{function}{StrPos}
\Declaration
Function StrPos (S1,S2 : PChar) : PChar;
\Description
Returns a pointer to the first occurrence of \var{S2} in \var{S1}.
If \var{S2} does not occur in \var{S1}, returns \var{Nil}.
\Errors
None.
\SeeAlso
\seem{Pos}{}, \seef{StrScan}, \seef{StrRScan}
\end{function}

\FPCexample{ex15}

\begin{function}{StrRScan}
\Declaration
Function StrRScan (P : PChar; C : Char) : PChar;
\Description
Returns a pointer to the last occurrence of the character \var{C} in the
null-terminated string \var{P}. If \var{C} does not occur, returns
\var{Nil}.
\Errors
None.
\SeeAlso
\seem{Pos}{}, \seef{StrScan}, \seef{StrPos}
\end{function}


For an example, see \seef{StrScan}.


\begin{function}{StrScan}
\Declaration
Function StrScan (P : PChar; C : Char) : PChar;
\Description
Returns a pointer to the first occurrence of the character \var{C} in the
null-terminated string \var{P}. If \var{C} does not occur, returns
\var{Nil}.

\Errors
None.
\SeeAlso
\seem{Pos}{}, \seef{StrRScan}, \seef{StrPos}
\end{function}

\FPCexample{ex13}

\begin{function}{StrUpper}
\Declaration
Function StrUpper (P : PChar) : PChar;
\Description
Converts \var{P} to an all-uppercase string. Returns \var{P}.
\Errors
None.
\SeeAlso
\seem{Upcase}{}, \seef{StrLower}
\end{function}

For an example, see \seef{StrLower}