diff options
Diffstat (limited to '')
-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; |