remove strcmp and fix hidden bugs
This commit is contained in:
4
Makefile
4
Makefile
@ -11,8 +11,8 @@ libstrops.a : strops.o
|
||||
ar cr libstrops.a strops.o
|
||||
|
||||
strops.o : strops.c
|
||||
# gcc -c -fPIC -ansi -ggdb -o strops.o strops.c
|
||||
gcc -c -ansi -O2 -pipe -o strops.o strops.c
|
||||
# gcc -c -ansi -fPIC -ggdb -o strops.o strops.c
|
||||
gcc -c -ansi -fpic -O2 -pipe -o strops.o strops.c
|
||||
|
||||
.PHONY : install uninstall
|
||||
|
||||
|
7
strops.c
7
strops.c
@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user