summaryrefslogtreecommitdiff
path: root/utils/utils.c
diff options
context:
space:
mode:
authorVincent Sanders <vince@netsurf-browser.org>2013-05-04 09:49:11 +0100
committerVincent Sanders <vince@netsurf-browser.org>2013-05-04 09:49:11 +0100
commit52c5cccdeb15db5f996a661657d5eb195f930b00 (patch)
tree2fbb0cb03376e91fd6f050666dade50f81d40c70 /utils/utils.c
parent926be456b4316012e12c05a82f56637ce920397b (diff)
downloadnetsurf-52c5cccdeb15db5f996a661657d5eb195f930b00.tar.gz
netsurf-52c5cccdeb15db5f996a661657d5eb195f930b00.tar.bz2
cleanup tree_create_leaf_node text ownership
Diffstat (limited to 'utils/utils.c')
-rw-r--r--utils/utils.c38
1 files changed, 23 insertions, 15 deletions
diff --git a/utils/utils.c b/utils/utils.c
index 3398a7df8..8155f4af1 100644
--- a/utils/utils.c
+++ b/utils/utils.c
@@ -98,26 +98,34 @@ char *remove_underscores(const char *s, bool replacespace)
/**
* Replace consecutive whitespace with a single space.
*
+ * @todo determine if squash_whitespace utf-8 safe and that it needs to be
+ *
* \param s source string
- * \return heap allocated result, or 0 on memory exhaustion
+ * \return heap allocated result, or NULL on memory exhaustion
*/
-char * squash_whitespace(const char *s)
+char *squash_whitespace(const char *s)
{
- char *c = malloc(strlen(s) + 1);
+ char *c;
int i = 0, j = 0;
- if (!c)
- return 0;
- do {
- if (s[i] == ' ' || s[i] == '\n' || s[i] == '\r' ||
- s[i] == '\t') {
- c[j++] = ' ';
- while (s[i] == ' ' || s[i] == '\n' || s[i] == '\r' ||
- s[i] == '\t')
- i++;
- }
- c[j++] = s[i++];
- } while (s[i - 1] != 0);
+
+ c = malloc(strlen(s) + 1);
+ if (c != NULL) {
+ do {
+ if (s[i] == ' ' ||
+ s[i] == '\n' ||
+ s[i] == '\r' ||
+ s[i] == '\t') {
+ c[j++] = ' ';
+ while (s[i] == ' ' ||
+ s[i] == '\n' ||
+ s[i] == '\r' ||
+ s[i] == '\t')
+ i++;
+ }
+ c[j++] = s[i++];
+ } while (s[i - 1] != 0);
+ }
return c;
}