diff options
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | src/common/utf8.c | 50 | ||||
-rw-r--r-- | src/common/utf8.h | 11 | ||||
-rw-r--r-- | src/irc/irc-recv.c | 26 | ||||
-rw-r--r-- | weechat/ChangeLog | 3 | ||||
-rw-r--r-- | weechat/src/common/utf8.c | 50 | ||||
-rw-r--r-- | weechat/src/common/utf8.h | 11 | ||||
-rw-r--r-- | weechat/src/irc/irc-recv.c | 26 |
8 files changed, 144 insertions, 36 deletions
@@ -1,10 +1,11 @@ WeeChat - Wee Enhanced Environment for Chat =========================================== -ChangeLog - 2007-08-09 +ChangeLog - 2007-08-12 Version 0.2.6 (under dev!): + * fixed bug with highlight and UTF-8 chars around word (bug #20753) * added swedish quickstart guide * added support of channel mode +u (channel user) (bug #20717) * improved /connect command to connect to a host by creating a temporary diff --git a/src/common/utf8.c b/src/common/utf8.c index abcef47cf..176fee797 100644 --- a/src/common/utf8.c +++ b/src/common/utf8.c @@ -26,16 +26,6 @@ #include <stdlib.h> #include <string.h> -#ifndef __USE_XOPEN -#define __USE_XOPEN -#endif - -#if defined(__OpenBSD__) -#include <utf8/wchar.h> -#else -#include <wchar.h> -#endif - #include "weechat.h" #include "utf8.h" #include "util.h" @@ -394,3 +384,43 @@ utf8_pos (char *string, int real_pos) } return count; } + +/* + * utf8_get_wc: get wide char from string (first char) + */ + +wint_t +utf8_get_wc (char *string) +{ + int char_size; + wint_t result; + + if (!string || !string[0]) + return WEOF; + + char_size = utf8_char_size (string); + switch (char_size) + { + case 1: + result = (wint_t)string[0]; + break; + case 2: + result = ((wint_t)((unsigned char)string[0])) << 8 + | ((wint_t)((unsigned char)string[1])); + break; + case 3: + result = ((wint_t)((unsigned char)string[0])) << 16 + | ((wint_t)((unsigned char)string[1])) << 8 + | ((wint_t)((unsigned char)string[2])); + break; + case 4: + result = ((wint_t)((unsigned char)string[0])) << 24 + | ((wint_t)((unsigned char)string[1])) << 16 + | ((wint_t)((unsigned char)string[2])) << 8 + | ((wint_t)((unsigned char)string[3])); + break; + default: + result = WEOF; + } + return result; +} diff --git a/src/common/utf8.h b/src/common/utf8.h index 3a35bec69..caf7b7b10 100644 --- a/src/common/utf8.h +++ b/src/common/utf8.h @@ -20,6 +20,16 @@ #ifndef __WEECHAT_UTF8_H #define __WEECHAT_UTF8_H 1 +#ifndef __USE_XOPEN +#define __USE_XOPEN +#endif + +#if defined(__OpenBSD__) +#include <utf8/wchar.h> +#else +#include <wchar.h> +#endif + extern int local_utf8; extern void utf8_init (); @@ -35,5 +45,6 @@ extern int utf8_width_screen (char *); extern char *utf8_add_offset (char *, int); extern int utf8_real_pos (char *, int); extern int utf8_pos (char *, int); +extern wint_t utf8_get_wc (char *); #endif /* utf8.h */ diff --git a/src/irc/irc-recv.c b/src/irc/irc-recv.c index 0c115de87..03960d788 100644 --- a/src/irc/irc-recv.c +++ b/src/irc/irc-recv.c @@ -29,6 +29,7 @@ #include <stdio.h> #include <string.h> #include <ctype.h> +#include <wctype.h> #include <sys/time.h> #include <time.h> #include <sys/utsname.h> @@ -39,6 +40,7 @@ #include "../common/alias.h" #include "../common/command.h" #include "../common/hotlist.h" +#include "../common/utf8.h" #include "../common/util.h" #include "../common/weeconfig.h" #include "../gui/gui.h" @@ -57,9 +59,14 @@ int command_ignored, command_force_highlight; */ int -irc_recv_is_word_char (char c) +irc_recv_is_word_char (char *str) { - if (isalnum (c)) + wint_t c = utf8_get_wc (str); + + if (c == WEOF) + return 0; + + if (iswalnum (c)) return 1; switch (c) @@ -113,10 +120,12 @@ irc_recv_is_highlight (char *message, char *nick) match = strstr (message, nick); if (match) { - match_pre = match - 1; + match_pre = utf8_prev_char (message, match); + if (!match_pre) + match_pre = match - 1; match_post = match + strlen(nick); - startswith = ((match == message) || (!irc_recv_is_word_char (match_pre[0]))); - endswith = ((!match_post[0]) || (!irc_recv_is_word_char (match_post[0]))); + startswith = ((match == message) || (!irc_recv_is_word_char (match_pre))); + endswith = ((!match_post[0]) || (!irc_recv_is_word_char (match_post))); if (startswith && endswith) return 1; } @@ -188,9 +197,12 @@ irc_recv_is_highlight (char *message, char *nick) while ((match = strstr (msg_pos, pos)) != NULL) { match_pre = match - 1; + match_pre = utf8_prev_char (msg, match); + if (!match_pre) + match_pre = match - 1; match_post = match + length; - startswith = ((match == msg) || (!irc_recv_is_word_char (match_pre[0]))); - endswith = ((!match_post[0]) || (!irc_recv_is_word_char (match_post[0]))); + startswith = ((match == msg) || (!irc_recv_is_word_char (match_pre))); + endswith = ((!match_post[0]) || (!irc_recv_is_word_char (match_post))); if ((wildcard_start && wildcard_end) || (!wildcard_start && !wildcard_end && startswith && endswith) || diff --git a/weechat/ChangeLog b/weechat/ChangeLog index cf6c44bc9..b9335628d 100644 --- a/weechat/ChangeLog +++ b/weechat/ChangeLog @@ -1,10 +1,11 @@ WeeChat - Wee Enhanced Environment for Chat =========================================== -ChangeLog - 2007-08-09 +ChangeLog - 2007-08-12 Version 0.2.6 (under dev!): + * fixed bug with highlight and UTF-8 chars around word (bug #20753) * added swedish quickstart guide * added support of channel mode +u (channel user) (bug #20717) * improved /connect command to connect to a host by creating a temporary diff --git a/weechat/src/common/utf8.c b/weechat/src/common/utf8.c index abcef47cf..176fee797 100644 --- a/weechat/src/common/utf8.c +++ b/weechat/src/common/utf8.c @@ -26,16 +26,6 @@ #include <stdlib.h> #include <string.h> -#ifndef __USE_XOPEN -#define __USE_XOPEN -#endif - -#if defined(__OpenBSD__) -#include <utf8/wchar.h> -#else -#include <wchar.h> -#endif - #include "weechat.h" #include "utf8.h" #include "util.h" @@ -394,3 +384,43 @@ utf8_pos (char *string, int real_pos) } return count; } + +/* + * utf8_get_wc: get wide char from string (first char) + */ + +wint_t +utf8_get_wc (char *string) +{ + int char_size; + wint_t result; + + if (!string || !string[0]) + return WEOF; + + char_size = utf8_char_size (string); + switch (char_size) + { + case 1: + result = (wint_t)string[0]; + break; + case 2: + result = ((wint_t)((unsigned char)string[0])) << 8 + | ((wint_t)((unsigned char)string[1])); + break; + case 3: + result = ((wint_t)((unsigned char)string[0])) << 16 + | ((wint_t)((unsigned char)string[1])) << 8 + | ((wint_t)((unsigned char)string[2])); + break; + case 4: + result = ((wint_t)((unsigned char)string[0])) << 24 + | ((wint_t)((unsigned char)string[1])) << 16 + | ((wint_t)((unsigned char)string[2])) << 8 + | ((wint_t)((unsigned char)string[3])); + break; + default: + result = WEOF; + } + return result; +} diff --git a/weechat/src/common/utf8.h b/weechat/src/common/utf8.h index 3a35bec69..caf7b7b10 100644 --- a/weechat/src/common/utf8.h +++ b/weechat/src/common/utf8.h @@ -20,6 +20,16 @@ #ifndef __WEECHAT_UTF8_H #define __WEECHAT_UTF8_H 1 +#ifndef __USE_XOPEN +#define __USE_XOPEN +#endif + +#if defined(__OpenBSD__) +#include <utf8/wchar.h> +#else +#include <wchar.h> +#endif + extern int local_utf8; extern void utf8_init (); @@ -35,5 +45,6 @@ extern int utf8_width_screen (char *); extern char *utf8_add_offset (char *, int); extern int utf8_real_pos (char *, int); extern int utf8_pos (char *, int); +extern wint_t utf8_get_wc (char *); #endif /* utf8.h */ diff --git a/weechat/src/irc/irc-recv.c b/weechat/src/irc/irc-recv.c index 0c115de87..03960d788 100644 --- a/weechat/src/irc/irc-recv.c +++ b/weechat/src/irc/irc-recv.c @@ -29,6 +29,7 @@ #include <stdio.h> #include <string.h> #include <ctype.h> +#include <wctype.h> #include <sys/time.h> #include <time.h> #include <sys/utsname.h> @@ -39,6 +40,7 @@ #include "../common/alias.h" #include "../common/command.h" #include "../common/hotlist.h" +#include "../common/utf8.h" #include "../common/util.h" #include "../common/weeconfig.h" #include "../gui/gui.h" @@ -57,9 +59,14 @@ int command_ignored, command_force_highlight; */ int -irc_recv_is_word_char (char c) +irc_recv_is_word_char (char *str) { - if (isalnum (c)) + wint_t c = utf8_get_wc (str); + + if (c == WEOF) + return 0; + + if (iswalnum (c)) return 1; switch (c) @@ -113,10 +120,12 @@ irc_recv_is_highlight (char *message, char *nick) match = strstr (message, nick); if (match) { - match_pre = match - 1; + match_pre = utf8_prev_char (message, match); + if (!match_pre) + match_pre = match - 1; match_post = match + strlen(nick); - startswith = ((match == message) || (!irc_recv_is_word_char (match_pre[0]))); - endswith = ((!match_post[0]) || (!irc_recv_is_word_char (match_post[0]))); + startswith = ((match == message) || (!irc_recv_is_word_char (match_pre))); + endswith = ((!match_post[0]) || (!irc_recv_is_word_char (match_post))); if (startswith && endswith) return 1; } @@ -188,9 +197,12 @@ irc_recv_is_highlight (char *message, char *nick) while ((match = strstr (msg_pos, pos)) != NULL) { match_pre = match - 1; + match_pre = utf8_prev_char (msg, match); + if (!match_pre) + match_pre = match - 1; match_post = match + length; - startswith = ((match == msg) || (!irc_recv_is_word_char (match_pre[0]))); - endswith = ((!match_post[0]) || (!irc_recv_is_word_char (match_post[0]))); + startswith = ((match == msg) || (!irc_recv_is_word_char (match_pre))); + endswith = ((!match_post[0]) || (!irc_recv_is_word_char (match_post))); if ((wildcard_start && wildcard_end) || (!wildcard_start && !wildcard_end && startswith && endswith) || |