source: trunk/third/nmh/sbr/trimcpy.c @ 12455

Revision 12455, 700 bytes checked in by danw, 26 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r12454, which included commits to RCS files with non-trunk default branches.
Line 
1
2/*
3 * trimcpy.c -- strip leading and trailing whitespace,
4 *           -- replace internal whitespace with spaces,
5 *           -- then return a copy.
6 *
7 * $Id: trimcpy.c,v 1.1.1.1 1999-02-07 18:14:10 danw Exp $
8 */
9
10#include <h/mh.h>
11
12
13char *
14trimcpy (char *cp)
15{
16    char *sp;
17
18    /* skip over leading whitespace */
19    while (isspace(*cp))
20        cp++;
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    /* replace remaining whitespace with spaces */
31    for (sp = cp; *sp; sp++) {
32        if (isspace(*sp))
33            *sp = ' ';
34    }
35
36    /* now return a copy */
37    return getcpy(cp);
38}
Note: See TracBrowser for help on using the repository browser.