diff options
-rw-r--r-- | lib/misc.c | 16 | ||||
-rw-r--r-- | lib/misc.h | 1 | ||||
-rw-r--r-- | otr.c | 11 |
3 files changed, 20 insertions, 8 deletions
@@ -770,3 +770,19 @@ gboolean parse_int64(char *string, int base, guint64 *number) return TRUE; } +/* Filters all the characters in 'blacklist' replacing them with 'replacement'. + * Modifies the string in-place and returns the string itself. + * For the opposite, use g_strcanon() */ +char *str_reject_chars(char *string, const char *reject, char replacement) +{ + char *c = string; + + while (*c) { + c += strcspn(c, reject); + if (*c) { + *c = replacement; + } + } + + return string; +} @@ -149,5 +149,6 @@ G_MODULE_EXPORT char **split_command_parts(char *command, int limit); G_MODULE_EXPORT char *get_rfc822_header(const char *text, const char *header, int len); G_MODULE_EXPORT int truncate_utf8(char *string, int maxlen); G_MODULE_EXPORT gboolean parse_int64(char *string, int base, guint64 *number); +G_MODULE_EXPORT char *str_reject_chars(char *string, const char *reject, char replacement); #endif @@ -750,14 +750,9 @@ void op_create_instag(void *opdata, const char *account, const char *protocol) } } -static char *otr_filter_colors(char *msg) { - int i; - for (i = 0; msg[i]; i++) { - if (msg[i] == '\x02' || msg[i] == '\x03') { - msg[i] = '?'; - } - } - return msg; +static char *otr_filter_colors(char *msg) +{ + return str_reject_chars(msg, "\x02\x03", '?'); } /* returns newly allocated string */ |