summaryrefslogtreecommitdiff
path: root/functions.c
diff options
context:
space:
mode:
authorLuke Bratch <luke@bratch.co.uk>2019-05-08 21:02:26 +0100
committerLuke Bratch <luke@bratch.co.uk>2019-05-08 21:02:26 +0100
commit4c9ef597e5503fa571276fd16739410cd9847f91 (patch)
treeca8efa3593a107edd394221be06586fd2726b2ef /functions.c
parent243d947c43a4f71c2a027e9909a154ab48c09907 (diff)
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.
Diffstat (limited to 'functions.c')
-rw-r--r--functions.c35
1 files changed, 35 insertions, 0 deletions
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));
+}