9f08d99d2a18a5b65153134d28dd8a75ecb9117b
[mmh] / sbr / trim.c
1 /*
2 ** trim.c -- strip leading and trailing whitespace ... inplace!
3 **
4 ** This code is Copyright (c) 2002, by the authors of nmh.  See the
5 ** COPYRIGHT file in the root directory of the nmh distribution for
6 ** complete copyright information.
7 */
8
9 #include <h/mh.h>
10
11
12 char *
13 trim(unsigned char *cp)
14 {
15         unsigned char *sp;
16
17         /* skip over leading whitespace */
18         while (isspace(*cp)) {
19                 cp++;
20         }
21
22         /* start at the end and zap trailing whitespace */
23         for (sp = cp + strlen(cp) - 1; sp >= cp; sp--) {
24                 if (isspace(*sp)) {
25                         *sp = '\0';
26                 } else {
27                         break;
28                 }
29         }
30
31         return cp;
32 }