From fe1fdbaf24ac0e4e18527e0bdfd2f2e1b217dc1b Mon Sep 17 00:00:00 2001 From: Daniel-Constantin Mierla Date: Tue, 6 Sep 2016 12:49:16 +0200 Subject: [PATCH] core: macro helper to trim zeros from str value --- trim.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/trim.h b/trim.h index 4989075a735..baee6a0fb82 100644 --- a/trim.h +++ b/trim.h @@ -105,5 +105,19 @@ static inline void trim(str* _s) for(;(_s_).s[0]==' ';(_s_).s=(_s_).s+1,(_s_).len--); \ \ } while(0); - + +/* + * right and left zero trimming + * + * WARNING: String structure will be modified ! + * Make a copy otherwise you might be + * unable to free _s_->s for example ! + */ +#define trim_zeros_lr(_s_) \ + do{ \ + for(;(_s_)->s[(_s_)->len-1]=='\0';(_s_)->s[--(_s_)->len]=0); \ + for(;(_s_)->s[0]=='\0';(_s_)->s=(_s_)->s+1,(_s_)->len--); \ + \ + } while(0); + #endif /* TRIM_H */