progress on implementation

This commit is contained in:
2025-05-07 19:18:14 +02:00
parent a9cb36e2f6
commit e2eaa512dd
3 changed files with 311 additions and 13 deletions

View File

@ -3,8 +3,6 @@
#include <stdlib.h>
#include <assert.h>
#include <stdio.h>
/* Function template
char* strops_(const char* string) {
char *result = malloc(strlen(string));
@ -76,3 +74,99 @@ char* strops_trim_both_whitespace(const char* string) {
result = strops_trim_left_whitespace(result);
return result;
}
char* strops_trim_right_chars(const char* string, const char* chars_to_remove) {
char *result = malloc(strlen(string));
memcpy(result, string, strlen(string));
while(strchr(chars_to_remove, result[strlen(result) - 1]) != NULL) {
result = strops_remove_at_pos(result, strlen(result) - 1);
}
result = realloc(result, strlen(result));
return result;
}
char* strops_trim_left_chars(const char* string, const char* chars_to_remove) {
char *result = malloc(strlen(string));
memcpy(result, string, strlen(string));
while(strchr(chars_to_remove, result[0]) != NULL) {
result = strops_remove_at_pos(result, 0);
}
result = realloc(result, strlen(result));
return result;
}
char* strops_trim_both_chars(const char* string, const char* chars_to_remove) {
char *result = malloc(strlen(string));
memcpy(result, string, strlen(string));
result = strops_trim_right_chars(result, chars_to_remove);
result = strops_trim_left_chars(result, chars_to_remove);
return result;
}
char* strops_trim_right_string(const char* string, const char* string_to_remove) {
char *result = malloc(strlen(string));
memcpy(result, string, strlen(string));
return result;
}
char* strops_trim_left_string(const char* string, const char* string_to_remove) {
char *result = malloc(strlen(string));
memcpy(result, string, strlen(string));
return result;
}
char* strops_trim_both_string(const char* string, const char* string_to_remove) {
char *result = malloc(strlen(string));
memcpy(result, string, strlen(string));
result = strops_trim_right_string(result, string_to_remove);
result = strops_trim_left_string(result, string_to_remove);
return result;
}
char* strops_remove_chars(const char* string, const char* chars_to_remove) {
char *result = malloc(strlen(string));
memcpy(result, string, strlen(string));
size_t i;
for (i = 0; i < strlen(chars_to_remove); i++) {
while(strchr(result, chars_to_remove[i]) != NULL) {
result = strops_remove_at_pos(result, strlen(result) - strlen(strchr(result, chars_to_remove[i])));
}
}
result = realloc(result, strlen(result));
return result;
}
char* strops_remove_string(const char* string, const char* string_to_remove) {
char *result = malloc(strlen(string));
memcpy(result, string, strlen(string));
while(strstr(result, string_to_remove) != NULL) {
size_t offset = strlen(result) - strlen(strstr(result, string_to_remove));
size_t i;
for (i = 0; i < strlen(string_to_remove); i++) {
result = strops_remove_at_pos(result, offset);
}
}
result = realloc(result, strlen(result));
return result;
}
size_t strops_word_count(const char* string) {
char *result = malloc(strlen(string));
memcpy(result, string, strlen(string));
return 0;
}
char* strops_url_encode(const char* string) {
char *result = malloc(strlen(string));
memcpy(result, string, strlen(string));
return result;
}
char* strops_url_decode(const char* string) {
char *result = malloc(strlen(string));
memcpy(result, string, strlen(string));
return result;
}