From 02674693069358fc9f59700ea150d3811281f296 Mon Sep 17 00:00:00 2001 From: James Bursa Date: Fri, 11 Apr 2003 21:06:51 +0000 Subject: [project @ 2003-04-11 21:06:51 by bursa] Memory usage and CSS fixes. svn path=/import/netsurf/; revision=122 --- utils/utils.c | 37 ++++++++++++++++++++++++++++++++++++- utils/utils.h | 5 ++++- 2 files changed, 40 insertions(+), 2 deletions(-) (limited to 'utils') 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 #include #include #include +#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 +#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 -- cgit v1.2.3