home *** CD-ROM | disk | FTP | other *** search
/ Power CD-ROM!! 7 / POWERCD7.ISO / prgmming / clipper / strcspn.c < prev    next >
C/C++ Source or Header  |  1993-10-14  |  2KB  |  79 lines

  1. /*
  2.  * GT CLIPPER STANDARD HEADER
  3.  *
  4.  * File......: strcspn.c
  5.  * Author....: Andy M Leighton
  6.  * BBS.......: The Dark Knight Returns
  7.  * Net/Node..: 050/069
  8.  * User Name.: Andy Leighton
  9.  * Date......: 23/05/93
  10.  * Revision..: 1.00
  11.  *
  12.  * This is an original work by Andy Leighton and is placed in the
  13.  * public domain.
  14.  *
  15.  * Modification history:
  16.  * ---------------------
  17.  *
  18.  * $Log$
  19.  *
  20.  */
  21.  
  22. /*
  23.  *  $DOC$
  24.  *  $FUNCNAME$
  25.  *      GT_STRCSPN()
  26.  *  $CATEGORY$
  27.  *      String
  28.  *  $ONELINER$
  29.  *      Return length of prefix in string of chars NOT in set.
  30.  *  $SYNTAX$
  31.  *      GT_strcspn(<cString>, <cSet>) --> nLength
  32.  *  $ARGUMENTS$
  33.  *      <cString> - The string to find the prefix in
  34.  *      <cSet>    - The set of characters
  35.  *  $RETURNS$
  36.  *      nLength   - The length of a string upto a character in the set
  37.  *  $DESCRIPTION$
  38.  *      Return the number of characters in the leading segment of a
  39.  *      string that consists solely of characters NOT in the set.
  40.  *  $EXAMPLES$
  41.  *
  42.  *      ? GT_strcspn("this is a test", "as ")      // prints 3
  43.  *      ? GT_strcspn("this is a test", "elnjpq")   // prints 11
  44.  *
  45.  *  $END$
  46.  */
  47.  
  48.  
  49. #include "extend.h"
  50.  
  51.  
  52. CLIPPER
  53. gt_strcspn()
  54. {
  55.   char *string;
  56.   char *cset;
  57.   int  l1, l2;
  58.   int  p1, p2;
  59.  
  60.   if (ISCHAR(1) && ISCHAR(2)) {
  61.     string = _parc(1);
  62.     cset   = _parc(2);
  63.     l1     = _parclen(1);
  64.     l2     = _parclen(2);
  65.  
  66.     for (p1 = 0; p1 < l1; ++p1) {
  67.       for (p2 = 0; (p2 < l2) && (string[p1] != cset[p2]); ++p2)
  68.          ;
  69.  
  70.       if (p2 < l2)
  71.          break;
  72.     }
  73.     _retni(p1);
  74.   } else {
  75.     _retni(-1);                     // parameter mismatch - error -1
  76.   }
  77. }
  78.  
  79.