remove url stuff
I recommend using libcurl or similar for that
This commit is contained in:
44
strops.c
44
strops.c
@ -359,47 +359,3 @@ ull_t strops_word_count(const char* string) {
|
||||
return word_count;
|
||||
}
|
||||
|
||||
/* TODO: verify that this is correct */
|
||||
int strops_is_url_encoded(const char* string) {
|
||||
if (strops_contains_char(string, '%')) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
char* strops_url_encode(const char* string) {
|
||||
if (strops_is_url_encoded(string)) { return 0; }
|
||||
/* multiplied by 3, because example: ( => %28. Three times the chars */
|
||||
char* result = strops_copy(string);
|
||||
char* unsafe_chars = "()";
|
||||
char replacement[4];
|
||||
replacement[0] = '%';
|
||||
replacement[3] = '\0';
|
||||
|
||||
ull_t i, j;
|
||||
for (i = 0; i < strops_length(unsafe_chars); i++) {
|
||||
j = 0;
|
||||
while (strops_contains_char(result, unsafe_chars[i])) {
|
||||
if (result[j] == unsafe_chars[i]) {
|
||||
char bad = result[j];
|
||||
sprintf(replacement + 1, "%02X", bad);
|
||||
result = strops_remove_at_pos_char(result, j);
|
||||
result = strops_insert_at_pos_string(result, replacement, j);
|
||||
j += 2;
|
||||
} else {
|
||||
j += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
result = realloc(result, strops_length(result));
|
||||
return result;
|
||||
}
|
||||
|
||||
char* strops_url_decode(const char* string) {
|
||||
if (!strops_is_url_encoded(string)) { return 0; }
|
||||
char* result = strops_copy(string);
|
||||
|
||||
result = realloc(result, strops_length(result));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user