cleanup of fix_markup(...)
This commit is contained in:
parent
b65735970b
commit
96a632cfcc
83
dunst.c
83
dunst.c
@ -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("<", "<", str);
|
||||||
strpos = str;
|
str = string_replace(">", ">", 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, """, strlen("""))) {
|
|
||||||
*tmppos = '"';
|
|
||||||
tmppos++;
|
|
||||||
strpos += strlen(""");
|
|
||||||
}
|
|
||||||
else if(!strncmp(strpos, "'", strlen("apos;"))) {
|
|
||||||
*tmppos = '\'';
|
|
||||||
tmppos++;
|
|
||||||
strpos += strlen("'");
|
|
||||||
}
|
|
||||||
else if(!strncmp(strpos, "&", strlen("amp;"))) {
|
|
||||||
*tmppos = '&';
|
|
||||||
tmppos++;
|
|
||||||
strpos += strlen("&");
|
|
||||||
}
|
|
||||||
else if(!strncmp(strpos, "<", strlen("lt;"))) {
|
|
||||||
*tmppos = '<';
|
|
||||||
tmppos++;
|
|
||||||
strpos += strlen("<");
|
|
||||||
}
|
|
||||||
else if(!strncmp(strpos, ">", strlen("gt;"))) {
|
|
||||||
*tmppos = '>';
|
|
||||||
tmppos++;
|
|
||||||
strpos += strlen(">");
|
|
||||||
}
|
|
||||||
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;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user