diff options
author | Curtis McEnroe | 2018-09-13 16:16:11 -0400 |
---|---|---|
committer | Curtis McEnroe | 2018-09-13 16:16:11 -0400 |
commit | 0d7854c0d48e3f9f3b0a3ea4b5c71cbd6b332df5 (patch) | |
tree | af3ee6ca206286f9528c9c0ded2be05a5dfea45b /format.c | |
parent | 117e6ac9d62cbc4ed18a9087d5bc99e254885fdd (diff) |
Move color selection to format.c
Diffstat (limited to 'format.c')
-rw-r--r-- | format.c | 25 |
1 files changed, 23 insertions, 2 deletions
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 <http://www.gnu.org/licenses/>. */ -#include <wchar.h> -#include <stdlib.h> #include <stdbool.h> +#include <stdint.h> +#include <stdlib.h> +#include <wchar.h> #include "chat.h" +// Adapted from <https://github.com/cbreeden/fxhash/blob/master/lib.rs>. +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; |