File: libcgi_string.3

package info (click to toggle)
libcgi 1.0-5
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 940 kB
  • ctags: 268
  • sloc: sh: 2,700; ansic: 2,134; makefile: 232
file content (580 lines) | stat: -rw-r--r-- 11,606 bytes parent folder | download | duplicates (2)
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
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
.TH "Strings" 3 "13 Mar 2003" "LibCGI" \" -*- nroff -*-
.ad l
.nh
.SH NAME
Strings \- 
.SH "Detailed Description"
.PP 
General string manipulation and utilities functions.
.SS "Functions"

.in +1c
.ti -1c
.RI "char * \fBstr_base64_encode\fP (char *str)"
.br
.RI "\fIEncodes a given tring to its base64 form.\fP"
.ti -1c
.RI "char * \fBstr_base64_decode\fP (char *str)"
.br
.RI "\fIDecode a base64 encoded string.\fP"
.ti -1c
.RI "char * \fBaddnslashes\fP (char *s, int n)"
.br
.RI "\fISame to \fBaddslashes()\fP, except that this one only do the action while 'n' is great than 0.\fP"
.ti -1c
.RI "char * \fBaddslashes\fP (char *s)"
.br
.RI "\fIAdd slashes to a string when necessary.\fP"
.ti -1c
.RI "char * \fBstripnslashes\fP (char *s, int n)"
.br
.RI "\fIStrip no more than 'n' slashes from a string.\fP"
.ti -1c
.RI "char * \fBstripslashes\fP (char *str)"
.br
.RI "\fIStrip slashes from a string.\fP"
.ti -1c
.RI "void \fBltrim\fP (char *str)"
.br
.RI "\fIStrip left white spaces from a string.\fP"
.ti -1c
.RI "void \fBrtrim\fP (char *str)"
.br
.RI "\fIStrip right white spaces from a string.\fP"
.ti -1c
.RI "void \fBtrim\fP (char *str)"
.br
.RI "\fIStrip both left and right white spaces from a string.\fP"
.ti -1c
.RI "char * \fBsubstr\fP (char *src, const int start, const int count)"
.br
.RI "\fICopy part of a string.\fP"
.ti -1c
.RI "char ** \fBexplode\fP (char *src, const char *token, int *total)"
.br
.RI "\fICreate an array from a string separated by some special char.\fP"
.ti -1c
.RI "char * \fBstr_nreplace\fP (char *src, const char *delim, const char *with, int n)"
.br
.RI "\fIReplace characteres in a string, but not more than 'n'.\fP"
.ti -1c
.RI "char * \fBstr_replace\fP (char *str, const char *delim, const char *with)"
.br
.RI "\fIReplace characteres in a string.\fP"
.ti -1c
.RI "int \fBstrnpos\fP (char *s, char *ch, unsigned int count)"
.br
.RI "\fIReturns the position of a character in a string, but parses no more that 'n' chars.\fP"
.ti -1c
.RI "int \fBstrpos\fP (char *s, char *ch)"
.br
.RI "\fIReturns the position of a character in a string.\fP"
.ti -1c
.RI "char * \fBstrdel\fP (char *s, int start, int count)"
.br
.RI "\fIDelete characters from a string.\fP"
.ti -1c
.RI "char * \fBrecvline\fP (FILE *s)"
.br
.RI "\fIReads an entire line.\fP"
.ti -1c
.RI "char * \fBmake_string\fP (char *s,...)"
.br
.RI "\fIMakes a string.\fP"
.in -1c
.SH "Function Documentation"
.PP 
.SS "char* addnslashes (char * s, int n)"
.PP
Same to \fBaddslashes()\fP, except that this one only do the action while 'n' is great than 0.\fBParameters:\fP
.RS 4
\fIs\fP String to parse 
.br
\fIn\fP Number of characters to work with. 
.RE
.PP
\fBSee also:\fP
.RS 4
\fBaddslashes()\fP 
.PP
.nf

 char *name = 'My test string is called \'foobar\'';
 puts(name); // will display My test string is called 'foobar'
 
 name = addnslashes(name, 31);
 puts(name); // will display My test string is called \'foobar'
 

.PP
.RE
.PP

.SS "char* addslashes (char * s)"
.PP
Add slashes to a string when necessary.Adds a '\\' in every quote ( ' ), apostrophe ( ' ) or backslash ( \\ ) It's useful when working with databases, for example, because someone can try insert this caracters to try hack the application... 
.PP
\fBParameters:\fP
.RS 4
\fI*s\fP String to parse 
.RE
.PP
\fBReturns:\fP
.RS 4
The new string, with slashes 
.RE
.PP
\fBSee also:\fP
.RS 4
stripslashes, addnslashes
.RE
.PP
.PP
.nf

 char *name = 'My test string is called \'foobar\'';
 puts(name); // will display My test string is called 'foobar'
 
 name = addslashes(name);
 puts(name); // will display My test string is called \'foobar\'
 
.PP

