From b12a73c8ea3a2b38eff4ad21cac3ac44cdf579cc Mon Sep 17 00:00:00 2001 From: =?utf8?q?Wilfried=20G=C3=B6esgens?= Date: Thu, 6 Sep 2007 22:12:52 +0000 Subject: [PATCH] * stresc() is used frequent, it needs to be fast. --- webcit/webcit.c | 82 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 54 insertions(+), 28 deletions(-) diff --git a/webcit/webcit.c b/webcit/webcit.c index 865c8b785..25efc69e1 100644 --- a/webcit/webcit.c +++ b/webcit/webcit.c @@ -206,36 +206,62 @@ void wDumpContent(int print_standard_html_footer) */ void stresc(char *target, char *strbuf, int nbsp, int nolinebreaks) { - int a, len; - strcpy(target, ""); + char *aptr, *bptr; - len = strlen(strbuf); - for (a = 0; a < len; ++a) { - if (strbuf[a] == '<') - strcat(target, "<"); - else if (strbuf[a] == '>') - strcat(target, ">"); - else if (strbuf[a] == '&') - strcat(target, "&"); - else if (strbuf[a] == '\"') - strcat(target, """); - else if (strbuf[a] == '\'') - strcat(target, "'"); - else if (strbuf[a] == LB) - strcat(target, "<"); - else if (strbuf[a] == RB) - strcat(target, ">"); - else if (strbuf[a] == QU) - strcat(target, "\""); - else if ((strbuf[a] == 32) && (nbsp == 1)) - strcat(target, " "); - else if ((strbuf[a] == '\n') && (nolinebreaks)) - strcat(target, ""); /* nothing */ - else if ((strbuf[a] == '\r') && (nolinebreaks)) - strcat(target, ""); /* nothing */ - else - strncat(target, &strbuf[a], 1); + *target = '\0'; + aptr = strbuf; + bptr = target; + + while (!IsEmptyStr(aptr) ){ + if (*aptr == '<') { + memcpy(bptr, "<", 4); + bptr += 4; + } + else if (*aptr == '>') { + memcpy(bptr, ">", 4); + bptr += 4; + } + else if (*aptr == '&') { + memcpy(bptr, "&", 5); + bptr += 5; + } + else if (*aptr == '\"') { + memcpy(bptr, """, 6); + bptr += 6; + } + else if (*aptr == '\'') { + memcpy(bptr, "'", 5); + bptr += 5; + } + else if (*aptr == LB) { + *bptr = '<'; + bptr ++; + } + else if (*aptr == RB) { + *bptr = '>'; + bptr ++; + } + else if (*aptr == QU) { + *bptr ='"'; + bptr ++; + } + else if ((*aptr == 32) && (nbsp == 1)) { + memcpy(bptr, " ", 6); + bptr += 6; + } + else if ((*aptr == '\n') && (nolinebreaks)) { + strcat(bptr, ""); /* nothing */ + } + else if ((*aptr == '\r') && (nolinebreaks)) { + strcat(bptr, ""); /* nothing */ + } + else{ + *bptr = *aptr; + bptr++; + } + aptr ++; } + *bptr = '\0'; } /** -- 2.39.2