home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / nsprpub / lib / libc / include / plstr.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  13.2 KB  |  429 lines

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