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

  1. /*
  2.  * GT CLIPPER STANDARD HEADER
  3.  *
  4.  * File......: strright.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_STRRIGHT()
  26.  *  $CATEGORY$
  27.  *      String
  28.  *  $ONELINER$
  29.  *      Find length of a suffix of a string
  30.  *  $SYNTAX$
  31.  *      GT_StrRight(<cStr>, <cChars>) --> nLen
  32.  *  $ARGUMENTS$
  33.  *      <cStr>   - The input string
  34.  *      <cChars> - The set of characters to find
  35.  *  $RETURNS$
  36.  *      nLen     - The length of the prefix found.
  37.  *  $DESCRIPTION$
  38.  *      Return the length of the trailing segment in the passed string
  39.  *      <cStr> that consists solely of the characters in the character
  40.  *      set <cChars>.
  41.  *
  42.  *      If no characters in the the search set are found, the function
  43.  *      shall return 0
  44.  *  $EXAMPLES$
  45.  *
  46.  *      ? GT_StrRight("this is a test", "teas ")       // prints 8
  47.  *      ? GT_StrRight("this is a test", "tes h")       // prints 5
  48.  *      ? GT_StrRight("this is a test", "zxy")         // prints 0
  49.  *
  50.  *  $END$
  51.  */
  52.  
  53.  
  54. #include "extend.h"
  55.  
  56.  
  57. CLIPPER
  58. GT_StrRight()
  59. {
  60.   char *string;
  61.   char *cset;
  62.   int l1, l2;
  63.   int p1, p2;
  64.  
  65.   if (ISCHAR(1) && ISCHAR(2)) {
  66.     string = _parc(1);
  67.     cset   = _parc(2);
  68.     l1     = _parclen(1);
  69.     l2     = _parclen(2);
  70.     p1     = p2 = 0;
  71.  
  72.     for (p1 = l1 - 1; p1 >= 0; p1--) {
  73.       for (p2 = 0; p2 < l2 && cset[p2] != string[p1]; p2++)
  74.          ;
  75.  
  76.       if (p2 == l2)
  77.          break;
  78.     }
  79.     _retni(l1 - p1 - 1);
  80.  
  81.   } else {
  82.     _retni(-1);               // parameter mismatch - error NullStr
  83.   }
  84. }
  85.  
  86.