VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/nsprpub/lib/libc/include/plstr.h@ 11551

Last change on this file since 11551 was 11551, checked in by vboxsync, 16 years ago

API/xpcom: prefix any C symbols in VBoxXPCOM.so, to avoid namespace pollution. Enabled only on Linux at the moment.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 16.0 KB
Line 
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2/* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is the Netscape Portable Runtime (NSPR).
16 *
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998-2000
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 * Roland Mainz <roland [email protected]>
24 *
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
36 *
37 * ***** END LICENSE BLOCK ***** */
38
39#ifndef _plstr_h
40#define _plstr_h
41
42/*
43 * plstr.h
44 *
45 * This header file exports the API to the NSPR portable library or string-
46 * handling functions.
47 *
48 * This API was not designed as an "optimal" or "ideal" string library; it
49 * was based on the good ol' unix string.3 functions, and was written to
50 *
51 * 1) replace the libc functions, for cross-platform consistancy,
52 * 2) complete the API on platforms lacking common functions (e.g.,
53 * strcase*), and
54 * 3) to implement some obvious "closure" functions that I've seen
55 * people hacking around in our code.
56 *
57 * Point number three largely means that most functions have an "strn"
58 * limited-length version, and all comparison routines have a non-case-
59 * sensitive version available.
60 */
61
62#include "prtypes.h"
63
64#ifdef VBOX_WITH_XPCOM_NAMESPACE_CLEANUP
65#define PL_strlen VBoxNsplPL_strlen
66#define PL_strcmp VBoxNsplPL_strcmp
67#define PL_strncmp VBoxNsplPL_strncmp
68#define PL_strcasecmp VBoxNsplPL_strcasecmp
69#define PL_strncasecmp VBoxNsplPL_strncasecmp
70#define PL_strdup VBoxNsplPL_strdup
71#define PL_strfree VBoxNsplPL_strfree
72#define PL_strncpy VBoxNsplPL_strncpy
73#define PL_strncpyz VBoxNsplPL_strncpyz
74#define PL_strrchr VBoxNsplPL_strrchr
75#define PL_strcaserstr VBoxNsplPL_strcaserstr
76#define PL_strcasestr VBoxNsplPL_strcasestr
77#define PL_strcat VBoxNsplPL_strcat
78#define PL_strcatn VBoxNsplPL_strcatn
79#define PL_strchr VBoxNsplPL_strchr
80#define PL_strcpy VBoxNsplPL_strcpy
81#define PL_strncaserstr VBoxNsplPL_strncaserstr
82#define PL_strncasestr VBoxNsplPL_strncasestr
83#define PL_strncat VBoxNsplPL_strncat
84#define PL_strnchr VBoxNsplPL_strnchr
85#define PL_strndup VBoxNsplPL_strndup
86#define PL_strnlen VBoxNsplPL_strnlen
87#define PL_strnpbrk VBoxNsplPL_strnpbrk
88#define PL_strnprbrk VBoxNsplPL_strnprbrk
89#define PL_strnrchr VBoxNsplPL_strnrchr
90#define PL_strnrstr VBoxNsplPL_strnrstr
91#define PL_strnstr VBoxNsplPL_strnstr
92#define PL_strpbrk VBoxNsplPL_strpbrk
93#define PL_strprbrk VBoxNsplPL_strprbrk
94#define PL_strrstr VBoxNsplPL_strrstr
95#define PL_strstr VBoxNsplPL_strstr
96#define PL_strtok_r VBoxNsplPL_strtok_r
97#endif /* VBOX_WITH_XPCOM_NAMESPACE_CLEANUP */
98
99PR_BEGIN_EXTERN_C
100/*
101 * PL_strlen
102 *
103 * Returns the length of the provided string, not including the trailing '\0'.
104 */
105
106PR_EXTERN(PRUint32)
107PL_strlen(const char *str);
108
109/*
110 * PL_strnlen
111 *
112 * Returns the length of the provided string, not including the trailing '\0',
113 * up to the indicated maximum. The string will not be examined beyond the
114 * maximum; if no terminating '\0' is found, the maximum will be returned.
115 */
116
117PR_EXTERN(PRUint32)
118PL_strnlen(const char *str, PRUint32 max);
119
120/*
121 * PL_strcpy
122 *
123 * Copies the source string, up to and including the trailing '\0', into the
124 * destination buffer. It does not (can not) verify that the destination
125 * buffer is large enough. It returns the "dest" argument.
126 */
127
128PR_EXTERN(char *)
129PL_strcpy(char *dest, const char *src);
130
131/*
132 * PL_strncpy
133 *
134 * Copies the source string into the destination buffer, up to and including
135 * the trailing '\0' or up to and including the max'th character, whichever
136 * comes first. It does not (can not) verify that the destination buffer is
137 * large enough. If the source string is longer than the maximum length,
138 * the result will *not* be null-terminated (JLRU).
139 */
140
141PR_EXTERN(char *)
142PL_strncpy(char *dest, const char *src, PRUint32 max);
143
144/*
145 * PL_strncpyz
146 *
147 * Copies the source string into the destination buffer, up to and including
148 * the trailing '\0' or up but not including the max'th character, whichever
149 * comes first. It does not (can not) verify that the destination buffer is
150 * large enough. The destination string is always terminated with a '\0',
151 * unlike the traditional libc implementation. It returns the "dest" argument.
152 *
153 * NOTE: If you call this with a source "abcdefg" and a max of 5, the
154 * destination will end up with "abcd\0" (i.e., it's strlen length will be 4)!
155 *
156 * This means you can do this:
157 *
158 * char buffer[ SOME_SIZE ];
159 * PL_strncpyz(buffer, src, sizeof(buffer));
160 *
161 * and the result will be properly terminated.
162 */
163
164PR_EXTERN(char *)
165PL_strncpyz(char *dest, const char *src, PRUint32 max);
166
167/*
168 * PL_strdup
169 *
170 * Returns a pointer to a malloc'd extent of memory containing a duplicate
171 * of the argument string. The size of the allocated extent is one greater
172 * than the length of the argument string, because of the terminator. A
173 * null argument, like a zero-length argument, will result in a pointer to
174 * a one-byte extent containing the null value. This routine returns null
175 * upon malloc failure.
176 */
177
178PR_EXTERN(char *)
179PL_strdup(const char *s);
180
181/*
182 * PL_strfree
183 *
184 * Free memory allocated by PL_strdup
185 */
186
187PR_EXTERN(void)
188PL_strfree(char *s);
189
190/*
191 * PL_strndup
192 *
193 * Returns a pointer to a malloc'd extent of memory containing a duplicate
194 * of the argument string, up to the maximum specified. If the argument
195 * string has a length greater than the value of the specified maximum, the
196 * return value will be a pointer to an extent of memory of length one
197 * greater than the maximum specified. A null string, a zero-length string,
198 * or a zero maximum will all result in a pointer to a one-byte extent
199 * containing the null value. This routine returns null upon malloc failure.
200 */
201
202PR_EXTERN(char *)
203PL_strndup(const char *s, PRUint32 max);
204
205/*
206 * PL_strcat
207 *
208 * Appends a copy of the string pointed to by the second argument to the
209 * end of the string pointed to by the first. The destination buffer is
210 * not (can not be) checked for sufficient size. A null destination
211 * argument returns null; otherwise, the first argument is returned.
212 */
213
214PR_EXTERN(char *)
215PL_strcat(char *dst, const char *src);
216
217/*
218 * PL_strncat
219 *
220 * Appends a copy of the string pointed to by the second argument, up to
221 * the maximum size specified, to the end of the string pointed to by the
222 * first. The destination buffer is not (can not be) checked for sufficient
223 * size. A null destination argument returns null; otherwise, the first
224 * argument is returned. If the maximum size limits the copy, then the
225 * result will *not* be null-terminated (JLRU). A null destination
226 * returns null; otherwise, the destination argument is returned.
227 */
228
229PR_EXTERN(char *)
230PL_strncat(char *dst, const char *src, PRUint32 max);
231
232/*
233 * PL_strcatn
234 *
235 * Appends a copy of the string pointed to by the third argument, to the
236 * end of the string pointed to by the first. The second argument specifies
237 * the maximum size of the destination buffer, including the null termination.
238 * If the existing string in dst is longer than the max, no action is taken.
239 * The resulting string will be null-terminated. A null destination returns
240 * null; otherwise, the destination argument is returned.
241 */
242
243PR_EXTERN(char *)
244PL_strcatn(char *dst, PRUint32 max, const char *src);
245
246/*
247 * PL_strcmp
248 *
249 * Returns an integer, the sign of which -- positive, zero, or negative --
250 * reflects the lexical sorting order of the two strings indicated. The
251 * result is positive if the first string comes after the second. The
252 * NSPR implementation is not i18n.
253 */
254
255PR_EXTERN(PRIntn)
256PL_strcmp(const char *a, const char *b);
257
258/*
259 * PL_strncmp
260 *
261 * Returns an integer, the sign of which -- positive, zero, or negative --
262 * reflects the lexical sorting order of the two strings indicated, up to
263 * the maximum specified. The result is positive if the first string comes
264 * after the second. The NSPR implementation is not i18n. If the maximum
265 * is zero, only the existance or non-existance (pointer is null) of the
266 * strings is compared.
267 */
268
269PR_EXTERN(PRIntn)
270PL_strncmp(const char *a, const char *b, PRUint32 max);
271
272/*
273 * PL_strcasecmp
274 *
275 * Returns an integer, the sign of which -- positive, zero or negative --
276 * reflects the case-insensitive lexical sorting order of the two strings
277 * indicated. The result is positive if the first string comes after the
278 * second. The NSPR implementation is not i18n.
279 */
280
281PR_EXTERN(PRIntn)
282PL_strcasecmp(const char *a, const char *b);
283
284/*
285 * PL_strncasecmp
286 *
287 * Returns an integer, the sign of which -- positive, zero or negative --
288 * reflects the case-insensitive lexical sorting order of the first n characters
289 * of the two strings indicated. The result is positive if the first string comes
290 * after the second. The NSPR implementation is not i18n.
291 */
292
293PR_EXTERN(PRIntn)
294PL_strncasecmp(const char *a, const char *b, PRUint32 max);
295
296/*
297 * PL_strchr
298 *
299 * Returns a pointer to the first instance of the specified character in the
300 * provided string. It returns null if the character is not found, or if the
301 * provided string is null. The character may be the null character.
302 */
303
304PR_EXTERN(char *)
305PL_strchr(const char *s, char c);
306
307/*
308 * PL_strrchr
309 *
310 * Returns a pointer to the last instance of the specified character in the
311 * provided string. It returns null if the character is not found, or if the
312 * provided string is null. The character may be the null character.
313 */
314
315PR_EXTERN(char *)
316PL_strrchr(const char *s, char c);
317
318/*
319 * PL_strnchr
320 *
321 * Returns a pointer to the first instance of the specified character within the
322 * first n characters of the provided string. It returns null if the character
323 * is not found, or if the provided string is null. The character may be the
324 * null character.
325 */
326
327PR_EXTERN(char *)
328PL_strnchr(const char *s, char c, PRUint32 n);
329
330/*
331 * PL_strnrchr
332 *
333 * Returns a pointer to the last instance of the specified character within the
334 * first n characters of the provided string. It returns null if the character is
335 * not found, or if the provided string is null. The character may be the null
336 * character.
337 */
338
339PR_EXTERN(char *)
340PL_strnrchr(const char *s, char c, PRUint32 n);
341
342/*
343 * NOTE: Looking for strcasechr, strcaserchr, strncasechr, or strncaserchr?
344 * Use strpbrk, strprbrk, strnpbrk or strnprbrk.
345 */
346
347/*
348 * PL_strpbrk
349 *
350 * Returns a pointer to the first instance in the first string of any character
351 * (not including the terminating null character) of the second string. It returns
352 * null if either string is null.
353 */
354
355PR_EXTERN(char *)
356PL_strpbrk(const char *s, const char *list);
357
358/*
359 * PL_strprbrk
360 *
361 * Returns a pointer to the last instance in the first string of any character
362 * (not including the terminating null character) of the second string. It returns
363 * null if either string is null.
364 */
365
366PR_EXTERN(char *)
367PL_strprbrk(const char *s, const char *list);
368
369/*
370 * PL_strnpbrk
371 *
372 * Returns a pointer to the first instance (within the first n characters) of any
373 * character (not including the terminating null character) of the second string.
374 * It returns null if either string is null.
375 */
376
377PR_EXTERN(char *)
378PL_strnpbrk(const char *s, const char *list, PRUint32 n);
379
380/*
381 * PL_strnprbrk
382 *
383 * Returns a pointer to the last instance (within the first n characters) of any
384 * character (not including the terminating null character) of the second string.
385 * It returns null if either string is null.
386 */
387
388PR_EXTERN(char *)
389PL_strnprbrk(const char *s, const char *list, PRUint32 n);
390
391/*
392 * PL_strstr
393 *
394 * Returns a pointer to the first instance of the little string within the
395 * big one. It returns null if either string is null.
396 */
397
398PR_EXTERN(char *)
399PL_strstr(const char *big, const char *little);
400
401/*
402 * PL_strrstr
403 *
404 * Returns a pointer to the last instance of the little string within the big one.
405 * It returns null if either string is null.
406 */
407
408PR_EXTERN(char *)
409PL_strrstr(const char *big, const char *little);
410
411/*
412 * PL_strnstr
413 *
414 * Returns a pointer to the first instance of the little string within the first
415 * n characters of the big one. It returns null if either string is null. It
416 * returns null if the length of the little string is greater than n.
417 */
418
419PR_EXTERN(char *)
420PL_strnstr(const char *big, const char *little, PRUint32 n);
421
422/*
423 * PL_strnrstr
424 *
425 * Returns a pointer to the last instance of the little string within the first
426 * n characters of the big one. It returns null if either string is null. It
427 * returns null if the length of the little string is greater than n.
428 */
429
430PR_EXTERN(char *)
431PL_strnrstr(const char *big, const char *little, PRUint32 max);
432
433/*
434 * PL_strcasestr
435 *
436 * Returns a pointer to the first instance of the little string within the big one,
437 * ignoring case. It returns null if either string is null.
438 */
439
440PR_EXTERN(char *)
441PL_strcasestr(const char *big, const char *little);
442
443/*
444 * PL_strcaserstr
445 *
446 * Returns a pointer to the last instance of the little string within the big one,
447 * ignoring case. It returns null if either string is null.
448 */
449
450PR_EXTERN(char *)
451PL_strcaserstr(const char *big, const char *little);
452
453/*
454 * PL_strncasestr
455 *
456 * Returns a pointer to the first instance of the listtle string within the first
457 * n characters of the big one, ignoring case. It returns null if either string is
458 * null. It returns null if the length of the little string is greater than n.
459 */
460
461PR_EXTERN(char *)
462PL_strncasestr(const char *big, const char *little, PRUint32 max);
463
464/*
465 * PL_strncaserstr
466 *
467 * Returns a pointer to the last instance of the little string within the first
468 * n characters of the big one, ignoring case. It returns null if either string is
469 * null. It returns null if the length of the little string is greater than n.
470 */
471
472PR_EXTERN(char *)
473PL_strncaserstr(const char *big, const char *little, PRUint32 max);
474
475/*
476 * PL_strtok_r
477 *
478 * Splits the string s1 into tokens, separated by one or more characters
479 * from the separator string s2. The argument lasts points to a
480 * user-supplied char * pointer in which PL_strtok_r stores information
481 * for it to continue scanning the same string.
482 *
483 * In the first call to PL_strtok_r, s1 points to a string and the value
484 * of *lasts is ignored. PL_strtok_r returns a pointer to the first
485 * token, writes '\0' into the character following the first token, and
486 * updates *lasts.
487 *
488 * In subsequent calls, s1 is null and lasts must stay unchanged from the
489 * previous call. The separator string s2 may be different from call to
490 * call. PL_strtok_r returns a pointer to the next token in s1. When no
491 * token remains in s1, PL_strtok_r returns null.
492 */
493
494PR_EXTERN(char *)
495PL_strtok_r(char *s1, const char *s2, char **lasts);
496
497/*
498 * Things not (yet?) included: strspn/strcspn, strsep.
499 * memchr, memcmp, memcpy, memccpy, index, rindex, bcmp, bcopy, bzero.
500 * Any and all i18n/l10n stuff.
501 */
502
503PR_END_EXTERN_C
504
505#endif /* _plstr_h */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette