1
0
mirror of https://github.com/irssi/irssi.git synced 2024-12-04 14:46:39 -05:00

Be smart about case-matching the nicks.

If the prefix contains an uppercase letter then don't use the
case-insensitive search functions.
This commit is contained in:
LemonBoy 2016-06-06 22:25:32 +02:00
parent 52ced0728b
commit 78c1c1518a

View File

@ -52,6 +52,18 @@ static int completion_auto, completion_strict;
last_msg_add(&((MODULE_CHANNEL_REC *) MODULE_DATA(channel))->lastmsgs, \ last_msg_add(&((MODULE_CHANNEL_REC *) MODULE_DATA(channel))->lastmsgs, \
nick, own, keep_publics_count) nick, own, keep_publics_count)
static int contains_uppercase(const char *s1)
{
const char *ch;
for (ch = s1; *ch != '\0'; ch++) {
if (g_ascii_isupper(*ch))
return TRUE;
}
return FALSE;
}
static LAST_MSG_REC *last_msg_find(GSList *list, const char *nick) static LAST_MSG_REC *last_msg_find(GSList *list, const char *nick)
{ {
while (list != NULL) { while (list != NULL) {
@ -336,7 +348,8 @@ GList *completion_msg(SERVER_REC *win_server,
} }
static void complete_from_nicklist(GList **outlist, CHANNEL_REC *channel, static void complete_from_nicklist(GList **outlist, CHANNEL_REC *channel,
const char *nick, const char *suffix) const char *nick, const char *suffix,
const int match_case)
{ {
MODULE_CHANNEL_REC *mchannel; MODULE_CHANNEL_REC *mchannel;
GSList *tmp; GSList *tmp;
@ -352,8 +365,10 @@ static void complete_from_nicklist(GList **outlist, CHANNEL_REC *channel,
for (tmp = mchannel->lastmsgs; tmp != NULL; tmp = tmp->next) { for (tmp = mchannel->lastmsgs; tmp != NULL; tmp = tmp->next) {
LAST_MSG_REC *rec = tmp->data; LAST_MSG_REC *rec = tmp->data;
if (g_ascii_strncasecmp(rec->nick, nick, len) == 0 && if ((match_case? strncmp(rec->nick, nick, len)
glist_find_icase_string(*outlist, rec->nick) == NULL) { : g_ascii_strncasecmp(rec->nick, nick, len)) == 0 &&
(match_case? glist_find_string(*outlist, rec->nick)
: glist_find_icase_string(*outlist, rec->nick)) == NULL) {
str = g_strconcat(rec->nick, suffix, NULL); str = g_strconcat(rec->nick, suffix, NULL);
if (completion_lowercase) ascii_strdown(str); if (completion_lowercase) ascii_strdown(str);
if (rec->own) if (rec->own)
@ -368,7 +383,8 @@ static void complete_from_nicklist(GList **outlist, CHANNEL_REC *channel,
static GList *completion_nicks_nonstrict(CHANNEL_REC *channel, static GList *completion_nicks_nonstrict(CHANNEL_REC *channel,
const char *nick, const char *nick,
const char *suffix) const char *suffix,
const int match_case)
{ {
GSList *nicks, *tmp; GSList *nicks, *tmp;
GList *list; GList *list;
@ -404,7 +420,8 @@ static GList *completion_nicks_nonstrict(CHANNEL_REC *channel,
*out = '\0'; *out = '\0';
/* add to list if 'cleaned' nick matches */ /* add to list if 'cleaned' nick matches */
if (g_ascii_strncasecmp(str, nick, len) == 0) { if ((match_case? strncmp(str, nick, len)
: g_ascii_strncasecmp(str, nick, len)) == 0) {
tnick = g_strconcat(rec->nick, suffix, NULL); tnick = g_strconcat(rec->nick, suffix, NULL);
if (completion_lowercase) if (completion_lowercase)
ascii_strdown(tnick); ascii_strdown(tnick);
@ -428,7 +445,7 @@ static GList *completion_channel_nicks(CHANNEL_REC *channel, const char *nick,
GSList *nicks, *tmp; GSList *nicks, *tmp;
GList *list; GList *list;
char *str; char *str;
int len; int len, match_case;
g_return_val_if_fail(channel != NULL, NULL); g_return_val_if_fail(channel != NULL, NULL);
g_return_val_if_fail(nick != NULL, NULL); g_return_val_if_fail(nick != NULL, NULL);
@ -437,9 +454,11 @@ static GList *completion_channel_nicks(CHANNEL_REC *channel, const char *nick,
if (suffix != NULL && *suffix == '\0') if (suffix != NULL && *suffix == '\0')
suffix = NULL; suffix = NULL;
match_case = contains_uppercase(nick);
/* put first the nicks who have recently said something */ /* put first the nicks who have recently said something */
list = NULL; list = NULL;
complete_from_nicklist(&list, channel, nick, suffix); complete_from_nicklist(&list, channel, nick, suffix, match_case);
/* and add the rest of the nicks too */ /* and add the rest of the nicks too */
len = strlen(nick); len = strlen(nick);
@ -447,7 +466,8 @@ static GList *completion_channel_nicks(CHANNEL_REC *channel, const char *nick,
for (tmp = nicks; tmp != NULL; tmp = tmp->next) { for (tmp = nicks; tmp != NULL; tmp = tmp->next) {
NICK_REC *rec = tmp->data; NICK_REC *rec = tmp->data;
if (g_ascii_strncasecmp(rec->nick, nick, len) == 0 && if ((match_case? strncmp(rec->nick, nick, len)
: g_ascii_strncasecmp(rec->nick, nick, len)) == 0 &&
rec != channel->ownnick) { rec != channel->ownnick) {
str = g_strconcat(rec->nick, suffix, NULL); str = g_strconcat(rec->nick, suffix, NULL);
if (completion_lowercase) if (completion_lowercase)
@ -463,7 +483,7 @@ static GList *completion_channel_nicks(CHANNEL_REC *channel, const char *nick,
/* remove non alphanum chars from nick and search again in case /* remove non alphanum chars from nick and search again in case
list is still NULL ("foo<tab>" would match "_foo_" f.e.) */ list is still NULL ("foo<tab>" would match "_foo_" f.e.) */
if (!completion_strict) if (!completion_strict)
list = g_list_concat(list, completion_nicks_nonstrict(channel, nick, suffix)); list = g_list_concat(list, completion_nicks_nonstrict(channel, nick, suffix, match_case));
return list; return list;
} }