diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2010-07-17 10:21:25 +0200 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2010-07-17 10:21:25 +0200 |
commit | 54468b8ef3d1b79e8cef6b77dd4892f7203723d9 (patch) | |
tree | c4bc8d099d3f458346221994694e8acc4d74dcf4 /src/plugins/irc/irc-nick.c | |
parent | 8dc23863c5375ac349822672955d8dd67d00708c (diff) | |
download | weechat-54468b8ef3d1b79e8cef6b77dd4892f7203723d9.zip |
Add new option irc.look.nick_color_stop_chars
Diffstat (limited to 'src/plugins/irc/irc-nick.c')
-rw-r--r-- | src/plugins/irc/irc-nick.c | 87 |
1 files changed, 69 insertions, 18 deletions
diff --git a/src/plugins/irc/irc-nick.c b/src/plugins/irc/irc-nick.c index 835d39482..a9e5110af 100644 --- a/src/plugins/irc/irc-nick.c +++ b/src/plugins/irc/irc-nick.c @@ -90,15 +90,55 @@ irc_nick_is_nick (const char *string) } /* - * irc_nick_find_color: find a color code for a nick - * (according to nick letters) + * irc_nick_strdup_for_color: duplicate a nick and stop at first char in list + * (using option irc.look.nick_color_stop_chars) */ -const char * -irc_nick_find_color (const char *nickname) +char * +irc_nick_strdup_for_color (const char *nickname) +{ + int char_size, other_char_seen; + char *result, *pos, utf_char[16]; + + result = malloc (strlen (nickname) + 1); + pos = result; + other_char_seen = 0; + while (nickname[0]) + { + char_size = weechat_utf8_char_size (nickname); + memcpy (utf_char, nickname, char_size); + utf_char[char_size] = '\0'; + + if (strstr (weechat_config_string (irc_config_look_nick_color_stop_chars), + utf_char)) + { + if (other_char_seen) + { + pos[0] = '\0'; + return result; + } + } + else + { + other_char_seen = 1; + } + memcpy (pos, utf_char, char_size); + pos += char_size; + + nickname += char_size; + } + pos[0] = '\0'; + return result; +} + +/* + * irc_nick_hash_color: hash a nickname to find color + */ + +int +irc_nick_hash_color (const char *nickname) { int color; - char color_name[64]; const char *ptr_nick; color = 0; @@ -108,8 +148,25 @@ irc_nick_find_color (const char *nickname) color += weechat_utf8_char_int (ptr_nick); ptr_nick = weechat_utf8_next_char (ptr_nick); } - color = (color % - weechat_config_integer (weechat_config_get ("weechat.look.color_nicks_number"))); + return (color % + weechat_config_integer (weechat_config_get ("weechat.look.color_nicks_number"))); +} + +/* + * irc_nick_find_color: find a color code for a nick + * (according to nick letters) + */ + +const char * +irc_nick_find_color (const char *nickname) +{ + int color; + char *nickname2, color_name[64]; + + nickname2 = irc_nick_strdup_for_color (nickname); + color = irc_nick_hash_color ((nickname2) ? nickname2 : nickname); + if (nickname2) + free (nickname2); snprintf (color_name, sizeof (color_name), "chat_nick_color%02d", color + 1); @@ -126,18 +183,12 @@ const char * irc_nick_find_color_name (const char *nickname) { int color; - char color_name[128]; - const char *ptr_nick; + char *nickname2, color_name[128]; - color = 0; - ptr_nick = nickname; - while (ptr_nick && ptr_nick[0]) - { - color += weechat_utf8_char_int (ptr_nick); - ptr_nick = weechat_utf8_next_char (ptr_nick); - } - color = (color % - weechat_config_integer (weechat_config_get ("weechat.look.color_nicks_number"))); + nickname2 = irc_nick_strdup_for_color (nickname); + color = irc_nick_hash_color ((nickname2) ? nickname2 : nickname); + if (nickname2) + free (nickname2); snprintf (color_name, sizeof (color_name), "weechat.color.chat_nick_color%02d", color + 1); |