X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/1c570cbefde061bf4aee1d0ab99bebb9fab40846..6345e60c392bbf92b3d7ca2bba473f9da5c073ff:/sbr/trimcpy.c diff --git a/sbr/trimcpy.c b/sbr/trimcpy.c index 6bcf3aec..6ed00b99 100644 --- a/sbr/trimcpy.c +++ b/sbr/trimcpy.c @@ -1,6 +1,4 @@ - -/* - * trimcpy.c -- strip leading and trailing whitespace, +/* trimcpy.c -- strip leading and trailing whitespace, * -- replace internal whitespace with spaces, * -- then return a copy. * @@ -9,8 +7,8 @@ * complete copyright information. */ -#include -#include +#include "h/mh.h" +#include "h/utils.h" char * @@ -37,7 +35,7 @@ trimcpy (char *cp) } /* now return a copy */ - return getcpy(cp); + return mh_xstrdup(cp); } @@ -51,14 +49,15 @@ trimcpy (char *cp) * complete copyright information. */ char * -cpytrim (const char *sp) { +cpytrim (const char *sp) +{ char *dp; char *cp; /* skip over leading whitespace */ while (isspace ((unsigned char) *sp)) ++sp; - dp = add (sp, NULL); + dp = mh_xstrdup(sp); /* start at the end and zap trailing whitespace */ for (cp = dp + strlen (dp) - 1; @@ -72,3 +71,26 @@ cpytrim (const char *sp) { return dp; } + + +/* + * rtrim() -- modify the argument to: + * -- strip trailing whitespace + * + * This code is Copyright (c) 2014, by the authors of nmh. See the + * COPYRIGHT file in the root directory of the nmh distribution for + * complete copyright information. + */ +char * +rtrim (char *sp) +{ + char *cp; + + /* start at the end and zap trailing whitespace */ + for (cp = sp + strlen (sp) - 1; + cp >= sp && isspace ((unsigned char) *cp); + --cp) { continue; } + *++cp = '\0'; + + return sp; +}