.SS "char** explode (char * src, const char * token, int * total)"
.PP
Create an array from a string separated by some special char.Divides the src string in pieces, each delimited by token and storing the total of pieces in total 
.PP
\fBParameters:\fP
.RS 4
\fIsrc\fP String to parse 
.br
\fItoken\fP Character delimiter to search. 
.br
\fItotal\fP An integer variable passed as reference, which stores the total of itens of the array 
.RE
.PP
\fBReturns:\fP
.RS 4
The array, where each item is one separeted by token
.RE
.PP
.PP
.nf

  
  char **pieces;
  char *name = 'This,is,a,string,of,test';
  int total, i;
  pieces = explode(name, ',', &total);
  for (i = 0; i < total; i++)
        printf('Piece %d: %s\n', i, *(pieces+i));
 
.PP

.SS "void ltrim (char * str)"
.PP
Strip left white spaces from a string.\fBParameters:\fP
.RS 4
\fIstr\fP String to parse 
.RE
.PP
\fBReturns:\fP
.RS 4
The new string, without left spaces 
.RE
.PP
\fBAuthor:\fP
.RS 4
Original code was contribuition by Erik Jansson 
.RE
.PP
\fBSee also:\fP
.RS 4
rtrim, trim
.RE
.PP
.PP
.nf

 char *s = '     String with spaces    ';
 printf('_%s_\n', s);
 s = ltrim(s);
 printf('_%s_\n', s);
 
.PP

.SS "char* make_string (char * s, ...)"
.PP
Makes a string.Works like printf(), with the difference that it returns a string that is the concatenation of the values passed as parameter.
.PP
\fBParameters:\fP
.RS 4
\fI*s\fP Inicial String and optionally formatation parameters ( just s is allowed ) 
.RE
.PP
\fBReturns:\fP
.RS 4
The new String 
.PP
.nf

 char *sql = make_string('INSERT INTO myTable VALUES ('%s', '%s', '%s')', varValue1, varValue2, varValue3);
 

.PP
.RE
.PP
\fBTodo\fP
.RS 4
String limits/error checking 
.RE
.PP

.SS "char* recvline (FILE * s)"
.PP
Reads an entire line.Reads a line from the file specified by the file pointer passed as parameter. This function is intead to replace the non-portable GNU getline() function.
.PP
\fBParameters:\fP
.RS 4
\fIs\fP File pointer to the file to read from. 
.RE
.PP
\fBReturns:\fP
.RS 4
String containing the line read or NULL if no more line are available 
.RE
.PP
\fBAuthor:\fP
.RS 4
Robert Csok 
.RE
.PP

.SS "void rtrim (char * str)"
.PP
Strip right white spaces from a string.\fBParameters:\fP
.RS 4
\fIstr\fP String to parse 
.RE
.PP
\fBReturns:\fP
.RS 4
The new string, without left spaces 
.RE
.PP
\fBAuthor:\fP
.RS 4
Original code was contribuition by Erik Jansson 
.RE
.PP
\fBSee also:\fP
.RS 4
ltrim, trim
.RE
.PP
.PP
.nf

 char *s = '     String with spaces    ';
 printf('_%s_\n', s);
 s = rtrim(s);
 printf('_%s_\n', s);
 
.PP

.SS "char* str_base64_decode (char * str)"
.PP
Decode a base64 encoded string.\fBParameters:\fP
.RS 4
\fI*str\fP Encoded String to decode 
.RE
.PP
\fBReturns:\fP
.RS 4
The decoded string 
.RE
.PP
\fBSee also:\fP
.RS 4
\fBstr_base64_encode\fP 
.RE
.PP

.SS "char* str_base64_encode (char * str)"
.PP
Encodes a given tring to its base64 form.\fBParameters:\fP
.RS 4
\fI*str\fP String to convert 
.RE
.PP
\fBReturns:\fP
.RS 4
Base64 encoded String 
.RE
.PP
\fBSee also:\fP
.RS 4
\fBstr_base64_decode\fP 
.RE
.PP

.SS "char* str_nreplace (char * src, const char * delim, const char * with, int n)"
.PP
Replace characteres in a string, but not more than 'n'.Replace all occourences of *delim on *src with characteres pointed by *with, stopping after 'n' char. 
.PP
\fBParameters:\fP
.RS 4
\fI*src\fP String to parse 
.br
\fI*delim\fP Character to search that will be replaced 
.br
\fIwith\fP String to replace with 
.br
\fIn\fP Maximum number of chars to parse 
.RE
.PP
\fBReturns:\fP
.RS 4
The new string 
.RE
.PP
\fBSee also:\fP
.RS 4
\fBstr_replace\fP
.RE
.PP
.PP
.nf

  char *linux = 'Linux C';
  linux = str_nreplace(linux, 'C', 'Cool', strlen(linux));
  puts(linux);
 //  -- OR --
  char *name = 'rAfAel steil';
  name = str_nreplace(name, 'A', 'a', 3);
  puts(name);
  
.PP

