	Removing whitespace

	[[del_trailing_blanks()]] removes whitespace at the end of the
	string. [[trim()]] removes whitespace at both ends.
	[[minimize()]] removes whitespace at both ends and collapses
	all whitespaces sequences to a single space.

<<*>>=
#include <config.h>

EXPORT void del_trailing_blanks(char *s)
{
    int i;

    if (!s) return;
    for (i = strlen(s) - 1; i >= 0 && isspace(s[i]); i--) s[i] = '\0';
}

EXPORT void trim(char *s)
{
    int i, j;

    if (!s) return;
    for (j = 0; isspace(s[j]); j++) ;
    for (i = strlen(s); i > j && isspace(s[i-1]); i--) s[i-1] = '\0';
    if (j != 0) memmove(s, s + j, i - j + 1);
}

EXPORT void minimize(char *s)
{
    int i, j;

    if (!s) return;

    for (j = 0; isspace(s[j]); j++) ;		/* Skip initial whitespace */
    for (i = 0; s[j]; i++)
	if (isspace(s[j])) {
	    s[i] = ' ';				/* Insert a space */
	    do j++; while (isspace(s[j]));	/* Skip other whitespace */
	} else if (i != j)
	    s[i] = s[j++];			/* Copy character */

    if (i != 0 && s[i-1] == ' ') s[i-1] = '\0';
    else if (i != j) s[i] = '\0';
}
