summaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/irc/irc-server.c66
-rw-r--r--src/plugins/irc/irc-server.h4
2 files changed, 70 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.
diff --git a/src/plugins/irc/irc-server.h b/src/plugins/irc/irc-server.h
index d34cb31d0..4ae647ed2 100644
--- a/src/plugins/irc/irc-server.h
+++ b/src/plugins/irc/irc-server.h
@@ -348,6 +348,10 @@ 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,