diff options
author | James Bursa <james@netsurf-browser.org> | 2003-04-11 21:06:51 +0000 |
---|---|---|
committer | James Bursa <james@netsurf-browser.org> | 2003-04-11 21:06:51 +0000 |
commit | 02674693069358fc9f59700ea150d3811281f296 (patch) | |
tree | 7b51c457a0a3efbdc84fb00509bea02a6413d9ee /utils | |
parent | 7c94cf8be972d6853cc15f3971bf36fe64b04d92 (diff) | |
download | netsurf-02674693069358fc9f59700ea150d3811281f296.tar.gz netsurf-02674693069358fc9f59700ea150d3811281f296.tar.bz2 |
[project @ 2003-04-11 21:06:51 by bursa]
Memory usage and CSS fixes.
svn path=/import/netsurf/; revision=122
Diffstat (limited to 'utils')
-rw-r--r-- | utils/utils.c | 37 | ||||
-rw-r--r-- | utils/utils.h | 5 |
2 files changed, 40 insertions, 2 deletions
diff --git a/utils/utils.c b/utils/utils.c index 47c90a4c0..a2fab4e12 100644 --- a/utils/utils.c +++ b/utils/utils.c @@ -1,11 +1,12 @@ /** - * $Id: utils.c,v 1.7 2003/04/05 21:38:06 bursa Exp $ + * $Id: utils.c,v 1.8 2003/04/11 21:06:51 bursa Exp $ */ #include <ctype.h> #include <stdlib.h> #include <stdio.h> #include <string.h> +#include "libxml/encoding.h" #include "libxml/uri.h" #include "netsurf/utils/log.h" #include "netsurf/utils/utils.h" @@ -98,6 +99,40 @@ char * squash_whitespace(const char * s) return c; } +char * tolat1(xmlChar * s) +{ + unsigned int length = strlen((char*) s); + char *d = xcalloc(length + 1, sizeof(char)); + char *d0 = d; + int u, chars; + + while (*s != 0) { + chars = length; + u = xmlGetUTF8Char((unsigned char *) s, &chars); + s += chars; + length -= chars; + if (u == 0x09 || u == 0x0a || u == 0x0d) + *d = ' '; + else if ((0x20 <= u && u <= 0x7f) || (0xa0 <= u && u <= 0xff)) + *d = u; + else + *d = '?'; + d++; + } + *d = 0; + + return d0; +} + +char *squash_tolat1(xmlChar *s) +{ + /* TODO: optimize */ + char *lat1 = tolat1(s); + char *squash = squash_whitespace(lat1); + free(lat1); + return squash; +} + char *url_join(const char* new, const char* base) { char* ret; diff --git a/utils/utils.h b/utils/utils.h index c55ab5b69..0a3540938 100644 --- a/utils/utils.h +++ b/utils/utils.h @@ -1,11 +1,12 @@ /** - * $Id: utils.h,v 1.6 2003/04/05 21:38:06 bursa Exp $ + * $Id: utils.h,v 1.7 2003/04/11 21:06:51 bursa Exp $ */ #ifndef _NETSURF_UTILS_UTILS_H_ #define _NETSURF_UTILS_UTILS_H_ #include <stdlib.h> +#include "libxml/encoding.h" void die(const char * const error); char * strip(char * const s); @@ -16,6 +17,8 @@ void xfree(void* p); char * xstrdup(const char * const s); char * load(const char * const path); char * squash_whitespace(const char * s); +char * tolat1(xmlChar * s); +char *squash_tolat1(xmlChar *s); char *url_join(const char* new, const char* base); #endif |