Compare commits
2 Commits
77ccd59ce3
...
main
Author | SHA1 | Date | |
---|---|---|---|
db208bd912
|
|||
e25b8236e4
|
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
|
||||
|
||||
|
11
strops.c
11
strops.c
@ -132,7 +132,9 @@ bool_t strops_equals(const char* string1, const char* string2) {
|
||||
}
|
||||
|
||||
bool_t strops_starts_with(const char* string1, const char* string2) {
|
||||
assert(strops_length(string1) >= strops_length(string2) && "string2 cannot be longer than string1");
|
||||
if (strops_length(string1) < strops_length(string2)) {
|
||||
return 0;
|
||||
}
|
||||
bool_t starts_with = 1;
|
||||
ull_t i;
|
||||
for (i = 0; i < strops_length(string2); i++) {
|
||||
@ -284,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);
|
||||
@ -299,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