40 lines
878 B
C
40 lines
878 B
C
|
#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, "&");
|
||
|
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;
|
||
|
}
|