Mercurial > ~mikael > mcabber > hg
diff mcabber/src/hooks.c @ 1207:8f0af3b88cef
MUC: improve nickname detection and add option 'muc_disable_nick_hl'
The nickname is recognized anywhere in the message, not only at the beginning.
Line highlighting can be disabled with the new option.
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Sun, 29 Apr 2007 11:07:36 +0200 |
parents | 2de8f8ba1f34 |
children | 7c8672bbede5 |
line wrap: on
line diff
--- a/mcabber/src/hooks.c Sat Apr 28 22:30:13 2007 +0200 +++ b/mcabber/src/hooks.c Sun Apr 29 11:07:36 2007 +0200 @@ -123,15 +123,27 @@ // highlight it. if (resname && !strcmp(resname, nick)) { message_flags |= HBB_PREFIX_HLIGHT_OUT; - } else { + } else if (!settings_opt_get_int("muc_disable_nick_hl")) { // We're not the sender. Can we see our nick? - if (startswith(msg, nick, TRUE)) { - // The message starts with our nick. Let's check it's not - // followed immediately by an alphnumeric character. - if (!iswalnum(get_char(msg+strlen(nick)))) + const char *msgptr = msg; + while ((msgptr = strcasestr(msgptr, nick)) != NULL) { + const char *leftb, *rightb; + // The message contains our nick. Let's check it's not + // in the middle of another word (i.e. preceded/followed + // immediately by an alphanumeric character or an underscore. + rightb = msgptr+strlen(nick); + if (msgptr == msg) + leftb = NULL; + else + leftb = prev_char((char*)msgptr, msg); + msgptr = next_char((char*)msgptr); + // Check left boundary + if (leftb && (iswalnum(get_char(leftb)) || get_char(leftb) == '_')) + continue; + // Check right boundary + if (!iswalnum(get_char(rightb)) && get_char(rightb) != '_') message_flags |= HBB_PREFIX_HLIGHT; } - // We could do a more global check... } } }