From 4c9ef597e5503fa571276fd16739410cd9847f91 Mon Sep 17 00:00:00 2001 From: Luke Bratch Date: Wed, 8 May 2019 21:02:26 +0100 Subject: Make TOPIC tracking/following/setting/etc. work for most/all scenarios and ensure it's always given out to new clients correctly. Also misc other bug fixes. --- functions.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'functions.c') diff --git a/functions.c b/functions.c index 56b37d6..c6bea40 100644 --- a/functions.c +++ b/functions.c @@ -127,3 +127,38 @@ void extractfinalparameter(char *string) { printf("extractfinalparameter(): finishing with '%s', strlen: %zd.\n", string, strlen(string)); } + +// Extract the IRC nick from a prefix +// e.g. given this string: +// ":foo!bar@baz" +// We want to end up with: +// "foo" +void extractnickfromprefix(char *string) { + // Position of bang + int bangpos = -1; + + printf("extractnickfromprefix(): starting with '%s', strlen: %zd.\n", string, strlen(string)); + + // Strip the colon at position 0 if there is one + stripprefix(string); + + // Find the bang + for (size_t i = 0; i < strlen(string); i++) { + printf("i: %zd. strlen: %zd.\n", i, strlen(string)); + if (string[i] == '!') { + printf("Found bang at position %zd!\n", i); + bangpos = i; + break; + } + } + + if (bangpos == -1) { + printf("no bang found, returning\n"); + return; + } + + // Terminate the string at whatever position we found the bang + string[bangpos] = '\0'; + + printf("extractnickfromprefix(): finishing with '%s', strlen: %zd.\n", string, strlen(string)); +} -- cgit v1.2.3