Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / nsprpub / lib / libc / include / plstr.h
blob4d21cc46ef0e1460c4ad01dd56b8109953005001
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
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/
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.
15 * The Original Code is the Netscape Portable Runtime (NSPR).
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.
22 * Contributor(s):
23 * Roland Mainz <roland mainz@informatik.med.uni-giessen.de>
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.
37 * ***** END LICENSE BLOCK ***** */
39 #ifndef _plstr_h
40 #define _plstr_h
43 * plstr.h
45 * This header file exports the API to the NSPR portable library or string-
46 * handling functions.
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
51 * 1) replace the libc functions, for cross-platform consistency,
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.
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.
62 #include "prtypes.h"
64 PR_BEGIN_EXTERN_C
66 * PL_strlen
68 * Returns the length of the provided string, not including the trailing '\0'.
71 PR_EXTERN(PRUint32)
72 PL_strlen(const char *str);
75 * PL_strnlen
77 * Returns the length of the provided string, not including the trailing '\0',
78 * up to the indicated maximum. The string will not be examined beyond the
79 * maximum; if no terminating '\0' is found, the maximum will be returned.
82 PR_EXTERN(PRUint32)
83 PL_strnlen(const char *str, PRUint32 max);
86 * PL_strcpy
88 * Copies the source string, up to and including the trailing '\0', into the
89 * destination buffer. It does not (can not) verify that the destination
90 * buffer is large enough. It returns the "dest" argument.
93 PR_EXTERN(char *)
94 PL_strcpy(char *dest, const char *src);
97 * PL_strncpy
99 * Copies the source string into the destination buffer, up to and including
100 * the trailing '\0' or up to and including the max'th character, whichever
101 * comes first. It does not (can not) verify that the destination buffer is
102 * large enough. If the source string is longer than the maximum length,
103 * the result will *not* be null-terminated (JLRU).
106 PR_EXTERN(char *)
107 PL_strncpy(char *dest, const char *src, PRUint32 max);
110 * PL_strncpyz
112 * Copies the source string into the destination buffer, up to and including
113 * the trailing '\0' or up but not including the max'th character, whichever
114 * comes first. It does not (can not) verify that the destination buffer is
115 * large enough. The destination string is always terminated with a '\0',
116 * unlike the traditional libc implementation. It returns the "dest" argument.
118 * NOTE: If you call this with a source "abcdefg" and a max of 5, the
119 * destination will end up with "abcd\0" (i.e., its strlen length will be 4)!
121 * This means you can do this:
123 * char buffer[ SOME_SIZE ];
124 * PL_strncpyz(buffer, src, sizeof(buffer));
126 * and the result will be properly terminated.
129 PR_EXTERN(char *)
130 PL_strncpyz(char *dest, const char *src, PRUint32 max);
133 * PL_strdup
135 * Returns a pointer to a malloc'd extent of memory containing a duplicate
136 * of the argument string. The size of the allocated extent is one greater
137 * than the length of the argument string, because of the terminator. A
138 * null argument, like a zero-length argument, will result in a pointer to
139 * a one-byte extent containing the null value. This routine returns null
140 * upon malloc failure.
143 PR_EXTERN(char *)
144 PL_strdup(const char *s);
147 * PL_strfree
149 * Free memory allocated by PL_strdup
152 PR_EXTERN(void)
153 PL_strfree(char *s);
156 * PL_strndup
158 * Returns a pointer to a malloc'd extent of memory containing a duplicate
159 * of the argument string, up to the maximum specified. If the argument
160 * string has a length greater than the value of the specified maximum, the
161 * return value will be a pointer to an extent of memory of length one
162 * greater than the maximum specified. A null string, a zero-length string,
163 * or a zero maximum will all result in a pointer to a one-byte extent
164 * containing the null value. This routine returns null upon malloc failure.
167 PR_EXTERN(char *)
168 PL_strndup(const char *s, PRUint32 max);
171 * PL_strcat
173 * Appends a copy of the string pointed to by the second argument to the
174 * end of the string pointed to by the first. The destination buffer is
175 * not (can not be) checked for sufficient size. A null destination
176 * argument returns null; otherwise, the first argument is returned.
179 PR_EXTERN(char *)
180 PL_strcat(char *dst, const char *src);
183 * PL_strncat
185 * Appends a copy of the string pointed to by the second argument, up to
186 * the maximum size specified, to the end of the string pointed to by the
187 * first. The destination buffer is not (can not be) checked for sufficient
188 * size. A null destination argument returns null; otherwise, the first
189 * argument is returned. If the maximum size limits the copy, then the
190 * result will *not* be null-terminated (JLRU). A null destination
191 * returns null; otherwise, the destination argument is returned.
194 PR_EXTERN(char *)
195 PL_strncat(char *dst, const char *src, PRUint32 max);
198 * PL_strcatn
200 * Appends a copy of the string pointed to by the third argument, to the
201 * end of the string pointed to by the first. The second argument specifies
202 * the maximum size of the destination buffer, including the null termination.
203 * If the existing string in dst is longer than the max, no action is taken.
204 * The resulting string will be null-terminated. A null destination returns
205 * null; otherwise, the destination argument is returned.
208 PR_EXTERN(char *)
209 PL_strcatn(char *dst, PRUint32 max, const char *src);
212 * PL_strcmp
214 * Returns an integer, the sign of which -- positive, zero, or negative --
215 * reflects the lexical sorting order of the two strings indicated. The
216 * result is positive if the first string comes after the second. The
217 * NSPR implementation is not i18n.
220 PR_EXTERN(PRIntn)
221 PL_strcmp(const char *a, const char *b);
224 * PL_strncmp
226 * Returns an integer, the sign of which -- positive, zero, or negative --
227 * reflects the lexical sorting order of the two strings indicated, up to
228 * the maximum specified. The result is positive if the first string comes
229 * after the second. The NSPR implementation is not i18n. If the maximum
230 * is zero, only the existance or non-existance (pointer is null) of the
231 * strings is compared.
234 PR_EXTERN(PRIntn)
235 PL_strncmp(const char *a, const char *b, PRUint32 max);
238 * PL_strcasecmp
240 * Returns an integer, the sign of which -- positive, zero or negative --
241 * reflects the case-insensitive lexical sorting order of the two strings
242 * indicated. The result is positive if the first string comes after the
243 * second. The NSPR implementation is not i18n.
246 PR_EXTERN(PRIntn)
247 PL_strcasecmp(const char *a, const char *b);
250 * PL_strncasecmp
252 * Returns an integer, the sign of which -- positive, zero or negative --
253 * reflects the case-insensitive lexical sorting order of the first n characters
254 * of the two strings indicated. The result is positive if the first string comes
255 * after the second. The NSPR implementation is not i18n.
258 PR_EXTERN(PRIntn)
259 PL_strncasecmp(const char *a, const char *b, PRUint32 max);
262 * PL_strchr
264 * Returns a pointer to the first instance of the specified character in the
265 * provided string. It returns null if the character is not found, or if the
266 * provided string is null. The character may be the null character.
269 PR_EXTERN(char *)
270 PL_strchr(const char *s, char c);
273 * PL_strrchr
275 * Returns a pointer to the last instance of the specified character in the
276 * provided string. It returns null if the character is not found, or if the
277 * provided string is null. The character may be the null character.
280 PR_EXTERN(char *)
281 PL_strrchr(const char *s, char c);
284 * PL_strnchr
286 * Returns a pointer to the first instance of the specified character within the
287 * first n characters of the provided string. It returns null if the character
288 * is not found, or if the provided string is null. The character may be the
289 * null character.
292 PR_EXTERN(char *)
293 PL_strnchr(const char *s, char c, PRUint32 n);
296 * PL_strnrchr
298 * Returns a pointer to the last instance of the specified character within the
299 * first n characters of the provided string. It returns null if the character is
300 * not found, or if the provided string is null. The character may be the null
301 * character.
304 PR_EXTERN(char *)
305 PL_strnrchr(const char *s, char c, PRUint32 n);
308 * NOTE: Looking for strcasechr, strcaserchr, strncasechr, or strncaserchr?
309 * Use strpbrk, strprbrk, strnpbrk or strnprbrk.
313 * PL_strpbrk
315 * Returns a pointer to the first instance in the first string of any character
316 * (not including the terminating null character) of the second string. It returns
317 * null if either string is null.
320 PR_EXTERN(char *)
321 PL_strpbrk(const char *s, const char *list);
324 * PL_strprbrk
326 * Returns a pointer to the last instance in the first string of any character
327 * (not including the terminating null character) of the second string. It returns
328 * null if either string is null.
331 PR_EXTERN(char *)
332 PL_strprbrk(const char *s, const char *list);
335 * PL_strnpbrk
337 * Returns a pointer to the first instance (within the first n characters) of any
338 * character (not including the terminating null character) of the second string.
339 * It returns null if either string is null.
342 PR_EXTERN(char *)
343 PL_strnpbrk(const char *s, const char *list, PRUint32 n);
346 * PL_strnprbrk
348 * Returns a pointer to the last instance (within the first n characters) of any
349 * character (not including the terminating null character) of the second string.
350 * It returns null if either string is null.
353 PR_EXTERN(char *)
354 PL_strnprbrk(const char *s, const char *list, PRUint32 n);
357 * PL_strstr
359 * Returns a pointer to the first instance of the little string within the
360 * big one. It returns null if either string is null.
363 PR_EXTERN(char *)
364 PL_strstr(const char *big, const char *little);
367 * PL_strrstr
369 * Returns a pointer to the last instance of the little string within the big one.
370 * It returns null if either string is null.
373 PR_EXTERN(char *)
374 PL_strrstr(const char *big, const char *little);
377 * PL_strnstr
379 * Returns a pointer to the first instance of the little string within the first
380 * n characters of the big one. It returns null if either string is null. It
381 * returns null if the length of the little string is greater than n.
384 PR_EXTERN(char *)
385 PL_strnstr(const char *big, const char *little, PRUint32 n);
388 * PL_strnrstr
390 * Returns a pointer to the last instance of the little string within the first
391 * n characters of the big one. It returns null if either string is null. It
392 * returns null if the length of the little string is greater than n.
395 PR_EXTERN(char *)
396 PL_strnrstr(const char *big, const char *little, PRUint32 max);
399 * PL_strcasestr
401 * Returns a pointer to the first instance of the little string within the big one,
402 * ignoring case. It returns null if either string is null.
405 PR_EXTERN(char *)
406 PL_strcasestr(const char *big, const char *little);
409 * PL_strcaserstr
411 * Returns a pointer to the last instance of the little string within the big one,
412 * ignoring case. It returns null if either string is null.
415 PR_EXTERN(char *)
416 PL_strcaserstr(const char *big, const char *little);
419 * PL_strncasestr
421 * Returns a pointer to the first instance of the little string within the first
422 * n characters of the big one, ignoring case. It returns null if either string is
423 * null. It returns null if the length of the little string is greater than n.
426 PR_EXTERN(char *)
427 PL_strncasestr(const char *big, const char *little, PRUint32 max);
430 * PL_strncaserstr
432 * Returns a pointer to the last instance of the little string within the first
433 * n characters of the big one, ignoring case. It returns null if either string is
434 * null. It returns null if the length of the little string is greater than n.
437 PR_EXTERN(char *)
438 PL_strncaserstr(const char *big, const char *little, PRUint32 max);
441 * PL_strtok_r
443 * Splits the string s1 into tokens, separated by one or more characters
444 * from the separator string s2. The argument lasts points to a
445 * user-supplied char * pointer in which PL_strtok_r stores information
446 * for it to continue scanning the same string.
448 * In the first call to PL_strtok_r, s1 points to a string and the value
449 * of *lasts is ignored. PL_strtok_r returns a pointer to the first
450 * token, writes '\0' into the character following the first token, and
451 * updates *lasts.
453 * In subsequent calls, s1 is null and lasts must stay unchanged from the
454 * previous call. The separator string s2 may be different from call to
455 * call. PL_strtok_r returns a pointer to the next token in s1. When no
456 * token remains in s1, PL_strtok_r returns null.
459 PR_EXTERN(char *)
460 PL_strtok_r(char *s1, const char *s2, char **lasts);
463 * Things not (yet?) included: strspn/strcspn, strsep.
464 * memchr, memcmp, memcpy, memccpy, index, rindex, bcmp, bcopy, bzero.
465 * Any and all i18n/l10n stuff.
468 PR_END_EXTERN_C
470 #endif /* _plstr_h */