remove ?utm for strings
This commit is contained in:
parent
24b95be6dc
commit
cb9ec6141c
4
TODO.md
4
TODO.md
|
@ -1,5 +1,9 @@
|
|||
# To do
|
||||
|
||||
- [ ] Look into improving speed and performance:
|
||||
- [ ] Creating objects only once, e.g., for js strings that I execte
|
||||
- [ ] Look into using global controllers, rather than one for each webview
|
||||
- [ ] etc.
|
||||
- [ ] Move to a later C standard (C11?) and use safer string handling functions provided by it.
|
||||
- The thing is, I kinda feel attached to C89-C99
|
||||
- [ ] Consider
|
||||
|
|
|
@ -68,5 +68,7 @@ int libre_redirect(const char* uri, char* output)
|
|||
}
|
||||
strcpy(output, uri);
|
||||
}
|
||||
return 0;
|
||||
|
||||
int utm_check = str_destructively_omit_from(output, "?utm");
|
||||
return utm_check * 2;
|
||||
}
|
||||
|
|
|
@ -59,3 +59,26 @@ See also:
|
|||
* <https://web.archive.org/web/20160201212501/coding.debuntu.org/c-implementing-str_replace-replace-all-occurrences-substring>
|
||||
* https://github.com/irl/la-cucina/blob/master/str_replace.c
|
||||
*/
|
||||
|
||||
|
||||
int str_destructively_omit_from(char* input, const char* from){
|
||||
// input = "https://url.com/?utm=blah", from = "?utm"
|
||||
int l1 = strlen(input);
|
||||
int l2 = strlen(from);
|
||||
|
||||
for(int i=0; i<l1; i++){
|
||||
if((i + l2) > l1) { // no more room
|
||||
continue;
|
||||
}
|
||||
for(int j=0; j<l2; j++){
|
||||
if(input[i+j] != from[j]){
|
||||
goto cont;
|
||||
}
|
||||
}
|
||||
input[i]='\0';
|
||||
printf("Replaced utm %s\n", input);
|
||||
return 1;
|
||||
cont:;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -2,3 +2,4 @@
|
|||
|
||||
void str_init(char* str, int n);
|
||||
int str_replace_start(const char* string, const char* target, const char* replacement, char* output);
|
||||
int str_destructively_omit_from(const char* input, const char* from);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#define STYLE_N 9331 + 1000
|
||||
#define STYLE_N 9379 + 1000
|
||||
|
||||
void read_style_js(char* string)
|
||||
{
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#pragma once
|
||||
|
||||
#define STYLE_N 9331 + 1000
|
||||
#define STYLE_N 9379 + 1000
|
||||
|
||||
void read_style_js(char* string);
|
||||
|
|
Loading…
Reference in New Issue
Block a user