Changeset 47ab9a9


Ignore:
Timestamp:
2015-11-27T23:42:00Z (9 years ago)
Author:
dequis <dx@…>
Branches:
master
Children:
31d9930
Parents:
d088ee8
Message:

misc.c: Add a str_reject_chars function, use it in otr_filter_colors

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • lib/misc.c

    rd088ee8 r47ab9a9  
    771771}
    772772
     773/* Filters all the characters in 'blacklist' replacing them with 'replacement'.
     774 * Modifies the string in-place and returns the string itself.
     775 * For the opposite, use g_strcanon() */
     776char *str_reject_chars(char *string, const char *reject, char replacement)
     777{
     778        char *c = string;
     779
     780        while (*c) {
     781                c += strcspn(c, reject);
     782                if (*c) {
     783                        *c = replacement;
     784                }
     785        }
     786
     787        return string;
     788}
  • lib/misc.h

    rd088ee8 r47ab9a9  
    150150G_MODULE_EXPORT int truncate_utf8(char *string, int maxlen);
    151151G_MODULE_EXPORT gboolean parse_int64(char *string, int base, guint64 *number);
     152G_MODULE_EXPORT char *str_reject_chars(char *string, const char *reject, char replacement);
    152153
    153154#endif
  • otr.c

    rd088ee8 r47ab9a9  
    751751}
    752752
    753 static char *otr_filter_colors(char *msg) {
    754         int i;
    755         for (i = 0; msg[i]; i++) {
    756                 if (msg[i] == '\x02' || msg[i] == '\x03') {
    757                         msg[i] = '?';
    758                 }
    759         }
    760         return msg;
     753static char *otr_filter_colors(char *msg)
     754{
     755        return str_reject_chars(msg, "\x02\x03", '?');
    761756}
    762757
Note: See TracChangeset for help on using the changeset viewer.