summaryrefslogtreecommitdiff
path: root/functions.c
diff options
context:
space:
mode:
Diffstat (limited to 'functions.c')
-rw-r--r--functions.c27
1 files changed, 17 insertions, 10 deletions
diff --git a/functions.c b/functions.c
index e89d836..7184bfa 100644
--- a/functions.c
+++ b/functions.c
@@ -213,15 +213,19 @@ void stripprefix(char *string, int debug) {
}
// Extract final parameter from IRC message, removing the leading colon ':'
-// e.g. given this string:
-// ":irc.tghost.co.uk 332 blabounce #test :This is a test topic!"
+// e.g. given either of these strings:
+// ":irc.tghost.co.uk 332 blabounce #test :foo:bar topic!"
+// ":nick!user@fe80:1:2:3:5:6:7:8 TOPIC #test :foo:bar topic!"
// We want to end up with:
-// "This is a test topic!"
+// "foo:bar topic!"
void extractfinalparameter(char *string) {
+ // The method used is to look for the first space (" ") followed by a colon (":")
+ // and take everything after that colon as the final parameter.
+
// Make a copy to work with
char string2[strlen(string)];
- // Position of colon
+ // Position of final parameter's leading colon
int colonpos = -1;
debugprint(DEBUG_FULL, "extractfinalparameter(): starting with '%s', strlen: %zd.\n", string, strlen(string));
@@ -229,17 +233,20 @@ void extractfinalparameter(char *string) {
// Strip the colon at position 0 if there is one
stripprefix(string, 1);
- // Find the colon
+ // Look for spaces...
for (size_t i = 0; i < strlen(string); i++) {
- if (string[i] == ':') {
- debugprint(DEBUG_FULL, "Found colon at position %zd!\n", i);
- colonpos = i;
- break;
+ if (string[i] == ' ') {
+ debugprint(DEBUG_FULL, "extractfinalparameter(): found space at position %zd! Checking for colon...\n", i);
+ // ...and check if the next character is a colon
+ if (string[i + 1] == ':') {
+ colonpos = i + 1;
+ break;
+ }
}
}
if (colonpos == -1) {
- debugprint(DEBUG_FULL, "no colon found, returning\n");
+ debugprint(DEBUG_SOME, "extractfinalparameter(): no space followed by a colon found, returning.\n");
return;
}