~vcs-imports/pidgin-musictracker/trunk

« back to all changes in this revision

Viewing changes to src/filter.c

  • Committer: jon.turney at org
  • Date: 2010-03-02 15:42:24 UTC
  • Revision ID: svn-v4:dccc4ef9-3752-0410-9079-47cdceed9760:trunk:449
Always apply printable character filter to track information

(issue 198)

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
#include "utils.h"
6
6
#include "musictracker.h"
7
7
 
8
 
/* Filters out all black-listed words, as well as non-printable characters
 
8
/* Filters out all black-listed words
9
9
 */
10
10
void
11
 
filter(char *str)
 
11
filter_profanity(char *str)
12
12
{
13
13
        gboolean changed = FALSE;
14
14
 
17
17
        char **list = g_strsplit(purple_prefs_get_string(PREF_FILTER),
18
18
                        ",", 0);
19
19
 
20
 
 
21
20
        char **p;
22
21
        for (p = list; *p != 0; ++p) {
23
22
                int len = strlen(*p);
25
24
                  continue;
26
25
 
27
26
                // construct a regex pattern which matches the distinct word
28
 
                // i.e. use word boundaries to avoid matchin as a substring...
 
27
                // i.e. use word boundaries to avoid matching as a substring...
29
28
                char pattern[len+10];
30
29
                sprintf(pattern, "\\b(%s)\\b", *p);
31
30
                pcre *re = regex(pattern, PCRE_CASELESS | PCRE_UTF8);
38
37
                    changed = TRUE;
39
38
                  }
40
39
 
41
 
                pcre_free(re);                
 
40
                pcre_free(re);
42
41
        }
43
42
        g_strfreev(list);
44
43
 
45
 
        // Remove unprintable chars
46
 
        char *u = str;
47
 
        while (*u != 0)
48
 
          {
49
 
            gunichar c = g_utf8_get_char(u);
50
 
            gchar *next = g_utf8_next_char(u);
51
 
            if (!g_unichar_isprint(c))
52
 
              {
53
 
                for (; u < next; u++)  
54
 
                  *u = mask;
55
 
                changed = TRUE;
56
 
              }
57
 
            u = next;
58
 
          }
59
 
 
60
44
        // debug report that filtering happened
61
45
        if (changed)
62
46
          {
63
 
              trace("filtered to: %s", str);
 
47
              trace("profanity filtered to: %s", str);
64
48
          }
65
49
}
66
50
 
 
51
/*
 
52
   Filters out non-printable characters
 
53
 */
 
54
void
 
55
filter_printable(char *str)
 
56
{
 
57
  gboolean changed = FALSE;
 
58
 
 
59
  char mask = *purple_prefs_get_string(PREF_MASK);
 
60
 
 
61
  // Remove unprintable chars
 
62
  char *u = str;
 
63
  while (*u != 0)
 
64
    {
 
65
      gunichar c = g_utf8_get_char(u);
 
66
      gchar *next = g_utf8_next_char(u);
 
67
      if (!g_unichar_isprint(c))
 
68
        {
 
69
          for (; u < next; u++)
 
70
            *u = mask;
 
71
          changed = TRUE;
 
72
        }
 
73
      u = next;
 
74
    }
 
75
 
 
76
  // debug report that filtering happened
 
77
  if (changed)
 
78
    {
 
79
      trace("printable filtered to: %s", str);
 
80
    }
 
81
}
 
82
 
67
83
const char*
68
84
filter_get_default()
69
85
{