Mercurial > pidgin.yaz
comparison libpurple/util.c @ 24806:e7b27ee5e7b6
Make purple_utf8_has_word() better about detecting word boundaries (still not
really "correct") and prevent stuff like "&" spuriously matching a nick of
"amp". Fixes #7328.
author | Daniel Atallah <daniel.atallah@gmail.com> |
---|---|
date | Fri, 19 Dec 2008 04:11:15 +0000 |
parents | 104f6f755c7e |
children | 3d3376237a7c e2b193decaa5 421857b25052 |
comparison
equal
deleted
inserted
replaced
24805:7608cf033a88 | 24806:e7b27ee5e7b6 |
---|---|
4570 /* previously conversation::find_nick() */ | 4570 /* previously conversation::find_nick() */ |
4571 gboolean | 4571 gboolean |
4572 purple_utf8_has_word(const char *haystack, const char *needle) | 4572 purple_utf8_has_word(const char *haystack, const char *needle) |
4573 { | 4573 { |
4574 char *hay, *pin, *p; | 4574 char *hay, *pin, *p; |
4575 const char *start, *prev_char; | |
4576 gunichar before, after; | |
4575 int n; | 4577 int n; |
4576 gboolean ret = FALSE; | 4578 gboolean ret = FALSE; |
4577 | 4579 |
4578 hay = g_utf8_strdown(haystack, -1); | 4580 start = hay = g_utf8_strdown(haystack, -1); |
4579 | 4581 |
4580 pin = g_utf8_strdown(needle, -1); | 4582 pin = g_utf8_strdown(needle, -1); |
4581 n = strlen(pin); | 4583 n = strlen(pin); |
4582 | 4584 |
4583 if ((p = strstr(hay, pin)) != NULL) { | 4585 while ((p = strstr(start, pin)) != NULL) { |
4584 if ((p == hay || !isalnum(*(p - 1))) && !isalnum(*(p + n))) { | 4586 prev_char = g_utf8_find_prev_char(hay, p); |
4587 before = -2; | |
4588 if (prev_char) { | |
4589 before = g_utf8_get_char(prev_char); | |
4590 } | |
4591 after = g_utf8_get_char_validated(p + n, - 1); | |
4592 | |
4593 if ((p == hay || | |
4594 /* The character before is a reasonable guess for a word boundary | |
4595 ("!g_unichar_isalnum()" is not a valid way to determine word | |
4596 boundaries, but it is the only reasonable thing to do here), | |
4597 and isn't the '&' from a "&" or some such entity*/ | |
4598 (before != -2 && !g_unichar_isalnum(before) && *(p - 1) != '&')) | |
4599 && after != -2 && !g_unichar_isalnum(after)) { | |
4585 ret = TRUE; | 4600 ret = TRUE; |
4586 } | 4601 break; |
4602 } | |
4603 start = p + 1; | |
4587 } | 4604 } |
4588 | 4605 |
4589 g_free(pin); | 4606 g_free(pin); |
4590 g_free(hay); | 4607 g_free(hay); |
4591 | 4608 |