]>
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.
19 /* skip over leading whitespace */
20 while (isspace((unsigned char) *cp
))
23 /* start at the end and zap trailing whitespace */
24 for (sp
= cp
+ strlen(cp
) - 1; sp
>= cp
; sp
--) {
25 if (isspace((unsigned char) *sp
))
31 /* replace remaining whitespace with spaces */
32 for (sp
= cp
; *sp
; sp
++) {
33 if (isspace((unsigned char) *sp
))
37 /* now return a copy */
38 return mh_xstrdup(cp
);
43 * cpytrim() -- return a copy of the argument with:
44 * -- stripped leading and trailing whitespace, and
45 * -- internal whitespace replaced with spaces.
47 * This code is Copyright (c) 2013, by the authors of nmh. See the
48 * COPYRIGHT file in the root directory of the nmh distribution for
49 * complete copyright information.
52 cpytrim (const char *sp
) {
56 /* skip over leading whitespace */
57 while (isspace ((unsigned char) *sp
)) ++sp
;
61 /* start at the end and zap trailing whitespace */
62 for (cp
= dp
+ strlen (dp
) - 1;
63 cp
>= dp
&& isspace ((unsigned char) *cp
);
64 *cp
-- = '\0') continue;
66 /* replace remaining whitespace with spaces */
67 for (cp
= dp
; *cp
; ++cp
) {
68 if (isspace ((unsigned char) *cp
)) *cp
= ' ';
76 * rtrim() -- modify the argument to:
77 * -- strip trailing whitespace
79 * This code is Copyright (c) 2014, by the authors of nmh. See the
80 * COPYRIGHT file in the root directory of the nmh distribution for
81 * complete copyright information.
87 /* start at the end and zap trailing whitespace */
88 for (cp
= sp
+ strlen (sp
) - 1;
89 cp
>= sp
&& isspace ((unsigned char) *cp
);