From 75c94e88d9a7e12839d343bf4c7978cb7ecf91e1 Mon Sep 17 00:00:00 2001 From: Timerix Date: Sat, 1 Nov 2025 00:15:41 +0500 Subject: [PATCH] fixed str_trim bugs --- src/string/str.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/string/str.c b/src/string/str.c index 84f74c4..26b58c9 100755 --- a/src/string/str.c +++ b/src/string/str.c @@ -134,10 +134,10 @@ str hex_to_str(Array(u8) buf, bool uppercase){ } void str_trim(str* line, bool set_zero_at_end){ - bool stop = false; // loop forward + bool stop = false; while(line->size > 0 && !stop){ - char first_char = line->data[line->size - 1]; + char first_char = line->data[0]; switch(first_char){ case '\0': case '\r': case '\n': case '\t': case ' ': @@ -149,7 +149,9 @@ void str_trim(str* line, bool set_zero_at_end){ break; } } + // loop backward + stop = false; while(line->size > 0 && !stop) { char last_char = line->data[line->size - 1]; @@ -163,6 +165,7 @@ void str_trim(str* line, bool set_zero_at_end){ break; } } + if(set_zero_at_end){ line->data[line->size] = '\0'; line->isZeroTerminated = true;