Add %(unmailto) format function for List-Post headers
[mmh] / sbr / trimcpy.c
1 /*
2 ** trimcpy.c -- strip leading and trailing whitespace,
3 **           -- replace internal whitespace with spaces,
4 **           -- then return a copy.
5 **
6 ** This code is Copyright (c) 2002, by the authors of nmh.  See the
7 ** COPYRIGHT file in the root directory of the nmh distribution for
8 ** complete copyright information.
9 */
10
11 #include <h/mh.h>
12 #include <h/utils.h>
13 #include <ctype.h>
14
15
16 char *
17 trimcpy(unsigned char *cp)
18 {
19         unsigned char *sp;
20
21         /* skip over leading whitespace */
22         while (isspace(*cp))
23                 cp++;
24
25         /* start at the end and zap trailing whitespace */
26         for (sp = cp + strlen(cp) - 1; sp >= cp; sp--) {
27                 if (isspace(*sp))
28                         *sp = '\0';
29                 else
30                         break;
31         }
32
33         /* replace remaining whitespace with spaces */
34         for (sp = cp; *sp; sp++) {
35                 if (isspace(*sp))
36                         *sp = ' ';
37         }
38
39         /* now return a copy */
40         return mh_xstrdup(cp);
41 }