remove strcmp and fix hidden bugs

This commit is contained in:
2025-06-02 23:50:20 +02:00
parent e25b8236e4
commit db208bd912
3 changed files with 5 additions and 8 deletions

View File

@ -286,7 +286,7 @@ char* strops_trim_right_string(const char* string, const char* string_to_remove)
ull_t offset = strops_length(result) - strops_length(string_to_remove);
char* tmp = result + offset;
while (strcmp(tmp, string_to_remove) == 0) {
while (strops_equals(tmp, string_to_remove)) {
ull_t i;
for (i = 0; i < strops_length(string_to_remove); i++) {
strops_remove_at_pos_char_inplace(result, offset);
@ -301,16 +301,13 @@ char* strops_trim_right_string(const char* string, const char* string_to_remove)
char* strops_trim_left_string(const char* string, const char* string_to_remove) {
assert(strops_length(string) >= strops_length(string_to_remove) && "string_to_remove cannot be bigger than string");
char* result = strops_copy(string);
char* tmp = strops_copy(string_to_remove);
while (strcmp(tmp, string_to_remove) == 0) {
while (strops_first_pos_of_string(result, string_to_remove) == 0) {
ull_t i;
for (i = 0; i < strops_length(string_to_remove); i++) {
strops_remove_at_pos_char_inplace(result, 0);
}
tmp = strops_copy_amount(result, strops_length(string_to_remove));
}
free(tmp);
result = realloc(result, strops_length(result));
return result;
}