nsprpub/lib/libc/include/plstr.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef _plstr_h
michael@0 7 #define _plstr_h
michael@0 8
michael@0 9 /*
michael@0 10 * plstr.h
michael@0 11 *
michael@0 12 * This header file exports the API to the NSPR portable library or string-
michael@0 13 * handling functions.
michael@0 14 *
michael@0 15 * This API was not designed as an "optimal" or "ideal" string library; it
michael@0 16 * was based on the good ol' unix string.3 functions, and was written to
michael@0 17 *
michael@0 18 * 1) replace the libc functions, for cross-platform consistency,
michael@0 19 * 2) complete the API on platforms lacking common functions (e.g.,
michael@0 20 * strcase*), and
michael@0 21 * 3) to implement some obvious "closure" functions that I've seen
michael@0 22 * people hacking around in our code.
michael@0 23 *
michael@0 24 * Point number three largely means that most functions have an "strn"
michael@0 25 * limited-length version, and all comparison routines have a non-case-
michael@0 26 * sensitive version available.
michael@0 27 */
michael@0 28
michael@0 29 #include "prtypes.h"
michael@0 30
michael@0 31 PR_BEGIN_EXTERN_C
michael@0 32 /*
michael@0 33 * PL_strlen
michael@0 34 *
michael@0 35 * Returns the length of the provided string, not including the trailing '\0'.
michael@0 36 */
michael@0 37
michael@0 38 PR_EXTERN(PRUint32)
michael@0 39 PL_strlen(const char *str);
michael@0 40
michael@0 41 /*
michael@0 42 * PL_strnlen
michael@0 43 *
michael@0 44 * Returns the length of the provided string, not including the trailing '\0',
michael@0 45 * up to the indicated maximum. The string will not be examined beyond the
michael@0 46 * maximum; if no terminating '\0' is found, the maximum will be returned.
michael@0 47 */
michael@0 48
michael@0 49 PR_EXTERN(PRUint32)
michael@0 50 PL_strnlen(const char *str, PRUint32 max);
michael@0 51
michael@0 52 /*
michael@0 53 * PL_strcpy
michael@0 54 *
michael@0 55 * Copies the source string, up to and including the trailing '\0', into the
michael@0 56 * destination buffer. It does not (can not) verify that the destination
michael@0 57 * buffer is large enough. It returns the "dest" argument.
michael@0 58 */
michael@0 59
michael@0 60 PR_EXTERN(char *)
michael@0 61 PL_strcpy(char *dest, const char *src);
michael@0 62
michael@0 63 /*
michael@0 64 * PL_strncpy
michael@0 65 *
michael@0 66 * Copies the source string into the destination buffer, up to and including
michael@0 67 * the trailing '\0' or up to and including the max'th character, whichever
michael@0 68 * comes first. It does not (can not) verify that the destination buffer is
michael@0 69 * large enough. If the source string is longer than the maximum length,
michael@0 70 * the result will *not* be null-terminated (JLRU).
michael@0 71 */
michael@0 72
michael@0 73 PR_EXTERN(char *)
michael@0 74 PL_strncpy(char *dest, const char *src, PRUint32 max);
michael@0 75
michael@0 76 /*
michael@0 77 * PL_strncpyz
michael@0 78 *
michael@0 79 * Copies the source string into the destination buffer, up to and including
michael@0 80 * the trailing '\0' or up but not including the max'th character, whichever
michael@0 81 * comes first. It does not (can not) verify that the destination buffer is
michael@0 82 * large enough. The destination string is always terminated with a '\0',
michael@0 83 * unlike the traditional libc implementation. It returns the "dest" argument.
michael@0 84 *
michael@0 85 * NOTE: If you call this with a source "abcdefg" and a max of 5, the
michael@0 86 * destination will end up with "abcd\0" (i.e., its strlen length will be 4)!
michael@0 87 *
michael@0 88 * This means you can do this:
michael@0 89 *
michael@0 90 * char buffer[ SOME_SIZE ];
michael@0 91 * PL_strncpyz(buffer, src, sizeof(buffer));
michael@0 92 *
michael@0 93 * and the result will be properly terminated.
michael@0 94 */
michael@0 95
michael@0 96 PR_EXTERN(char *)
michael@0 97 PL_strncpyz(char *dest, const char *src, PRUint32 max);
michael@0 98
michael@0 99 /*
michael@0 100 * PL_strdup
michael@0 101 *
michael@0 102 * Returns a pointer to a malloc'd extent of memory containing a duplicate
michael@0 103 * of the argument string. The size of the allocated extent is one greater
michael@0 104 * than the length of the argument string, because of the terminator. A
michael@0 105 * null argument, like a zero-length argument, will result in a pointer to
michael@0 106 * a one-byte extent containing the null value. This routine returns null
michael@0 107 * upon malloc failure.
michael@0 108 */
michael@0 109
michael@0 110 PR_EXTERN(char *)
michael@0 111 PL_strdup(const char *s);
michael@0 112
michael@0 113 /*
michael@0 114 * PL_strfree
michael@0 115 *
michael@0 116 * Free memory allocated by PL_strdup
michael@0 117 */
michael@0 118
michael@0 119 PR_EXTERN(void)
michael@0 120 PL_strfree(char *s);
michael@0 121
michael@0 122 /*
michael@0 123 * PL_strndup
michael@0 124 *
michael@0 125 * Returns a pointer to a malloc'd extent of memory containing a duplicate
michael@0 126 * of the argument string, up to the maximum specified. If the argument
michael@0 127 * string has a length greater than the value of the specified maximum, the
michael@0 128 * return value will be a pointer to an extent of memory of length one
michael@0 129 * greater than the maximum specified. A null string, a zero-length string,
michael@0 130 * or a zero maximum will all result in a pointer to a one-byte extent
michael@0 131 * containing the null value. This routine returns null upon malloc failure.
michael@0 132 */
michael@0 133
michael@0 134 PR_EXTERN(char *)
michael@0 135 PL_strndup(const char *s, PRUint32 max);
michael@0 136
michael@0 137 /*
michael@0 138 * PL_strcat
michael@0 139 *
michael@0 140 * Appends a copy of the string pointed to by the second argument to the
michael@0 141 * end of the string pointed to by the first. The destination buffer is
michael@0 142 * not (can not be) checked for sufficient size. A null destination
michael@0 143 * argument returns null; otherwise, the first argument is returned.
michael@0 144 */
michael@0 145
michael@0 146 PR_EXTERN(char *)
michael@0 147 PL_strcat(char *dst, const char *src);
michael@0 148
michael@0 149 /*
michael@0 150 * PL_strncat
michael@0 151 *
michael@0 152 * Appends a copy of the string pointed to by the second argument, up to
michael@0 153 * the maximum size specified, to the end of the string pointed to by the
michael@0 154 * first. The destination buffer is not (can not be) checked for sufficient
michael@0 155 * size. A null destination argument returns null; otherwise, the first
michael@0 156 * argument is returned. If the maximum size limits the copy, then the
michael@0 157 * result will *not* be null-terminated (JLRU). A null destination
michael@0 158 * returns null; otherwise, the destination argument is returned.
michael@0 159 */
michael@0 160
michael@0 161 PR_EXTERN(char *)
michael@0 162 PL_strncat(char *dst, const char *src, PRUint32 max);
michael@0 163
michael@0 164 /*
michael@0 165 * PL_strcatn
michael@0 166 *
michael@0 167 * Appends a copy of the string pointed to by the third argument, to the
michael@0 168 * end of the string pointed to by the first. The second argument specifies
michael@0 169 * the maximum size of the destination buffer, including the null termination.
michael@0 170 * If the existing string in dst is longer than the max, no action is taken.
michael@0 171 * The resulting string will be null-terminated. A null destination returns
michael@0 172 * null; otherwise, the destination argument is returned.
michael@0 173 */
michael@0 174
michael@0 175 PR_EXTERN(char *)
michael@0 176 PL_strcatn(char *dst, PRUint32 max, const char *src);
michael@0 177
michael@0 178 /*
michael@0 179 * PL_strcmp
michael@0 180 *
michael@0 181 * Returns an integer, the sign of which -- positive, zero, or negative --
michael@0 182 * reflects the lexical sorting order of the two strings indicated. The
michael@0 183 * result is positive if the first string comes after the second. The
michael@0 184 * NSPR implementation is not i18n.
michael@0 185 */
michael@0 186
michael@0 187 PR_EXTERN(PRIntn)
michael@0 188 PL_strcmp(const char *a, const char *b);
michael@0 189
michael@0 190 /*
michael@0 191 * PL_strncmp
michael@0 192 *
michael@0 193 * Returns an integer, the sign of which -- positive, zero, or negative --
michael@0 194 * reflects the lexical sorting order of the two strings indicated, up to
michael@0 195 * the maximum specified. The result is positive if the first string comes
michael@0 196 * after the second. The NSPR implementation is not i18n. If the maximum
michael@0 197 * is zero, only the existance or non-existance (pointer is null) of the
michael@0 198 * strings is compared.
michael@0 199 */
michael@0 200
michael@0 201 PR_EXTERN(PRIntn)
michael@0 202 PL_strncmp(const char *a, const char *b, PRUint32 max);
michael@0 203
michael@0 204 /*
michael@0 205 * PL_strcasecmp
michael@0 206 *
michael@0 207 * Returns an integer, the sign of which -- positive, zero or negative --
michael@0 208 * reflects the case-insensitive lexical sorting order of the two strings
michael@0 209 * indicated. The result is positive if the first string comes after the
michael@0 210 * second. The NSPR implementation is not i18n.
michael@0 211 */
michael@0 212
michael@0 213 PR_EXTERN(PRIntn)
michael@0 214 PL_strcasecmp(const char *a, const char *b);
michael@0 215
michael@0 216 /*
michael@0 217 * PL_strncasecmp
michael@0 218 *
michael@0 219 * Returns an integer, the sign of which -- positive, zero or negative --
michael@0 220 * reflects the case-insensitive lexical sorting order of the first n characters
michael@0 221 * of the two strings indicated. The result is positive if the first string comes
michael@0 222 * after the second. The NSPR implementation is not i18n.
michael@0 223 */
michael@0 224
michael@0 225 PR_EXTERN(PRIntn)
michael@0 226 PL_strncasecmp(const char *a, const char *b, PRUint32 max);
michael@0 227
michael@0 228 /*
michael@0 229 * PL_strchr
michael@0 230 *
michael@0 231 * Returns a pointer to the first instance of the specified character in the
michael@0 232 * provided string. It returns null if the character is not found, or if the
michael@0 233 * provided string is null. The character may be the null character.
michael@0 234 */
michael@0 235
michael@0 236 PR_EXTERN(char *)
michael@0 237 PL_strchr(const char *s, char c);
michael@0 238
michael@0 239 /*
michael@0 240 * PL_strrchr
michael@0 241 *
michael@0 242 * Returns a pointer to the last instance of the specified character in the
michael@0 243 * provided string. It returns null if the character is not found, or if the
michael@0 244 * provided string is null. The character may be the null character.
michael@0 245 */
michael@0 246
michael@0 247 PR_EXTERN(char *)
michael@0 248 PL_strrchr(const char *s, char c);
michael@0 249
michael@0 250 /*
michael@0 251 * PL_strnchr
michael@0 252 *
michael@0 253 * Returns a pointer to the first instance of the specified character within the
michael@0 254 * first n characters of the provided string. It returns null if the character
michael@0 255 * is not found, or if the provided string is null. The character may be the
michael@0 256 * null character.
michael@0 257 */
michael@0 258
michael@0 259 PR_EXTERN(char *)
michael@0 260 PL_strnchr(const char *s, char c, PRUint32 n);
michael@0 261
michael@0 262 /*
michael@0 263 * PL_strnrchr
michael@0 264 *
michael@0 265 * Returns a pointer to the last instance of the specified character within the
michael@0 266 * first n characters of the provided string. It returns null if the character is
michael@0 267 * not found, or if the provided string is null. The character may be the null
michael@0 268 * character.
michael@0 269 */
michael@0 270
michael@0 271 PR_EXTERN(char *)
michael@0 272 PL_strnrchr(const char *s, char c, PRUint32 n);
michael@0 273
michael@0 274 /*
michael@0 275 * NOTE: Looking for strcasechr, strcaserchr, strncasechr, or strncaserchr?
michael@0 276 * Use strpbrk, strprbrk, strnpbrk or strnprbrk.
michael@0 277 */
michael@0 278
michael@0 279 /*
michael@0 280 * PL_strpbrk
michael@0 281 *
michael@0 282 * Returns a pointer to the first instance in the first string of any character
michael@0 283 * (not including the terminating null character) of the second string. It returns
michael@0 284 * null if either string is null.
michael@0 285 */
michael@0 286
michael@0 287 PR_EXTERN(char *)
michael@0 288 PL_strpbrk(const char *s, const char *list);
michael@0 289
michael@0 290 /*
michael@0 291 * PL_strprbrk
michael@0 292 *
michael@0 293 * Returns a pointer to the last instance in the first string of any character
michael@0 294 * (not including the terminating null character) of the second string. It returns
michael@0 295 * null if either string is null.
michael@0 296 */
michael@0 297
michael@0 298 PR_EXTERN(char *)
michael@0 299 PL_strprbrk(const char *s, const char *list);
michael@0 300
michael@0 301 /*
michael@0 302 * PL_strnpbrk
michael@0 303 *
michael@0 304 * Returns a pointer to the first instance (within the first n characters) of any
michael@0 305 * character (not including the terminating null character) of the second string.
michael@0 306 * It returns null if either string is null.
michael@0 307 */
michael@0 308
michael@0 309 PR_EXTERN(char *)
michael@0 310 PL_strnpbrk(const char *s, const char *list, PRUint32 n);
michael@0 311
michael@0 312 /*
michael@0 313 * PL_strnprbrk
michael@0 314 *
michael@0 315 * Returns a pointer to the last instance (within the first n characters) of any
michael@0 316 * character (not including the terminating null character) of the second string.
michael@0 317 * It returns null if either string is null.
michael@0 318 */
michael@0 319
michael@0 320 PR_EXTERN(char *)
michael@0 321 PL_strnprbrk(const char *s, const char *list, PRUint32 n);
michael@0 322
michael@0 323 /*
michael@0 324 * PL_strstr
michael@0 325 *
michael@0 326 * Returns a pointer to the first instance of the little string within the
michael@0 327 * big one. It returns null if either string is null.
michael@0 328 */
michael@0 329
michael@0 330 PR_EXTERN(char *)
michael@0 331 PL_strstr(const char *big, const char *little);
michael@0 332
michael@0 333 /*
michael@0 334 * PL_strrstr
michael@0 335 *
michael@0 336 * Returns a pointer to the last instance of the little string within the big one.
michael@0 337 * It returns null if either string is null.
michael@0 338 */
michael@0 339
michael@0 340 PR_EXTERN(char *)
michael@0 341 PL_strrstr(const char *big, const char *little);
michael@0 342
michael@0 343 /*
michael@0 344 * PL_strnstr
michael@0 345 *
michael@0 346 * Returns a pointer to the first instance of the little string within the first
michael@0 347 * n characters of the big one. It returns null if either string is null. It
michael@0 348 * returns null if the length of the little string is greater than n.
michael@0 349 */
michael@0 350
michael@0 351 PR_EXTERN(char *)
michael@0 352 PL_strnstr(const char *big, const char *little, PRUint32 n);
michael@0 353
michael@0 354 /*
michael@0 355 * PL_strnrstr
michael@0 356 *
michael@0 357 * Returns a pointer to the last instance of the little string within the first
michael@0 358 * n characters of the big one. It returns null if either string is null. It
michael@0 359 * returns null if the length of the little string is greater than n.
michael@0 360 */
michael@0 361
michael@0 362 PR_EXTERN(char *)
michael@0 363 PL_strnrstr(const char *big, const char *little, PRUint32 max);
michael@0 364
michael@0 365 /*
michael@0 366 * PL_strcasestr
michael@0 367 *
michael@0 368 * Returns a pointer to the first instance of the little string within the big one,
michael@0 369 * ignoring case. It returns null if either string is null.
michael@0 370 */
michael@0 371
michael@0 372 PR_EXTERN(char *)
michael@0 373 PL_strcasestr(const char *big, const char *little);
michael@0 374
michael@0 375 /*
michael@0 376 * PL_strcaserstr
michael@0 377 *
michael@0 378 * Returns a pointer to the last instance of the little string within the big one,
michael@0 379 * ignoring case. It returns null if either string is null.
michael@0 380 */
michael@0 381
michael@0 382 PR_EXTERN(char *)
michael@0 383 PL_strcaserstr(const char *big, const char *little);
michael@0 384
michael@0 385 /*
michael@0 386 * PL_strncasestr
michael@0 387 *
michael@0 388 * Returns a pointer to the first instance of the little string within the first
michael@0 389 * n characters of the big one, ignoring case. It returns null if either string is
michael@0 390 * null. It returns null if the length of the little string is greater than n.
michael@0 391 */
michael@0 392
michael@0 393 PR_EXTERN(char *)
michael@0 394 PL_strncasestr(const char *big, const char *little, PRUint32 max);
michael@0 395
michael@0 396 /*
michael@0 397 * PL_strncaserstr
michael@0 398 *
michael@0 399 * Returns a pointer to the last instance of the little string within the first
michael@0 400 * n characters of the big one, ignoring case. It returns null if either string is
michael@0 401 * null. It returns null if the length of the little string is greater than n.
michael@0 402 */
michael@0 403
michael@0 404 PR_EXTERN(char *)
michael@0 405 PL_strncaserstr(const char *big, const char *little, PRUint32 max);
michael@0 406
michael@0 407 /*
michael@0 408 * PL_strtok_r
michael@0 409 *
michael@0 410 * Splits the string s1 into tokens, separated by one or more characters
michael@0 411 * from the separator string s2. The argument lasts points to a
michael@0 412 * user-supplied char * pointer in which PL_strtok_r stores information
michael@0 413 * for it to continue scanning the same string.
michael@0 414 *
michael@0 415 * In the first call to PL_strtok_r, s1 points to a string and the value
michael@0 416 * of *lasts is ignored. PL_strtok_r returns a pointer to the first
michael@0 417 * token, writes '\0' into the character following the first token, and
michael@0 418 * updates *lasts.
michael@0 419 *
michael@0 420 * In subsequent calls, s1 is null and lasts must stay unchanged from the
michael@0 421 * previous call. The separator string s2 may be different from call to
michael@0 422 * call. PL_strtok_r returns a pointer to the next token in s1. When no
michael@0 423 * token remains in s1, PL_strtok_r returns null.
michael@0 424 */
michael@0 425
michael@0 426 PR_EXTERN(char *)
michael@0 427 PL_strtok_r(char *s1, const char *s2, char **lasts);
michael@0 428
michael@0 429 /*
michael@0 430 * Things not (yet?) included: strspn/strcspn, strsep.
michael@0 431 * memchr, memcmp, memcpy, memccpy, index, rindex, bcmp, bcopy, bzero.
michael@0 432 * Any and all i18n/l10n stuff.
michael@0 433 */
michael@0 434
michael@0 435 PR_END_EXTERN_C
michael@0 436
michael@0 437 #endif /* _plstr_h */

mercurial