#include #include #include "string_buffer.h" #include "utils.h" int contain_special(const char *s) { return strchr(s, '&') || strchr(s, '"') || strchr(s, '\'') || strchr(s, '<') || strchr(s, '>'); } 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, "&"); break; case '"': sb_add_string(buffer, """); break; case '\'': sb_add_string(buffer, "'"); break; case '<': sb_add_string(buffer, "<"); break; case '>': sb_add_string(buffer, ">"); break; default: sb_add_char(buffer, c); } } SB_MOVE(buffer, retval); return retval; }