From 0d7854c0d48e3f9f3b0a3ea4b5c71cbd6b332df5 Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Thu, 13 Sep 2018 16:16:11 -0400 Subject: Move color selection to format.c --- format.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'format.c') diff --git a/format.c b/format.c index 8c2b0ed..58735c5 100644 --- a/format.c +++ b/format.c @@ -14,12 +14,33 @@ * along with this program. If not, see . */ -#include -#include #include +#include +#include +#include #include "chat.h" +// Adapted from . +static uint32_t hashChar(uint32_t hash, char ch) { + hash = (hash << 5) | (hash >> 27); + hash ^= ch; + hash *= 0x27220A95; + return hash; +} + +enum IRCColor formatColor(const char *str) { + if (!str) return IRCDefault; + uint32_t hash = 0; + for (; str[0]; ++str) { + hash = hashChar(hash, str[0]); + } + while (IRCBlack == (hash & IRCLightGray)) { + hash = hashChar(hash, '\0'); + } + return (hash & IRCLightGray); +} + void formatReset(struct Format *format) { format->bold = false; format->italic = false; -- cgit 1.4.1