cleanup of fix_markup(...)

This commit is contained in:
Sascha Kruse 2011-10-03 20:56:42 +02:00
parent b65735970b
commit 96a632cfcc

83
dunst.c
View File

@ -334,90 +334,47 @@ dunst_printf(const char *fmt, ...) {
char char
*fix_markup(char *str) { *fix_markup(char *str) {
char *tmpString, *strpos, *tmppos;
char *replace_buf, *start, *end; char *replace_buf, *start, *end;
if(str == NULL) { if(str == NULL) {
return NULL; return NULL;
} }
/* tmpString can never be bigger than str */ str = string_replace(""", "\"", str);
tmpString = (char *) calloc(strlen(str), sizeof(char) + 1); str = string_replace("'", "'", str);
memset(tmpString, '\0', strlen(tmpString) * sizeof(char) + 1); str = string_replace("&", "&", str);
tmppos = tmpString; str = string_replace("&lt;", "<", str);
strpos = str; str = string_replace("&gt;", ">", str);
while(*strpos != '\0') { str = string_replace("\n", " ", str);
if(*strpos != '&') {
/* not the beginning of an xml-escape */
*tmppos = *strpos;
strpos++;
tmppos++;
continue;
}
else if(!strncmp(strpos, "&quot;", strlen("&quot;"))) {
*tmppos = '"';
tmppos++;
strpos += strlen("&quot;");
}
else if(!strncmp(strpos, "&apos;", strlen("apos;"))) {
*tmppos = '\'';
tmppos++;
strpos += strlen("&apos;");
}
else if(!strncmp(strpos, "&amp;", strlen("amp;"))) {
*tmppos = '&';
tmppos++;
strpos += strlen("&amp;");
}
else if(!strncmp(strpos, "&lt;", strlen("lt;"))) {
*tmppos = '<';
tmppos++;
strpos += strlen("&lt;");
}
else if(!strncmp(strpos, "&gt;", strlen("gt;"))) {
*tmppos = '>';
tmppos++;
strpos += strlen("&gt;");
}
else {
*tmppos = *strpos;
strpos++;
tmppos++;
}
}
free(str);
tmpString = string_replace("\n", " ", tmpString);
/* remove tags */ /* remove tags */
tmpString = string_replace("<b>", "", tmpString); str = string_replace("<b>", "", str);
tmpString = string_replace("</b>", "", tmpString); str = string_replace("</b>", "", str);
tmpString = string_replace("<i>", "", tmpString); str = string_replace("<i>", "", str);
tmpString = string_replace("</i>", "", tmpString); str = string_replace("</i>", "", str);
tmpString = string_replace("<u>", "", tmpString); str = string_replace("<u>", "", str);
tmpString = string_replace("</u>", "", tmpString); str = string_replace("</u>", "", str);
tmpString = string_replace("</a>", "", tmpString); str = string_replace("</a>", "", str);
start = strstr(tmpString, "<a href"); start = strstr(str, "<a href");
if(start != NULL) { if(start != NULL) {
end = strstr(tmpString, ">"); end = strstr(str, ">");
if(end != NULL) { if(end != NULL) {
replace_buf = strndup(start, end-start+1); replace_buf = strndup(start, end-start+1);
tmpString = string_replace(replace_buf, "", tmpString); str = string_replace(replace_buf, "", str);
free(replace_buf); free(replace_buf);
} }
} }
start = strstr(tmpString, "<img src"); start = strstr(str, "<img src");
if(start != NULL) { if(start != NULL) {
end = strstr(tmpString, "/>"); end = strstr(str, "/>");
if(end != NULL) { if(end != NULL) {
replace_buf = strndup(start, end-start+2); replace_buf = strndup(start, end-start+2);
tmpString = string_replace(replace_buf, "", tmpString); str = string_replace(replace_buf, "", str);
free(replace_buf); free(replace_buf);
} }
} }
return tmpString; return str;
} }