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;