new strops_copy_amount

This commit is contained in:
2025-05-21 17:54:43 +02:00
parent 9610831c9e
commit 7e26a39ec6

View File

@ -39,6 +39,25 @@ char* strops_copy(const char* string) {
for(i = 0; i < length; i++) {
result[i] = string[i];
}
result[i] = '\0';
return result;
}
char* strops_copy_amount(const char* string, ull_t amount) {
if (!string) {
return 0;
}
if (amount > strops_length(string)) {
return 0;
}
char* result = malloc(amount);
ull_t i;
for(i = 0; i < amount; i++) {
result[i] = string[i];
}
result[i] = '\0';
return result;
}
@ -234,7 +253,7 @@ char* strops_trim_left_string(const char* string, const char* string_to_remove)
for (i = 0; i < strops_length(string_to_remove); i++) {
result = strops_remove_at_pos_char(result, 0);
}
memcpy(tmp, result, strops_length(string_to_remove));
tmp = strops_copy_amount(result, strops_length(string_to_remove));
}
free(tmp);
result = realloc(result, strops_length(result));