summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2019-08-20 21:20:33 +0200
committerSébastien Helleu <flashcode@flashtux.org>2019-08-20 21:20:33 +0200
commit608ec9f4834630a2a73a8d0292883cf6dd837622 (patch)
tree039291c39886fdc81fb8aa0c7c97ff03c66fda95 /src
parent21dca71ee06d8fe4897f1348ce10ac483d8bcc5c (diff)
downloadweechat-608ec9f4834630a2a73a8d0292883cf6dd837622.zip
core: add values djb2_32 and sum_32 for option weechat.look.nick_color_hash (issue #1394)
Diffstat (limited to 'src')
-rw-r--r--src/core/wee-config.c6
-rw-r--r--src/core/wee-config.h2
-rw-r--r--src/gui/gui-nick.c22
3 files changed, 28 insertions, 2 deletions
diff --git a/src/core/wee-config.c b/src/core/wee-config.c
index d09ed7773..cfde1bdb3 100644
--- a/src/core/wee-config.c
+++ b/src/core/wee-config.c
@@ -3240,8 +3240,10 @@ config_weechat_init_options ()
"nick_color_hash", "integer",
N_("hash algorithm used to find the color for a nick: djb2 = variant "
"of djb2 (position of letters matters: anagrams of a nick have "
- "different color), sum = sum of letters"),
- "djb2|sum", 0, 0, "djb2", NULL, 0,
+ "different color), djb2_32 = variant of djb2 using 32-bit instead "
+ "of 64-bit integer, sum = sum of letters, sum_32 = sum of letters "
+ "using 32-bit instead of 64-bit integer"),
+ "djb2|sum|djb2_32|sum_32", 0, 0, "djb2", NULL, 0,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
config_look_nick_color_stop_chars = config_file_new_option (
weechat_config_file, ptr_section,
diff --git a/src/core/wee-config.h b/src/core/wee-config.h
index d3fc51694..8cf1a61bf 100644
--- a/src/core/wee-config.h
+++ b/src/core/wee-config.h
@@ -58,6 +58,8 @@ enum t_config_look_nick_color_hash
{
CONFIG_LOOK_NICK_COLOR_HASH_DJB2 = 0,
CONFIG_LOOK_NICK_COLOR_HASH_SUM,
+ CONFIG_LOOK_NICK_COLOR_HASH_DJB2_32,
+ CONFIG_LOOK_NICK_COLOR_HASH_SUM_32,
};
enum t_config_look_prefix_align
diff --git a/src/gui/gui-nick.c b/src/gui/gui-nick.c
index e2685dc5e..9a575cb2a 100644
--- a/src/gui/gui-nick.c
+++ b/src/gui/gui-nick.c
@@ -47,6 +47,7 @@ int
gui_nick_hash_color (const char *nickname)
{
uint64_t color;
+ uint32_t color_32;
const char *ptr_nick;
if (!nickname || !nickname[0])
@@ -81,6 +82,27 @@ gui_nick_hash_color (const char *nickname)
ptr_nick = utf8_next_char (ptr_nick);
}
break;
+ case CONFIG_LOOK_NICK_COLOR_HASH_DJB2_32:
+ /* variant of djb2 hash (using 32-bit integer) */
+ color_32 = 5381;
+ while (ptr_nick && ptr_nick[0])
+ {
+ color_32 ^= (color_32 << 5) + (color_32 >> 2)
+ + utf8_char_int (ptr_nick);
+ ptr_nick = utf8_next_char (ptr_nick);
+ }
+ color = color_32;
+ break;
+ case CONFIG_LOOK_NICK_COLOR_HASH_SUM_32:
+ /* sum of letters (using 32-bit integer) */
+ color_32 = 0;
+ while (ptr_nick && ptr_nick[0])
+ {
+ color_32 += utf8_char_int (ptr_nick);
+ ptr_nick = utf8_next_char (ptr_nick);
+ }
+ color = color_32;
+ break;
}
return (color % config_num_nick_colors);