mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-12-22 20:16:54 +03:00
[project @ 2002-05-21 21:27:29 by bursa]
Add squash_whitespace(). svn path=/import/netsurf/; revision=17
This commit is contained in:
parent
1ff128beaf
commit
f78fab56c7
@ -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;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/**
|
||||
* $Id: utils.h,v 1.1.1.1 2002/04/22 09:24:34 bursa Exp $
|
||||
* $Id: utils.h,v 1.2 2002/05/21 21:27:29 bursa Exp $
|
||||
*/
|
||||
|
||||
void die(const char * const error);
|
||||
@ -9,3 +9,5 @@ void * xcalloc(const size_t n, const size_t size);
|
||||
void * xrealloc(void * p, const size_t size);
|
||||
char * xstrdup(const char * const s);
|
||||
char * load(const char * const path);
|
||||
char * squash_whitespace(const char * s);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user