Util: Add rtrim
Jeffrey Pfau jeffrey@endrift.com
Fri, 19 Aug 2016 05:06:45 -0700
3 files changed,
14 insertions(+),
0 deletions(-)
M
src/util/string.c
→
src/util/string.c
@@ -340,3 +340,14 @@ value |= nybble;
*out = value; return line; } + +void rtrim(char* string) { + if (!*string) { + return; + } + char* end = string + strlen(string) - 1; + while (isspace((int) *end) && end >= string) { + *end = '\0'; + --end; + } +}
M
src/util/string.h
→
src/util/string.h
@@ -33,4 +33,6 @@ const char* hex12(const char* line, uint16_t* out);
const char* hex8(const char* line, uint8_t* out); const char* hex4(const char* line, uint8_t* out); +void rtrim(char* string); + #endif