diff options
author | James Bursa <james@netsurf-browser.org> | 2002-05-21 21:27:29 +0000 |
---|---|---|
committer | James Bursa <james@netsurf-browser.org> | 2002-05-21 21:27:29 +0000 |
commit | f78fab56c779effaa4d859c99f8585ccf46f9033 (patch) | |
tree | dbecd4eb1ec816d2d4b5208f72cf6edb47b9394d /utils/utils.c | |
parent | 1ff128beafba38a36d4bce950afa8d595e8f5613 (diff) | |
download | netsurf-f78fab56c779effaa4d859c99f8585ccf46f9033.tar.gz netsurf-f78fab56c779effaa4d859c99f8585ccf46f9033.tar.bz2 |
[project @ 2002-05-21 21:27:29 by bursa]
Add squash_whitespace().
svn path=/import/netsurf/; revision=17
Diffstat (limited to 'utils/utils.c')
-rw-r--r-- | utils/utils.c | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/utils/utils.c b/utils/utils.c index a5df77f7b..8440c7b12 100644 --- a/utils/utils.c +++ b/utils/utils.c @@ -1,5 +1,5 @@ /** - * $Id: utils.c,v 1.1.1.1 2002/04/22 09:24:34 bursa Exp $ + * $Id: utils.c,v 1.2 2002/05/21 21:27:29 bursa Exp $ */ #include <ctype.h> @@ -73,3 +73,20 @@ char * load(const char * const path) fclose(fp); return buf; } + +char * squash_whitespace(const char * s) +{ + char * c = malloc(strlen(s) + 1); + int i = 0, j = 0; + if (c == 0) die("Out of memory in squash_whitespace()"); + do { + if (isspace(s[i])) { + c[j++] = ' '; + while (s[i] != 0 && isspace(s[i])) + i++; + } + c[j++] = s[i++]; + } while (s[i - 1] != 0); + return c; +} + |