diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2023-08-23 16:48:09 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2023-08-24 09:24:42 +0200 |
commit | c2426e88c9583fab1d58d7d26e3bbe9d500ea570 (patch) | |
tree | f2dd4ea404ed258b7a511998583f000690d54931 /src/plugins/irc/irc-server.c | |
parent | 09eae3e2af7ea5c05d613b4056a6b90bf201e227 (diff) | |
download | weechat-c2426e88c9583fab1d58d7d26e3bbe9d500ea570.zip |
irc: add functions to convert strings to lower/upper case (following casemapping) (issue #194)
Diffstat (limited to 'src/plugins/irc/irc-server.c')
-rw-r--r-- | src/plugins/irc/irc-server.c | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/plugins/irc/irc-server.c b/src/plugins/irc/irc-server.c index 2cd37d1ff..1c4106796 100644 --- a/src/plugins/irc/irc-server.c +++ b/src/plugins/irc/irc-server.c @@ -334,6 +334,72 @@ 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. |