]>
diplodocus.org Git - nmh/blob - sbr/trimcpy.c
1 /* trimcpy.c -- strip leading and trailing whitespace,
2 * -- replace internal whitespace with spaces,
3 * -- then return a copy.
5 * This code is Copyright (c) 2002, by the authors of nmh. See the
6 * COPYRIGHT file in the root directory of the nmh distribution for
7 * complete copyright information.
20 /* skip over leading whitespace */
21 while (isspace((unsigned char) *cp
))
24 /* start at the end and zap trailing whitespace */
25 for (sp
= cp
+ strlen(cp
) - 1; sp
>= cp
; sp
--) {
26 if (isspace((unsigned char) *sp
))
32 /* replace remaining whitespace with spaces */
33 for (sp
= cp
; *sp
; sp
++) {
34 if (isspace((unsigned char) *sp
))
38 /* now return a copy */
39 return mh_xstrdup(cp
);
44 * cpytrim() -- return a copy of the argument with:
45 * -- stripped leading and trailing whitespace, and
46 * -- internal whitespace replaced with spaces.
48 * This code is Copyright (c) 2013, by the authors of nmh. See the
49 * COPYRIGHT file in the root directory of the nmh distribution for
50 * complete copyright information.
53 cpytrim (const char *sp
)
58 /* skip over leading whitespace */
59 while (isspace ((unsigned char) *sp
)) ++sp
;
63 /* start at the end and zap trailing whitespace */
64 for (cp
= dp
+ strlen (dp
) - 1;
65 cp
>= dp
&& isspace ((unsigned char) *cp
);
66 *cp
-- = '\0') continue;
68 /* replace remaining whitespace with spaces */
69 for (cp
= dp
; *cp
; ++cp
) {
70 if (isspace ((unsigned char) *cp
)) *cp
= ' ';
78 * rtrim() -- modify the argument to:
79 * -- strip trailing whitespace
81 * This code is Copyright (c) 2014, by the authors of nmh. See the
82 * COPYRIGHT file in the root directory of the nmh distribution for
83 * complete copyright information.
90 /* start at the end and zap trailing whitespace */
91 for (cp
= sp
+ strlen (sp
) - 1;
92 cp
>= sp
&& isspace ((unsigned char) *cp
);