home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / c / string.arc / STRTRIM.C < prev    next >
C/C++ Source or Header  |  1984-12-31  |  1KB  |  45 lines

  1. /*  File   : strtrim.c
  2.     Author : Richard A. O'Keefe.
  3.     Updated: 20 April 1984
  4.     Defines: strtrim()
  5.  
  6.     strtrim(dst, src, set, ends)
  7.     copies src to dst, but will skip leading characters in set if "ends"
  8.     is <= 0, and will skip trailing characters in set if ends is >= 0.
  9.     Thus there are three cases:
  10.     ends < 0 :    trim a prefix
  11.     ends = 0 :    trim a prefix and a suffix both
  12.     ends > 0 :    trim a suffix
  13.     To compress internal runs, see strpack.  The normal use of this is
  14.     strtrim(buffer, buffer, " \t", 0);  The result is the address of the
  15.     NUL which now terminates dst.
  16. */
  17.  
  18. #include "strings.h"
  19. #include "_str2set.h"
  20.  
  21. char *strtrim(dst, src, set, ends)
  22.     register char *dst, *src;
  23.     char *set;
  24.     int ends;
  25.     {
  26.     _str2set(set);
  27.     if (ends <= 0) {
  28.         while (_set_vec[*src] == _set_ctr) src++;
  29.     }
  30.     if (ends >= 0) {
  31.         register int chr;
  32.         register char *save = dst;
  33.         while (chr = *src++) {
  34.         *dst++ = chr;
  35.         if (_set_vec[chr] != _set_ctr) save = dst;
  36.         }
  37.         dst = save, *dst = NUL;
  38.     } else {
  39.         while (*dst++ = *src++) ;
  40.         --dst;
  41.     }
  42.     return dst;
  43.     }
  44.