simple-discuss/src/utils.c

40 lines
878 B
C
Raw Normal View History

2023-07-03 14:58:09 +03:00
#include <stdlib.h>
#include "string_buffer.h"
#include "utils.h"
char *
mk_specialchars(const char *input)
{
StringBuffer _buffer, *buffer;
char c;
char *retval;
buffer = &_buffer;
sb_init_empty(buffer);
while ((c = *(input++))) {
switch (c) {
case '&':
sb_add_string(buffer, "&amp;");
break;
case '"':
sb_add_string(buffer, "&quot;");
break;
case '\'':
sb_add_string(buffer, "&#039;");
break;
case '<':
sb_add_string(buffer, "&lt;");
break;
case '>':
sb_add_string(buffer, "&gt;");
break;
default:
sb_add_char(buffer, c);
}
}
SB_MOVE(buffer, retval);
return retval;
}