summaryrefslogtreecommitdiff
path: root/functions.c
diff options
context:
space:
mode:
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));
+}