string trimming

This commit is contained in:
iceman1001 committed 2025-06-01 14:37:55 +02:00
1 parent 9be3473864
commit 810eaeac25
2 files changed
+16

No files matched your search

+14
View File
@@ -1409,6 +1409,20 @@ void str_inverse_bin(char *buf, size_t len) {
}
}
void str_trim(char *s) {
if (s == NULL) {
return;
}
// handle empty string
if (!*s) {
return;
}
char *ptr;
for (ptr = s + strlen(s) - 1; (ptr >= s) && isspace(*ptr); --ptr);
ptr[1] = '\0';
}
/**
* Converts a hex string to component "hi2", "hi" and "lo" 32-bit integers