comparison libpurple/util.c @ 24838:0d7c21b5f1d7

propagate from branch 'im.pidgin.pidgin' (head c06356e8e8d2c586f0192a5564053c2584020da8) to branch 'im.pidgin.pidgin.openq' (head a7077bc12b850d60ea7d768f4b9d4ee6ae6ad2c1)
author SHiNE CsyFeK <csyfek@gmail.com>
date Thu, 25 Dec 2008 14:06:10 +0000
parents 3d3376237a7c
children 43b721aa4b76 fb89c9f6e57a 45434c3fd878
comparison
equal deleted inserted replaced
24606:68eba2bafa6f 24838:0d7c21b5f1d7
1674 { 1674 {
1675 case 1: 1675 case 1:
1676 size = "xx-small"; 1676 size = "xx-small";
1677 break; 1677 break;
1678 case 2: 1678 case 2:
1679 size = "x-small"; 1679 size = "small";
1680 break; 1680 break;
1681 case 3: 1681 case 3:
1682 size = "small"; 1682 size = "medium";
1683 break; 1683 break;
1684 case 4: 1684 case 4:
1685 size = "medium"; 1685 size = "large";
1686 break; 1686 break;
1687 case 5: 1687 case 5:
1688 size = "large"; 1688 size = "x-large";
1689 break; 1689 break;
1690 case 6: 1690 case 6:
1691 size = "x-large";
1692 break;
1693 case 7: 1691 case 7:
1694 size = "xx-large"; 1692 size = "xx-large";
1695 break; 1693 break;
1696 default: 1694 default:
1697 break; 1695 break;
4570 /* previously conversation::find_nick() */ 4568 /* previously conversation::find_nick() */
4571 gboolean 4569 gboolean
4572 purple_utf8_has_word(const char *haystack, const char *needle) 4570 purple_utf8_has_word(const char *haystack, const char *needle)
4573 { 4571 {
4574 char *hay, *pin, *p; 4572 char *hay, *pin, *p;
4573 const char *start, *prev_char;
4574 gunichar before, after;
4575 int n; 4575 int n;
4576 gboolean ret = FALSE; 4576 gboolean ret = FALSE;
4577 4577
4578 hay = g_utf8_strdown(haystack, -1); 4578 start = hay = g_utf8_strdown(haystack, -1);
4579 4579
4580 pin = g_utf8_strdown(needle, -1); 4580 pin = g_utf8_strdown(needle, -1);
4581 n = strlen(pin); 4581 n = strlen(pin);
4582 4582
4583 if ((p = strstr(hay, pin)) != NULL) { 4583 while ((p = strstr(start, pin)) != NULL) {
4584 if ((p == hay || !isalnum(*(p - 1))) && !isalnum(*(p + n))) { 4584 prev_char = g_utf8_find_prev_char(hay, p);
4585 before = -2;
4586 if (prev_char) {
4587 before = g_utf8_get_char(prev_char);
4588 }
4589 after = g_utf8_get_char_validated(p + n, - 1);
4590
4591 if ((p == hay ||
4592 /* The character before is a reasonable guess for a word boundary
4593 ("!g_unichar_isalnum()" is not a valid way to determine word
4594 boundaries, but it is the only reasonable thing to do here),
4595 and isn't the '&' from a "&amp;" or some such entity*/
4596 (before != -2 && !g_unichar_isalnum(before) && *(p - 1) != '&'))
4597 && after != -2 && !g_unichar_isalnum(after)) {
4585 ret = TRUE; 4598 ret = TRUE;
4586 } 4599 break;
4600 }
4601 start = p + 1;
4587 } 4602 }
4588 4603
4589 g_free(pin); 4604 g_free(pin);
4590 g_free(hay); 4605 g_free(hay);
4591 4606