]>
diplodocus.org Git - nmh/blob - sbr/trimcpy.c
3 * trimcpy.c -- strip leading and trailing whitespace,
4 * -- replace internal whitespace with spaces,
5 * -- then return a copy.
7 * This code is Copyright (c) 2002, by the authors of nmh. See the
8 * COPYRIGHT file in the root directory of the nmh distribution for
9 * complete copyright information.
21 /* skip over leading whitespace */
22 while (isspace((unsigned char) *cp
))
25 /* start at the end and zap trailing whitespace */
26 for (sp
= cp
+ strlen(cp
) - 1; sp
>= cp
; sp
--) {
27 if (isspace((unsigned char) *sp
))
33 /* replace remaining whitespace with spaces */
34 for (sp
= cp
; *sp
; sp
++) {
35 if (isspace((unsigned char) *sp
))
39 /* now return a copy */
40 return mh_xstrdup(cp
);
45 * cpytrim() -- return a copy of the argument with:
46 * -- stripped leading and trailing whitespace, and
47 * -- internal whitespace replaced with spaces.
49 * This code is Copyright (c) 2013, by the authors of nmh. See the
50 * COPYRIGHT file in the root directory of the nmh distribution for
51 * complete copyright information.
54 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.
89 /* start at the end and zap trailing whitespace */
90 for (cp
= sp
+ strlen (sp
) - 1;
91 cp
>= sp
&& isspace ((unsigned char) *cp
);