From db208bd91229a68e1604b87e1703429a74f3de13 Mon Sep 17 00:00:00 2001 From: AustrianToast Date: Mon, 2 Jun 2025 23:50:20 +0200 Subject: [PATCH] remove strcmp and fix hidden bugs --- Makefile | 4 ++-- strops.c | 7 ++----- strops.h | 2 +- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 53955ac..d153508 100644 --- a/Makefile +++ b/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 diff --git a/strops.c b/strops.c index 83f0394..266072b 100644 --- a/strops.c +++ b/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; } diff --git a/strops.h b/strops.h index 76c3c80..a3fa875 100644 --- a/strops.h +++ b/strops.h @@ -12,7 +12,7 @@ typedef unsigned long long ull_t; typedef unsigned char bool_t; -char* strops_lenght(const char* string); +ull_t strops_length(const char* string); char* strops_copy(const char* string); char* strops_copy_amount(const char* string, ull_t amount);