diff options
Diffstat (limited to 'src/plugins/irc')
-rw-r--r-- | src/plugins/irc/irc-info.c | 10 | ||||
-rw-r--r-- | src/plugins/irc/irc-nick.c | 38 | ||||
-rw-r--r-- | src/plugins/irc/irc-server.c | 66 | ||||
-rw-r--r-- | src/plugins/irc/irc-server.h | 5 |
4 files changed, 31 insertions, 88 deletions
diff --git a/src/plugins/irc/irc-info.c b/src/plugins/irc/irc-info.c index e3318d416..ebd0265cd 100644 --- a/src/plugins/irc/irc-info.c +++ b/src/plugins/irc/irc-info.c @@ -1259,15 +1259,17 @@ irc_info_init () &irc_info_info_irc_nick_from_host_cb, NULL, NULL); weechat_hook_info ( "irc_nick_color", - N_("get nick color code (nick is first converted to lower case, " - "following the value of CASEMAPPING on the server, " + N_("get nick color code, ignoring case (this calls the info " + "\"nick_color_ignore_case\" with appropriate range, according " + "to the value of CASEMAPPING on the server, " "defaulting to \"rfc1459\" if the server is not given)"), N_("server,nickname (server is optional)"), &irc_info_info_irc_nick_color_cb, NULL, NULL); weechat_hook_info ( "irc_nick_color_name", - N_("get nick color name (nick is first converted to lower case, " - "following the value of CASEMAPPING on the server, " + N_("get nick color name, ignoring case (this calls the info " + "\"nick_color_name_ignore_case\" with appropriate range, according " + "to the value of CASEMAPPING on the server, " "defaulting to \"rfc1459\" if the server is not given)"), N_("server,nickname (server is optional)"), &irc_info_info_irc_nick_color_name_cb, NULL, NULL); diff --git a/src/plugins/irc/irc-nick.c b/src/plugins/irc/irc-nick.c index f593c9312..286907999 100644 --- a/src/plugins/irc/irc-nick.c +++ b/src/plugins/irc/irc-nick.c @@ -141,15 +141,20 @@ irc_nick_is_nick (struct t_irc_server *server, const char *string) char * irc_nick_find_color (struct t_irc_server *server, const char *nickname) { - char *nickname_lower, *result; + char str_args[4096]; + int casemapping, range; - nickname_lower = irc_server_string_tolower (server, nickname); - if (!nickname_lower) - return NULL; + casemapping = (server) ? server->casemapping : -1; + if ((casemapping < 0) || (casemapping >= IRC_SERVER_NUM_CASEMAPPING)) + casemapping = IRC_SERVER_CASEMAPPING_RFC1459; + range = irc_server_casemapping_range[casemapping]; - result = weechat_info_get ("nick_color", nickname_lower); - free (nickname_lower); - return result; + snprintf (str_args, sizeof (str_args), + "%s;%d", + (nickname) ? nickname : "", + range); + + return weechat_info_get ("nick_color_ignore_case", str_args); } /* @@ -161,15 +166,20 @@ irc_nick_find_color (struct t_irc_server *server, const char *nickname) char * irc_nick_find_color_name (struct t_irc_server *server, const char *nickname) { - char *nickname_lower, *result; + char str_args[4096]; + int casemapping, range; - nickname_lower = irc_server_string_tolower (server, nickname); - if (!nickname_lower) - return NULL; + casemapping = (server) ? server->casemapping : -1; + if ((casemapping < 0) || (casemapping >= IRC_SERVER_NUM_CASEMAPPING)) + casemapping = IRC_SERVER_CASEMAPPING_RFC1459; + range = irc_server_casemapping_range[casemapping]; - result = weechat_info_get ("nick_color_name", nickname_lower); - free (nickname_lower); - return result; + snprintf (str_args, sizeof (str_args), + "%s;%d", + (nickname) ? nickname: "", + range); + + return weechat_info_get ("nick_color_name_ignore_case", str_args); } /* diff --git a/src/plugins/irc/irc-server.c b/src/plugins/irc/irc-server.c index 1c4106796..2cd37d1ff 100644 --- a/src/plugins/irc/irc-server.c +++ b/src/plugins/irc/irc-server.c @@ -334,72 +334,6 @@ irc_server_strncasecmp (struct t_irc_server *server, } /* - * Converts string to lower case, following server casemapping. - * - * Note: result must be freed after use. - */ - -char * -irc_server_string_tolower (struct t_irc_server *server, const char *string) -{ - char *result, *ptr_result; - int casemapping, range; - - if (!string) - return NULL; - - casemapping = (server) ? server->casemapping : -1; - if ((casemapping < 0) || (casemapping >= IRC_SERVER_NUM_CASEMAPPING)) - casemapping = IRC_SERVER_CASEMAPPING_RFC1459; - - range = irc_server_casemapping_range[casemapping]; - - result = strdup (string); - ptr_result = result; - while (ptr_result && ptr_result[0]) - { - if ((ptr_result[0] >= 'A') && (ptr_result[0] < 'A' + range)) - ptr_result[0] += ('a' - 'A'); - ptr_result = (char *)weechat_utf8_next_char (ptr_result); - } - - return result; -} - -/* - * Converts string to upper case, following server casemapping. - * - * Note: result must be freed after use. - */ - -char * -irc_server_string_toupper (struct t_irc_server *server, const char *string) -{ - char *result, *ptr_result; - int casemapping, range; - - if (!string) - return NULL; - - casemapping = (server) ? server->casemapping : -1; - if ((casemapping < 0) || (casemapping >= IRC_SERVER_NUM_CASEMAPPING)) - casemapping = IRC_SERVER_CASEMAPPING_RFC1459; - - range = irc_server_casemapping_range[casemapping]; - - result = strdup (string); - ptr_result = result; - while (ptr_result && ptr_result[0]) - { - if ((ptr_result[0] >= 'a') && (ptr_result[0] < 'a' + range)) - ptr_result[0] -= ('a' - 'A'); - ptr_result = (char *)weechat_utf8_next_char (ptr_result); - } - - return result; -} - -/* * Evaluates a string using the server as context: * ${irc_server.xxx} and ${server} are replaced by a server option and the * server name. diff --git a/src/plugins/irc/irc-server.h b/src/plugins/irc/irc-server.h index 4ae647ed2..054516a8f 100644 --- a/src/plugins/irc/irc-server.h +++ b/src/plugins/irc/irc-server.h @@ -328,6 +328,7 @@ enum t_irc_fingerprint_digest_algo IRC_FINGERPRINT_NUM_ALGOS, }; +extern int irc_server_casemapping_range[]; extern char *irc_server_prefix_modes_default; extern char *irc_server_prefix_chars_default; extern char *irc_server_chanmodes_default; @@ -348,10 +349,6 @@ extern int irc_server_strcasecmp (struct t_irc_server *server, extern int irc_server_strncasecmp (struct t_irc_server *server, const char *string1, const char *string2, int max); -extern char *irc_server_string_tolower (struct t_irc_server *server, - const char *string); -extern char *irc_server_string_toupper (struct t_irc_server *server, - const char *string); extern char *irc_server_eval_expression (struct t_irc_server *server, const char *string); extern void irc_server_sasl_get_creds (struct t_irc_server *server, |