X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=sbr%2Ftrim.c;fp=sbr%2Ftrim.c;h=9f08d99d2a18a5b65153134d28dd8a75ecb9117b;hp=0000000000000000000000000000000000000000;hb=d854cd83e7b14f3bc686688ef7099b5d75157647;hpb=ffabbf91237cb3b11f0dcb03334fe8f1e688d3e3 diff --git a/sbr/trim.c b/sbr/trim.c new file mode 100644 index 0000000..9f08d99 --- /dev/null +++ b/sbr/trim.c @@ -0,0 +1,32 @@ +/* +** trim.c -- strip leading and trailing whitespace ... inplace! +** +** This code is Copyright (c) 2002, by the authors of nmh. See the +** COPYRIGHT file in the root directory of the nmh distribution for +** complete copyright information. +*/ + +#include + + +char * +trim(unsigned char *cp) +{ + unsigned char *sp; + + /* skip over leading whitespace */ + while (isspace(*cp)) { + cp++; + } + + /* start at the end and zap trailing whitespace */ + for (sp = cp + strlen(cp) - 1; sp >= cp; sp--) { + if (isspace(*sp)) { + *sp = '\0'; + } else { + break; + } + } + + return cp; +}