From f3eb2093a3b733abb770578f741cec570aa106d2 Mon Sep 17 00:00:00 2001 From: Johannes Lange Date: Thu, 29 Dec 2016 19:35:15 +0100 Subject: [PATCH] added strip_trailing_spaces() function that removes spaces/tabs at the end of a string --- utils.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/utils.h b/utils.h index fd78c1fb8..36afc0acc 100644 --- a/utils.h +++ b/utils.h @@ -137,6 +137,15 @@ static inline int ends_with(const char *str, const char *suffix) return strstr(str, suffix) + strlen(suffix) == str + strlen(str); } +static inline void strip_trailing_spaces(char *str) +{ + char *end = str + strlen(str); + while (end > str && is_space(*(end-1))) { + end--; + } + *end = 0; +} + static inline uint32_t hash_str(const char *s) { const unsigned char *p = (const unsigned char *)s;