.SS "char* str_replace (char * str, const char * delim, const char * with)"
.PP
Replace characteres in a string.Replace all occourences of *delim on *src with characteres pointed by *with. The problem with the folowing code is that the function only searches for the first caracter of *delim, ingoring the rest. Other problem is speed relacioned: note that the function ever compare the length of *with to do the correct action. 
.PP
\fBParameters:\fP
.RS 4
\fIsrc\fP String to parse 
.br
\fIdelim\fP Character to search that will be replaced 
.br
\fIwith\fP String to replace with 
.RE
.PP
\fBReturns:\fP
.RS 4
The new string 
.RE
.PP
\fBSee also:\fP
.RS 4
\fBstr_nreplace\fP
.RE
.PP
.PP
.nf

  char *linux = 'Linux C';
  linux = str_replace(linux, 'C', 'Cool');
  puts(linux);
 //  -- OR --
  char *name = 'rAfAel steil';
  name = str_replace(name, 'A', 'a');
  puts(name);
  
.PP

.SS "char* strdel (char * s, int start, int count)"
.PP
Delete characters from a string.Delete count characters of s, starting in start 
.PP
\fBParameters:\fP
.RS 4
\fIs\fP String to search 
.br
\fIstart\fP Initial offset to begin search 
.br
\fIcount\fP Number of characteres to delete 
.RE
.PP
\fBReturns:\fP
.RS 4
The new string 
.RE
.PP
\fBSee also:\fP
.RS 4
strndel()
.RE
.PP
.PP
.nf

  *txt = 'Some text to test anything';
  puts(txt);
  txt = strdel(txt, 2, 8);
  puts(txt);
 
.PP

.SS "char* stripnslashes (char * s, int n)"
.PP
Strip no more than 'n' slashes from a string.Strip the backslash character ( \\ ) from a string, stopping after 'n' char 
.PP
\fBParameters:\fP
.RS 4
\fIs\fP String to parse 
.br
\fIn\fP Maximum number of chars to parse 
.RE
.PP
\fBReturns:\fP
.RS 4
The new string, without slashes 
.RE
.PP
\fBSee also:\fP
.RS 4
addslashes, stripslashes
.RE
.PP
.PP
.nf

 char *name = 'My another string is called \\\'blablabla\\\'';
 puts(name); // will display My another string is called \'blablabla\'
 name = stripslashes(name, 33);
 puts(name); // will display My another string is called 'blablabla\'
 
.PP

.SS "char* stripslashes (char * str)"
.PP
Strip slashes from a string.Strip the backslash character ( \\ ) from a string 
.PP
\fBParameters:\fP
.RS 4
\fIs\fP String to parse 
.RE
.PP
\fBReturns:\fP
.RS 4
The new string, without slashes 
.RE
.PP
\fBSee also:\fP
.RS 4
addslashes, stripnslashes
.RE
.PP
.PP
.nf

 char *name = 'My another string is called \\\'blablabla\\\'';
 puts(name); // will display My another string is called \'blablabla\'
 name = stripslashes(name);
 puts(name); // will display My another string is called 'blablabla'
 
.PP

.SS "int strnpos (char * s, char * ch, unsigned int count)"
.PP
Returns the position of a character in a string, but parses no more that 'n' chars.\fBParameters:\fP
.RS 4
\fIs\fP String where the search will be done 
.br
\fIch\fP Character to search 
.br
\fIcount\fP Maximum number of chars to parse before exiting the function 
.RE
.PP
\fBSee also:\fP
.RS 4
\fBstrpos()\fP 
.RE
.PP

.SS "int strpos (char * s, char * ch)"
.PP
Returns the position of a character in a string.\fBParameters:\fP
.RS 4
\fIs\fP String where the search will be done 
.br
\fIch\fP Character to search 
.br
\fIcount\fP Maximum number of ch to search 
.RE
.PP
\fBSee also:\fP
.RS 4
\fBstrnpos()\fP 
.RE
.PP

.SS "char* substr (char * src, const int start, const int count)"
.PP
Copy part of a string.Copy count characters from src, starting from start 
.PP
\fBParameters:\fP
.RS 4
\fIsrc\fP String to copy from 
.br
\fIstart\fP Initial offset 
.br
\fIcount\fP Number of chars to copy 
.RE
.PP
\fBReturns:\fP
.RS 4
The new string
.RE
.PP
.PP
.nf

 char *part, *str = 'Test one, test two';
 part = substr(str, 1, 5);
 puts(part); // -> est o
 
.PP

.SS "void trim (char * str)"
.PP
Strip both left and right white spaces from a string.\fBParameters:\fP
.RS 4
\fIstr\fP String to parse 
.RE
.PP
\fBReturns:\fP
.RS 4
The new string, without left spaces 
.RE
.PP
\fBAuthor:\fP
.RS 4
Original code was contribuition by Erik Jansson 
.RE
.PP
\fBSee also:\fP
.RS 4
ltrim, trim
.RE
.PP
.PP
.nf

 char *s = '     String with spaces    ';
 printf('_%s_\n', s);
 s = trim(s);
 printf('_%s_\n', s);
 
.PP