tweak: conciseness tweaks.

This commit is contained in:
NunoSempere 2022-12-13 20:18:23 +00:00
parent 304b4b274c
commit 76ab73e38c
4 changed files with 15 additions and 12 deletions

Binary file not shown.

View File

@ -5,19 +5,15 @@
int main(){
char uri[] = "https://reddit.com/r/blah";
int uri_length = strlen(uri);
int l = LIBRE_N+uri_length;
char uri_filtered[l++];
for(int i=0; i<l; i++){
uri_filtered[i] = ' ';
}
uri_filtered[l] = '\0';
int l = LIBRE_N + strlen(uri) + 1;
char uri_filtered[l];
str_init(uri_filtered, l);
int libre_check = libre_redirect(uri, uri_filtered);
if(!libre_check){
printf("Filtered url: %s", uri_filtered);
printf("Filtered url: %s\n", uri_filtered);
}else{
printf("Uri: %s", uri);
printf("Uri: %s\n", uri);
// failure; do something with the original uri.
}
}

View File

@ -6,6 +6,13 @@
// int str_replace_start(const char* string, const char* target, const char* replacement, char* output){
void str_init(char* str, int n){
for(int i=0; i<n; i++){
str[i] = ' ';
}
str[n] = '\0';
} // could also use <https://manpages.ubuntu.com/manpages/impish/man3/strinit.3pub.html>
int libre_redirect(const char* uri, char* output){
/* inv.riverside.rocks */
// max length
@ -16,7 +23,7 @@ int libre_redirect(const char* uri, char* output){
return 1; // not enough memory.
}else{
char tmp_uri[l2++];
strcpy(tmp_uri, uri);
strcpy(tmp_uri, uri); // includes terminating '\0'
char* sites[] = {
"https://youtube.com",
@ -39,7 +46,6 @@ int libre_redirect(const char* uri, char* output){
strcpy(tmp_uri, output);
}
strcpy(output, tmp_uri);
}
return 0;

View File

@ -4,5 +4,6 @@
#define LIBRE_N 12
int libre_redirect(const char* uri, char* uri_filtered);
void str_init(char* str, int n);
#endif