summaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2023-08-23 15:24:53 +0200
committerSébastien Helleu <flashcode@flashtux.org>2023-08-23 15:33:34 +0200
commit25b3f2eae7feea6e498a6a0665857fa06f7ddfc9 (patch)
tree8da32330151933b1ff905a142693b072080916ed /src/plugins
parent9462c87ce5aa0ead85d123f5e1fed94e8a1656ed (diff)
downloadweechat-25b3f2eae7feea6e498a6a0665857fa06f7ddfc9.zip
irc: fix string comparison when CASEMAPPING is set to "ascii"
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/irc/irc-server.c54
1 files changed, 18 insertions, 36 deletions
diff --git a/src/plugins/irc/irc-server.c b/src/plugins/irc/irc-server.c
index 10f14c981..2cd37d1ff 100644
--- a/src/plugins/irc/irc-server.c
+++ b/src/plugins/irc/irc-server.c
@@ -132,6 +132,8 @@ char *irc_server_options[IRC_SERVER_NUM_OPTIONS][2] =
char *irc_server_casemapping_string[IRC_SERVER_NUM_CASEMAPPING] =
{ "rfc1459", "strict-rfc1459", "ascii" };
+int irc_server_casemapping_range[IRC_SERVER_NUM_CASEMAPPING] =
+{ 30, 29, 26 };
char *irc_server_utf8mapping_string[IRC_SERVER_NUM_UTF8MAPPING] =
{ "none", "rfc8265" };
@@ -295,25 +297,15 @@ int
irc_server_strcasecmp (struct t_irc_server *server,
const char *string1, const char *string2)
{
- int casemapping, rc;
+ int casemapping, range;
- casemapping = (server) ? server->casemapping : IRC_SERVER_CASEMAPPING_RFC1459;
- switch (casemapping)
- {
- case IRC_SERVER_CASEMAPPING_RFC1459:
- rc = weechat_strcasecmp_range (string1, string2, 30);
- break;
- case IRC_SERVER_CASEMAPPING_STRICT_RFC1459:
- rc = weechat_strcasecmp_range (string1, string2, 29);
- break;
- case IRC_SERVER_CASEMAPPING_ASCII:
- rc = weechat_strcasecmp (string1, string2);
- break;
- default:
- rc = weechat_strcasecmp_range (string1, string2, 30);
- break;
- }
- return rc;
+ casemapping = (server) ? server->casemapping : -1;
+ if ((casemapping < 0) || (casemapping >= IRC_SERVER_NUM_CASEMAPPING))
+ casemapping = IRC_SERVER_CASEMAPPING_RFC1459;
+
+ range = irc_server_casemapping_range[casemapping];
+
+ return weechat_strcasecmp_range (string1, string2, range);
}
/*
@@ -330,25 +322,15 @@ int
irc_server_strncasecmp (struct t_irc_server *server,
const char *string1, const char *string2, int max)
{
- int casemapping, rc;
+ int casemapping, range;
- casemapping = (server) ? server->casemapping : IRC_SERVER_CASEMAPPING_RFC1459;
- switch (casemapping)
- {
- case IRC_SERVER_CASEMAPPING_RFC1459:
- rc = weechat_strncasecmp_range (string1, string2, max, 30);
- break;
- case IRC_SERVER_CASEMAPPING_STRICT_RFC1459:
- rc = weechat_strncasecmp_range (string1, string2, max, 29);
- break;
- case IRC_SERVER_CASEMAPPING_ASCII:
- rc = weechat_strncasecmp (string1, string2, max);
- break;
- default:
- rc = weechat_strncasecmp_range (string1, string2, max, 30);
- break;
- }
- return rc;
+ casemapping = (server) ? server->casemapping : -1;
+ if ((casemapping < 0) || (casemapping >= IRC_SERVER_NUM_CASEMAPPING))
+ casemapping = IRC_SERVER_CASEMAPPING_RFC1459;
+
+ range = irc_server_casemapping_range[casemapping];
+
+ return weechat_strncasecmp_range (string1, string2, max, range);
}
/*